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
#include "iop.h"
00028
00029
#ifdef ALLOC_PRAGMA
00030
#pragma alloc_text(PAGE, NtQueryEaFile)
00031
#pragma alloc_text(PAGE, NtSetEaFile)
00032
#endif
00033
00034
NTSTATUS
00035 NtQueryEaFile(
00036 IN HANDLE FileHandle,
00037 OUT PIO_STATUS_BLOCK IoStatusBlock,
00038 OUT PVOID Buffer,
00039 IN ULONG Length,
00040 IN BOOLEAN ReturnSingleEntry,
00041 IN PVOID EaList OPTIONAL,
00042 IN ULONG EaListLength,
00043 IN PULONG EaIndex OPTIONAL,
00044 IN BOOLEAN RestartScan
00045 )
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 #define
GET_OFFSET_LENGTH( CurrentEa, EaBase ) ( \
00090 (ULONG) ((PCHAR) CurrentEa - (PCHAR) EaBase) )
00091
00092
00093 {
00094
PIRP irp;
00095
NTSTATUS status;
00096
PFILE_OBJECT fileObject;
00097
PDEVICE_OBJECT deviceObject;
00098
PKEVENT event = (
PKEVENT)
NULL;
00099 PCHAR auxiliaryBuffer = (PCHAR)
NULL;
00100 BOOLEAN eaListPresent =
FALSE;
00101 ULONG eaIndexValue = 0
L;
00102
KPROCESSOR_MODE requestorMode;
00103
PIO_STACK_LOCATION irpSp;
00104 IO_STATUS_BLOCK localIoStatus;
00105 BOOLEAN synchronousIo;
00106
00107
PAGED_CODE();
00108
00109
00110
00111
00112
00113 requestorMode = KeGetPreviousMode();
00114
00115
if (requestorMode !=
KernelMode) {
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
try {
00126
00127
00128
00129
00130
00131
ProbeForWriteIoStatus( IoStatusBlock );
00132
00133
00134
00135
00136
00137
ProbeForWrite(
Buffer, Length,
sizeof( ULONG ) );
00138
00139
00140
00141
00142
00143
00144
if (ARGUMENT_PRESENT( EaIndex )) {
00145 eaIndexValue =
ProbeAndReadUlong( EaIndex );
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
if (ARGUMENT_PRESENT( EaList ) && EaListLength != 0) {
00155
00156 PFILE_GET_EA_INFORMATION eas;
00157 LONG tempLength;
00158 ULONG entrySize;
00159
00160 eaListPresent =
TRUE;
00161
00162
ProbeForRead( EaList, EaListLength,
sizeof( ULONG ) );
00163 auxiliaryBuffer =
ExAllocatePoolWithQuota(
NonPagedPool,
00164 EaListLength );
00165 RtlCopyMemory( auxiliaryBuffer, EaList, EaListLength );
00166
00167 eas = (PFILE_GET_EA_INFORMATION) auxiliaryBuffer;
00168 tempLength = EaListLength;
00169
00170
00171
00172
00173
00174
00175
00176
for (;;) {
00177
00178
00179
00180
00181
00182
if (tempLength < FIELD_OFFSET( FILE_GET_EA_INFORMATION, EaName[0])) {
00183 tempLength = 0;
00184
ExFreePool( auxiliaryBuffer );
00185 auxiliaryBuffer = (PVOID)
NULL;
00186 IoStatusBlock->Status = STATUS_EA_LIST_INCONSISTENT;
00187 IoStatusBlock->Information = tempLength;
00188
return STATUS_EA_LIST_INCONSISTENT;
00189 }
00190
00191 entrySize = FIELD_OFFSET( FILE_GET_EA_INFORMATION, EaName[0] ) + eas->EaNameLength + 1;
00192
00193
if ((ULONG) tempLength < entrySize) {
00194 tempLength =
GET_OFFSET_LENGTH( eas, auxiliaryBuffer );
00195
ExFreePool( auxiliaryBuffer );
00196 auxiliaryBuffer = (PVOID)
NULL;
00197 IoStatusBlock->Status = STATUS_EA_LIST_INCONSISTENT;
00198 IoStatusBlock->Information = tempLength;
00199
return STATUS_EA_LIST_INCONSISTENT;
00200 }
00201
00202
if (eas->NextEntryOffset != 0) {
00203
00204
00205
00206
00207
00208
00209
00210
00211
if ((((entrySize + 3) & ~3) != eas->NextEntryOffset) ||
00212 ((LONG) eas->NextEntryOffset < 0)) {
00213 tempLength =
GET_OFFSET_LENGTH( eas, auxiliaryBuffer );
00214
ExFreePool( auxiliaryBuffer );
00215 auxiliaryBuffer = (PVOID)
NULL;
00216 IoStatusBlock->Status = STATUS_EA_LIST_INCONSISTENT;
00217 IoStatusBlock->Information = tempLength;
00218
return STATUS_EA_LIST_INCONSISTENT;
00219
00220 }
else {
00221
00222
00223
00224
00225
00226
00227
00228
00229 tempLength -= eas->NextEntryOffset;
00230
if (tempLength < 0) {
00231 tempLength =
GET_OFFSET_LENGTH( eas, auxiliaryBuffer );
00232
ExFreePool( auxiliaryBuffer );
00233 auxiliaryBuffer = (PVOID)
NULL;
00234 IoStatusBlock->Status = STATUS_EA_LIST_INCONSISTENT;
00235 IoStatusBlock->Information = tempLength;
00236
return STATUS_EA_LIST_INCONSISTENT;
00237 }
00238 eas = (PFILE_GET_EA_INFORMATION) ((PCHAR) eas + eas->NextEntryOffset);
00239 }
00240
00241 }
else {
00242
00243
00244
00245
00246
00247
00248
00249
00250 tempLength -= entrySize;
00251
break;
00252 }
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
if (tempLength < 0) {
00262 tempLength =
GET_OFFSET_LENGTH( eas, auxiliaryBuffer );
00263
ExFreePool( auxiliaryBuffer );
00264 auxiliaryBuffer = (PVOID)
NULL;
00265 IoStatusBlock->Status = STATUS_EA_LIST_INCONSISTENT;
00266 IoStatusBlock->Information = tempLength;
00267
return STATUS_EA_LIST_INCONSISTENT;
00268 }
00269
00270 }
00271
00272 } except(
EXCEPTION_EXECUTE_HANDLER) {
00273
00274
00275
00276
00277
00278
00279
00280
00281
if (auxiliaryBuffer !=
NULL) {
00282
ExFreePool( auxiliaryBuffer );
00283 }
00284
00285
return GetExceptionCode();
00286
00287 }
00288
00289 }
else {
00290
00291
00292
00293
00294
00295
00296
00297
if (ARGUMENT_PRESENT( EaList ) && (EaListLength != 0)) {
00298 eaListPresent =
TRUE;
00299
try {
00300 auxiliaryBuffer =
ExAllocatePoolWithQuota(
NonPagedPool,
00301 EaListLength );
00302 } except(
EXCEPTION_EXECUTE_HANDLER) {
00303
return GetExceptionCode();
00304 }
00305 RtlCopyMemory( auxiliaryBuffer, EaList, EaListLength );
00306 }
00307
00308
if (ARGUMENT_PRESENT( EaIndex )) {
00309 eaIndexValue = *EaIndex;
00310 }
00311 }
00312
00313
00314
00315
00316
00317
00318
00319
00320 status =
ObReferenceObjectByHandle( FileHandle,
00321 FILE_READ_EA,
00322
IoFileObjectType,
00323 requestorMode,
00324 (PVOID *) &fileObject,
00325
NULL );
00326
if (!
NT_SUCCESS( status )) {
00327
if (eaListPresent) {
00328
ExFreePool( auxiliaryBuffer );
00329 }
00330
return status;
00331 }
00332
00333
00334
00335
00336
00337
00338
00339
00340
if (fileObject->Flags &
FO_SYNCHRONOUS_IO) {
00341
00342 BOOLEAN interrupted;
00343
00344
if (!
IopAcquireFastLock( fileObject )) {
00345 status =
IopAcquireFileObjectLock( fileObject,
00346 requestorMode,
00347 (BOOLEAN) ((fileObject->Flags &
FO_ALERTABLE_IO) != 0),
00348 &interrupted );
00349
if (interrupted) {
00350
if (eaListPresent) {
00351
ExFreePool( auxiliaryBuffer );
00352 }
00353
ObDereferenceObject( fileObject );
00354
return status;
00355 }
00356 }
00357 synchronousIo =
TRUE;
00358 }
else {
00359
00360
00361
00362
00363
00364
00365
00366
00367 event =
ExAllocatePool(
NonPagedPool,
sizeof(
KEVENT ) );
00368
if (event ==
NULL) {
00369
if (eaListPresent) {
00370
ExFreePool( auxiliaryBuffer );
00371 }
00372
ObDereferenceObject( fileObject );
00373
return STATUS_INSUFFICIENT_RESOURCES;
00374 }
00375
KeInitializeEvent( event, SynchronizationEvent,
FALSE );
00376 synchronousIo =
FALSE;
00377 }
00378
00379
00380
00381
00382
00383
KeClearEvent( &fileObject->Event );
00384
00385
00386
00387
00388
00389 deviceObject =
IoGetRelatedDeviceObject( fileObject );
00390
00391
00392
00393
00394
00395
00396 irp =
IoAllocateIrp( deviceObject->
StackSize,
TRUE );
00397
if (!irp) {
00398
00399
00400
00401
00402
00403
00404
if (!(fileObject->Flags &
FO_SYNCHRONOUS_IO)) {
00405
ExFreePool( event );
00406 }
00407
00408
IopAllocateIrpCleanup( fileObject, (
PKEVENT)
NULL );
00409
00410
if (eaListPresent) {
00411
ExFreePool( auxiliaryBuffer );
00412 }
00413
00414
return STATUS_INSUFFICIENT_RESOURCES;
00415 }
00416 irp->
Tail.Overlay.OriginalFileObject = fileObject;
00417 irp->
Tail.Overlay.Thread =
PsGetCurrentThread();
00418 irp->
RequestorMode = requestorMode;
00419
00420
00421
00422
00423
00424
if (synchronousIo) {
00425 irp->
UserEvent = (
PKEVENT)
NULL;
00426 irp->
UserIosb = IoStatusBlock;
00427 }
else {
00428 irp->
UserEvent = event;
00429 irp->
UserIosb = &localIoStatus;
00430 irp->
Flags =
IRP_SYNCHRONOUS_API;
00431 }
00432 irp->
Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE)
NULL;
00433
00434
00435
00436
00437
00438
00439 irpSp =
IoGetNextIrpStackLocation( irp );
00440 irpSp->
MajorFunction =
IRP_MJ_QUERY_EA;
00441 irpSp->
FileObject = fileObject;
00442
00443
00444
00445
00446
00447
00448
00449
if (eaListPresent) {
00450 irp->
Tail.Overlay.AuxiliaryBuffer = auxiliaryBuffer;
00451 irpSp->
Parameters.QueryEa.EaList = auxiliaryBuffer;
00452 irpSp->
Parameters.QueryEa.EaListLength = EaListLength;
00453 }
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
if (deviceObject->
Flags &
DO_BUFFERED_IO) {
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
if (Length) {
00480
try {
00481
00482
00483
00484
00485
00486
00487 irp->
AssociatedIrp.SystemBuffer =
00488
ExAllocatePoolWithQuota(
NonPagedPool, Length );
00489
00490 } except(
EXCEPTION_EXECUTE_HANDLER) {
00491
00492
00493
00494
00495
00496
00497
00498
00499
IopExceptionCleanup( fileObject,
00500 irp,
00501 (
PKEVENT)
NULL,
00502 event );
00503
00504
if (auxiliaryBuffer !=
NULL) {
00505
ExFreePool( auxiliaryBuffer );
00506 }
00507
00508
return GetExceptionCode();
00509
00510 }
00511
00512
00513
00514
00515
00516
00517
00518
00519 irp->
UserBuffer =
Buffer;
00520 irp->
Flags |= (ULONG) (
IRP_BUFFERED_IO |
00521
IRP_DEALLOCATE_BUFFER |
00522
IRP_INPUT_OPERATION);
00523 }
else {
00524
00525
00526
00527
00528
00529
00530
00531 irp->
AssociatedIrp.SystemBuffer =
NULL;
00532 irp->
Flags |= (ULONG) (
IRP_BUFFERED_IO |
IRP_INPUT_OPERATION);
00533
00534 }
00535
00536 }
else if (deviceObject->
Flags &
DO_DIRECT_IO) {
00537
00538
PMDL mdl;
00539
00540
00541
00542
00543
00544
00545
00546
00547
if (Length) {
00548 mdl = (
PMDL)
NULL;
00549
00550
try {
00551
00552
00553
00554
00555
00556
00557
00558
00559 mdl =
IoAllocateMdl(
Buffer, Length,
FALSE,
TRUE, irp );
00560
if (mdl ==
NULL) {
00561
ExRaiseStatus( STATUS_INSUFFICIENT_RESOURCES );
00562 }
00563
MmProbeAndLockPages( mdl, requestorMode,
IoWriteAccess );
00564
00565 } except(
EXCEPTION_EXECUTE_HANDLER) {
00566
00567
00568
00569
00570
00571
00572
00573
00574
IopExceptionCleanup( fileObject,
00575 irp,
00576 (
PKEVENT)
NULL,
00577 event );
00578
00579
if (auxiliaryBuffer !=
NULL) {
00580
ExFreePool( auxiliaryBuffer );
00581 }
00582
00583
return GetExceptionCode();
00584
00585 }
00586 }
00587
00588 }
else {
00589
00590
00591
00592
00593
00594
00595 irp->
UserBuffer =
Buffer;
00596
00597 }
00598
00599
00600
00601
00602
00603
00604 irpSp->
Parameters.QueryEa.Length = Length;
00605 irpSp->
Parameters.QueryEa.EaIndex = eaIndexValue;
00606 irpSp->
Flags = 0;
00607
if (RestartScan) {
00608 irpSp->
Flags =
SL_RESTART_SCAN;
00609 }
00610
if (ReturnSingleEntry) {
00611 irpSp->
Flags |=
SL_RETURN_SINGLE_ENTRY;
00612 }
00613
if (ARGUMENT_PRESENT( EaIndex )) {
00614 irpSp->
Flags |=
SL_INDEX_SPECIFIED;
00615 }
00616
00617
00618
00619
00620
00621
00622 status =
IopSynchronousServiceTail( deviceObject,
00623 irp,
00624 fileObject,
00625
FALSE,
00626 requestorMode,
00627 synchronousIo,
00628
OtherTransfer );
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
if (!synchronousIo) {
00639
00640 status =
IopSynchronousApiServiceTail( status,
00641 event,
00642 irp,
00643 requestorMode,
00644 &localIoStatus,
00645 IoStatusBlock );
00646 }
00647
00648
return status;
00649 }
00650
00651
NTSTATUS
00652 NtSetEaFile(
00653 IN HANDLE FileHandle,
00654 OUT PIO_STATUS_BLOCK IoStatusBlock,
00655 IN PVOID Buffer,
00656 IN ULONG Length
00657 )
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684 {
00685
PIRP irp;
00686
NTSTATUS status;
00687
PFILE_OBJECT fileObject;
00688
PDEVICE_OBJECT deviceObject;
00689
PKEVENT event = (
PKEVENT)
NULL;
00690
KPROCESSOR_MODE requestorMode;
00691
PIO_STACK_LOCATION irpSp;
00692 IO_STATUS_BLOCK localIoStatus;
00693 BOOLEAN synchronousIo;
00694
00695
PAGED_CODE();
00696
00697
00698
00699
00700
00701 requestorMode = KeGetPreviousMode();
00702
00703
if (requestorMode !=
KernelMode) {
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
try {
00714
00715
00716
00717
00718
00719
ProbeForWriteIoStatus( IoStatusBlock );
00720
00721
00722
00723
00724
00725
ProbeForRead(
Buffer, Length,
sizeof( ULONG ) );
00726
00727 } except(
EXCEPTION_EXECUTE_HANDLER) {
00728
00729
00730
00731
00732
00733
00734
return GetExceptionCode();
00735 }
00736 }
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746 status =
ObReferenceObjectByHandle( FileHandle,
00747 FILE_WRITE_EA,
00748
IoFileObjectType,
00749 requestorMode,
00750 (PVOID *) &fileObject,
00751
NULL );
00752
if (!
NT_SUCCESS( status )) {
00753
return status;
00754 }
00755
00756
00757
00758
00759
00760
00761
00762
00763
if (fileObject->Flags &
FO_SYNCHRONOUS_IO) {
00764
00765 BOOLEAN interrupted;
00766
00767
if (!
IopAcquireFastLock( fileObject )) {
00768 status =
IopAcquireFileObjectLock( fileObject,
00769 requestorMode,
00770 (BOOLEAN) ((fileObject->Flags &
FO_ALERTABLE_IO) != 0),
00771 &interrupted );
00772
if (interrupted) {
00773
ObDereferenceObject( fileObject );
00774
return status;
00775 }
00776 }
00777 synchronousIo =
TRUE;
00778 }
else {
00779
00780
00781
00782
00783
00784
00785
00786
00787 event =
ExAllocatePool(
NonPagedPool,
sizeof(
KEVENT ) );
00788
if (event ==
NULL) {
00789
ObDereferenceObject( fileObject );
00790
return STATUS_INSUFFICIENT_RESOURCES;
00791 }
00792
KeInitializeEvent( event, SynchronizationEvent,
FALSE );
00793 synchronousIo =
FALSE;
00794 }
00795
00796
00797
00798
00799
00800
KeClearEvent( &fileObject->Event );
00801
00802
00803
00804
00805
00806 deviceObject =
IoGetRelatedDeviceObject( fileObject );
00807
00808
00809
00810
00811
00812
00813 irp =
IoAllocateIrp( deviceObject->
StackSize,
TRUE );
00814
if (!irp) {
00815
00816
00817
00818
00819
00820
00821
if (!(fileObject->Flags &
FO_SYNCHRONOUS_IO)) {
00822
ExFreePool( event );
00823 }
00824
00825
IopAllocateIrpCleanup( fileObject, (
PKEVENT)
NULL );
00826
00827
return STATUS_INSUFFICIENT_RESOURCES;
00828 }
00829 irp->
Tail.Overlay.OriginalFileObject = fileObject;
00830 irp->
Tail.Overlay.Thread =
PsGetCurrentThread();
00831 irp->
RequestorMode = requestorMode;
00832
00833
00834
00835
00836
00837
if (synchronousIo) {
00838 irp->
UserEvent = (
PKEVENT)
NULL;
00839 irp->
UserIosb = IoStatusBlock;
00840 }
else {
00841 irp->
UserEvent = event;
00842 irp->
UserIosb = &localIoStatus;
00843 irp->
Flags =
IRP_SYNCHRONOUS_API;
00844 }
00845 irp->
Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE)
NULL;
00846
00847
00848
00849
00850
00851
00852 irpSp =
IoGetNextIrpStackLocation( irp );
00853 irpSp->
MajorFunction =
IRP_MJ_SET_EA;
00854 irpSp->
FileObject = fileObject;
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
if (deviceObject->
Flags &
DO_BUFFERED_IO) {
00869
00870 PFILE_FULL_EA_INFORMATION systemBuffer;
00871 ULONG errorOffset;
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
if (Length) {
00883
try {
00884
00885
00886
00887
00888
00889
00890
00891 systemBuffer =
ExAllocatePoolWithQuota(
NonPagedPool, Length );
00892
00893 irp->
AssociatedIrp.SystemBuffer = systemBuffer;
00894
00895 RtlCopyMemory( systemBuffer,
Buffer, Length );
00896
00897 status =
IoCheckEaBufferValidity( systemBuffer,
00898 Length,
00899 &errorOffset );
00900
00901
if (!
NT_SUCCESS( status )) {
00902 IoStatusBlock->Status = status;
00903 IoStatusBlock->Information = errorOffset;
00904
ExRaiseStatus( status );
00905 }
00906
00907 } except(
EXCEPTION_EXECUTE_HANDLER) {
00908
00909
00910
00911
00912
00913
00914
00915
00916
IopExceptionCleanup( fileObject,
00917 irp,
00918 (
PKEVENT)
NULL,
00919 event );
00920
00921
return GetExceptionCode();
00922
00923 }
00924
00925
00926
00927
00928
00929
00930 irp->
Flags |=
IRP_BUFFERED_IO |
IRP_DEALLOCATE_BUFFER;
00931 }
else {
00932 irp->
AssociatedIrp.SystemBuffer =
NULL;
00933 }
00934
00935
00936 }
else if (deviceObject->
Flags &
DO_DIRECT_IO) {
00937
00938
PMDL mdl;
00939
00940
00941
00942
00943
00944
00945
00946
00947 mdl = (
PMDL)
NULL;
00948
00949
if (Length) {
00950
try {
00951
00952
00953
00954
00955
00956
00957
00958
00959 mdl =
IoAllocateMdl(
Buffer, Length,
FALSE,
TRUE, irp );
00960
if (mdl ==
NULL) {
00961
ExRaiseStatus( STATUS_INSUFFICIENT_RESOURCES );
00962 }
00963
MmProbeAndLockPages( mdl, requestorMode,
IoReadAccess );
00964
00965 } except(
EXCEPTION_EXECUTE_HANDLER) {
00966
00967
00968
00969
00970
00971
00972
00973
IopExceptionCleanup( fileObject,
00974 irp,
00975 (
PKEVENT)
NULL,
00976 event );
00977
00978
return GetExceptionCode();
00979
00980 }
00981 }
00982
00983 }
else {
00984
00985
00986
00987
00988
00989
00990 irp->
UserBuffer =
Buffer;
00991
00992 }
00993
00994
00995
00996
00997
00998
00999 irpSp->
Parameters.SetEa.Length = Length;
01000
01001
01002
01003
01004
01005
01006
01007 status =
IopSynchronousServiceTail( deviceObject,
01008 irp,
01009 fileObject,
01010
FALSE,
01011 requestorMode,
01012 synchronousIo,
01013
OtherTransfer );
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
if (!synchronousIo) {
01024
01025 status =
IopSynchronousApiServiceTail( status,
01026 event,
01027 irp,
01028 requestorMode,
01029 &localIoStatus,
01030 IoStatusBlock );
01031 }
01032
01033
return status;
01034 }