00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
#include "FsRtlP.h"
00042
00043
00044
00045
00046
00047 #define Dbg (0x10000000)
00048
00049
00050
00051
00052
00053
#if DBG
00054
00055
extern ULONG DaveDebug;
00056
#define DavePrint if (DaveDebug) DbgPrint
00057
00058
#else
00059
00060 #define DavePrint NOTHING
00061
00062
#endif
00063
00064
00065
00066
00067
00068
#undef MODULE_POOL_TAG
00069 #define MODULE_POOL_TAG ('nrSF')
00070
00071
00072
00073
00074
00075 BOOLEAN
00076
FsRtlIsNameInExpressionPrivate (
00077 IN PUNICODE_STRING Expression,
00078 IN PUNICODE_STRING Name,
00079 IN BOOLEAN IgnoreCase,
00080 IN PWCH UpcaseTable
00081 );
00082
00083
#ifdef ALLOC_PRAGMA
00084
#pragma alloc_text(PAGE, FsRtlAreNamesEqual)
00085
#pragma alloc_text(PAGE, FsRtlDissectName)
00086
#pragma alloc_text(PAGE, FsRtlDoesNameContainWildCards)
00087
#pragma alloc_text(PAGE, FsRtlIsNameInExpression)
00088
#pragma alloc_text(PAGE, FsRtlIsNameInExpressionPrivate)
00089
#endif
00090
00091
00092
VOID
00093 FsRtlDissectName (
00094 IN UNICODE_STRING Path,
00095 OUT PUNICODE_STRING FirstName,
00096 OUT PUNICODE_STRING RemainingName
00097 )
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 {
00148 ULONG i = 0;
00149 ULONG PathLength;
00150 ULONG FirstNameStart;
00151
00152
PAGED_CODE();
00153
00154
00155
00156
00157
00158 FirstName->Length = 0;
00159 FirstName->MaximumLength = 0;
00160 FirstName->Buffer =
NULL;
00161
00162 RemainingName->Length = 0;
00163 RemainingName->MaximumLength = 0;
00164 RemainingName->Buffer =
NULL;
00165
00166 PathLength = Path.Length /
sizeof(WCHAR);
00167
00168
00169
00170
00171
00172
if (PathLength == 0) {
00173
00174
return;
00175 }
00176
00177
00178
00179
00180
00181
if ( Path.Buffer[0] ==
L'\\' ) {
00182
00183 i = 1;
00184 }
00185
00186
00187
00188
00189
00190
00191
for ( FirstNameStart = i;
00192 (i < PathLength) && (Path.Buffer[i] !=
L'\\');
00193 i += 1 ) {
00194
00195 NOTHING;
00196 }
00197
00198
00199
00200
00201
00202
00203 FirstName->Length = (
USHORT)((i - FirstNameStart) *
sizeof(WCHAR));
00204 FirstName->MaximumLength = FirstName->Length;
00205 FirstName->Buffer = &Path.Buffer[FirstNameStart];
00206
00207
00208
00209
00210
00211
00212
00213
00214
if (i < PathLength) {
00215
00216 RemainingName->Length = (
USHORT)((PathLength - (i + 1)) *
sizeof(WCHAR));
00217 RemainingName->MaximumLength = RemainingName->Length;
00218 RemainingName->Buffer = &Path.Buffer[i + 1];
00219 }
00220
00221
00222
00223
00224
00225
return;
00226 }
00227
00228 BOOLEAN
00229 FsRtlDoesNameContainWildCards (
00230 IN PUNICODE_STRING Name
00231 )
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 {
00250
PUSHORT p;
00251
00252
PAGED_CODE();
00253
00254
00255
00256
00257
00258
00259
if(
Name->Length ) {
00260
for( p =
Name->Buffer + (
Name->Length /
sizeof(WCHAR)) - 1;
00261 p >=
Name->Buffer && *p !=
L'\\' ;
00262 p-- ) {
00263
00264
00265
00266
00267
00268
if (
FsRtlIsUnicodeCharacterWild( *p )) {
00269
00270
00271
00272
00273
00274
return TRUE;
00275 }
00276 }
00277 }
00278
00279
00280
00281
00282
00283
return FALSE;
00284 }
00285
00286
00287 BOOLEAN
00288 FsRtlAreNamesEqual (
00289 PCUNICODE_STRING ConstantNameA,
00290 PCUNICODE_STRING ConstantNameB,
00291 IN BOOLEAN IgnoreCase,
00292 IN PCWCH UpcaseTable OPTIONAL
00293 )
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 {
00321 ULONG
Index;
00322 ULONG NameLength;
00323 BOOLEAN FreeStrings =
FALSE;
00324
00325 UNICODE_STRING LocalNameA;
00326 UNICODE_STRING LocalNameB;
00327
00328
PAGED_CODE();
00329
00330
00331
00332
00333
00334
if ( ConstantNameA->Length != ConstantNameB->Length ) {
00335
00336
return FALSE;
00337 }
00338
00339 NameLength = ConstantNameA->Length /
sizeof(WCHAR);
00340
00341
00342
00343
00344
00345
00346
if ( IgnoreCase && !ARGUMENT_PRESENT(UpcaseTable) ) {
00347
00348
NTSTATUS Status;
00349
00350
Status =
RtlUpcaseUnicodeString( &LocalNameA, ConstantNameA,
TRUE );
00351
00352
if ( !
NT_SUCCESS(
Status) ) {
00353
00354
ExRaiseStatus(
Status );
00355 }
00356
00357
Status =
RtlUpcaseUnicodeString( &LocalNameB, ConstantNameB,
TRUE );
00358
00359
if ( !
NT_SUCCESS(
Status) ) {
00360
00361
RtlFreeUnicodeString( &LocalNameA );
00362
00363
ExRaiseStatus(
Status );
00364 }
00365
00366 ConstantNameA = &LocalNameA;
00367 ConstantNameB = &LocalNameB;
00368
00369 IgnoreCase =
FALSE;
00370 FreeStrings =
TRUE;
00371 }
00372
00373
00374
00375
00376
00377
if ( !IgnoreCase ) {
00378
00379 BOOLEAN BytesEqual;
00380
00381 BytesEqual = (BOOLEAN) RtlEqualMemory( ConstantNameA->Buffer,
00382 ConstantNameB->Buffer,
00383 ConstantNameA->Length );
00384
00385
if ( FreeStrings ) {
00386
00387
RtlFreeUnicodeString( &LocalNameA );
00388
RtlFreeUnicodeString( &LocalNameB );
00389 }
00390
00391
return BytesEqual;
00392
00393 }
else {
00394
00395
for (
Index = 0;
Index < NameLength;
Index += 1) {
00396
00397
if ( UpcaseTable[ConstantNameA->Buffer[
Index]] !=
00398 UpcaseTable[ConstantNameB->Buffer[
Index]] ) {
00399
00400
return FALSE;
00401 }
00402 }
00403
00404
return TRUE;
00405 }
00406 }
00407
00408
00409
00410
00411
00412
00413
00414 BOOLEAN
00415 FsRtlIsNameInExpression (
00416 IN PUNICODE_STRING Expression,
00417 IN PUNICODE_STRING Name,
00418 IN BOOLEAN IgnoreCase,
00419 IN PWCH UpcaseTable OPTIONAL
00420 )
00421
00422 {
00423 BOOLEAN Result;
00424 UNICODE_STRING LocalName;
00425
00426
00427
00428
00429
00430
00431
if ( IgnoreCase && !ARGUMENT_PRESENT(UpcaseTable) ) {
00432
00433
NTSTATUS Status;
00434
00435
Status =
RtlUpcaseUnicodeString( &LocalName,
Name,
TRUE );
00436
00437
if ( !
NT_SUCCESS(
Status) ) {
00438
00439
ExRaiseStatus(
Status );
00440 }
00441
00442
Name = &LocalName;
00443
00444 IgnoreCase =
FALSE;
00445
00446 }
else {
00447
00448 LocalName.Buffer =
NULL;
00449 }
00450
00451
00452
00453
00454
00455
00456
try {
00457
00458 Result =
FsRtlIsNameInExpressionPrivate( Expression,
00459
Name,
00460 IgnoreCase,
00461 UpcaseTable );
00462
00463 } finally {
00464
00465
if (LocalName.Buffer !=
NULL) {
00466
00467
RtlFreeUnicodeString( &LocalName );
00468 }
00469 }
00470
00471
return Result;
00472 }
00473
00474
00475 #define MATCHES_ARRAY_SIZE 16
00476
00477
00478
00479
00480
00481 BOOLEAN
00482 FsRtlIsNameInExpressionPrivate (
00483 IN PUNICODE_STRING Expression,
00484 IN PUNICODE_STRING Name,
00485 IN BOOLEAN IgnoreCase,
00486 IN PWCH UpcaseTable
00487 )
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578 {
00579
USHORT NameOffset;
00580
USHORT ExprOffset;
00581
00582 ULONG SrcCount;
00583 ULONG DestCount;
00584 ULONG PreviousDestCount;
00585 ULONG MatchesCount;
00586
00587 WCHAR NameChar, ExprChar;
00588
00589
USHORT LocalBuffer[
MATCHES_ARRAY_SIZE * 2];
00590
00591
USHORT *AuxBuffer =
NULL;
00592
USHORT *PreviousMatches;
00593
USHORT *CurrentMatches;
00594
00595
USHORT MaxState;
00596
USHORT CurrentState;
00597
00598 BOOLEAN NameFinished =
FALSE;
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
PAGED_CODE();
00609
00610
DebugTrace(+1,
Dbg,
"FsRtlIsNameInExpression\n", 0);
00611
DebugTrace( 0,
Dbg,
" Expression = %Z\n", Expression );
00612
DebugTrace( 0,
Dbg,
" Name = %Z\n",
Name );
00613
DebugTrace( 0,
Dbg,
" CaseInsensitive = %08lx\n", CaseInsensitive );
00614
00615
ASSERT(
Name->Length != 0 );
00616
ASSERT( Expression->Length != 0 );
00617
00618
00619
00620
00621
00622
if ( (
Name->Length == 0) || (Expression->Length == 0) ) {
00623
00624
return (BOOLEAN)(!(
Name->Length + Expression->Length));
00625 }
00626
00627
00628
00629
00630
00631
if ((Expression->Length == 2) && (Expression->Buffer[0] ==
L'*')) {
00632
00633
return TRUE;
00634 }
00635
00636
ASSERT(
FsRtlDoesNameContainWildCards( Expression ) );
00637
00638
ASSERT( !IgnoreCase || ARGUMENT_PRESENT(UpcaseTable) );
00639
00640
00641
00642
00643
00644
00645
if (Expression->Buffer[0] ==
L'*') {
00646
00647 UNICODE_STRING LocalExpression;
00648
00649 LocalExpression = *Expression;
00650
00651 LocalExpression.Buffer += 1;
00652 LocalExpression.Length -= 2;
00653
00654
00655
00656
00657
00658
if ( !
FsRtlDoesNameContainWildCards( &LocalExpression ) ) {
00659
00660 ULONG StartingNameOffset;
00661
00662
if (
Name->Length < (
USHORT)(Expression->Length -
sizeof(WCHAR))) {
00663
00664
return FALSE;
00665 }
00666
00667 StartingNameOffset = (
Name->Length -
00668 LocalExpression.Length ) /
sizeof(WCHAR);
00669
00670
00671
00672
00673
00674
00675
if ( !IgnoreCase ) {
00676
00677
return (BOOLEAN) RtlEqualMemory( LocalExpression.Buffer,
00678
Name->Buffer + StartingNameOffset,
00679 LocalExpression.Length );
00680
00681 }
else {
00682
00683
for ( ExprOffset = 0;
00684 ExprOffset < (
USHORT)(LocalExpression.Length /
sizeof(WCHAR));
00685 ExprOffset += 1 ) {
00686
00687 NameChar =
Name->Buffer[StartingNameOffset + ExprOffset];
00688 NameChar = UpcaseTable[NameChar];
00689
00690 ExprChar = LocalExpression.Buffer[ExprOffset];
00691
00692
ASSERT( ExprChar == UpcaseTable[ExprChar] );
00693
00694
if ( NameChar != ExprChar ) {
00695
00696
return FALSE;
00697 }
00698 }
00699
00700
return TRUE;
00701 }
00702 }
00703 }
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754 PreviousMatches = &LocalBuffer[0];
00755 CurrentMatches = &LocalBuffer[
MATCHES_ARRAY_SIZE];
00756
00757 PreviousMatches[0] = 0;
00758 MatchesCount = 1;
00759
00760 NameOffset = 0;
00761
00762 MaxState = (
USHORT)(Expression->Length * 2);
00763
00764
while ( !NameFinished ) {
00765
00766
if ( NameOffset <
Name->Length ) {
00767
00768 NameChar =
Name->Buffer[NameOffset /
sizeof(WCHAR)];
00769
00770 NameOffset +=
sizeof(WCHAR);;
00771
00772 }
else {
00773
00774 NameFinished =
TRUE;
00775
00776
00777
00778
00779
00780
00781
if ( PreviousMatches[MatchesCount-1] == MaxState ) {
00782
00783
break;
00784 }
00785 }
00786
00787
00788
00789
00790
00791
00792
00793 SrcCount = 0;
00794 DestCount = 0;
00795 PreviousDestCount = 0;
00796
00797
while ( SrcCount < MatchesCount ) {
00798
00799
USHORT Length;
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810 ExprOffset = (
USHORT)((PreviousMatches[SrcCount++] + 1) / 2);
00811
00812
00813 Length = 0;
00814
00815
while (
TRUE ) {
00816
00817
if ( ExprOffset == Expression->Length ) {
00818
00819
break;
00820 }
00821
00822
00823
00824
00825
00826
00827 ExprOffset += Length;
00828 Length =
sizeof(WCHAR);
00829
00830 CurrentState = (
USHORT)(ExprOffset * 2);
00831
00832
if ( ExprOffset == Expression->Length ) {
00833
00834 CurrentMatches[DestCount++] = MaxState;
00835
break;
00836 }
00837
00838 ExprChar = Expression->Buffer[ExprOffset /
sizeof(WCHAR)];
00839
00840
ASSERT( !IgnoreCase || !((ExprChar >=
L'a') && (ExprChar <=
L'z')) );
00841
00842
00843
00844
00845
00846
00847
00848
00849
if ( (DestCount >=
MATCHES_ARRAY_SIZE - 2) &&
00850 (AuxBuffer ==
NULL) ) {
00851
00852 ULONG ExpressionChars;
00853
00854 ExpressionChars = Expression->Length /
sizeof(WCHAR);
00855
00856 AuxBuffer =
FsRtlpAllocatePool(
PagedPool,
00857 (ExpressionChars+1) *
00858
sizeof(
USHORT)*2*2 );
00859
00860 RtlCopyMemory( AuxBuffer,
00861 CurrentMatches,
00862
MATCHES_ARRAY_SIZE *
sizeof(
USHORT) );
00863
00864 CurrentMatches = AuxBuffer;
00865
00866 RtlCopyMemory( AuxBuffer + (ExpressionChars+1)*2,
00867 PreviousMatches,
00868
MATCHES_ARRAY_SIZE *
sizeof(
USHORT) );
00869
00870 PreviousMatches = AuxBuffer + (ExpressionChars+1)*2;
00871 }
00872
00873
00874
00875
00876
00877
if (ExprChar ==
L'*') {
00878
00879 CurrentMatches[DestCount++] = CurrentState;
00880 CurrentMatches[DestCount++] = CurrentState + 3;
00881
continue;
00882 }
00883
00884
00885
00886
00887
00888
if (ExprChar == DOS_STAR) {
00889
00890 BOOLEAN ICanEatADot =
FALSE;
00891
00892
00893
00894
00895
00896
00897
if ( !NameFinished && (NameChar ==
'.') ) {
00898
00899
USHORT Offset;
00900
00901
for (
Offset = NameOffset;
00902
Offset <
Name->Length;
00903
Offset += Length ) {
00904
00905
if (
Name->Buffer[
Offset /
sizeof(WCHAR)] ==
L'.') {
00906
00907 ICanEatADot =
TRUE;
00908
break;
00909 }
00910 }
00911 }
00912
00913
if (NameFinished || (NameChar !=
L'.') || ICanEatADot) {
00914
00915 CurrentMatches[DestCount++] = CurrentState;
00916 CurrentMatches[DestCount++] = CurrentState + 3;
00917
continue;
00918
00919 }
else {
00920
00921
00922
00923
00924
00925
00926 CurrentMatches[DestCount++] = CurrentState + 3;
00927
continue;
00928 }
00929 }
00930
00931
00932
00933
00934
00935
00936
00937 CurrentState += (
USHORT)(
sizeof(WCHAR) * 2);
00938
00939
00940
00941
00942
00943
00944
00945
00946
if ( ExprChar == DOS_QM ) {
00947
00948
if ( NameFinished || (NameChar ==
L'.') ) {
00949
00950
continue;
00951 }
00952
00953 CurrentMatches[DestCount++] = CurrentState;
00954
break;
00955 }
00956
00957
00958
00959
00960
00961
00962
if (ExprChar == DOS_DOT) {
00963
00964
if ( NameFinished ) {
00965
00966
continue;
00967 }
00968
00969
if (NameChar ==
L'.') {
00970
00971 CurrentMatches[DestCount++] = CurrentState;
00972
break;
00973 }
00974 }
00975
00976
00977
00978
00979
00980
00981
if ( NameFinished ) {
00982
00983
break;
00984 }
00985
00986
00987
00988
00989
00990
if (ExprChar ==
L'?') {
00991
00992 CurrentMatches[DestCount++] = CurrentState;
00993
break;
00994 }
00995
00996
00997
00998
00999
01000
if (ExprChar == (WCHAR)(IgnoreCase ?
01001 UpcaseTable[NameChar] : NameChar)) {
01002
01003 CurrentMatches[DestCount++] = CurrentState;
01004
break;
01005 }
01006
01007
01008
01009
01010
01011
01012
break;
01013 }
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
if ((SrcCount < MatchesCount) &&
01026 (PreviousDestCount < DestCount) ) {
01027
01028
while (PreviousDestCount < DestCount) {
01029
01030
while ( PreviousMatches[SrcCount] <
01031 CurrentMatches[PreviousDestCount] ) {
01032
01033 SrcCount += 1;
01034 }
01035
01036 PreviousDestCount += 1;
01037 }
01038 }
01039 }
01040
01041
01042
01043
01044
01045
01046
if ( DestCount == 0 ) {
01047
01048
if (AuxBuffer !=
NULL) {
ExFreePool( AuxBuffer ); }
01049
01050
return FALSE;
01051 }
01052
01053
01054
01055
01056
01057 {
01058
USHORT *Tmp;
01059
01060 Tmp = PreviousMatches;
01061
01062 PreviousMatches = CurrentMatches;
01063
01064 CurrentMatches = Tmp;
01065 }
01066
01067 MatchesCount = DestCount;
01068 }
01069
01070
01071 CurrentState = PreviousMatches[MatchesCount-1];
01072
01073
if (AuxBuffer !=
NULL) {
ExFreePool( AuxBuffer ); }
01074
01075
01076
return (BOOLEAN)(CurrentState == MaxState);
01077 }
01078