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
#include "iop.h"
00027
00028
#ifdef ALLOC_PRAGMA
00029
#pragma alloc_text(PAGE, IopCloseFile)
00030
#pragma alloc_text(PAGE, IopDeleteDevice)
00031
#pragma alloc_text(PAGE, IopDeleteDriver)
00032
#pragma alloc_text(PAGE, IopGetSetSecurityObject)
00033
#endif
00034
00035
VOID
00036 IopCloseFile(
00037 IN
PEPROCESS Process OPTIONAL,
00038 IN PVOID Object,
00039 IN ULONG GrantedAccess,
00040 IN ULONG ProcessHandleCount,
00041 IN ULONG SystemHandleCount
00042 )
00043
00044
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
PIRP irp;
00082
PIO_STACK_LOCATION irpSp;
00083
PDEVICE_OBJECT deviceObject;
00084
PFAST_IO_DISPATCH fastIoDispatch;
00085
NTSTATUS status;
00086
KEVENT event;
00087
PFILE_OBJECT fileObject;
00088 KIRQL irql;
00089
00090 UNREFERENCED_PARAMETER( Process );
00091 UNREFERENCED_PARAMETER( GrantedAccess );
00092
00093
PAGED_CODE();
00094
00095
00096
00097
00098
00099
00100
if (ProcessHandleCount != 1) {
00101
return;
00102 }
00103
00104 fileObject = (
PFILE_OBJECT) Object;
00105
00106
if (fileObject->
LockOperation && SystemHandleCount != 1) {
00107
00108 IO_STATUS_BLOCK localIoStatus;
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
if (!(fileObject->
Flags &
FO_DIRECT_DEVICE_OPEN)) {
00125 deviceObject =
IoGetRelatedDeviceObject( fileObject );
00126 }
else {
00127 deviceObject =
IoGetAttachedDevice( fileObject->
DeviceObject );
00128 }
00129 fastIoDispatch = deviceObject->
DriverObject->
FastIoDispatch;
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
if (fileObject->
Flags &
FO_SYNCHRONOUS_IO) {
00143
00144 BOOLEAN interrupted;
00145
00146
if (!
IopAcquireFastLock( fileObject )) {
00147 (
VOID)
IopAcquireFileObjectLock( fileObject,
00148
KernelMode,
00149
FALSE,
00150 &interrupted );
00151 }
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
if (fastIoDispatch &&
00162 fastIoDispatch->
FastIoUnlockAll &&
00163 fastIoDispatch->
FastIoUnlockAll( fileObject,
00164
PsGetCurrentProcess(),
00165 &localIoStatus,
00166 deviceObject )) {
00167
00168 NOTHING;
00169
00170 }
else {
00171
00172
00173
00174
00175
00176
00177
KeInitializeEvent( &event, SynchronizationEvent,
FALSE );
00178
00179
00180
00181
00182
00183
KeClearEvent( &fileObject->
Event );
00184
00185
00186
00187
00188
00189
00190 irp =
IopAllocateIrpMustSucceed( deviceObject->
StackSize );
00191 irp->
Tail.Overlay.OriginalFileObject = fileObject;
00192 irp->
Tail.Overlay.Thread =
PsGetCurrentThread();
00193 irp->
RequestorMode =
KernelMode;
00194
00195
00196
00197
00198
00199 irp->
UserEvent = &event;
00200 irp->
UserIosb = &irp->
IoStatus;
00201 irp->
Flags =
IRP_SYNCHRONOUS_API;
00202 irp->
Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE)
NULL;
00203
00204
00205
00206
00207
00208
00209
00210 irpSp =
IoGetNextIrpStackLocation( irp );
00211 irpSp->
MajorFunction =
IRP_MJ_LOCK_CONTROL;
00212 irpSp->
MinorFunction =
IRP_MN_UNLOCK_ALL;
00213 irpSp->
FileObject = fileObject;
00214
00215
00216
00217
00218
00219
ObReferenceObject( fileObject );
00220
00221
00222
00223
00224
00225
IopQueueThreadIrp( irp );
00226
00227
00228
00229
00230
00231 status =
IoCallDriver( deviceObject, irp );
00232
00233
00234
00235
00236
00237
if (status == STATUS_PENDING) {
00238 (
VOID)
KeWaitForSingleObject( &event,
00239
UserRequest,
00240
KernelMode,
00241
FALSE,
00242 (PLARGE_INTEGER)
NULL );
00243 }
00244 }
00245
00246
00247
00248
00249
00250
00251
if (fileObject->
Flags &
FO_SYNCHRONOUS_IO) {
00252
IopReleaseFileObjectLock( fileObject );
00253 }
00254 }
00255
00256
if (SystemHandleCount == 1) {
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
if (!(fileObject->
Flags &
FO_DIRECT_DEVICE_OPEN)) {
00271 deviceObject =
IoGetRelatedDeviceObject( fileObject );
00272 }
else {
00273 deviceObject =
IoGetAttachedDevice( fileObject->
DeviceObject );
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 fileObject->
Flags |=
FO_HANDLE_CREATED;
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
if (fileObject->
Flags &
FO_SYNCHRONOUS_IO) {
00298
00299 BOOLEAN interrupted;
00300
00301
if (!
IopAcquireFastLock( fileObject )) {
00302 (
VOID)
IopAcquireFileObjectLock( fileObject,
00303
KernelMode,
00304
FALSE,
00305 &interrupted );
00306 }
00307 }
00308
00309
00310
00311
00312
00313
00314
KeInitializeEvent( &event, SynchronizationEvent,
FALSE );
00315
00316
00317
00318
00319
00320
KeClearEvent( &fileObject->
Event );
00321
00322
00323
00324
00325
00326
00327 irp =
IopAllocateIrpMustSucceed( deviceObject->
StackSize );
00328 irp->
Tail.Overlay.OriginalFileObject = fileObject;
00329 irp->
Tail.Overlay.Thread =
PsGetCurrentThread();
00330 irp->
RequestorMode =
KernelMode;
00331
00332
00333
00334
00335
00336 irp->
UserEvent = &event;
00337 irp->
UserIosb = &irp->
IoStatus;
00338 irp->
Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE)
NULL;
00339 irp->
Flags =
IRP_SYNCHRONOUS_API |
IRP_CLOSE_OPERATION;
00340
00341
00342
00343
00344
00345
00346
00347 irpSp =
IoGetNextIrpStackLocation( irp );
00348 irpSp->
MajorFunction =
IRP_MJ_CLEANUP;
00349 irpSp->
FileObject = fileObject;
00350
00351
00352
00353
00354
00355
IopQueueThreadIrp( irp );
00356
00357
00358
00359
00360
00361
00362
IopUpdateOtherOperationCount();
00363
00364
00365
00366
00367
00368 status =
IoCallDriver( deviceObject, irp );
00369
00370
00371
00372
00373
00374
if (status == STATUS_PENDING) {
00375 (
VOID)
KeWaitForSingleObject( &event,
00376
UserRequest,
00377
KernelMode,
00378
FALSE,
00379 (PLARGE_INTEGER)
NULL );
00380 }
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
KeRaiseIrql(
APC_LEVEL, &irql );
00394
IopDequeueThreadIrp( irp );
00395
KeLowerIrql( irql );
00396
00397
00398
00399
00400
00401
IoFreeIrp( irp );
00402
00403
00404
00405
00406
00407
00408
if (fileObject->
Flags &
FO_SYNCHRONOUS_IO) {
00409
IopReleaseFileObjectLock( fileObject );
00410 }
00411 }
00412
00413
return;
00414 }
00415
00416
VOID
00417 IopDeleteFile(
00418 IN PVOID Object
00419 )
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 {
00448
PIRP irp;
00449
PIO_STACK_LOCATION irpSp;
00450
PDEVICE_OBJECT deviceObject;
00451 IO_STATUS_BLOCK ioStatusBlock;
00452 KIRQL irql;
00453
NTSTATUS status;
00454
PFILE_OBJECT fileObject;
00455
KEVENT event;
00456
PVPB vpb;
00457 BOOLEAN referenceCountDecremented;
00458
00459
00460
00461
00462
00463 fileObject = (
PFILE_OBJECT) Object;
00464
00465
00466
00467
00468
00469
00470
00471
00472
if (fileObject->
DeviceObject) {
00473
if (!(fileObject->
Flags &
FO_DIRECT_DEVICE_OPEN)) {
00474 deviceObject =
IoGetRelatedDeviceObject( fileObject );
00475 }
else {
00476 deviceObject =
IoGetAttachedDevice( fileObject->
DeviceObject );
00477 }
00478
00479
00480
00481
00482
00483
00484
00485
if (!(fileObject->
Flags &
FO_HANDLE_CREATED)) {
00486
IopCloseFile( (
PEPROCESS)
NULL,
00487 Object,
00488 0,
00489 1,
00490 1 );
00491 }
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
if (fileObject->
Flags &
FO_SYNCHRONOUS_IO) {
00505
00506 BOOLEAN interrupted;
00507
00508
if (!
IopAcquireFastLock( fileObject )) {
00509 (
VOID)
IopAcquireFileObjectLock( fileObject,
00510
KernelMode,
00511
FALSE,
00512 &interrupted );
00513 }
00514 }
00515
00516
00517
00518
00519
00520
00521
KeInitializeEvent( &event, SynchronizationEvent,
FALSE );
00522
00523
00524
00525
00526
00527
KeClearEvent( &fileObject->
Event );
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537 irp =
IoAllocateIrp( deviceObject->
StackSize,
FALSE );
00538
if (!irp) {
00539 irp =
IopAllocateIrpMustSucceed( deviceObject->
StackSize );
00540 }
00541
00542
00543
00544
00545
00546
00547 irpSp =
IoGetNextIrpStackLocation( irp );
00548
00549
00550
00551
00552
00553 irpSp->
MajorFunction =
IRP_MJ_CLOSE;
00554 irpSp->
FileObject = fileObject;
00555 irp->
UserIosb = &ioStatusBlock;
00556 irp->
UserEvent = &event;
00557 irp->
Tail.Overlay.OriginalFileObject = fileObject;
00558 irp->
Tail.Overlay.Thread =
PsGetCurrentThread();
00559 irp->
AssociatedIrp.SystemBuffer = (PVOID)
NULL;
00560 irp->
Flags =
IRP_CLOSE_OPERATION |
IRP_SYNCHRONOUS_API;
00561
00562
00563
00564
00565
00566
IopQueueThreadIrp( irp );
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580 vpb = fileObject->
Vpb;
00581
00582
if (vpb && !(fileObject->
Flags &
FO_DIRECT_DEVICE_OPEN)) {
00583
ExInterlockedAddUlong( &vpb->
ReferenceCount,
00584 0xffffffff,
00585 &
IopVpbSpinLock );
00586 }
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
if (fileObject->
DeviceObject->
Flags &
DO_NEVER_LAST_DEVICE) {
00598
ExInterlockedAddUlong( &fileObject->
DeviceObject->
ReferenceCount,
00599 0xffffffff,
00600 &
IopDatabaseLock );
00601
00602 referenceCountDecremented =
TRUE;
00603 }
else {
00604 referenceCountDecremented =
FALSE;
00605 }
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618 status =
IoCallDriver( deviceObject, irp );
00619
00620
if (status == STATUS_PENDING) {
00621 (
VOID)
KeWaitForSingleObject( &event,
00622
Executive,
00623
KernelMode,
00624
FALSE,
00625 (PLARGE_INTEGER)
NULL );
00626 }
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
KeRaiseIrql(
APC_LEVEL, &irql );
00651
IopDequeueThreadIrp( irp );
00652
KeLowerIrql( irql );
00653
00654
IoFreeIrp( irp );
00655
00656
00657
00658
00659
00660
if (fileObject->
FileName.Length != 0) {
00661
ExFreePool( fileObject->
FileName.Buffer );
00662 }
00663
00664
00665
00666
00667
00668
00669
if (fileObject->
CompletionContext) {
00670
ObDereferenceObject( fileObject->
CompletionContext->
Port );
00671
ExFreePool( fileObject->
CompletionContext );
00672 }
00673
00674
00675
00676
00677
00678
00679 deviceObject = fileObject->
DeviceObject;
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
if (!referenceCountDecremented) {
00692
IopDecrementDeviceObjectRef( deviceObject,
FALSE );
00693 }
00694 }
00695 }
00696
00697
VOID
00698 IopDeleteDriver(
00699 IN PVOID Object
00700 )
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722 {
00723
PDRIVER_OBJECT driverObject = (
PDRIVER_OBJECT) Object;
00724
PIO_CLIENT_EXTENSION extension;
00725
PIO_CLIENT_EXTENSION nextExtension;
00726
00727
PAGED_CODE();
00728
00729
ASSERT( !driverObject->
DeviceObject );
00730
00731
00732
00733
00734
00735
extension = driverObject->
DriverExtension->
ClientDriverExtension;
00736
while (
extension !=
NULL) {
00737
00738 nextExtension =
extension->NextExtension;
00739
ExFreePool(
extension );
00740
extension = nextExtension;
00741 }
00742
00743
00744
00745
00746
00747
if (driverObject->
DriverSection !=
NULL) {
00748
MmUnloadSystemImage( driverObject->
DriverSection );
00749 }
00750
00751
00752
00753
00754
00755
if (driverObject->
DriverName.Buffer) {
00756
ExFreePool( driverObject->
DriverName.Buffer );
00757 }
00758
00759
00760
00761
00762
00763
if (driverObject->
DriverExtension->
ServiceKeyName.Buffer) {
00764
ExFreePool( driverObject->
DriverExtension->
ServiceKeyName.Buffer );
00765 }
00766 }
00767
00768
VOID
00769 IopDeleteDevice(
00770 IN PVOID Object
00771 )
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793 {
00794
PDEVICE_OBJECT deviceObject = (
PDEVICE_OBJECT) Object;
00795
PVPB vpb =
NULL;
00796
00797
PAGED_CODE();
00798
00799
IopDestroyDeviceNode(deviceObject->
DeviceObjectExtension->
DeviceNode);
00800
00801
#if DBG
00802
IopCheckDeviceNodeTree (deviceObject,
NULL);
00803
#endif
00804
00805
00806
00807
00808
00809 vpb = InterlockedExchangePointer(&(deviceObject->
Vpb), vpb);
00810
00811
if(vpb !=
NULL) {
00812
00813
ASSERTMSG(
"Unreferenced device object to be deleted is still in use",
00814 ((vpb->
Flags & (
VPB_MOUNTED |
VPB_LOCKED)) == 0));
00815
00816
ASSERT(vpb->
ReferenceCount == 0);
00817
ExFreePool(vpb);
00818 }
00819
if (deviceObject->
DriverObject !=
NULL) {
00820
ObDereferenceObject( deviceObject->
DriverObject );
00821 }
00822 }
00823
00824
00825
PDEVICE_OBJECT
00826 IopGetDevicePDO(
00827 IN
PDEVICE_OBJECT DeviceObject
00828 )
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845 {
00846
PDEVICE_OBJECT deviceBaseObject;
00847 KIRQL irql;
00848
00849
ASSERT(DeviceObject);
00850
00851
IopAcquireEnumerationLock(
NULL);
00852
00853 ExAcquireSpinLock(&
IopDatabaseLock,&irql);
00854 deviceBaseObject =
IopGetDeviceAttachmentBase(DeviceObject);
00855
if ((deviceBaseObject->
Flags &
DO_BUS_ENUMERATED_DEVICE) != 0) {
00856
00857
00858
00859
ObReferenceObject( deviceBaseObject );
00860
00861 }
else {
00862
00863
00864
00865 deviceBaseObject =
NULL;
00866 }
00867 ExReleaseSpinLock(&
IopDatabaseLock,irql);
00868
00869
IopReleaseEnumerationLock(
NULL);
00870
00871
return deviceBaseObject;
00872 }
00873
00874
00875
00876
NTSTATUS
00877 IopSetDeviceSecurityDescriptors(
00878 IN
PDEVICE_OBJECT DeviceObject,
00879 IN PSECURITY_INFORMATION SecurityInformation,
00880 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
00881 IN POOL_TYPE PoolType,
00882 IN PGENERIC_MAPPING GenericMapping,
00883 IN BOOLEAN DoAttachedDevices
00884 )
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905 {
00906
PDEVICE_OBJECT NewDeviceObject =
NULL;
00907 PSECURITY_DESCRIPTOR OldSecurityDescriptor;
00908 KIRQL irql;
00909
NTSTATUS status;
00910
NTSTATUS firsterr = STATUS_SUCCESS;
00911 BOOLEAN first =
TRUE;
00912
00913
ASSERT(DeviceObject);
00914
00915
IopAcquireEnumerationLock(
NULL);
00916
00917
00918
00919
ObReferenceObject( DeviceObject );
00920
00921
do {
00922
KeEnterCriticalRegion();
00923
ExAcquireResourceExclusive( &
IopSecurityResource,
TRUE );
00924
00925 OldSecurityDescriptor = DeviceObject->SecurityDescriptor;
00926
00927
if (OldSecurityDescriptor || first) {
00928
00929
00930
00931 status =
SeSetSecurityDescriptorInfo(
NULL,
00932 SecurityInformation,
00933 SecurityDescriptor,
00934 &DeviceObject->SecurityDescriptor,
00935 PoolType,
00936 GenericMapping );
00937
00938
if (
NT_SUCCESS(firsterr)) {
00939 firsterr = status;
00940 }
00941
if (
NT_SUCCESS( status )) {
00942
ASSERT(OldSecurityDescriptor);
00943
ExFreePool( OldSecurityDescriptor );
00944 }
00945 first =
FALSE;
00946 }
00947
00948
ExReleaseResource( &
IopSecurityResource );
00949
KeLeaveCriticalRegion();
00950
00951
00952
00953
00954 ExAcquireSpinLock(&
IopDatabaseLock,&irql);
00955 NewDeviceObject = DeviceObject->
AttachedDevice;
00956
if ( NewDeviceObject !=
NULL ) {
00957
ObReferenceObject( NewDeviceObject );
00958 }
else {
00959 DoAttachedDevices =
FALSE;
00960 }
00961 ExReleaseSpinLock(&
IopDatabaseLock,irql);
00962
00963
ObDereferenceObject( DeviceObject );
00964 DeviceObject = NewDeviceObject;
00965
00966 }
while(DoAttachedDevices);
00967
00968
IopReleaseEnumerationLock(
NULL);
00969
00970
return firsterr;
00971 }
00972
00973
00974
NTSTATUS
00975 IopGetSetSecurityObject(
00976 IN PVOID Object,
00977 IN SECURITY_OPERATION_CODE OperationCode,
00978 IN PSECURITY_INFORMATION SecurityInformation,
00979 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
00980 IN OUT PULONG CapturedLength,
00981 IN OUT PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor,
00982 IN POOL_TYPE PoolType,
00983 IN PGENERIC_MAPPING GenericMapping
00984 )
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031 {
01032
NTSTATUS status;
01033
PFILE_OBJECT fileObject;
01034
PDEVICE_OBJECT deviceObject;
01035
PDEVICE_OBJECT devicePDO =
NULL;
01036 BOOLEAN synchronousIo;
01037
01038 UNREFERENCED_PARAMETER( ObjectsSecurityDescriptor );
01039 UNREFERENCED_PARAMETER( PoolType );
01040
01041
PAGED_CODE();
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
if (((
PDEVICE_OBJECT) (Object))->Type ==
IO_TYPE_DEVICE) {
01053 deviceObject = (
PDEVICE_OBJECT) Object;
01054 fileObject = (
PFILE_OBJECT)
NULL;
01055 }
else {
01056 fileObject = (
PFILE_OBJECT) Object;
01057
if (fileObject->
Flags &
FO_DIRECT_DEVICE_OPEN) {
01058 deviceObject =
IoGetAttachedDevice( fileObject->
DeviceObject );
01059 }
01060
else {
01061 deviceObject = fileObject->
DeviceObject;
01062 }
01063 }
01064
01065
if (!fileObject ||
01066 (!fileObject->
FileName.Length && !fileObject->
RelatedFileObject) ||
01067 (fileObject->
Flags &
FO_DIRECT_DEVICE_OPEN)) {
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
if (OperationCode ==
AssignSecurityDescriptor) {
01080
01081
01082
01083
01084
01085
01086
if (fileObject ==
NULL || !(fileObject->
Flags &
FO_STREAM_FILE)) {
01087
KeEnterCriticalRegion();
01088
ExAcquireResourceExclusive( &
IopSecurityResource,
TRUE );
01089 deviceObject->
SecurityDescriptor = SecurityDescriptor;
01090
ExReleaseResource( &
IopSecurityResource );
01091
KeLeaveCriticalRegion();
01092 }
01093 status = STATUS_SUCCESS;
01094
01095 }
else if (OperationCode ==
SetSecurityDescriptor) {
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
if (fileObject ==
NULL || !(fileObject->
Flags &
FO_DIRECT_DEVICE_OPEN)) {
01109
01110
01111
01112 devicePDO =
IopGetDevicePDO(deviceObject);
01113 }
else {
01114 devicePDO =
NULL;
01115 }
01116
if (devicePDO) {
01117
01118
01119
01120 status =
IopSetDeviceSecurityDescriptors(devicePDO,SecurityInformation,SecurityDescriptor,PoolType,GenericMapping,
TRUE);
01121
ObDereferenceObject( devicePDO );
01122 }
else {
01123
01124
01125
01126 status =
IopSetDeviceSecurityDescriptors(deviceObject,SecurityInformation,SecurityDescriptor,PoolType,GenericMapping,
FALSE);
01127 }
01128
01129 }
else if (OperationCode ==
QuerySecurityDescriptor) {
01130
01131
01132
01133
01134
01135
01136
01137
KeEnterCriticalRegion();
01138
ExAcquireResourceShared( &
IopSecurityResource,
TRUE );
01139 status =
SeQuerySecurityDescriptorInfo( SecurityInformation,
01140 SecurityDescriptor,
01141 CapturedLength,
01142 &deviceObject->
SecurityDescriptor );
01143
ExReleaseResource( &
IopSecurityResource );
01144
KeLeaveCriticalRegion();
01145
01146 }
else {
01147
01148
01149
01150
01151
01152
01153 status = STATUS_SUCCESS;
01154
01155 }
01156
01157 }
else if (OperationCode ==
DeleteSecurityDescriptor) {
01158
01159
01160
01161
01162
01163
01164
01165
01166 status = STATUS_SUCCESS;
01167
01168 }
else {
01169
01170
PIRP irp;
01171 IO_STATUS_BLOCK localIoStatus;
01172
KEVENT event;
01173
PIO_STACK_LOCATION irpSp;
01174
KPROCESSOR_MODE requestorMode;
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189 requestorMode = KeGetPreviousMode();
01190
01191
01192
01193
01194
01195
01196
01197
01198
ObReferenceObject( fileObject );
01199
01200
01201
01202
01203
01204
01205
01206
01207
if (fileObject->
Flags &
FO_SYNCHRONOUS_IO) {
01208
01209 BOOLEAN interrupted;
01210
01211
if (!
IopAcquireFastLock( fileObject )) {
01212 status =
IopAcquireFileObjectLock( fileObject,
01213 requestorMode,
01214 (BOOLEAN) ((fileObject->
Flags &
FO_ALERTABLE_IO) != 0),
01215 &interrupted );
01216
if (interrupted) {
01217
ObDereferenceObject( fileObject );
01218
return status;
01219 }
01220 }
01221 synchronousIo =
TRUE;
01222 }
else {
01223
KeInitializeEvent( &event, SynchronizationEvent,
FALSE );
01224 synchronousIo =
FALSE;
01225 }
01226
01227
01228
01229
01230
01231
KeClearEvent( &fileObject->
Event );
01232
01233
01234
01235
01236
01237 deviceObject =
IoGetRelatedDeviceObject( fileObject );
01238
01239
01240
01241
01242
01243
01244 irp =
IoAllocateIrp( deviceObject->
StackSize,
TRUE );
01245
if (!irp) {
01246
01247
01248
01249
01250
01251
01252
IopAllocateIrpCleanup( fileObject, (
PKEVENT)
NULL );
01253
01254
return STATUS_INSUFFICIENT_RESOURCES;
01255 }
01256 irp->
Tail.Overlay.OriginalFileObject = fileObject;
01257 irp->
Tail.Overlay.Thread =
PsGetCurrentThread();
01258 irp->
RequestorMode = requestorMode;
01259
01260
01261
01262
01263
01264
if (fileObject->
Flags &
FO_SYNCHRONOUS_IO) {
01265 irp->
UserEvent = (
PKEVENT)
NULL;
01266 }
else {
01267 irp->
UserEvent = &event;
01268 irp->
Flags =
IRP_SYNCHRONOUS_API;
01269 }
01270 irp->
UserIosb = &localIoStatus;
01271 irp->
Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE)
NULL;
01272
01273
01274
01275
01276
01277
01278 irpSp =
IoGetNextIrpStackLocation( irp );
01279
01280
01281
01282
01283
01284
if (OperationCode ==
QuerySecurityDescriptor) {
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298 irpSp->
MajorFunction =
IRP_MJ_QUERY_SECURITY;
01299 irpSp->
Parameters.QuerySecurity.SecurityInformation = *SecurityInformation;
01300 irpSp->
Parameters.QuerySecurity.Length = *CapturedLength;
01301 irp->
UserBuffer = SecurityDescriptor;
01302
01303 }
else {
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313 irpSp->
MajorFunction =
IRP_MJ_SET_SECURITY;
01314 irpSp->
Parameters.SetSecurity.SecurityInformation = *SecurityInformation;
01315 irpSp->
Parameters.SetSecurity.SecurityDescriptor = SecurityDescriptor;
01316
01317 }
01318
01319 irpSp->
FileObject = fileObject;
01320
01321
01322
01323
01324
01325
IopQueueThreadIrp( irp );
01326
01327
01328
01329
01330
01331
01332
IopUpdateOtherOperationCount();
01333
01334
01335
01336
01337
01338 status =
IoCallDriver( deviceObject, irp );
01339
01340
01341
01342
01343
01344
01345
01346
01347
if (synchronousIo) {
01348
if (status == STATUS_PENDING) {
01349 (
VOID)
KeWaitForSingleObject( &fileObject->
Event,
01350
Executive,
01351
KernelMode,
01352
FALSE,
01353 (PLARGE_INTEGER)
NULL );
01354 status = fileObject->
FinalStatus;
01355 }
01356
IopReleaseFileObjectLock( fileObject );
01357
01358 }
else {
01359
01360
01361
01362
01363
01364
01365
01366
01367
if (status == STATUS_PENDING) {
01368 (
VOID)
KeWaitForSingleObject( &event,
01369
Executive,
01370
KernelMode,
01371
FALSE,
01372 (PLARGE_INTEGER)
NULL );
01373 status = localIoStatus.Status;
01374 }
01375 }
01376
01377
01378
01379
01380
01381
01382
01383
if (status == STATUS_INVALID_DEVICE_REQUEST) {
01384
01385
01386
01387
01388
01389
01390
01391
if (OperationCode ==
QuerySecurityDescriptor) {
01392
01393
01394
01395
01396
01397
01398
01399
01400
try {
01401 status =
SeAssignWorldSecurityDescriptor(
01402 SecurityDescriptor,
01403 CapturedLength,
01404 SecurityInformation
01405 );
01406
01407 } except(
EXCEPTION_EXECUTE_HANDLER ) {
01408
01409
01410
01411
01412
01413
01414
01415 status = GetExceptionCode();
01416 }
01417
01418 }
else {
01419
01420
01421
01422
01423
01424
01425 status = STATUS_SUCCESS;
01426 }
01427
01428 }
else if (OperationCode ==
QuerySecurityDescriptor) {
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
if (status == STATUS_BUFFER_OVERFLOW) {
01445 status = STATUS_BUFFER_TOO_SMALL;
01446 }
01447
01448
try {
01449
01450 *CapturedLength = (ULONG) localIoStatus.Information;
01451
01452 } except(
EXCEPTION_EXECUTE_HANDLER ) {
01453 status = GetExceptionCode();
01454 }
01455 }
01456 }
01457
01458
return status;
01459 }