ReactOS 0.4.15-dev-5666-gc548b97
name.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for name.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN NTAPI FsRtlIsNameInExpressionPrivate (IN PUNICODE_STRING Expression, IN PUNICODE_STRING Name, IN BOOLEAN IgnoreCase, IN PWCHAR UpcaseTable OPTIONAL)
 
BOOLEAN NTAPI FsRtlAreNamesEqual (IN PCUNICODE_STRING Name1, IN PCUNICODE_STRING Name2, IN BOOLEAN IgnoreCase, IN PCWCH UpcaseTable OPTIONAL)
 
VOID NTAPI FsRtlDissectName (IN UNICODE_STRING Name, OUT PUNICODE_STRING FirstPart, OUT PUNICODE_STRING RemainingPart)
 
BOOLEAN NTAPI FsRtlDoesNameContainWildCards (IN PUNICODE_STRING Name)
 
BOOLEAN NTAPI FsRtlIsNameInExpression (IN PUNICODE_STRING Expression, IN PUNICODE_STRING Name, IN BOOLEAN IgnoreCase, IN PWCHAR UpcaseTable OPTIONAL)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file name.c.

Function Documentation

◆ FsRtlAreNamesEqual()

BOOLEAN NTAPI FsRtlAreNamesEqual ( IN PCUNICODE_STRING  Name1,
IN PCUNICODE_STRING  Name2,
IN BOOLEAN  IgnoreCase,
IN PCWCH UpcaseTable  OPTIONAL 
)

Definition at line 296 of file name.c.

300{
301 UNICODE_STRING UpcaseName1;
302 UNICODE_STRING UpcaseName2;
303 BOOLEAN StringsAreEqual, MemoryAllocated = FALSE;
304 USHORT i;
306 PAGED_CODE();
307
308 /* Well, first check their size */
309 if (Name1->Length != Name2->Length) return FALSE;
310
311 /* Check if the caller didn't give an upcase table */
312 if ((IgnoreCase) && !(UpcaseTable))
313 {
314 /* Upcase the string ourselves */
315 Status = RtlUpcaseUnicodeString(&UpcaseName1, Name1, TRUE);
317
318 /* Upcase the second string too */
319 Status = RtlUpcaseUnicodeString(&UpcaseName2, Name2, TRUE);
320 if (!NT_SUCCESS(Status))
321 {
322 RtlFreeUnicodeString(&UpcaseName1);
324 }
325
326 Name1 = &UpcaseName1;
327 Name2 = &UpcaseName2;
328
329 /* Make sure we go through the path below, but free the strings */
332 }
333
334 /* Do a case-sensitive search */
335 if (!IgnoreCase)
336 {
337 /* Use a raw memory compare */
338 StringsAreEqual = RtlEqualMemory(Name1->Buffer,
339 Name2->Buffer,
340 Name1->Length);
341
342 /* Check if we allocated strings */
343 if (MemoryAllocated)
344 {
345 /* Free them */
346 RtlFreeUnicodeString(&UpcaseName1);
347 RtlFreeUnicodeString(&UpcaseName2);
348 }
349
350 /* Return the equality */
351 return StringsAreEqual;
352 }
353 else
354 {
355 /* Case in-sensitive search */
356 for (i = 0; i < Name1->Length / sizeof(WCHAR); i++)
357 {
358 /* Check if the character matches */
359 if (UpcaseTable[Name1->Buffer[i]] != UpcaseTable[Name2->Buffer[i]])
360 {
361 /* Non-match found! */
362 return FALSE;
363 }
364 }
365
366 /* We finished the loop so we are equal */
367 return TRUE;
368 }
369}
#define PAGED_CODE()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define IgnoreCase
Definition: cdprocs.h:461
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
_Must_inspect_result_ _In_ PCUNICODE_STRING Name2
Definition: fsrtlfuncs.h:796
_Must_inspect_result_ _In_ PUNICODE_STRING _In_ BOOLEAN _In_opt_ PWCHAR UpcaseTable
Definition: fsrtlfuncs.h:809
Status
Definition: gdiplustypes.h:25
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
#define RtlEqualMemory(a, b, c)
Definition: kdvm.h:18
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
unsigned short USHORT
Definition: pedump.c:61
_Out_ PSECURITY_DESCRIPTOR _Out_ PBOOLEAN MemoryAllocated
Definition: obfuncs.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by Ext2SetLinkInfo(), Ext2SetRenameInfo(), FatSetRenameInfo(), file_create(), FindFile(), registry_load_volume_options(), registry_mark_volume_unmounted_path(), and VfatSetRenameInformation().

