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
#include "sep.h"
00029
#include <sertlp.h>
00030
00031
#ifdef ALLOC_PRAGMA
00032
#pragma alloc_text(PAGE,SeCaptureSecurityDescriptor)
00033
#pragma alloc_text(PAGE,SeReleaseSecurityDescriptor)
00034
#pragma alloc_text(PAGE,SeCaptureSecurityQos)
00035
#pragma alloc_text(PAGE,SeCaptureSid)
00036
#pragma alloc_text(PAGE,SeReleaseSid)
00037
#pragma alloc_text(PAGE,SeCaptureAcl)
00038
#pragma alloc_text(PAGE,SeReleaseAcl)
00039
#pragma alloc_text(PAGE,SeCaptureLuidAndAttributesArray)
00040
#pragma alloc_text(PAGE,SeReleaseLuidAndAttributesArray)
00041
#pragma alloc_text(PAGE,SeCaptureSidAndAttributesArray)
00042
#pragma alloc_text(PAGE,SeReleaseSidAndAttributesArray)
00043
#pragma alloc_text(PAGE,SeComputeQuotaInformationSize)
00044
#pragma alloc_text(PAGE,SepCopyProxyData)
00045
#pragma alloc_text(PAGE,SepProbeAndCaptureQosData)
00046
#pragma alloc_text(PAGE,SepFreeProxyData)
00047
#endif
00048
00049 #define LongAligned( ptr ) (LongAlignPtr(ptr) == (ptr))
00050
00051
00052
NTSTATUS
00053 SeCaptureSecurityDescriptor (
00054 IN PSECURITY_DESCRIPTOR InputSecurityDescriptor,
00055 IN KPROCESSOR_MODE RequestorMode,
00056 IN POOL_TYPE PoolType,
00057 IN BOOLEAN ForceCapture,
00058 OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor
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
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 {
00118 SECURITY_DESCRIPTOR Captured;
00119 SECURITY_DESCRIPTOR_RELATIVE *PIOutputSecurityDescriptor;
00120 PCHAR DescriptorOffset;
00121
00122 ULONG SaclSize;
00123 ULONG NewSaclSize;
00124
00125 ULONG DaclSize;
00126 ULONG NewDaclSize;
00127
00128 ULONG OwnerSubAuthorityCount;
00129 ULONG OwnerSize;
00130 ULONG NewOwnerSize;
00131
00132 ULONG GroupSubAuthorityCount;
00133 ULONG GroupSize;
00134 ULONG NewGroupSize;
00135
00136 ULONG
Size;
00137
00138
PAGED_CODE();
00139
00140
00141
00142
00143
00144
00145
if (InputSecurityDescriptor ==
NULL) {
00146
00147 (*OutputSecurityDescriptor) =
NULL;
00148
00149
return STATUS_SUCCESS;
00150
00151 }
00152
00153
00154
00155
00156
00157
00158
if ((RequestorMode ==
KernelMode) && (ForceCapture ==
FALSE)) {
00159
00160
00161
00162
00163
00164
00165 (*OutputSecurityDescriptor) = InputSecurityDescriptor;
00166
00167
return STATUS_SUCCESS;
00168
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
if (RequestorMode !=
KernelMode) {
00179
00180
00181
00182
00183
00184
try {
00185
00186
00187
00188
00189
00190
ProbeForRead( InputSecurityDescriptor,
00191
sizeof(SECURITY_DESCRIPTOR_RELATIVE),
00192
sizeof(ULONG) );
00193
00194
00195
00196
00197
00198 RtlCopyMemory( (&Captured),
00199 InputSecurityDescriptor,
00200
sizeof(SECURITY_DESCRIPTOR_RELATIVE) );
00201
00202
00203
00204
00205
00206
00207
if (!(Captured.Control & SE_SELF_RELATIVE)) {
00208
00209
if ((ULONG_PTR) InputSecurityDescriptor & (
sizeof(ULONG_PTR) - 1)) {
00210
ExRaiseDatatypeMisalignment();
00211 }
00212 }
00213
00214
00215 } except(
EXCEPTION_EXECUTE_HANDLER) {
00216
return GetExceptionCode();
00217 }
00218
00219 }
else {
00220
00221
00222
00223
00224
00225
00226
00227
00228 RtlCopyMemory( (&Captured),
00229 InputSecurityDescriptor,
00230
sizeof(SECURITY_DESCRIPTOR_RELATIVE) );
00231
00232 }
00233
00234
00235
00236
00237
00238
if (Captured.Revision != SECURITY_DESCRIPTOR_REVISION) {
00239
return STATUS_UNKNOWN_REVISION;
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
try {
00253
00254 Captured.Owner = RtlpOwnerAddrSecurityDescriptor(
00255 (SECURITY_DESCRIPTOR *)InputSecurityDescriptor
00256 );
00257 Captured.Group = RtlpGroupAddrSecurityDescriptor(
00258 (SECURITY_DESCRIPTOR *)InputSecurityDescriptor
00259 );
00260 Captured.Sacl = RtlpSaclAddrSecurityDescriptor (
00261 (SECURITY_DESCRIPTOR *)InputSecurityDescriptor
00262 );
00263 Captured.Dacl = RtlpDaclAddrSecurityDescriptor (
00264 (SECURITY_DESCRIPTOR *)InputSecurityDescriptor
00265 );
00266 Captured.Control &= ~SE_SELF_RELATIVE;
00267
00268 } except(
EXCEPTION_EXECUTE_HANDLER) {
00269
return GetExceptionCode();
00270 }
00271
00272
00273
00274
00275
00276
00277
00278
00279 SaclSize = 0;
00280 DaclSize = 0;
00281
00282 NewSaclSize = 0;
00283 NewDaclSize = 0;
00284 NewGroupSize = 0;
00285 NewOwnerSize = 0;
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
if ((Captured.Control & SE_SACL_PRESENT) &&
00297 (Captured.Sacl !=
NULL) ) {
00298
00299
if (RequestorMode !=
KernelMode) {
00300
00301
try {
00302 SaclSize =
ProbeAndReadUshort( &(Captured.Sacl->AclSize) );
00303
ProbeForRead( Captured.Sacl,
00304 SaclSize,
00305
sizeof(ULONG) );
00306 } except(
EXCEPTION_EXECUTE_HANDLER) {
00307
return GetExceptionCode();
00308 }
00309
00310 }
else {
00311
00312 SaclSize = Captured.Sacl->AclSize;
00313
00314 }
00315
00316 NewSaclSize = (ULONG)LongAlignSize( SaclSize );
00317
00318 }
else {
00319
00320
00321
00322 Captured.Sacl =
NULL;
00323 }
00324
00325
00326
00327
00328
00329
if ((Captured.Control & SE_DACL_PRESENT) &&
00330 (Captured.Dacl !=
NULL) ) {
00331
00332
if (RequestorMode !=
KernelMode) {
00333
00334
try {
00335 DaclSize =
ProbeAndReadUshort( &(Captured.Dacl->AclSize) );
00336
ProbeForRead( Captured.Dacl,
00337 DaclSize,
00338
sizeof(ULONG) );
00339 } except(
EXCEPTION_EXECUTE_HANDLER) {
00340
return GetExceptionCode();
00341 }
00342
00343 }
else {
00344
00345 DaclSize = Captured.Dacl->AclSize;
00346
00347 }
00348
00349 NewDaclSize = (ULONG)LongAlignSize( DaclSize );
00350
00351 }
else {
00352
00353
00354
00355 Captured.Dacl =
NULL;
00356 }
00357
00358
00359
00360
00361
00362
if (Captured.Owner !=
NULL) {
00363
00364
if (RequestorMode !=
KernelMode) {
00365
00366
try {
00367 OwnerSubAuthorityCount =
00368
ProbeAndReadUchar( &(((SID *)(Captured.Owner))->SubAuthorityCount) );
00369 OwnerSize =
RtlLengthRequiredSid( OwnerSubAuthorityCount );
00370
ProbeForRead( Captured.Owner,
00371 OwnerSize,
00372
sizeof(ULONG) );
00373 } except(
EXCEPTION_EXECUTE_HANDLER) {
00374
return GetExceptionCode();
00375 }
00376
00377 }
else {
00378
00379 OwnerSubAuthorityCount = ((SID *)(Captured.Owner))->SubAuthorityCount;
00380 OwnerSize =
RtlLengthRequiredSid( OwnerSubAuthorityCount );
00381
00382 }
00383
00384 NewOwnerSize = (ULONG)LongAlignSize( OwnerSize );
00385
00386 }
00387
00388
00389
00390
00391
00392
if (Captured.Group !=
NULL) {
00393
00394
if (RequestorMode !=
KernelMode) {
00395
00396
try {
00397 GroupSubAuthorityCount =
00398
ProbeAndReadUchar( &(((SID *)(Captured.Group))->SubAuthorityCount) );
00399 GroupSize =
RtlLengthRequiredSid( GroupSubAuthorityCount );
00400
ProbeForRead( Captured.Group,
00401 GroupSize,
00402
sizeof(ULONG) );
00403 } except(
EXCEPTION_EXECUTE_HANDLER) {
00404
return GetExceptionCode();
00405 }
00406
00407 }
else {
00408
00409 GroupSubAuthorityCount = ((SID *)(Captured.Group))->SubAuthorityCount;
00410 GroupSize =
RtlLengthRequiredSid( GroupSubAuthorityCount );
00411
00412 }
00413
00414 NewGroupSize = (ULONG)LongAlignSize( GroupSize );
00415
00416 }
00417
00418
00419
00420
00421
00422
00423
00424
Size =
sizeof(SECURITY_DESCRIPTOR_RELATIVE) +
00425 NewSaclSize +
00426 NewDaclSize +
00427 NewOwnerSize +
00428 NewGroupSize;
00429
00430 (PIOutputSecurityDescriptor) = (SECURITY_DESCRIPTOR_RELATIVE *)
ExAllocatePoolWithTag( PoolType,
00431
Size,
00432 'cSeS' );
00433
00434
if ( PIOutputSecurityDescriptor ==
NULL ) {
00435
return( STATUS_INSUFFICIENT_RESOURCES );
00436 }
00437
00438 (*OutputSecurityDescriptor) = (PSECURITY_DESCRIPTOR)PIOutputSecurityDescriptor;
00439 DescriptorOffset = (PCHAR)(PIOutputSecurityDescriptor);
00440
00441
00442
00443
00444
00445
00446 RtlCopyMemory( DescriptorOffset,
00447 &Captured,
00448
sizeof(SECURITY_DESCRIPTOR_RELATIVE) );
00449 DescriptorOffset +=
sizeof(SECURITY_DESCRIPTOR_RELATIVE);
00450
00451
00452
00453
00454
00455 PIOutputSecurityDescriptor->Control |= SE_SELF_RELATIVE;
00456
00457
00458
00459
00460
00461
00462
if ((Captured.Control & SE_SACL_PRESENT) && (Captured.Sacl !=
NULL)) {
00463
00464
00465
try {
00466 RtlCopyMemory( DescriptorOffset,
00467 Captured.Sacl,
00468 SaclSize );
00469
00470
00471 } except(
EXCEPTION_EXECUTE_HANDLER) {
00472
ExFreePool( PIOutputSecurityDescriptor );
00473
return GetExceptionCode();
00474 }
00475
00476
if ((RequestorMode !=
KernelMode) &&
00477 (!
SepCheckAcl( (PACL) DescriptorOffset, SaclSize )) ) {
00478
00479
ExFreePool( PIOutputSecurityDescriptor );
00480
return STATUS_INVALID_ACL;
00481 }
00482
00483
00484
00485
00486
00487 PIOutputSecurityDescriptor->Sacl =
00488 RtlPointerToOffset( PIOutputSecurityDescriptor,
00489 DescriptorOffset,
00490 );
00491
00492 ((PACL) DescriptorOffset)->AclSize = (
USHORT) NewSaclSize;
00493 DescriptorOffset += NewSaclSize;
00494 }
else {
00495 PIOutputSecurityDescriptor->Sacl = 0;
00496 }
00497
00498
00499
00500
00501
00502
00503
if ((Captured.Control & SE_DACL_PRESENT) && (Captured.Dacl !=
NULL)) {
00504
00505
00506
try {
00507 RtlCopyMemory( DescriptorOffset,
00508 Captured.Dacl,
00509 DaclSize );
00510 } except(
EXCEPTION_EXECUTE_HANDLER) {
00511
ExFreePool( PIOutputSecurityDescriptor );
00512
return GetExceptionCode();
00513 }
00514
00515
if ((RequestorMode !=
KernelMode) &&
00516 (!
SepCheckAcl( (PACL) DescriptorOffset, DaclSize )) ) {
00517
00518
ExFreePool( PIOutputSecurityDescriptor );
00519
return STATUS_INVALID_ACL;
00520 }
00521
00522
00523
00524
00525
00526 PIOutputSecurityDescriptor->Dacl =
00527 RtlPointerToOffset(
00528 PIOutputSecurityDescriptor,
00529 DescriptorOffset
00530 );
00531
00532 ((PACL) DescriptorOffset)->AclSize = (
USHORT) NewDaclSize;
00533 DescriptorOffset += NewDaclSize;
00534 }
else {
00535 PIOutputSecurityDescriptor->Dacl = 0;
00536 }
00537
00538
00539
00540
00541
00542
00543
if (Captured.Owner !=
NULL) {
00544
00545
00546
try {
00547 RtlCopyMemory( DescriptorOffset,
00548 Captured.Owner,
00549 OwnerSize );
00550 ((SID *) (DescriptorOffset))->SubAuthorityCount = (UCHAR) OwnerSubAuthorityCount;
00551
00552 } except(
EXCEPTION_EXECUTE_HANDLER) {
00553
ExFreePool( PIOutputSecurityDescriptor );
00554
return GetExceptionCode();
00555 }
00556
00557
if ((RequestorMode !=
KernelMode) &&
00558 (!
RtlValidSid( (PSID) DescriptorOffset )) ) {
00559
00560
ExFreePool( PIOutputSecurityDescriptor );
00561
return STATUS_INVALID_SID;
00562 }
00563
00564
00565
00566
00567
00568 PIOutputSecurityDescriptor->Owner =
00569 RtlPointerToOffset(
00570 PIOutputSecurityDescriptor,
00571 DescriptorOffset
00572 );
00573
00574 DescriptorOffset += NewOwnerSize;
00575
00576 }
else {
00577 PIOutputSecurityDescriptor->Owner = 0;
00578 }
00579
00580
00581
00582
00583
00584
00585
if (Captured.Group !=
NULL) {
00586
00587
00588
try {
00589 RtlCopyMemory( DescriptorOffset,
00590 Captured.Group,
00591 GroupSize );
00592
00593 ((SID *) DescriptorOffset)->SubAuthorityCount = (UCHAR) GroupSubAuthorityCount;
00594 } except(
EXCEPTION_EXECUTE_HANDLER) {
00595
ExFreePool( PIOutputSecurityDescriptor );
00596
return GetExceptionCode();
00597 }
00598
00599
if ((RequestorMode !=
KernelMode) &&
00600 (!
RtlValidSid( (PSID) DescriptorOffset )) ) {
00601
00602
ExFreePool( PIOutputSecurityDescriptor );
00603
return STATUS_INVALID_SID;
00604 }
00605
00606
00607
00608
00609
00610 PIOutputSecurityDescriptor->Group =
00611 RtlPointerToOffset(
00612 PIOutputSecurityDescriptor,
00613 DescriptorOffset
00614 );
00615
00616 DescriptorOffset += NewGroupSize;
00617 }
else {
00618 PIOutputSecurityDescriptor->Group = 0;
00619 }
00620
00621
00622
00623
00624
00625
return STATUS_SUCCESS;
00626
00627 }
00628
00629
00630
VOID
00631 SeReleaseSecurityDescriptor (
00632 IN PSECURITY_DESCRIPTOR CapturedSecurityDescriptor,
00633 IN KPROCESSOR_MODE RequestorMode,
00634 IN BOOLEAN ForceCapture
00635 )
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660 {
00661
00662
00663
00664
00665
00666
PAGED_CODE();
00667
00668
if ( ((RequestorMode ==
KernelMode) && (ForceCapture ==
TRUE)) ||
00669 (RequestorMode ==
UserMode ) ) {
00670
if ( CapturedSecurityDescriptor ) {
00671
ExFreePool(CapturedSecurityDescriptor);
00672 }
00673 }
00674
00675
return;
00676
00677 }
00678
00679
00680
NTSTATUS
00681 SepCopyProxyData (
00682 OUT PSECURITY_TOKEN_PROXY_DATA * DestProxyData,
00683 IN PSECURITY_TOKEN_PROXY_DATA SourceProxyData
00684 )
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704 {
00705
00706
PAGED_CODE();
00707
00708 *DestProxyData =
ExAllocatePoolWithTag(
PagedPool,
sizeof( SECURITY_TOKEN_PROXY_DATA ), 'dPoT' );
00709
00710
if (*DestProxyData ==
NULL) {
00711
return( STATUS_INSUFFICIENT_RESOURCES );
00712 }
00713
00714
00715
00716 (*DestProxyData)->PathInfo.Buffer =
ExAllocatePoolWithTag(
PagedPool, SourceProxyData->PathInfo.Length, 'dPoT' );
00717
00718
if ((*DestProxyData)->PathInfo.Buffer ==
NULL) {
00719
ExFreePool( *DestProxyData );
00720 *DestProxyData =
NULL;
00721
return( STATUS_INSUFFICIENT_RESOURCES );
00722 }
00723
00724 (*DestProxyData)->Length = SourceProxyData->Length;
00725 (*DestProxyData)->ProxyClass = SourceProxyData->ProxyClass;
00726 (*DestProxyData)->PathInfo.MaximumLength =
00727 (*DestProxyData)->PathInfo.Length = SourceProxyData->PathInfo.Length;
00728 (*DestProxyData)->ContainerMask = SourceProxyData->ContainerMask;
00729 (*DestProxyData)->ObjectMask = SourceProxyData->ObjectMask;
00730
00731
RtlCopyUnicodeString( &(*DestProxyData)->PathInfo, &SourceProxyData->PathInfo );
00732
00733
return( STATUS_SUCCESS );
00734 }
00735
00736
VOID
00737 SepFreeProxyData (
00738 IN PSECURITY_TOKEN_PROXY_DATA ProxyData
00739 )
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756 {
00757
PAGED_CODE();
00758
00759
if (ProxyData !=
NULL) {
00760
00761
if (ProxyData->PathInfo.Buffer !=
NULL) {
00762
ExFreePool( ProxyData->PathInfo.Buffer );
00763 }
00764
00765
ExFreePool( ProxyData );
00766 }
00767 }
00768
00769
00770
00771
00772
NTSTATUS
00773 SepProbeAndCaptureQosData(
00774 IN PSECURITY_ADVANCED_QUALITY_OF_SERVICE CapturedSecurityQos
00775 )
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800 {
00801
NTSTATUS Status;
00802 PSECURITY_TOKEN_PROXY_DATA CapturedProxyData;
00803 PSECURITY_TOKEN_AUDIT_DATA CapturedAuditData;
00804 SECURITY_TOKEN_PROXY_DATA StackProxyData;
00805
PAGED_CODE();
00806
00807 CapturedProxyData = CapturedSecurityQos->ProxyData;
00808 CapturedSecurityQos->ProxyData =
NULL;
00809 CapturedAuditData = CapturedSecurityQos->AuditData;
00810 CapturedSecurityQos->AuditData =
NULL;
00811
00812
if (ARGUMENT_PRESENT( CapturedProxyData )) {
00813
00814
00815
00816
00817
00818
ProbeForRead(
00819 CapturedProxyData,
00820
sizeof(SECURITY_TOKEN_PROXY_DATA),
00821
sizeof(ULONG)
00822 );
00823
00824 StackProxyData = *CapturedProxyData;
00825
00826
if (StackProxyData.Length !=
sizeof( SECURITY_TOKEN_PROXY_DATA )) {
00827
return( STATUS_INVALID_PARAMETER );
00828 }
00829
00830
00831
00832
00833
00834
00835
ProbeForRead(
00836 StackProxyData.PathInfo.Buffer,
00837 StackProxyData.PathInfo.Length,
00838
sizeof( UCHAR )
00839 );
00840
00841
Status =
SepCopyProxyData( &CapturedSecurityQos->ProxyData, &StackProxyData );
00842
00843
if (!
NT_SUCCESS(
Status)) {
00844
00845
if (CapturedSecurityQos->ProxyData !=
NULL) {
00846
SepFreeProxyData( CapturedSecurityQos->ProxyData );
00847 CapturedSecurityQos->ProxyData =
NULL;
00848 }
00849
00850
return(
Status );
00851 }
00852
00853 }
00854
00855
if (ARGUMENT_PRESENT( CapturedAuditData )) {
00856
00857 PSECURITY_TOKEN_AUDIT_DATA LocalAuditData;
00858
00859
00860
00861
00862
00863
ProbeForRead(
00864 CapturedAuditData,
00865
sizeof( SECURITY_TOKEN_AUDIT_DATA ),
00866
sizeof( ULONG )
00867 );
00868
00869
00870 LocalAuditData =
ExAllocatePool(
PagedPool,
sizeof( SECURITY_TOKEN_AUDIT_DATA ));
00871
00872
if (LocalAuditData ==
NULL) {
00873
00874
00875
00876
00877
00878
SepFreeProxyData( CapturedSecurityQos->ProxyData );
00879 CapturedSecurityQos->ProxyData =
NULL;
00880
00881
return( STATUS_INSUFFICIENT_RESOURCES );
00882
00883 }
00884
00885
00886
00887
00888
00889
00890
00891 CapturedSecurityQos->AuditData = LocalAuditData;
00892
00893 *CapturedSecurityQos->AuditData = *CapturedAuditData;
00894
00895
if ( LocalAuditData->Length !=
sizeof( SECURITY_TOKEN_AUDIT_DATA ) ) {
00896
SepFreeProxyData( CapturedSecurityQos->ProxyData );
00897 CapturedSecurityQos->ProxyData =
NULL;
00898
ExFreePool(CapturedSecurityQos->AuditData);
00899 CapturedSecurityQos->AuditData =
NULL;
00900
return( STATUS_INVALID_PARAMETER );
00901 }
00902 }
00903
00904
return( STATUS_SUCCESS );
00905
00906 }
00907
00908
00909
VOID
00910 SeFreeCapturedSecurityQos(
00911 IN PVOID SecurityQos
00912 )
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932 {
00933 PSECURITY_ADVANCED_QUALITY_OF_SERVICE IAdvancedSecurityQos;
00934
00935
PAGED_CODE();
00936
00937 IAdvancedSecurityQos = (PSECURITY_ADVANCED_QUALITY_OF_SERVICE)
SecurityQos;
00938
00939
if (IAdvancedSecurityQos->Length ==
sizeof( SECURITY_ADVANCED_QUALITY_OF_SERVICE )) {
00940
00941
if (IAdvancedSecurityQos->AuditData !=
NULL) {
00942
ExFreePool( IAdvancedSecurityQos->AuditData );
00943 }
00944
00945
SepFreeProxyData( IAdvancedSecurityQos->ProxyData );
00946 }
00947
00948
return;
00949 }
00950
00951
00952
NTSTATUS
00953 SeCaptureSecurityQos (
00954 IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
00955 IN KPROCESSOR_MODE RequestorMode,
00956 OUT PBOOLEAN SecurityQosPresent,
00957 OUT PSECURITY_ADVANCED_QUALITY_OF_SERVICE CapturedSecurityQos
00958 )
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989 {
00990
00991 PSECURITY_QUALITY_OF_SERVICE LocalSecurityQos;
00992 ULONG LocalQosLength;
00993 PSECURITY_ADVANCED_QUALITY_OF_SERVICE LocalAdvancedSecurityQos;
00994
NTSTATUS Status;
00995 BOOLEAN CapturedQos;
00996
00997
PAGED_CODE();
00998
00999 CapturedQos =
FALSE;
01000
01001
01002
01003
01004 (*SecurityQosPresent) =
FALSE;
01005
01006
01007
01008
01009
01010
if (RequestorMode !=
KernelMode) {
01011
try {
01012
01013
if ( ARGUMENT_PRESENT(
ObjectAttributes) ) {
01014
01015
ProbeForRead(
ObjectAttributes,
01016
sizeof(OBJECT_ATTRIBUTES),
01017
sizeof(ULONG)
01018 );
01019
01020 LocalSecurityQos =
01021 (PSECURITY_QUALITY_OF_SERVICE)
ObjectAttributes->SecurityQualityOfService;
01022
01023
if ( ARGUMENT_PRESENT(LocalSecurityQos) ) {
01024
01025
ProbeForRead(
01026 LocalSecurityQos,
01027
sizeof(SECURITY_QUALITY_OF_SERVICE),
01028
sizeof(ULONG)
01029 );
01030
01031 LocalQosLength = LocalSecurityQos->Length;
01032
01033
01034
01035
01036
01037
01038
if (LocalQosLength ==
sizeof( SECURITY_QUALITY_OF_SERVICE )) {
01039
01040
01041
01042
01043
01044 (*SecurityQosPresent) =
TRUE;
01045 RtlMoveMemory( CapturedSecurityQos, LocalSecurityQos,
sizeof( SECURITY_QUALITY_OF_SERVICE ));
01046 CapturedSecurityQos->ProxyData =
NULL;
01047 CapturedSecurityQos->AuditData =
NULL;
01048 CapturedSecurityQos->Length = LocalQosLength;
01049
01050 }
else {
01051
01052
if (LocalQosLength ==
sizeof( SECURITY_ADVANCED_QUALITY_OF_SERVICE )) {
01053
01054 LocalAdvancedSecurityQos =
01055 (PSECURITY_ADVANCED_QUALITY_OF_SERVICE)
ObjectAttributes->SecurityQualityOfService;
01056
01057
ProbeForRead(
01058 LocalAdvancedSecurityQos,
01059
sizeof(SECURITY_ADVANCED_QUALITY_OF_SERVICE),
01060
sizeof(ULONG)
01061 );
01062
01063 (*SecurityQosPresent) =
TRUE;
01064 *CapturedSecurityQos = *LocalAdvancedSecurityQos;
01065 CapturedSecurityQos->Length = LocalQosLength;
01066
01067
01068
01069
01070
01071
if ( ARGUMENT_PRESENT(CapturedSecurityQos->ProxyData) || ARGUMENT_PRESENT( CapturedSecurityQos->AuditData ) ) {
01072
01073 CapturedQos =
TRUE;
01074
Status =
SepProbeAndCaptureQosData( CapturedSecurityQos );
01075
01076
if (!
NT_SUCCESS(
Status )) {
01077
01078
return(
Status );
01079 }
01080 }
01081
01082 }
else {
01083
01084
return( STATUS_INVALID_PARAMETER );
01085 }
01086 }
01087
01088 }
01089
01090
01091 }
01092
01093 } except(
EXCEPTION_EXECUTE_HANDLER) {
01094
01095
01096
01097
01098
01099
01100
if ( CapturedQos ) {
01101
01102
SepFreeProxyData( CapturedSecurityQos->ProxyData );
01103
01104
if ( CapturedSecurityQos->AuditData !=
NULL ) {
01105
ExFreePool( CapturedSecurityQos->AuditData );
01106 }
01107 }
01108
01109
return GetExceptionCode();
01110 }
01111
01112
01113 }
else {
01114
01115
if ( ARGUMENT_PRESENT(
ObjectAttributes) ) {
01116
if ( ARGUMENT_PRESENT(
ObjectAttributes->SecurityQualityOfService) ) {
01117 (*SecurityQosPresent) =
TRUE;
01118
01119
if (((PSECURITY_QUALITY_OF_SERVICE)(
ObjectAttributes->SecurityQualityOfService))->Length ==
sizeof( SECURITY_QUALITY_OF_SERVICE )) {
01120
01121 RtlMoveMemory( CapturedSecurityQos,
ObjectAttributes->SecurityQualityOfService,
sizeof( SECURITY_QUALITY_OF_SERVICE ));
01122 CapturedSecurityQos->ProxyData =
NULL;
01123 CapturedSecurityQos->AuditData =
NULL;
01124
01125 }
else {
01126
01127 (*CapturedSecurityQos) =
01128 (*(SECURITY_ADVANCED_QUALITY_OF_SERVICE *)(
ObjectAttributes->SecurityQualityOfService));
01129 }
01130
01131
01132 }
01133 }
01134
01135 }
01136
01137
return STATUS_SUCCESS;
01138 }
01139
01140
NTSTATUS
01141 SeCaptureSid (
01142 IN PSID InputSid,
01143 IN KPROCESSOR_MODE RequestorMode,
01144 IN PVOID CaptureBuffer OPTIONAL,
01145 IN ULONG CaptureBufferLength,
01146 IN POOL_TYPE PoolType,
01147 IN BOOLEAN ForceCapture,
01148 OUT PSID *CapturedSid
01149 )
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210 {
01211
01212
01213
01214 ULONG GetSidSubAuthorityCount;
01215 ULONG SidSize;
01216
01217
PAGED_CODE();
01218
01219
01220
01221
01222
01223
01224
if ((RequestorMode ==
KernelMode) && (ForceCapture ==
FALSE)) {
01225
01226
01227
01228
01229
01230
01231 (*CapturedSid) = InputSid;
01232
01233
return STATUS_SUCCESS;
01234 }
01235
01236
01237
01238
01239
01240
01241
if (RequestorMode !=
KernelMode) {
01242
01243
try {
01244 GetSidSubAuthorityCount =
01245
ProbeAndReadUchar( &(((SID *)(InputSid))->SubAuthorityCount) );
01246 SidSize =
RtlLengthRequiredSid( GetSidSubAuthorityCount );
01247
ProbeForRead( InputSid,
01248 SidSize,
01249
sizeof(ULONG) );
01250 } except(
EXCEPTION_EXECUTE_HANDLER) {
01251
return GetExceptionCode();
01252 }
01253
01254 }
else {
01255
01256 GetSidSubAuthorityCount = ((SID *)(InputSid))->SubAuthorityCount;
01257 SidSize =
RtlLengthRequiredSid( GetSidSubAuthorityCount );
01258
01259 }
01260
01261
01262
01263
01264
01265
01266
01267
if (ARGUMENT_PRESENT(CaptureBuffer)) {
01268
01269
if (SidSize > CaptureBufferLength) {
01270
return STATUS_BUFFER_TOO_SMALL;
01271 }
else {
01272
01273 (*CapturedSid) = CaptureBuffer;
01274 }
01275
01276 }
else {
01277
01278 (*CapturedSid) = (PSID)
ExAllocatePoolWithTag(PoolType, SidSize, 'iSeS');
01279
01280
if ( *CapturedSid ==
NULL ) {
01281
return( STATUS_INSUFFICIENT_RESOURCES );
01282 }
01283
01284 }
01285
01286
01287
01288
01289
01290
try {
01291
01292 RtlMoveMemory( (*CapturedSid), InputSid, SidSize );
01293 ((SID *)(*CapturedSid))->SubAuthorityCount = (UCHAR) GetSidSubAuthorityCount;
01294
01295 } except(
EXCEPTION_EXECUTE_HANDLER) {
01296
if (!ARGUMENT_PRESENT(CaptureBuffer)) {
01297
ExFreePool( (*CapturedSid) );
01298 *CapturedSid =
NULL;
01299 }
01300
01301
return GetExceptionCode();
01302 }
01303
01304
if ((!
RtlValidSid( (*CapturedSid) )) ) {
01305
01306
if (!ARGUMENT_PRESENT(CaptureBuffer)) {
01307
ExFreePool( (*CapturedSid) );
01308 *CapturedSid =
NULL;
01309 }
01310
01311
return STATUS_INVALID_SID;
01312 }
01313
01314
return STATUS_SUCCESS;
01315
01316 }
01317
01318
01319
VOID
01320 SeReleaseSid (
01321 IN PSID CapturedSid,
01322 IN KPROCESSOR_MODE RequestorMode,
01323 IN BOOLEAN ForceCapture
01324 )
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350 {
01351
01352
01353
01354
01355
01356
PAGED_CODE();
01357
01358
if ( ((RequestorMode ==
KernelMode) && (ForceCapture ==
TRUE)) ||
01359 (RequestorMode ==
UserMode ) ) {
01360
01361
ExFreePool(CapturedSid);
01362
01363 }
01364
01365
return;
01366
01367 }
01368
01369
NTSTATUS
01370 SeCaptureAcl (
01371 IN PACL InputAcl,
01372 IN KPROCESSOR_MODE RequestorMode,
01373 IN PVOID CaptureBuffer OPTIONAL,
01374 IN ULONG CaptureBufferLength,
01375 IN POOL_TYPE PoolType,
01376 IN BOOLEAN ForceCapture,
01377 OUT PACL *CapturedAcl,
01378 OUT PULONG AlignedAclSize
01379 )
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443 {
01444
01445 ULONG AclSize;
01446
01447
PAGED_CODE();
01448
01449
01450
01451
01452
01453
01454
if ((RequestorMode ==
KernelMode) && (ForceCapture ==
FALSE)) {
01455
01456
01457
01458
01459
01460
01461 (*CapturedAcl) = InputAcl;
01462
01463
return STATUS_SUCCESS;
01464 }
01465
01466
01467
01468
01469
01470
01471
if (RequestorMode !=
KernelMode) {
01472
01473
try {
01474
01475 AclSize =
ProbeAndReadUshort( &(InputAcl->AclSize) );
01476
01477
ProbeForRead( InputAcl,
01478 AclSize,
01479
sizeof(ULONG) );
01480
01481 } except(
EXCEPTION_EXECUTE_HANDLER) {
01482
return GetExceptionCode();
01483 }
01484
01485 }
else {
01486
01487 AclSize = InputAcl->AclSize;
01488
01489 }
01490
01491
01492
01493
01494
01495
01496
if (AclSize <
sizeof(ACL)) {
01497
return( STATUS_INVALID_ACL );
01498 }
01499
01500 (*AlignedAclSize) = (ULONG)LongAlignSize( AclSize );
01501
01502
01503
01504
01505
01506
01507
01508
if (ARGUMENT_PRESENT(CaptureBuffer)) {
01509
01510
if (AclSize > CaptureBufferLength) {
01511
return STATUS_BUFFER_TOO_SMALL;
01512 }
else {
01513
01514 (*CapturedAcl) = CaptureBuffer;
01515 }
01516
01517 }
else {
01518
01519 (*CapturedAcl) = (PACL)
ExAllocatePoolWithTag(PoolType, AclSize, 'cAeS');
01520
01521
if ( *CapturedAcl ==
NULL ) {
01522
return( STATUS_INSUFFICIENT_RESOURCES );
01523 }
01524
01525 }
01526
01527
01528
01529
01530
01531
try {
01532
01533 RtlMoveMemory( (*CapturedAcl), InputAcl, AclSize );
01534
01535 } except(
EXCEPTION_EXECUTE_HANDLER) {
01536
if (!ARGUMENT_PRESENT(CaptureBuffer)) {
01537
ExFreePool( (*CapturedAcl) );
01538 }
01539
01540 *CapturedAcl =
NULL;
01541
return GetExceptionCode();
01542 }
01543
01544
if ( (!
SepCheckAcl( (*CapturedAcl), AclSize )) ) {
01545
01546
if (!ARGUMENT_PRESENT(CaptureBuffer)) {
01547
ExFreePool( (*CapturedAcl) );
01548 }
01549
01550 *CapturedAcl =
NULL;
01551
return STATUS_INVALID_ACL;
01552 }
01553
01554
return STATUS_SUCCESS;
01555
01556 }
01557
01558
01559
VOID
01560 SeReleaseAcl (
01561 IN PACL CapturedAcl,
01562 IN KPROCESSOR_MODE RequestorMode,
01563 IN BOOLEAN ForceCapture
01564 )
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590 {
01591
01592
01593
01594
01595
01596
PAGED_CODE();
01597
01598
if ( ((RequestorMode ==
KernelMode) && (ForceCapture ==
TRUE)) ||
01599 (RequestorMode ==
UserMode ) ) {
01600
01601
ExFreePool(CapturedAcl);
01602
01603 }
01604
01605 }
01606
01607
NTSTATUS
01608 SeCaptureLuidAndAttributesArray (
01609 IN PLUID_AND_ATTRIBUTES InputArray,
01610 IN ULONG ArrayCount,
01611 IN KPROCESSOR_MODE RequestorMode,
01612 IN PVOID CaptureBuffer OPTIONAL,
01613 IN ULONG CaptureBufferLength,
01614 IN POOL_TYPE PoolType,
01615 IN BOOLEAN ForceCapture,
01616 OUT PLUID_AND_ATTRIBUTES *CapturedArray,
01617 OUT PULONG AlignedArraySize
01618 )
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684 {
01685
01686 ULONG ArraySize;
01687
01688
PAGED_CODE();
01689
01690
01691
01692
01693
01694
if (ArrayCount == 0) {
01695 (*CapturedArray) =
NULL;
01696 (*AlignedArraySize) = 0;
01697
return STATUS_SUCCESS;
01698 }
01699
01700
01701
01702
01703
01704
if (ArrayCount >
SEP_MAX_PRIVILEGE_COUNT) {
01705
return(STATUS_INVALID_PARAMETER);
01706 }
01707
01708
01709
01710
01711
01712
01713
if ((RequestorMode ==
KernelMode) && (ForceCapture ==
FALSE)) {
01714
01715
01716
01717
01718
01719
01720 (*CapturedArray) =
InputArray;
01721
01722
return STATUS_SUCCESS;
01723 }
01724
01725
01726
01727
01728
01729
01730 ArraySize = ArrayCount * (ULONG)
sizeof(LUID_AND_ATTRIBUTES);
01731 (*AlignedArraySize) = (ULONG)LongAlignSize( ArraySize );
01732
01733
if (RequestorMode !=
KernelMode) {
01734
01735
try {
01736
01737
01738
ProbeForRead(
InputArray,
01739 ArraySize,
01740
sizeof(ULONG) );
01741
01742 } except(
EXCEPTION_EXECUTE_HANDLER) {
01743
return GetExceptionCode();
01744 }
01745
01746 }
01747
01748
01749
01750
01751
01752
01753
01754
01755
if (ARGUMENT_PRESENT(CaptureBuffer)) {
01756
01757
if (ArraySize > CaptureBufferLength) {
01758
return STATUS_BUFFER_TOO_SMALL;
01759 }
else {
01760
01761 (*CapturedArray) = CaptureBuffer;
01762 }
01763
01764 }
else {
01765
01766 (*CapturedArray) =
01767 (PLUID_AND_ATTRIBUTES)
ExAllocatePoolWithTag(PoolType, ArraySize, 'uLeS');
01768
01769
if ( *CapturedArray ==
NULL ) {
01770
return( STATUS_INSUFFICIENT_RESOURCES );
01771 }
01772
01773 }
01774
01775
01776
01777
01778
01779
try {
01780
01781 RtlMoveMemory( (*CapturedArray),
InputArray, ArraySize );
01782
01783 } except(
EXCEPTION_EXECUTE_HANDLER) {
01784
if (!ARGUMENT_PRESENT(CaptureBuffer)) {
01785
ExFreePool( (*CapturedArray) );
01786 }
01787
01788
return GetExceptionCode();
01789 }
01790
01791
return STATUS_SUCCESS;
01792
01793 }
01794
01795
01796
VOID
01797 SeReleaseLuidAndAttributesArray (
01798 IN PLUID_AND_ATTRIBUTES CapturedArray,
01799 IN KPROCESSOR_MODE RequestorMode,
01800 IN BOOLEAN ForceCapture
01801 )
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827 {
01828
01829
01830
01831
01832
01833
PAGED_CODE();
01834
01835
if ( ((RequestorMode ==
KernelMode) && (ForceCapture ==
TRUE)) ||
01836 (RequestorMode ==
UserMode )) {
01837
01838
01839
01840
if (CapturedArray !=
NULL)
01841
ExFreePool(CapturedArray);
01842
01843 }
01844
01845
return;
01846
01847 }
01848
01849
NTSTATUS
01850 SeCaptureSidAndAttributesArray (
01851 IN PSID_AND_ATTRIBUTES InputArray,
01852 IN ULONG ArrayCount,
01853 IN KPROCESSOR_MODE RequestorMode,
01854 IN PVOID CaptureBuffer OPTIONAL,
01855 IN ULONG CaptureBufferLength,
01856 IN POOL_TYPE PoolType,
01857 IN BOOLEAN ForceCapture,
01858 OUT PSID_AND_ATTRIBUTES *CapturedArray,
01859 OUT PULONG AlignedArraySize
01860 )
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931 {
01932
01933
typedef struct _TEMP_ARRAY_ELEMENT {
01934 PISID Sid;
01935 ULONG SidLength;
01936 } TEMP_ARRAY_ELEMENT;
01937
01938
01939 TEMP_ARRAY_ELEMENT *TempArray;
01940
01941
NTSTATUS CompletionStatus = STATUS_SUCCESS;
01942
01943 ULONG ArraySize;
01944 ULONG AlignedLengthRequired;
01945
01946 ULONG NextIndex;
01947
01948 PSID_AND_ATTRIBUTES NextElement;
01949 PVOID NextBufferLocation;
01950
01951 ULONG GetSidSubAuthorityCount;
01952 ULONG SidSize;
01953 ULONG AlignedSidSize;
01954
01955
PAGED_CODE();
01956
01957
01958
01959
01960
01961
if (ArrayCount == 0) {
01962 (*CapturedArray) =
NULL;
01963 (*AlignedArraySize) = 0;
01964
return STATUS_SUCCESS;
01965 }
01966
01967
01968
01969
01970
01971
if (ArrayCount >
SEP_MAX_GROUP_COUNT) {
01972
return(STATUS_INVALID_PARAMETER);
01973 }
01974
01975
01976
01977
01978
01979
if ((RequestorMode ==
KernelMode) && (ForceCapture ==
FALSE)) {
01980
01981
01982
01983
01984
01985
01986 (*CapturedArray) =
InputArray;
01987
01988
return STATUS_SUCCESS;
01989 }
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030 ArraySize = ArrayCount * (ULONG)
sizeof(SID_AND_ATTRIBUTES);
02031 AlignedLengthRequired = (ULONG)LongAlignSize( ArraySize );
02032
02033
if (RequestorMode !=
KernelMode) {
02034
02035
02036
02037
02038
02039 TempArray =
02040 (TEMP_ARRAY_ELEMENT *)
ExAllocatePoolWithTag(PoolType, AlignedLengthRequired, 'aTeS');
02041
02042
if ( TempArray ==
NULL ) {
02043
return( STATUS_INSUFFICIENT_RESOURCES );
02044 }
02045
02046
02047
try {
02048
02049
02050
02051
02052
02053
ProbeForRead(
InputArray,
02054 ArraySize,
02055
sizeof(ULONG) );
02056
02057
02058
02059
02060
02061 NextIndex = 0;
02062
while (NextIndex < ArrayCount) {
02063 PSID TempSid;
02064
02065 TempSid =
InputArray[NextIndex].Sid;
02066 GetSidSubAuthorityCount =
02067
ProbeAndReadUchar( &((PISID)TempSid)->SubAuthorityCount);
02068
02069
if (GetSidSubAuthorityCount > SID_MAX_SUB_AUTHORITIES) {
02070 CompletionStatus = STATUS_INVALID_SID;
02071
break;
02072 }
02073
02074 TempArray[NextIndex].Sid = ((PISID)(TempSid));
02075 TempArray[NextIndex].SidLength =
02076
RtlLengthRequiredSid( GetSidSubAuthorityCount );
02077
02078
ProbeForRead( TempArray[NextIndex].Sid,
02079 TempArray[NextIndex].SidLength,
02080
sizeof(ULONG) );
02081
02082 AlignedLengthRequired +=
02083 (ULONG)LongAlignSize( TempArray[NextIndex].SidLength );
02084
02085 NextIndex += 1;
02086
02087 }
02088
02089 } except(
EXCEPTION_EXECUTE_HANDLER) {
02090
02091
ExFreePool( TempArray );
02092
return GetExceptionCode();
02093 }
02094
02095
if (!
NT_SUCCESS(CompletionStatus)) {
02096
ExFreePool( TempArray );
02097
return(CompletionStatus);
02098 }
02099
02100 }
else {
02101
02102
02103
02104
02105
02106
02107
02108 NextIndex = 0;
02109
02110
while (NextIndex < ArrayCount) {
02111
02112 GetSidSubAuthorityCount =
02113 ((PISID)(
InputArray[NextIndex].Sid))->SubAuthorityCount;
02114
02115 AlignedLengthRequired +=
02116 (ULONG)LongAlignSize(
RtlLengthRequiredSid(GetSidSubAuthorityCount));
02117
02118 NextIndex += 1;
02119
02120 }
02121
02122 }
02123
02124
02125
02126
02127
02128
02129
02130 (*AlignedArraySize) = AlignedLengthRequired;
02131
02132
02133
02134
02135
02136
02137
if (ARGUMENT_PRESENT(CaptureBuffer)) {
02138
02139
if (AlignedLengthRequired > CaptureBufferLength) {
02140
02141
if (RequestorMode !=
KernelMode) {
02142
ExFreePool( TempArray );
02143 }
02144
02145
return STATUS_BUFFER_TOO_SMALL;
02146
02147 }
else {
02148
02149 (*CapturedArray) = CaptureBuffer;
02150 }
02151
02152 }
else {
02153
02154 (*CapturedArray) =
02155 (PSID_AND_ATTRIBUTES)
ExAllocatePoolWithTag(PoolType, AlignedLengthRequired, 'aSeS');
02156
02157
if ( *CapturedArray ==
NULL ) {
02158
if (RequestorMode !=
KernelMode) {
02159
ExFreePool( TempArray );
02160 }
02161
return( STATUS_INSUFFICIENT_RESOURCES );
02162 }
02163 }
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176
if (RequestorMode !=
KernelMode) {
02177
try {
02178
02179
02180
02181
02182
02183
02184
02185 NextBufferLocation = (*CapturedArray);
02186 RtlMoveMemory( NextBufferLocation,
InputArray, ArraySize );
02187 NextBufferLocation = (PVOID)((ULONG_PTR)NextBufferLocation +
02188 (ULONG)LongAlignSize(ArraySize) );
02189
02190
02191
02192
02193
02194
02195 NextIndex = 0;
02196 NextElement = (*CapturedArray);
02197
while ( (NextIndex < ArrayCount) &&
02198 (CompletionStatus == STATUS_SUCCESS) ) {
02199
02200
02201 RtlMoveMemory( NextBufferLocation,
02202 TempArray[NextIndex].Sid,
02203 TempArray[NextIndex].SidLength );
02204
02205
02206 NextElement[NextIndex].Sid = (PSID)NextBufferLocation;
02207 NextBufferLocation =
02208 (PVOID)((ULONG_PTR)NextBufferLocation +
02209 (ULONG)LongAlignSize(TempArray[NextIndex].SidLength));
02210
02211
02212
02213
02214
02215
if (!
RtlValidSid(NextElement[NextIndex].Sid) ) {
02216 CompletionStatus = STATUS_INVALID_SID;
02217 }
else if (
RtlLengthSid(NextElement[NextIndex].Sid) != TempArray[NextIndex].SidLength) {
02218 CompletionStatus = STATUS_INVALID_SID;
02219 }
02220
02221
02222 NextIndex += 1;
02223
02224 }
02225
02226
02227 } except(
EXCEPTION_EXECUTE_HANDLER) {
02228
02229
if (!ARGUMENT_PRESENT(CaptureBuffer)) {
02230
ExFreePool( (*CapturedArray) );
02231 }
02232
02233
ExFreePool( TempArray );
02234
02235
return GetExceptionCode();
02236 }
02237 }
else {
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250 NextBufferLocation = (*CapturedArray);
02251 RtlMoveMemory( NextBufferLocation,
InputArray, ArraySize );
02252 NextBufferLocation = (PVOID)( (ULONG_PTR)NextBufferLocation +
02253 (ULONG)LongAlignSize(ArraySize));
02254
02255
02256
02257
02258
02259 NextIndex = 0;
02260 NextElement = (*CapturedArray);
02261
while (NextIndex < ArrayCount) {
02262
02263 GetSidSubAuthorityCount =
02264 ((PISID)(NextElement[NextIndex].Sid))->SubAuthorityCount;
02265
02266 RtlMoveMemory(
02267 NextBufferLocation,
02268 NextElement[NextIndex].Sid,
02269
RtlLengthRequiredSid(GetSidSubAuthorityCount) );
02270 SidSize =
RtlLengthRequiredSid( GetSidSubAuthorityCount );
02271 AlignedSidSize = (ULONG)LongAlignSize(SidSize);
02272
02273 NextElement[NextIndex].Sid = (PSID)NextBufferLocation;
02274
02275 NextIndex += 1;
02276 NextBufferLocation = (PVOID)((ULONG_PTR)NextBufferLocation +
02277 AlignedSidSize);
02278
02279 }
02280
02281 }
02282
02283
if (RequestorMode !=
KernelMode) {
02284
ExFreePool( TempArray );
02285 }
02286
02287
if (!ARGUMENT_PRESENT(CaptureBuffer) && !
NT_SUCCESS(CompletionStatus)) {
02288
ExFreePool( (*CapturedArray) );
02289 *CapturedArray =
NULL ;
02290 }
02291
02292
return CompletionStatus;
02293 }
02294
02295
02296
VOID
02297 SeReleaseSidAndAttributesArray (
02298 IN PSID_AND_ATTRIBUTES CapturedArray,
02299 IN KPROCESSOR_MODE RequestorMode,
02300 IN BOOLEAN ForceCapture
02301 )
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327 {
02328
02329
02330
02331
02332
02333
PAGED_CODE();
02334
02335
if ( ((RequestorMode ==
KernelMode) && (ForceCapture ==
TRUE)) ||
02336 (RequestorMode ==
UserMode ) ) {
02337
02338
ExFreePool(CapturedArray);
02339
02340 }
02341
02342
return;
02343
02344 }
02345
02346
02347
02348
02349
NTSTATUS
02350 SeComputeQuotaInformationSize(
02351 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
02352 OUT PULONG Size
02353 )
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382 {
02383 PISECURITY_DESCRIPTOR ISecurityDescriptor;
02384
02385 PSID
Group;
02386 PACL
Dacl;
02387
02388
PAGED_CODE();
02389
02390 ISecurityDescriptor = (PISECURITY_DESCRIPTOR)SecurityDescriptor;
02391 *
Size = 0;
02392
02393
if (ISecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION) {
02394
return( STATUS_UNKNOWN_REVISION );
02395 }
02396
02397
Group = RtlpGroupAddrSecurityDescriptor( ISecurityDescriptor );
02398
02399
Dacl = RtlpDaclAddrSecurityDescriptor( ISecurityDescriptor );
02400
02401
if (
Group !=
NULL) {
02402 *
Size += (ULONG)LongAlignSize(
SeLengthSid(
Group ));
02403 }
02404
02405
if (
Dacl !=
NULL) {
02406 *
Size += (ULONG)LongAlignSize(
Dacl->AclSize);
02407 }
02408
02409
return( STATUS_SUCCESS );
02410 }
02411
02412
02413 BOOLEAN
02414 SeValidSecurityDescriptor(
02415 IN ULONG Length,
02416 IN PSECURITY_DESCRIPTOR SecurityDescriptor
02417 )
02418
02419
02420
02421
02422
02423
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449 {
02450 PISECURITY_DESCRIPTOR_RELATIVE ISecurityDescriptor =
02451 (PISECURITY_DESCRIPTOR_RELATIVE)SecurityDescriptor;
02452 PISID OwnerSid;
02453 PISID GroupSid;
02454 PACE_HEADER Ace;
02455 PISID Sid;
02456 PISID Sid2;
02457 PACL
Dacl;
02458 PACL Sacl;
02459 ULONG i;
02460
02461
if (Length <
sizeof(SECURITY_DESCRIPTOR_RELATIVE)) {
02462
return(
FALSE);
02463 }
02464
02465
02466
02467
02468
02469
if (ISecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION) {
02470
return(
FALSE);
02471 }
02472
02473
02474
02475
02476
02477
if (!(ISecurityDescriptor->Control & SE_SELF_RELATIVE)) {
02478
return(
FALSE);
02479 }
02480
02481
02482
02483
02484
02485
02486
if ((ISecurityDescriptor->Owner == 0) ||
02487 (!
LongAligned((PVOID)(ULONG_PTR)(ULONG)ISecurityDescriptor->Owner)) ||
02488 (ISecurityDescriptor->Owner > Length) ||
02489 (Length - ISecurityDescriptor->Owner <
sizeof(SID))) {
02490
02491
return(
FALSE);
02492 }
02493
02494
02495
02496
02497
02498
02499 OwnerSid = (PSID)RtlOffsetToPointer( ISecurityDescriptor, ISecurityDescriptor->Owner );
02500
02501
if (OwnerSid->Revision != SID_REVISION) {
02502
return(
FALSE);
02503 }
02504
02505
if (OwnerSid->SubAuthorityCount > SID_MAX_SUB_AUTHORITIES) {
02506
return(
FALSE);
02507 }
02508
02509
if (Length - ISecurityDescriptor->Owner < (ULONG)
SeLengthSid(OwnerSid)) {
02510
return(
FALSE);
02511 }
02512
02513
02514
02515
02516
02517
02518
02519
if (ISecurityDescriptor->Group != 0) {
02520
02521
02522
02523
02524
02525
if (!
LongAligned( (PVOID)(ULONG_PTR)(ULONG)ISecurityDescriptor->Group)) {
02526
return(
FALSE);
02527 }
02528
02529
if (ISecurityDescriptor->Group > Length) {
02530
return(
FALSE);
02531 }
02532
02533
if (Length - ISecurityDescriptor->Group <
sizeof (SID)) {
02534
return(
FALSE);
02535 }
02536
02537
02538
02539
02540
02541
02542 GroupSid = (PSID)RtlOffsetToPointer( ISecurityDescriptor, ISecurityDescriptor->Group );
02543
02544
if (GroupSid->Revision != SID_REVISION) {
02545
return(
FALSE);
02546 }
02547
02548
if (GroupSid->SubAuthorityCount > SID_MAX_SUB_AUTHORITIES) {
02549
return(
FALSE);
02550 }
02551
02552
if (Length - ISecurityDescriptor->Group < (ULONG)
SeLengthSid(GroupSid)) {
02553
return(
FALSE);
02554 }
02555 }
02556
02557
02558
02559
02560
02561
02562
if (ISecurityDescriptor->Dacl != 0) {
02563
02564
02565
02566
02567
02568
if (!
LongAligned( (PVOID)(ULONG_PTR)(ULONG)ISecurityDescriptor->Dacl)) {
02569
return(
FALSE);
02570 }
02571
02572
02573
02574
02575
02576
if ((ISecurityDescriptor->Dacl > Length) ||
02577 (Length - ISecurityDescriptor->Dacl <
sizeof(ACL))) {
02578
return(
FALSE);
02579 }
02580
02581
Dacl = (PACL) RtlOffsetToPointer( ISecurityDescriptor, ISecurityDescriptor->Dacl );
02582
02583
02584
02585
02586
02587
02588
if (Length - ISecurityDescriptor->Dacl <
Dacl->AclSize) {
02589
return(
FALSE);
02590 }
02591
02592
02593
02594
02595
02596
if (!
RtlValidAcl(
Dacl )) {
02597
return(
FALSE);
02598 }
02599 }
02600
02601
02602
02603
02604
02605
02606
if (ISecurityDescriptor->Sacl != 0) {
02607
02608
02609
02610
02611
02612
if (!
LongAligned( (PVOID)(ULONG_PTR)(ULONG)ISecurityDescriptor->Sacl)) {
02613
return(
FALSE);
02614 }
02615
02616
02617
02618
02619
02620
if ((ISecurityDescriptor->Sacl > Length) ||
02621 (Length - ISecurityDescriptor->Sacl <
sizeof(ACL))) {
02622
return(
FALSE);
02623 }
02624
02625
02626
02627
02628
02629 Sacl = (PACL)RtlOffsetToPointer( ISecurityDescriptor, ISecurityDescriptor->Sacl );
02630
02631
02632
if (Length - ISecurityDescriptor->Sacl < Sacl->AclSize) {
02633
return(
FALSE);
02634 }
02635
02636
02637
02638
02639
02640
if (!
RtlValidAcl( Sacl )) {
02641
return(
FALSE);
02642 }
02643 }
02644
02645
return(
TRUE);
02646 }
02647