Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1071 lines
29 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. Name.c
  5. Abstract:
  6. The unicode name support package is for manipulating unicode strings
  7. The routines allow the caller to dissect and compare strings.
  8. This package uses the same FSRTL_COMPARISON_RESULT typedef used by name.c
  9. The following routines are provided by this package:
  10. o FsRtlDissectName - This routine takes a path name string and breaks
  11. into two parts. The first name in the string and the remainder.
  12. It also checks that the first name is valid for an NT file.
  13. o FsRtlColateNames - This routine is used to colate directories
  14. according to lexical ordering. Lexical ordering is strict unicode
  15. numerical oerdering.
  16. o FsRtlDoesNameContainsWildCards - This routine tells the caller if
  17. a string contains any wildcard characters.
  18. o FsRtlIsNameInExpression - This routine is used to compare a string
  19. against a template (possibly containing wildcards) to sees if the
  20. string is in the language denoted by the template.
  21. Author:
  22. Gary Kimura [GaryKi] 5-Feb-1990
  23. Revision History:
  24. --*/
  25. #include "FsRtlP.h"
  26. //
  27. // Trace level for the module
  28. //
  29. #define Dbg (0x10000000)
  30. //
  31. // Some special debugging stuff
  32. //
  33. #if DBG
  34. extern ULONG DaveDebug;
  35. #define DavePrint if (DaveDebug) DbgPrint
  36. #else
  37. #define DavePrint NOTHING
  38. #endif
  39. //
  40. // Define a tag for general pool allocations from this module
  41. //
  42. #undef MODULE_POOL_TAG
  43. #define MODULE_POOL_TAG ('nrSF')
  44. //
  45. // Local support routine prototypes
  46. //
  47. BOOLEAN
  48. FsRtlIsNameInExpressionPrivate (
  49. IN PUNICODE_STRING Expression,
  50. IN PUNICODE_STRING Name,
  51. IN BOOLEAN IgnoreCase,
  52. IN PWCH UpcaseTable
  53. );
  54. #ifdef ALLOC_PRAGMA
  55. #pragma alloc_text(PAGE, FsRtlAreNamesEqual)
  56. #pragma alloc_text(PAGE, FsRtlDissectName)
  57. #pragma alloc_text(PAGE, FsRtlDoesNameContainWildCards)
  58. #pragma alloc_text(PAGE, FsRtlIsNameInExpression)
  59. #pragma alloc_text(PAGE, FsRtlIsNameInExpressionPrivate)
  60. #endif
  61. VOID
  62. FsRtlDissectName (
  63. IN UNICODE_STRING Path,
  64. OUT PUNICODE_STRING FirstName,
  65. OUT PUNICODE_STRING RemainingName
  66. )
  67. /*++
  68. Routine Description:
  69. This routine cracks a path. It picks off the first element in the
  70. given path name and provides both it and the remaining part. A path
  71. is a set of file names separated by backslashes. If a name begins
  72. with a backslash, the FirstName is the string immediately following
  73. the backslash. Here are some examples:
  74. Path FirstName RemainingName
  75. ---- --------- -------------
  76. empty empty empty
  77. \ empty empty
  78. A A empty
  79. \A A empty
  80. A\B\C\D\E A B\C\D\E
  81. *A? *A? empty
  82. Note that both output strings use the same string buffer memory of the
  83. input string, and are not necessarily null terminated.
  84. Also, this routine makes no judgement as to the legality of each
  85. file name componant. This must be done separatly when each file name
  86. is extracted.
  87. Arguments:
  88. Path - The full path name to crack.
  89. FirstName - The first name in the path. Don't allocate a buffer for
  90. this string.
  91. RemainingName - The rest of the path. Don't allocate a buffer for this
  92. string.
  93. Return Value:
  94. None.
  95. --*/
  96. {
  97. ULONG i = 0;
  98. ULONG PathLength;
  99. ULONG FirstNameStart;
  100. PAGED_CODE();
  101. //
  102. // Make both output strings empty for now
  103. //
  104. FirstName->Length = 0;
  105. FirstName->MaximumLength = 0;
  106. FirstName->Buffer = NULL;
  107. RemainingName->Length = 0;
  108. RemainingName->MaximumLength = 0;
  109. RemainingName->Buffer = NULL;
  110. PathLength = Path.Length / sizeof(WCHAR);
  111. //
  112. // Check for an empty input string
  113. //
  114. if (PathLength == 0) {
  115. return;
  116. }
  117. //
  118. // Skip over a starting backslash, and make sure there is more.
  119. //
  120. if ( Path.Buffer[0] == L'\\' ) {
  121. i = 1;
  122. }
  123. //
  124. // Now run down the input string until we hit a backslash or the end
  125. // of the string, remembering where we started;
  126. //
  127. for ( FirstNameStart = i;
  128. (i < PathLength) && (Path.Buffer[i] != L'\\');
  129. i += 1 ) {
  130. NOTHING;
  131. }
  132. //
  133. // At this point all characters up to (but not including) i are
  134. // in the first part. So setup the first name
  135. //
  136. FirstName->Length = (USHORT)((i - FirstNameStart) * sizeof(WCHAR));
  137. FirstName->MaximumLength = FirstName->Length;
  138. FirstName->Buffer = &Path.Buffer[FirstNameStart];
  139. //
  140. // Now the remaining part needs a string only if the first part didn't
  141. // exhaust the entire input string. We know that if anything is left
  142. // that is must start with a backslash. Note that if there is only
  143. // a trailing backslash, the length will get correctly set to zero.
  144. //
  145. if (i < PathLength) {
  146. RemainingName->Length = (USHORT)((PathLength - (i + 1)) * sizeof(WCHAR));
  147. RemainingName->MaximumLength = RemainingName->Length;
  148. RemainingName->Buffer = &Path.Buffer[i + 1];
  149. }
  150. //
  151. // And return to our caller
  152. //
  153. return;
  154. }
  155. BOOLEAN
  156. FsRtlDoesNameContainWildCards (
  157. IN PUNICODE_STRING Name
  158. )
  159. /*++
  160. Routine Description:
  161. This routine simply scans the input Name string looking for any Nt
  162. wild card characters.
  163. Arguments:
  164. Name - The string to check.
  165. Return Value:
  166. BOOLEAN - TRUE if one or more wild card characters was found.
  167. --*/
  168. {
  169. PUSHORT p;
  170. PAGED_CODE();
  171. //
  172. // Check each character in the name to see if it's a wildcard
  173. // character.
  174. //
  175. if( Name->Length ) {
  176. for( p = Name->Buffer + (Name->Length / sizeof(WCHAR)) - 1;
  177. p >= Name->Buffer && *p != L'\\' ;
  178. p-- ) {
  179. //
  180. // check for a wild card character
  181. //
  182. if (FsRtlIsUnicodeCharacterWild( *p )) {
  183. //
  184. // Tell caller that this name contains wild cards
  185. //
  186. return TRUE;
  187. }
  188. }
  189. }
  190. //
  191. // No wildcard characters were found, so return to our caller
  192. //
  193. return FALSE;
  194. }
  195. BOOLEAN
  196. FsRtlAreNamesEqual (
  197. PCUNICODE_STRING ConstantNameA,
  198. PCUNICODE_STRING ConstantNameB,
  199. IN BOOLEAN IgnoreCase,
  200. IN PCWCH UpcaseTable OPTIONAL
  201. )
  202. /*++
  203. Routine Description:
  204. This routine simple returns whether the two names are exactly equal.
  205. If the two names are known to be constant, this routine is much
  206. faster than FsRtlIsNameInExpression.
  207. Arguments:
  208. ConstantNameA - Constant name.
  209. ConstantNameB - Constant name.
  210. IgnoreCase - TRUE if the Names should be Upcased before comparing.
  211. UpcaseTable - If supplied, use this table for case insensitive compares,
  212. otherwise, use the default system upcase table.
  213. Return Value:
  214. BOOLEAN - TRUE if the two names are lexically equal.
  215. --*/
  216. {
  217. ULONG Index;
  218. ULONG NameLength;
  219. BOOLEAN FreeStrings = FALSE;
  220. UNICODE_STRING LocalNameA;
  221. UNICODE_STRING LocalNameB;
  222. PAGED_CODE();
  223. //
  224. // If the names aren't even the same size, then return FALSE right away.
  225. //
  226. if ( ConstantNameA->Length != ConstantNameB->Length ) {
  227. return FALSE;
  228. }
  229. NameLength = ConstantNameA->Length / sizeof(WCHAR);
  230. //
  231. // If we weren't given an upcase table, we have to upcase the names
  232. // ourselves.
  233. //
  234. if ( IgnoreCase && !ARGUMENT_PRESENT(UpcaseTable) ) {
  235. NTSTATUS Status;
  236. Status = RtlUpcaseUnicodeString( &LocalNameA, ConstantNameA, TRUE );
  237. if ( !NT_SUCCESS(Status) ) {
  238. ExRaiseStatus( Status );
  239. }
  240. Status = RtlUpcaseUnicodeString( &LocalNameB, ConstantNameB, TRUE );
  241. if ( !NT_SUCCESS(Status) ) {
  242. RtlFreeUnicodeString( &LocalNameA );
  243. ExRaiseStatus( Status );
  244. }
  245. ConstantNameA = &LocalNameA;
  246. ConstantNameB = &LocalNameB;
  247. IgnoreCase = FALSE;
  248. FreeStrings = TRUE;
  249. }
  250. //
  251. // Do either case sensitive or insensitive compare.
  252. //
  253. if ( !IgnoreCase ) {
  254. BOOLEAN BytesEqual;
  255. BytesEqual = (BOOLEAN) RtlEqualMemory( ConstantNameA->Buffer,
  256. ConstantNameB->Buffer,
  257. ConstantNameA->Length );
  258. if ( FreeStrings ) {
  259. RtlFreeUnicodeString( &LocalNameA );
  260. RtlFreeUnicodeString( &LocalNameB );
  261. }
  262. return BytesEqual;
  263. } else {
  264. for (Index = 0; Index < NameLength; Index += 1) {
  265. if ( UpcaseTable[ConstantNameA->Buffer[Index]] !=
  266. UpcaseTable[ConstantNameB->Buffer[Index]] ) {
  267. return FALSE;
  268. }
  269. }
  270. return TRUE;
  271. }
  272. }
  273. //
  274. // The following routine is just a wrapper around
  275. // FsRtlIsNameInExpressionPrivate to make a last minute fix a bit safer.
  276. //
  277. BOOLEAN
  278. FsRtlIsNameInExpression (
  279. IN PUNICODE_STRING Expression,
  280. IN PUNICODE_STRING Name,
  281. IN BOOLEAN IgnoreCase,
  282. IN PWCH UpcaseTable OPTIONAL
  283. )
  284. {
  285. BOOLEAN Result = FALSE;
  286. UNICODE_STRING LocalName;
  287. //
  288. // If we weren't given an upcase table, we have to upcase the names
  289. // ourselves.
  290. //
  291. if ( IgnoreCase && !ARGUMENT_PRESENT(UpcaseTable) ) {
  292. NTSTATUS Status;
  293. Status = RtlUpcaseUnicodeString( &LocalName, Name, TRUE );
  294. if ( !NT_SUCCESS(Status) ) {
  295. ExRaiseStatus( Status );
  296. }
  297. Name = &LocalName;
  298. IgnoreCase = FALSE;
  299. } else {
  300. LocalName.Buffer = NULL;
  301. }
  302. //
  303. // Now call the main routine, remembering to free the upcased string
  304. // if we allocated one.
  305. //
  306. try {
  307. Result = FsRtlIsNameInExpressionPrivate( Expression,
  308. Name,
  309. IgnoreCase,
  310. UpcaseTable );
  311. } finally {
  312. if (LocalName.Buffer != NULL) {
  313. RtlFreeUnicodeString( &LocalName );
  314. }
  315. }
  316. return Result;
  317. }
  318. #define MATCHES_ARRAY_SIZE 16
  319. //
  320. // Local support routine prototypes
  321. //
  322. BOOLEAN
  323. FsRtlIsNameInExpressionPrivate (
  324. IN PUNICODE_STRING Expression,
  325. IN PUNICODE_STRING Name,
  326. IN BOOLEAN IgnoreCase,
  327. IN PWCH UpcaseTable
  328. )
  329. /*++
  330. Routine Description:
  331. This routine compares a Dbcs name and an expression and tells the caller
  332. if the name is in the language defined by the expression. The input name
  333. cannot contain wildcards, while the expression may contain wildcards.
  334. Expression wild cards are evaluated as shown in the nondeterministic
  335. finite automatons below. Note that ~* and ~? are DOS_STAR and DOS_QM.
  336. ~* is DOS_STAR, ~? is DOS_QM, and ~. is DOS_DOT
  337. S
  338. <-----<
  339. X | | e Y
  340. X * Y == (0)----->-(1)->-----(2)-----(3)
  341. S-.
  342. <-----<
  343. X | | e Y
  344. X ~* Y == (0)----->-(1)->-----(2)-----(3)
  345. X S S Y
  346. X ?? Y == (0)---(1)---(2)---(3)---(4)
  347. X . . Y
  348. X ~.~. Y == (0)---(1)----(2)------(3)---(4)
  349. | |________|
  350. | ^ |
  351. |_______________|
  352. ^EOF or .^
  353. X S-. S-. Y
  354. X ~?~? Y == (0)---(1)-----(2)-----(3)---(4)
  355. | |________|
  356. | ^ |
  357. |_______________|
  358. ^EOF or .^
  359. where S is any single character
  360. S-. is any single character except the final .
  361. e is a null character transition
  362. EOF is the end of the name string
  363. In words:
  364. * matches 0 or more characters.
  365. ? matches exactly 1 character.
  366. DOS_STAR matches 0 or more characters until encountering and matching
  367. the final . in the name.
  368. DOS_QM matches any single character, or upon encountering a period or
  369. end of name string, advances the expression to the end of the
  370. set of contiguous DOS_QMs.
  371. DOS_DOT matches either a . or zero characters beyond name string.
  372. Arguments:
  373. Expression - Supplies the input expression to check against
  374. (Caller must already upcase if passing CaseInsensitive TRUE.)
  375. Name - Supplies the input name to check for.
  376. CaseInsensitive - TRUE if Name should be Upcased before comparing.
  377. Return Value:
  378. BOOLEAN - TRUE if Name is an element in the set of strings denoted
  379. by the input Expression and FALSE otherwise.
  380. --*/
  381. {
  382. USHORT NameOffset;
  383. USHORT ExprOffset;
  384. ULONG SrcCount;
  385. ULONG DestCount;
  386. ULONG PreviousDestCount;
  387. ULONG MatchesCount;
  388. WCHAR NameChar = 0, ExprChar;
  389. USHORT LocalBuffer[MATCHES_ARRAY_SIZE * 2];
  390. USHORT *AuxBuffer = NULL;
  391. USHORT *PreviousMatches;
  392. USHORT *CurrentMatches;
  393. USHORT MaxState;
  394. USHORT CurrentState;
  395. BOOLEAN NameFinished = FALSE;
  396. //
  397. // The idea behind the algorithm is pretty simple. We keep track of
  398. // all possible locations in the regular expression that are matching
  399. // the name. If when the name has been exhausted one of the locations
  400. // in the expression is also just exhausted, the name is in the language
  401. // defined by the regular expression.
  402. //
  403. PAGED_CODE();
  404. DebugTrace(+1, Dbg, "FsRtlIsNameInExpression\n", 0);
  405. DebugTrace( 0, Dbg, " Expression = %Z\n", Expression );
  406. DebugTrace( 0, Dbg, " Name = %Z\n", Name );
  407. DebugTrace( 0, Dbg, " CaseInsensitive = %08lx\n", CaseInsensitive );
  408. //
  409. // If one string is empty return FALSE. If both are empty return TRUE.
  410. //
  411. if ( (Name->Length == 0) || (Expression->Length == 0) ) {
  412. return (BOOLEAN)(!(Name->Length + Expression->Length));
  413. }
  414. //
  415. // Special case by far the most common wild card search of *
  416. //
  417. if ((Expression->Length == 2) && (Expression->Buffer[0] == L'*')) {
  418. return TRUE;
  419. }
  420. ASSERT( !IgnoreCase || ARGUMENT_PRESENT(UpcaseTable) );
  421. //
  422. // Also special case expressions of the form *X. With this and the prior
  423. // case we have covered virtually all normal queries.
  424. //
  425. if (Expression->Buffer[0] == L'*') {
  426. UNICODE_STRING LocalExpression;
  427. LocalExpression = *Expression;
  428. LocalExpression.Buffer += 1;
  429. LocalExpression.Length -= 2;
  430. //
  431. // Only special case an expression with a single *
  432. //
  433. if ( !FsRtlDoesNameContainWildCards( &LocalExpression ) ) {
  434. ULONG StartingNameOffset;
  435. if (Name->Length < (USHORT)(Expression->Length - sizeof(WCHAR))) {
  436. return FALSE;
  437. }
  438. StartingNameOffset = ( Name->Length -
  439. LocalExpression.Length ) / sizeof(WCHAR);
  440. //
  441. // Do a simple memory compare if case sensitive, otherwise
  442. // we have got to check this one character at a time.
  443. //
  444. if ( !IgnoreCase ) {
  445. return (BOOLEAN) RtlEqualMemory( LocalExpression.Buffer,
  446. Name->Buffer + StartingNameOffset,
  447. LocalExpression.Length );
  448. } else {
  449. for ( ExprOffset = 0;
  450. ExprOffset < (USHORT)(LocalExpression.Length / sizeof(WCHAR));
  451. ExprOffset += 1 ) {
  452. NameChar = Name->Buffer[StartingNameOffset + ExprOffset];
  453. NameChar = UpcaseTable[NameChar];
  454. ExprChar = LocalExpression.Buffer[ExprOffset];
  455. ASSERT( ExprChar == UpcaseTable[ExprChar] );
  456. if ( NameChar != ExprChar ) {
  457. return FALSE;
  458. }
  459. }
  460. return TRUE;
  461. }
  462. }
  463. }
  464. //
  465. // Walk through the name string, picking off characters. We go one
  466. // character beyond the end because some wild cards are able to match
  467. // zero characters beyond the end of the string.
  468. //
  469. // With each new name character we determine a new set of states that
  470. // match the name so far. We use two arrays that we swap back and forth
  471. // for this purpose. One array lists the possible expression states for
  472. // all name characters up to but not including the current one, and other
  473. // array is used to build up the list of states considering the current
  474. // name character as well. The arrays are then switched and the process
  475. // repeated.
  476. //
  477. // There is not a one-to-one correspondence between state number and
  478. // offset into the expression. This is evident from the NFAs in the
  479. // initial comment to this function. State numbering is not continuous.
  480. // This allows a simple conversion between state number and expression
  481. // offset. Each character in the expression can represent one or two
  482. // states. * and DOS_STAR generate two states: ExprOffset*2 and
  483. // ExprOffset*2 + 1. All other expreesion characters can produce only
  484. // a single state. Thus ExprOffset = State/2.
  485. //
  486. //
  487. // Here is a short description of the variables involved:
  488. //
  489. // NameOffset - The offset of the current name char being processed.
  490. //
  491. // ExprOffset - The offset of the current expression char being processed.
  492. //
  493. // SrcCount - Prior match being investigated with current name char
  494. //
  495. // DestCount - Next location to put a matching assuming current name char
  496. //
  497. // NameFinished - Allows one more itteration through the Matches array
  498. // after the name is exhusted (to come *s for example)
  499. //
  500. // PreviousDestCount - This is used to prevent entry duplication, see coment
  501. //
  502. // PreviousMatches - Holds the previous set of matches (the Src array)
  503. //
  504. // CurrentMatches - Holds the current set of matches (the Dest array)
  505. //
  506. // AuxBuffer, LocalBuffer - the storage for the Matches arrays
  507. //
  508. //
  509. // Set up the initial variables
  510. //
  511. PreviousMatches = &LocalBuffer[0];
  512. CurrentMatches = &LocalBuffer[MATCHES_ARRAY_SIZE];
  513. PreviousMatches[0] = 0;
  514. MatchesCount = 1;
  515. NameOffset = 0;
  516. MaxState = (USHORT)(Expression->Length * 2);
  517. while ( !NameFinished ) {
  518. if ( NameOffset < Name->Length ) {
  519. NameChar = Name->Buffer[NameOffset / sizeof(WCHAR)];
  520. NameOffset += sizeof(WCHAR);;
  521. } else {
  522. NameFinished = TRUE;
  523. //
  524. // if we have already exhasted the expression, cool. Don't
  525. // continue.
  526. //
  527. if ( PreviousMatches[MatchesCount-1] == MaxState ) {
  528. break;
  529. }
  530. }
  531. //
  532. // Now, for each of the previous stored expression matches, see what
  533. // we can do with this name character.
  534. //
  535. SrcCount = 0;
  536. DestCount = 0;
  537. PreviousDestCount = 0;
  538. while ( SrcCount < MatchesCount ) {
  539. USHORT Length;
  540. //
  541. // We have to carry on our expression analysis as far as possible
  542. // for each character of name, so we loop here until the
  543. // expression stops matching. A clue here is that expression
  544. // cases that can match zero or more characters end with a
  545. // continue, while those that can accept only a single character
  546. // end with a break.
  547. //
  548. ExprOffset = (USHORT)((PreviousMatches[SrcCount++] + 1) / 2);
  549. Length = 0;
  550. while ( TRUE ) {
  551. if ( ExprOffset == Expression->Length ) {
  552. break;
  553. }
  554. //
  555. // The first time through the loop we don't want
  556. // to increment ExprOffset.
  557. //
  558. ExprOffset = (USHORT)(ExprOffset + Length);
  559. Length = sizeof(WCHAR);
  560. CurrentState = (USHORT)(ExprOffset * 2);
  561. if ( ExprOffset == Expression->Length ) {
  562. CurrentMatches[DestCount++] = MaxState;
  563. break;
  564. }
  565. ExprChar = Expression->Buffer[ExprOffset / sizeof(WCHAR)];
  566. ASSERT( !IgnoreCase || !((ExprChar >= L'a') && (ExprChar <= L'z')) );
  567. //
  568. // Before we get started, we have to check for something
  569. // really gross. We may be about to exhaust the local
  570. // space for ExpressionMatches[][], so we have to allocate
  571. // some pool if this is the case. Yuk!
  572. //
  573. if ( (DestCount >= MATCHES_ARRAY_SIZE - 2) &&
  574. (AuxBuffer == NULL) ) {
  575. ULONG ExpressionChars;
  576. ExpressionChars = Expression->Length / sizeof(WCHAR);
  577. AuxBuffer = FsRtlpAllocatePool( PagedPool,
  578. (ExpressionChars+1) *
  579. sizeof(USHORT)*2*2 );
  580. RtlCopyMemory( AuxBuffer,
  581. CurrentMatches,
  582. MATCHES_ARRAY_SIZE * sizeof(USHORT) );
  583. CurrentMatches = AuxBuffer;
  584. RtlCopyMemory( AuxBuffer + (ExpressionChars+1)*2,
  585. PreviousMatches,
  586. MATCHES_ARRAY_SIZE * sizeof(USHORT) );
  587. PreviousMatches = AuxBuffer + (ExpressionChars+1)*2;
  588. }
  589. //
  590. // * matches any character zero or more times.
  591. //
  592. if (ExprChar == L'*') {
  593. CurrentMatches[DestCount++] = CurrentState;
  594. CurrentMatches[DestCount++] = CurrentState + 3;
  595. continue;
  596. }
  597. //
  598. // DOS_STAR matches any character except . zero or more times.
  599. //
  600. if (ExprChar == DOS_STAR) {
  601. BOOLEAN ICanEatADot = FALSE;
  602. //
  603. // If we are at a period, determine if we are allowed to
  604. // consume it, ie. make sure it is not the last one.
  605. //
  606. if ( !NameFinished && (NameChar == '.') ) {
  607. USHORT Offset;
  608. for ( Offset = NameOffset;
  609. Offset < Name->Length;
  610. Offset = (USHORT)(Offset + Length) ) {
  611. if (Name->Buffer[Offset / sizeof(WCHAR)] == L'.') {
  612. ICanEatADot = TRUE;
  613. break;
  614. }
  615. }
  616. }
  617. if (NameFinished || (NameChar != L'.') || ICanEatADot) {
  618. CurrentMatches[DestCount++] = CurrentState;
  619. CurrentMatches[DestCount++] = CurrentState + 3;
  620. continue;
  621. } else {
  622. //
  623. // We are at a period. We can only match zero
  624. // characters (ie. the epsilon transition).
  625. //
  626. CurrentMatches[DestCount++] = CurrentState + 3;
  627. continue;
  628. }
  629. }
  630. //
  631. // The following expreesion characters all match by consuming
  632. // a character, thus force the expression, and thus state
  633. // forward.
  634. //
  635. CurrentState += (USHORT)(sizeof(WCHAR) * 2);
  636. //
  637. // DOS_QM is the most complicated. If the name is finished,
  638. // we can match zero characters. If this name is a '.', we
  639. // don't match, but look at the next expression. Otherwise
  640. // we match a single character.
  641. //
  642. if ( ExprChar == DOS_QM ) {
  643. if ( NameFinished || (NameChar == L'.') ) {
  644. continue;
  645. }
  646. CurrentMatches[DestCount++] = CurrentState;
  647. break;
  648. }
  649. //
  650. // A DOS_DOT can match either a period, or zero characters
  651. // beyond the end of name.
  652. //
  653. if (ExprChar == DOS_DOT) {
  654. if ( NameFinished ) {
  655. continue;
  656. }
  657. if (NameChar == L'.') {
  658. CurrentMatches[DestCount++] = CurrentState;
  659. break;
  660. }
  661. }
  662. //
  663. // From this point on a name character is required to even
  664. // continue, let alone make a match.
  665. //
  666. if ( NameFinished ) {
  667. break;
  668. }
  669. //
  670. // If this expression was a '?' we can match it once.
  671. //
  672. if (ExprChar == L'?') {
  673. CurrentMatches[DestCount++] = CurrentState;
  674. break;
  675. }
  676. //
  677. // Finally, check if the expression char matches the name char
  678. //
  679. if (ExprChar == (WCHAR)(IgnoreCase ?
  680. UpcaseTable[NameChar] : NameChar)) {
  681. CurrentMatches[DestCount++] = CurrentState;
  682. break;
  683. }
  684. //
  685. // The expression didn't match so go look at the next
  686. // previous match.
  687. //
  688. break;
  689. }
  690. //
  691. // Prevent duplication in the destination array.
  692. //
  693. // Each of the arrays is montonically increasing and non-
  694. // duplicating, thus we skip over any source element in the src
  695. // array if we just added the same element to the destination
  696. // array. This guarentees non-duplication in the dest. array.
  697. //
  698. while ((SrcCount < MatchesCount) &&
  699. (PreviousDestCount < DestCount)) {
  700. while ((SrcCount < MatchesCount) &&
  701. (PreviousMatches[SrcCount] <
  702. CurrentMatches[PreviousDestCount])) {
  703. SrcCount += 1;
  704. }
  705. PreviousDestCount += 1;
  706. }
  707. }
  708. //
  709. // If we found no matches in the just finished itteration, it's time
  710. // to bail.
  711. //
  712. if ( DestCount == 0 ) {
  713. if (AuxBuffer != NULL) { ExFreePool( AuxBuffer ); }
  714. return FALSE;
  715. }
  716. //
  717. // Swap the meaning the two arrays
  718. //
  719. {
  720. USHORT *Tmp;
  721. Tmp = PreviousMatches;
  722. PreviousMatches = CurrentMatches;
  723. CurrentMatches = Tmp;
  724. }
  725. MatchesCount = DestCount;
  726. }
  727. CurrentState = PreviousMatches[MatchesCount-1];
  728. if (AuxBuffer != NULL) { ExFreePool( AuxBuffer ); }
  729. return (BOOLEAN)(CurrentState == MaxState);
  730. }
  731.