◆ FsRtlDissectName()

VOID NTAPI FsRtlDissectName ( IN UNICODE_STRING  Name,
OUT PUNICODE_STRING  FirstPart,
OUT PUNICODE_STRING  RemainingPart 
)

Definition at line 398 of file name.c.

401{
402 USHORT FirstPosition, i;
403 USHORT SkipFirstSlash = 0;
404 PAGED_CODE();
405
406 /* Zero the strings before continuing */
409
410 /* Just quit if the string is empty */
411 if (!Name.Length) return;
412
413 /* Find first backslash */
414 FirstPosition = Name.Length / sizeof(WCHAR) ;
415 for (i = 0; i < Name.Length / sizeof(WCHAR); i++)
416 {
417 /* If we found one... */
418 if (Name.Buffer[i] == L'\\')
419 {
420 /* If it begins string, just notice it and continue */
421 if (i == 0)
422 {
423 SkipFirstSlash = 1;
424 }
425 else
426 {
427 /* Else, save its position and break out of the loop */
428 FirstPosition = i;
429 break;
430 }
431 }
432 }
433
434 /* Set up the first result string */
435 FirstPart->Buffer = Name.Buffer + SkipFirstSlash;
436 FirstPart->Length = (FirstPosition - SkipFirstSlash) * sizeof(WCHAR);
438
439 /* And second one, if necessary */
440 if (FirstPosition < (Name.Length / sizeof(WCHAR)))
441 {
442 RemainingPart->Buffer = Name.Buffer + FirstPosition + 1;
443 RemainingPart->Length = Name.Length - (FirstPosition + 1) * sizeof(WCHAR);
445 }
446}
_Out_ PANSI_STRING _Out_ PANSI_STRING RemainingPart
Definition: fsrtlfuncs.h:379
_Out_ PANSI_STRING FirstPart
Definition: fsrtlfuncs.h:378
#define L(x)
Definition: ntvdm.h:50
USHORT MaximumLength
Definition: env_spec_w32.h:377
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by AddFileName(), Ext2CreateFile(), NtfsLookupFileAt(), and START_TEST().

◆ FsRtlDoesNameContainWildCards()

BOOLEAN NTAPI FsRtlDoesNameContainWildCards ( IN PUNICODE_STRING  Name)

Definition at line 464 of file name.c.

465{
466 PWCHAR Ptr;
467 PAGED_CODE();
468
469 /* Loop through every character */
470 if (Name->Length)
471 {
472 Ptr = Name->Buffer + (Name->Length / sizeof(WCHAR)) - 1;
473 while ((Ptr >= Name->Buffer) && (*Ptr != L'\\'))
474 {
475 /* Check for Wildcard */
477 Ptr--;
478 }
479 }
480
481 /* Nothing Found */
482 return FALSE;
483}
#define FsRtlIsUnicodeCharacterWild(C)
Definition: fsrtlfuncs.h:1636
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by CdInitializeEnumeration(), Ext2CreateFile(), Ext2FillEntry(), Ext2QueryDirectory(), Ext2SetLinkInfo(), Ext2SetRenameInfo(), FindFile(), FsRtlIsNameInExpressionPrivate(), query_directory(), RxCanonicalizeNameAndObtainNetRoot(), RxQueryDirectory(), and UDFQueryDirectory().

◆ FsRtlIsNameInExpression()

BOOLEAN NTAPI FsRtlIsNameInExpression ( IN PUNICODE_STRING  Expression,
IN PUNICODE_STRING  Name,
IN BOOLEAN  IgnoreCase,
IN PWCHAR UpcaseTable  OPTIONAL 
)

Definition at line 514 of file name.c.

