ReactOS 0.4.15-dev-8058-ga7cbb60
names.c
Go to the documentation of this file.
1/*
2 * DNS support
3 *
4 * Copyright (C) 2006 Matthew Kehrer
5 * Copyright (C) 2006 Hans Leidekker
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22#include "precomp.h"
23
24#define NDEBUG
25#include <debug.h>
26
27/******************************************************************************
28 * DnsNameCompare_A [DNSAPI.@]
29 *
30 */
32{
33 BOOL ret;
34 PWSTR name1W, name2W;
35
36 name1W = dns_strdup_aw( name1 );
37 name2W = dns_strdup_aw( name2 );
38
39 ret = DnsNameCompare_W( name1W, name2W );
40
41 HeapFree(GetProcessHeap(), 0, name1W );
42 HeapFree(GetProcessHeap(), 0, name2W );
43
44 return ret;
45}
46
47/******************************************************************************
48 * DnsNameCompare_W [DNSAPI.@]
49 *
50 */
52{
53 PCWSTR p, q;
54
55 if (!name1 && !name2) return TRUE;
56 if (!name1 || !name2) return FALSE;
57
58 p = name1 + lstrlenW( name1 ) - 1;
59 q = name2 + lstrlenW( name2 ) - 1;
60
61 while (*p == '.' && p >= name1) p--;
62 while (*q == '.' && q >= name2) q--;
63
64 if (p - name1 != q - name2) return FALSE;
65
66 while (name1 <= p)
67 {
68 if (towupper( *name1 ) != towupper( *name2 ))
69 return FALSE;
70
71 name1++;
72 name2++;
73 }
74 return TRUE;
75}
76
77/******************************************************************************
78 * DnsValidateName_A [DNSAPI.@]
79 *
80 */
82{
84 DNS_STATUS ret;
85
88
90 return ret;
91}
92
93/******************************************************************************
94 * DnsValidateName_UTF8 [DNSAPI.@]
95 *
96 */
98{
100 DNS_STATUS ret;
101
104
106 return ret;
107}
108
109#define HAS_EXTENDED 0x0001
110#define HAS_NUMERIC 0x0002
111#define HAS_NON_NUMERIC 0x0004
112#define HAS_DOT 0x0008
113#define HAS_DOT_DOT 0x0010
114#define HAS_SPACE 0x0020
115#define HAS_INVALID 0x0040
116#define HAS_ASTERISK 0x0080
117#define HAS_UNDERSCORE 0x0100
118#define HAS_LONG_LABEL 0x0200
119
120/******************************************************************************
121 * DnsValidateName_W [DNSAPI.@]
122 *
123 */
125{
126 PCWSTR p;
127 unsigned int i, j, state = 0;
128 static const WCHAR invalid[] = {
129 '{','|','}','~','[','\\',']','^','\'',':',';','<','=','>',
130 '?','@','!','\"','#','$','%','^','`','(',')','+','/',',',0 };
131
132 if (!name) return ERROR_INVALID_NAME;
133
134 for (p = name, i = 0, j = 0; *p; p++, i++, j++)
135 {
136 if (*p == '.')
137 {
138 j = 0;
139 state |= HAS_DOT;
140 if (p[1] == '.') state |= HAS_DOT_DOT;
141 }
142 else if (*p < '0' || *p > '9') state |= HAS_NON_NUMERIC;
143 else state |= HAS_NUMERIC;
144
145 if (j > 62) state |= HAS_LONG_LABEL;
146
147 if (wcschr( invalid, *p )) state |= HAS_INVALID;
148 else if ((unsigned)*p > 127) state |= HAS_EXTENDED;
149 else if (*p == ' ') state |= HAS_SPACE;
150 else if (*p == '_') state |= HAS_UNDERSCORE;
151 else if (*p == '*') state |= HAS_ASTERISK;
152 }
153
154 if (i == 0 || i > 255 ||
155 (state & HAS_LONG_LABEL) ||
156 (state & HAS_DOT_DOT) ||
157 (name[0] == '.' && name[1])) return ERROR_INVALID_NAME;
158
159 switch (format)
160 {
161 case DnsNameDomain:
162 {
163 if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
165 if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
167 if ((state & HAS_SPACE) ||
168 (state & HAS_INVALID) ||
170 break;
171 }
173 {
174 if (state & HAS_DOT) return ERROR_INVALID_NAME;
175 if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
177 if ((state & HAS_SPACE) ||
178 (state & HAS_INVALID) ||
180 break;
181 }
183 {
184 if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
186 if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
188 if ((state & HAS_SPACE) ||
189 (state & HAS_INVALID) ||
191 break;
192 }
194 {
195 if (state & HAS_DOT) return ERROR_INVALID_NAME;
196 if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
198 if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
200 if ((state & HAS_SPACE) ||
201 (state & HAS_INVALID) ||
203 break;
204 }
205 case DnsNameWildcard:
206 {
207 if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
208 return ERROR_INVALID_NAME;
209 if (name[0] != '*') return ERROR_INVALID_NAME;
210 if (name[1] && name[1] != '.')
212 if ((state & HAS_EXTENDED) ||
213 (state & HAS_SPACE) ||
215 break;
216 }
217 case DnsNameSrvRecord:
218 {
219 if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
220 return ERROR_INVALID_NAME;
221 if (name[0] != '_') return ERROR_INVALID_NAME;
222 if ((state & HAS_UNDERSCORE) && !name[1])
224 if ((state & HAS_EXTENDED) ||
225 (state & HAS_SPACE) ||
227 break;
228 }
229 default:
230 DPRINT1( "unknown format: %d\n", format );
231 break;
232 }
233 return ERROR_SUCCESS;
234}
static int state
Definition: maze.c:121
static const WCHAR nameW[]
Definition: main.c:46
#define DPRINT1
Definition: precomp.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
#define ERROR_INVALID_NAME
Definition: compat.h:103
#define lstrlenW
Definition: compat.h:750
static LPWSTR dns_strdup_aw(LPCSTR str)
Definition: precomp.h:49
static LPWSTR dns_strdup_uw(const char *str)
Definition: precomp.h:37
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static WCHAR name1[]
Definition: record.c:34
static WCHAR name2[]
Definition: record.c:35
static const WCHAR invalid[]
Definition: assoc.c:39
#define HAS_INVALID
Definition: names.c:115
DNS_STATUS WINAPI DnsValidateName_UTF8(PCSTR name, DNS_NAME_FORMAT format)
Definition: names.c:97
DNS_STATUS WINAPI DnsValidateName_W(PCWSTR name, DNS_NAME_FORMAT format)
Definition: names.c:124
#define HAS_DOT_DOT
Definition: names.c:113
#define HAS_LONG_LABEL
Definition: names.c:118
#define HAS_UNDERSCORE
Definition: names.c:117
BOOL WINAPI DnsNameCompare_A(LPCSTR name1, LPCSTR name2)
Definition: names.c:31
#define HAS_EXTENDED
Definition: names.c:109
DNS_STATUS WINAPI DnsValidateName_A(PCSTR name, DNS_NAME_FORMAT format)
Definition: names.c:81
#define HAS_SPACE
Definition: names.c:114
#define HAS_NON_NUMERIC
Definition: names.c:111
#define HAS_ASTERISK
Definition: names.c:116
#define HAS_DOT
Definition: names.c:112
#define HAS_NUMERIC
Definition: names.c:110
BOOL WINAPI DnsNameCompare_W(PCWSTR name1, PCWSTR name2)
Definition: names.c:51
Definition: name.c:39
#define towupper(c)
Definition: wctype.h:99
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
const char * PCSTR
Definition: typedefs.h:52
int ret
@ DnsNameSrvRecord
Definition: windns.h:149
@ DnsNameHostnameLabel
Definition: windns.h:147
@ DnsNameDomainLabel
Definition: windns.h:145
@ DnsNameDomain
Definition: windns.h:144
@ DnsNameHostnameFull
Definition: windns.h:146
@ DnsNameWildcard
Definition: windns.h:148
enum _DNS_NAME_FORMAT DNS_NAME_FORMAT
#define WINAPI
Definition: msvc.h:6
#define DNS_ERROR_NUMERIC_NAME
Definition: winerror.h:1878
#define DNS_ERROR_NON_RFC_NAME
Definition: winerror.h:1872
#define DNS_ERROR_INVALID_NAME_CHAR
Definition: winerror.h:1877
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180