518{
521 UNICODE_STRING IntName;
522
523 if (IgnoreCase && !UpcaseTable)
524 {
526 if (!NT_SUCCESS(Status))
527 {
529 }
530 Name = &IntName;
532 }
533 else
534 {
535 IntName.Buffer = NULL;
536 }
537
539
540 if (IntName.Buffer != NULL)
541 {
542 RtlFreeUnicodeString(&IntName);
543 }
544
545 return Result;
546}
PCWSTR Expression
#define NULL
Definition: types.h:112
BOOLEAN NTAPI FsRtlIsNameInExpressionPrivate(IN PUNICODE_STRING Expression, IN PUNICODE_STRING Name, IN BOOLEAN IgnoreCase, IN PWCHAR UpcaseTable OPTIONAL)
Definition: name.c:21
#define ExRaiseStatus
Definition: ntoskrnl.h:108
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426

Referenced by CdIsNameInExpression(), CompareFileName(), Ext2FillEntry(), Ext2QueryDirectory(), FindFile(), FsRtlIsNameInExpressionTest(), query_directory(), UDFIsNameInExpression(), vfatAttachFCBToFileObject(), vfatDestroyFCB(), vfatFCBInitializeCacheFromVolume(), vfatGrabFCB(), and vfatReleaseFCB().

◆ FsRtlIsNameInExpressionPrivate()

BOOLEAN NTAPI FsRtlIsNameInExpressionPrivate ( IN PUNICODE_STRING  Expression,
IN PUNICODE_STRING  Name,
IN BOOLEAN  IgnoreCase,
IN PWCHAR UpcaseTable  OPTIONAL 
)

Definition at line 21 of file name.c.

25{
26 USHORT Offset, Position, BackTrackingPosition, OldBackTrackingPosition;
27 USHORT BackTrackingBuffer[16], OldBackTrackingBuffer[16] = {0};
28 PUSHORT BackTrackingSwap, BackTracking = BackTrackingBuffer, OldBackTracking = OldBackTrackingBuffer;
29 ULONG BackTrackingBufferSize = RTL_NUMBER_OF(BackTrackingBuffer);
30 PVOID AllocatedBuffer = NULL;
31 UNICODE_STRING IntExpression;
32 USHORT ExpressionPosition, NamePosition = 0, MatchingChars = 1;
33 BOOLEAN EndOfName = FALSE;
35 BOOLEAN DontSkipDot;
36 WCHAR CompareChar;
37 PAGED_CODE();
38
39 /* Check if we were given strings at all */
40 if (!Name->Length || !Expression->Length)
41 {
42 /* Return TRUE if both strings are empty, otherwise FALSE */
43 if (!Name->Length && !Expression->Length)
44 return TRUE;
45 else
46 return FALSE;
47 }
48
49 /* Check for a shortcut: just one wildcard */
50 if (Expression->Length == sizeof(WCHAR))
51 {
52 if (Expression->Buffer[0] == L'*')
53 return TRUE;
54 }
55
57
58 /* Another shortcut, wildcard followed by some string */
59 if (Expression->Buffer[0] == L'*')
60 {
61 /* Copy Expression to our local variable */
62 IntExpression = *Expression;
63
64 /* Skip the first char */
65 IntExpression.Buffer++;
66 IntExpression.Length -= sizeof(WCHAR);
67
68 /* Continue only if the rest of the expression does NOT contain
69 any more wildcards */
70 if (!FsRtlDoesNameContainWildCards(&IntExpression))
71 {
72 /* Check for a degenerate case */
73 if (Name->Length < (Expression->Length - sizeof(WCHAR)))
74 return FALSE;
75
76 /* Calculate position */
77 NamePosition = (Name->Length - IntExpression.Length) / sizeof(WCHAR);
78
79 /* Compare */
80 if (!IgnoreCase)
81 {
82 /* We can just do a byte compare */
83 return RtlEqualMemory(IntExpression.Buffer,
84 Name->Buffer + NamePosition,
85 IntExpression.Length);
86 }
87 else
88 {
89 /* Not so easy, need to upcase and check char by char */
90 for (ExpressionPosition = 0; ExpressionPosition < (IntExpression.Length / sizeof(WCHAR)); ExpressionPosition++)
91 {
92 /* Assert that expression is already upcased! */
93 ASSERT(IntExpression.Buffer[ExpressionPosition] == UpcaseTable[IntExpression.Buffer[ExpressionPosition]]);
94
95 /* Now compare upcased name char with expression */
96 if (UpcaseTable[Name->Buffer[NamePosition + ExpressionPosition]] !=
97 IntExpression.Buffer[ExpressionPosition])
98 {
99 return FALSE;
100 }
101 }
102
103 /* It matches */
104 return TRUE;
105 }
106 }
107 }
108
109 /* Name parsing loop */
110 for (; !EndOfName; MatchingChars = BackTrackingPosition, NamePosition++)
111 {
112 /* Reset positions */
113 OldBackTrackingPosition = BackTrackingPosition = 0;
114
115 if (NamePosition >= Name->Length / sizeof(WCHAR))
116 {
117 EndOfName = TRUE;
118 if (MatchingChars && (OldBackTracking[MatchingChars - 1] == Expression->Length * 2))
119 break;
120 }
121
122 while (MatchingChars > OldBackTrackingPosition)
123 {
124 ExpressionPosition = (OldBackTracking[OldBackTrackingPosition++] + 1) / 2;
125
126 /* Expression parsing loop */
127 for (Offset = 0; ExpressionPosition < Expression->Length; Offset = sizeof(WCHAR))
128 {
129 ExpressionPosition += Offset;
130
131 if (ExpressionPosition == Expression->Length)
132 {
133 BackTracking[BackTrackingPosition++] = Expression->Length * 2;
134 break;
135 }
136
137 /* If buffer too small */
138 if (BackTrackingPosition > BackTrackingBufferSize - 3)
139 {
140 /* We should only ever get here once! */
141 ASSERT(AllocatedBuffer == NULL);
142 ASSERT((BackTracking == BackTrackingBuffer) || (BackTracking == OldBackTrackingBuffer));
143 ASSERT((OldBackTracking == BackTrackingBuffer) || (OldBackTracking == OldBackTrackingBuffer));
144
145 /* Calculate buffer size */
146 BackTrackingBufferSize = Expression->Length / sizeof(WCHAR) * 2 + 1;
147
148 /* Allocate memory for both back-tracking buffers */
150 2 * BackTrackingBufferSize * sizeof(USHORT),
151 'nrSF');
152 if (AllocatedBuffer == NULL)
153 {
154 DPRINT1("Failed to allocate BackTracking buffer. BackTrackingBufferSize = =x%lx\n",
155 BackTrackingBufferSize);
156 Result = FALSE;
157 goto Exit;
158 }
159
160 /* Copy BackTracking content. Note that it can point to either BackTrackingBuffer or OldBackTrackingBuffer */
161 RtlCopyMemory(AllocatedBuffer,
162 BackTracking,
163 RTL_NUMBER_OF(BackTrackingBuffer) * sizeof(USHORT));
164
165 /* Place current Backtracking is at the start of the new buffer */
166 BackTracking = AllocatedBuffer;
167
168 /* Copy OldBackTracking content */
169 RtlCopyMemory(&BackTracking[BackTrackingBufferSize],
170 OldBackTracking,
171 RTL_NUMBER_OF(OldBackTrackingBuffer) * sizeof(USHORT));
172
173 /* Place current OldBackTracking after current BackTracking in the buffer */
174 OldBackTracking = &BackTracking[BackTrackingBufferSize];
175 }
176
177 /* Basic check to test if chars are equal */
178 CompareChar = (NamePosition >= Name->Length / sizeof(WCHAR)) ? UNICODE_NULL : (IgnoreCase ? UpcaseTable[Name->Buffer[NamePosition]] :
179 Name->Buffer[NamePosition]);
180 if (Expression->Buffer[ExpressionPosition / sizeof(WCHAR)] == CompareChar && !EndOfName)
181 {
182 BackTracking[BackTrackingPosition++] = (ExpressionPosition + sizeof(WCHAR)) * 2;
183 }
184 /* Check cases that eat one char */
185 else if (Expression->Buffer[ExpressionPosition / sizeof(WCHAR)] == L'?' && !EndOfName)
186 {
187 BackTracking[BackTrackingPosition++] = (ExpressionPosition + sizeof(WCHAR)) * 2;
188 }
189 /* Test star */
190 else if (Expression->Buffer[ExpressionPosition / sizeof(WCHAR)] == L'*')
191 {
192 BackTracking[BackTrackingPosition++] = ExpressionPosition * 2;
193 BackTracking[BackTrackingPosition++] = (ExpressionPosition * 2) + 3;
194 continue;
195 }
196 /* Check DOS_STAR */
197 else if (Expression->Buffer[ExpressionPosition / sizeof(WCHAR)] == DOS_STAR)
198 {
199 /* Look for last dot */
200 DontSkipDot = TRUE;
201 if (!EndOfName && Name->Buffer[NamePosition] == '.')
202 {
203 for (Position = NamePosition + 1; Position < Name->Length / sizeof(WCHAR); Position++)
204 {
205 if (Name->Buffer[Position] == L'.')
206 {
207 DontSkipDot = FALSE;
208 break;
209 }
210 }
211 }
212
213 if (EndOfName || Name->Buffer[NamePosition] != L'.' || !DontSkipDot)
214 BackTracking[BackTrackingPosition++] = ExpressionPosition * 2;
215
216 BackTracking[BackTrackingPosition++] = (ExpressionPosition * 2) + 3;
217 continue;
218 }
219 /* Check DOS_DOT */
220 else if (Expression->Buffer[ExpressionPosition / sizeof(WCHAR)] == DOS_DOT)
221 {
222 if (EndOfName) continue;
223
224 if (Name->Buffer[NamePosition] == L'.')
225 BackTracking[BackTrackingPosition++] = (ExpressionPosition + sizeof(WCHAR)) * 2;
226 }
227 /* Check DOS_QM */
228 else if (Expression->Buffer[ExpressionPosition / sizeof(WCHAR)] == DOS_QM)
229 {
230 if (EndOfName || Name->Buffer[NamePosition] == L'.') continue;
231
232 BackTracking[BackTrackingPosition++] = (ExpressionPosition + sizeof(WCHAR)) * 2;
233 }
234
235 /* Leave from loop */
236 break;
237 }
238
239 for (Position = 0; MatchingChars > OldBackTrackingPosition && Position < BackTrackingPosition; Position++)
240 {
241 while (MatchingChars > OldBackTrackingPosition &&
242 BackTracking[Position] > OldBackTracking[OldBackTrackingPosition])
243 {
244 ++OldBackTrackingPosition;
245 }
246 }
247 }
248
249 /* Swap pointers */
250 BackTrackingSwap = BackTracking;
251 BackTracking = OldBackTracking;
252 OldBackTracking = BackTrackingSwap;
253 }
254
255 /* Store result value */
256 Result = MatchingChars > 0 && (OldBackTracking[MatchingChars - 1] == (Expression->Length * 2));
257
258Exit:
259
260 /* Frees the memory if necessary */
261 if (AllocatedBuffer != NULL)
262 {
263 ExFreePoolWithTag(AllocatedBuffer, 'nrSF');
264 }
265
266 return Result;
267}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define DPRINT1
Definition: precomp.h:8
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define DOS_STAR
Definition: env_spec_w32.h:912
#define DOS_QM
Definition: env_spec_w32.h:913
#define DOS_DOT
Definition: env_spec_w32.h:914
#define PagedPool
Definition: env_spec_w32.h:308
unsigned short * PUSHORT
Definition: retypes.h:2
unsigned int ULONG
Definition: retypes.h:1
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define UNICODE_NULL
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
BOOLEAN NTAPI FsRtlDoesNameContainWildCards(IN PUNICODE_STRING Name)
Definition: name.c:464
static void Exit(void)
Definition: sock.c:1330
static COORD Position
Definition: mouse.c:34
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define POOL_RAISE_IF_ALLOCATION_FAILURE

Referenced by FsRtlIsNameInExpression().