00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include "sep.h"
00024
#include "tokenp.h"
00025
00026
#ifdef ALLOC_PRAGMA
00027
#pragma alloc_text(PAGE,NtQueryInformationToken)
00028
#pragma alloc_text(PAGE,SeQueryAuthenticationIdToken)
00029
#pragma alloc_text(PAGE,SeQueryInformationToken)
00030
#endif
00031
00032
00033
NTSTATUS
00034 NtQueryInformationToken (
00035 IN HANDLE TokenHandle,
00036 IN TOKEN_INFORMATION_CLASS TokenInformationClass,
00037 OUT PVOID TokenInformation,
00038 IN ULONG TokenInformationLength,
00039 OUT PULONG ReturnLength
00040 )
00041
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
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
00119
00120
00121
00122
00123
00124
00125
00126
00127 {
00128
00129
KPROCESSOR_MODE PreviousMode;
00130
NTSTATUS Status;
00131
00132
PTOKEN Token;
00133
00134 ULONG RequiredLength;
00135 ULONG
Index;
00136
00137 PTOKEN_TYPE LocalType;
00138 PTOKEN_USER LocalUser;
00139 PTOKEN_GROUPS LocalGroups;
00140 PTOKEN_PRIVILEGES LocalPrivileges;
00141 PTOKEN_OWNER LocalOwner;
00142 PTOKEN_PRIMARY_GROUP LocalPrimaryGroup;
00143 PTOKEN_DEFAULT_DACL LocalDefaultDacl;
00144 PTOKEN_SOURCE LocalSource;
00145 PSECURITY_IMPERSONATION_LEVEL LocalImpersonationLevel;
00146 PTOKEN_STATISTICS LocalStatistics;
00147
00148 PSID PSid;
00149 PACL PAcl;
00150
00151 PVOID Ignore;
00152 ULONG SessionId;
00153
00154
PAGED_CODE();
00155
00156
00157
00158
00159
00160 PreviousMode = KeGetPreviousMode();
00161
if (PreviousMode !=
KernelMode) {
00162
try {
00163
00164
ProbeForWrite(
00165 TokenInformation,
00166 TokenInformationLength,
00167
sizeof(ULONG)
00168 );
00169
00170
ProbeForWriteUlong(ReturnLength);
00171
00172 } except(
EXCEPTION_EXECUTE_HANDLER) {
00173
return GetExceptionCode();
00174 }
00175 }
00176
00177
00178
00179
00180
00181
switch ( TokenInformationClass ) {
00182
00183
case TokenUser:
00184
00185 LocalUser = (PTOKEN_USER)TokenInformation;
00186
00187
Status =
ObReferenceObjectByHandle(
00188 TokenHandle,
00189 TOKEN_QUERY,
00190
SepTokenObjectType,
00191 PreviousMode,
00192 (PVOID *)&
Token,
00193
NULL
00194 );
00195
00196
if ( !
NT_SUCCESS(
Status) ) {
00197
return Status;
00198 }
00199
00200
00201
00202
00203
00204
SepAcquireTokenReadLock(
Token );
00205
00206
00207
00208
00209
00210
00211
00212
00213 RequiredLength =
SeLengthSid(
Token->UserAndGroups[0].Sid) +
00214 (ULONG)
sizeof( TOKEN_USER );
00215
00216
try {
00217
00218 *ReturnLength = RequiredLength;
00219
00220 } except(
EXCEPTION_EXECUTE_HANDLER) {
00221
00222
SepReleaseTokenReadLock(
Token );
00223
ObDereferenceObject(
Token );
00224
return GetExceptionCode();
00225 }
00226
00227
if ( TokenInformationLength < RequiredLength ) {
00228
00229
SepReleaseTokenReadLock(
Token );
00230
ObDereferenceObject(
Token );
00231
return STATUS_BUFFER_TOO_SMALL;
00232
00233 }
00234
00235
00236
00237
00238
00239
try {
00240
00241
00242
00243
00244 PSid = (PSID)( (ULONG_PTR)LocalUser + (ULONG)
sizeof(TOKEN_USER) );
00245
00246
RtlCopySidAndAttributesArray(
00247 1,
00248
Token->UserAndGroups,
00249 RequiredLength,
00250 &(LocalUser->User),
00251 PSid,
00252 ((PSID *)&Ignore),
00253 ((PULONG)&Ignore)
00254 );
00255
00256 } except(
EXCEPTION_EXECUTE_HANDLER) {
00257
00258
SepReleaseTokenReadLock(
Token );
00259
ObDereferenceObject(
Token );
00260
return GetExceptionCode();
00261 }
00262
00263
00264
SepReleaseTokenReadLock(
Token );
00265
ObDereferenceObject(
Token );
00266
return STATUS_SUCCESS;
00267
00268
case TokenGroups:
00269
00270 LocalGroups = (PTOKEN_GROUPS)TokenInformation;
00271
00272
Status =
ObReferenceObjectByHandle(
00273 TokenHandle,
00274 TOKEN_QUERY,
00275
SepTokenObjectType,
00276 PreviousMode,
00277 (PVOID *)&
Token,
00278
NULL
00279 );
00280
00281
if ( !
NT_SUCCESS(
Status) ) {
00282
return Status;
00283 }
00284
00285
00286
00287
00288
00289
SepAcquireTokenReadLock(
Token );
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 RequiredLength = (ULONG)
sizeof(TOKEN_GROUPS) +
00301 ((
Token->UserAndGroupCount -
ANYSIZE_ARRAY - 1) *
00302 ((ULONG)
sizeof(SID_AND_ATTRIBUTES)) );
00303
00304
Index = 1;
00305
while (
Index <
Token->UserAndGroupCount) {
00306
00307 RequiredLength +=
SeLengthSid(
Token->UserAndGroups[
Index].Sid );
00308
00309
Index += 1;
00310
00311 }
00312
00313
00314
00315
00316
00317
00318
try {
00319
00320 *ReturnLength = RequiredLength;
00321
00322 } except(
EXCEPTION_EXECUTE_HANDLER) {
00323
00324
SepReleaseTokenReadLock(
Token );
00325
ObDereferenceObject(
Token );
00326
return GetExceptionCode();
00327 }
00328
00329
if ( TokenInformationLength < RequiredLength ) {
00330
00331
SepReleaseTokenReadLock(
Token );
00332
ObDereferenceObject(
Token );
00333
return STATUS_BUFFER_TOO_SMALL;
00334
00335 }
00336
00337
00338
00339
00340
00341
try {
00342
00343 LocalGroups->GroupCount =
Token->UserAndGroupCount - 1;
00344
00345 PSid = (PSID)( (ULONG_PTR)LocalGroups +
00346 (ULONG)
sizeof(TOKEN_GROUPS) +
00347 ( (
Token->UserAndGroupCount -
ANYSIZE_ARRAY - 1) *
00348 (ULONG)
sizeof(SID_AND_ATTRIBUTES) )
00349 );
00350
00351
RtlCopySidAndAttributesArray(
00352 (ULONG)(
Token->UserAndGroupCount - 1),
00353 &(
Token->UserAndGroups[1]),
00354 RequiredLength,
00355 LocalGroups->Groups,
00356 PSid,
00357 ((PSID *)&Ignore),
00358 ((PULONG)&Ignore)
00359 );
00360
00361 } except(
EXCEPTION_EXECUTE_HANDLER) {
00362
00363
SepReleaseTokenReadLock(
Token );
00364
ObDereferenceObject(
Token );
00365
return GetExceptionCode();
00366 }
00367
00368
00369
SepReleaseTokenReadLock(
Token );
00370
ObDereferenceObject(
Token );
00371
return STATUS_SUCCESS;
00372
00373
case TokenRestrictedSids:
00374
00375 LocalGroups = (PTOKEN_GROUPS)TokenInformation;
00376
00377
Status =
ObReferenceObjectByHandle(
00378 TokenHandle,
00379 TOKEN_QUERY,
00380
SepTokenObjectType,
00381 PreviousMode,
00382 (PVOID *)&
Token,
00383
NULL
00384 );
00385
00386
if ( !
NT_SUCCESS(
Status) ) {
00387
return Status;
00388 }
00389
00390
00391
00392
00393
00394
SepAcquireTokenReadLock(
Token );
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 RequiredLength = (ULONG)
sizeof(TOKEN_GROUPS) +
00406 ((
Token->RestrictedSidCount) *
00407 ((ULONG)
sizeof(SID_AND_ATTRIBUTES)) -
00408
ANYSIZE_ARRAY *
sizeof(SID_AND_ATTRIBUTES) );
00409
00410
Index = 0;
00411
while (
Index <
Token->RestrictedSidCount) {
00412
00413 RequiredLength +=
SeLengthSid(
Token->RestrictedSids[
Index].Sid );
00414
00415
Index += 1;
00416
00417 }
00418
00419
00420
00421
00422
00423
00424
try {
00425
00426 *ReturnLength = RequiredLength;
00427
00428 } except(
EXCEPTION_EXECUTE_HANDLER) {
00429
00430
SepReleaseTokenReadLock(
Token );
00431
ObDereferenceObject(
Token );
00432
return GetExceptionCode();
00433 }
00434
00435
if ( TokenInformationLength < RequiredLength ) {
00436
00437
SepReleaseTokenReadLock(
Token );
00438
ObDereferenceObject(
Token );
00439
return STATUS_BUFFER_TOO_SMALL;
00440
00441 }
00442
00443
00444
00445
00446
00447
try {
00448
00449 LocalGroups->GroupCount =
Token->RestrictedSidCount;
00450
00451 PSid = (PSID)( (ULONG_PTR)LocalGroups +
00452 (ULONG)
sizeof(TOKEN_GROUPS) +
00453 ( (
Token->RestrictedSidCount ) *
00454 (ULONG)
sizeof(SID_AND_ATTRIBUTES) -
00455
ANYSIZE_ARRAY *
sizeof(SID_AND_ATTRIBUTES) )
00456 );
00457
00458
RtlCopySidAndAttributesArray(
00459 (ULONG)(
Token->RestrictedSidCount),
00460
Token->RestrictedSids,
00461 RequiredLength,
00462 LocalGroups->Groups,
00463 PSid,
00464 ((PSID *)&Ignore),
00465 ((PULONG)&Ignore)
00466 );
00467
00468 } except(
EXCEPTION_EXECUTE_HANDLER) {
00469
00470
SepReleaseTokenReadLock(
Token );
00471
ObDereferenceObject(
Token );
00472
return GetExceptionCode();
00473 }
00474
00475
00476
SepReleaseTokenReadLock(
Token );
00477
ObDereferenceObject(
Token );
00478
return STATUS_SUCCESS;
00479
00480
case TokenPrivileges:
00481
00482 LocalPrivileges = (PTOKEN_PRIVILEGES)TokenInformation;
00483
00484
Status =
ObReferenceObjectByHandle(
00485 TokenHandle,
00486 TOKEN_QUERY,
00487
SepTokenObjectType,
00488 PreviousMode,
00489 (PVOID *)&
Token,
00490
NULL
00491 );
00492
00493
if ( !
NT_SUCCESS(
Status) ) {
00494
return Status;
00495 }
00496
00497
00498
00499
00500
00501
00502
SepAcquireTokenReadLock(
Token );
00503
00504
00505
00506
00507
00508
00509
00510 RequiredLength = (ULONG)
sizeof(TOKEN_PRIVILEGES) +
00511 ((
Token->PrivilegeCount -
ANYSIZE_ARRAY) *
00512 ((ULONG)
sizeof(LUID_AND_ATTRIBUTES)) );
00513
00514
00515
try {
00516
00517 *ReturnLength = RequiredLength;
00518
00519 } except(
EXCEPTION_EXECUTE_HANDLER) {
00520
00521
SepReleaseTokenReadLock(
Token );
00522
ObDereferenceObject(
Token );
00523
return GetExceptionCode();
00524 }
00525
00526
if ( TokenInformationLength < RequiredLength ) {
00527
00528
SepReleaseTokenReadLock(
Token );
00529
ObDereferenceObject(
Token );
00530
return STATUS_BUFFER_TOO_SMALL;
00531
00532 }
00533
00534
00535
00536
00537
00538
try {
00539
00540 LocalPrivileges->PrivilegeCount =
Token->PrivilegeCount;
00541
00542
RtlCopyLuidAndAttributesArray(
00543
Token->PrivilegeCount,
00544
Token->Privileges,
00545 LocalPrivileges->Privileges
00546 );
00547
00548 } except(
EXCEPTION_EXECUTE_HANDLER) {
00549
00550
SepReleaseTokenReadLock(
Token );
00551
ObDereferenceObject(
Token );
00552
return GetExceptionCode();
00553 }
00554
00555
00556
SepReleaseTokenReadLock(
Token );
00557
ObDereferenceObject(
Token );
00558
return STATUS_SUCCESS;
00559
00560
case TokenOwner:
00561
00562 LocalOwner = (PTOKEN_OWNER)TokenInformation;
00563
00564
Status =
ObReferenceObjectByHandle(
00565 TokenHandle,
00566 TOKEN_QUERY,
00567
SepTokenObjectType,
00568 PreviousMode,
00569 (PVOID *)&
Token,
00570
NULL
00571 );
00572
00573
if ( !
NT_SUCCESS(
Status) ) {
00574
return Status;
00575 }
00576
00577
00578
00579
00580
00581
00582
SepAcquireTokenReadLock(
Token );
00583
00584
00585
00586
00587
00588
00589 PSid =
Token->UserAndGroups[
Token->DefaultOwnerIndex].Sid;
00590 RequiredLength = (ULONG)
sizeof(TOKEN_OWNER) +
00591
SeLengthSid( PSid );
00592
00593
try {
00594
00595 *ReturnLength = RequiredLength;
00596
00597 } except(
EXCEPTION_EXECUTE_HANDLER) {
00598
00599
SepReleaseTokenReadLock(
Token );
00600
ObDereferenceObject(
Token );
00601
return GetExceptionCode();
00602 }
00603
00604
if ( TokenInformationLength < RequiredLength ) {
00605
00606
SepReleaseTokenReadLock(
Token );
00607
ObDereferenceObject(
Token );
00608
return STATUS_BUFFER_TOO_SMALL;
00609
00610 }
00611
00612
00613
00614
00615
00616 PSid = (PSID)((ULONG_PTR)LocalOwner +
00617 (ULONG)
sizeof(TOKEN_OWNER));
00618
00619
try {
00620
00621 LocalOwner->Owner = PSid;
00622
00623
Status =
RtlCopySid(
00624 (RequiredLength - (ULONG)
sizeof(TOKEN_OWNER)),
00625 PSid,
00626
Token->UserAndGroups[
Token->DefaultOwnerIndex].Sid
00627 );
00628
00629
ASSERT(
NT_SUCCESS(
Status) );
00630
00631 } except(
EXCEPTION_EXECUTE_HANDLER) {
00632
00633
SepReleaseTokenReadLock(
Token );
00634
ObDereferenceObject(
Token );
00635
return GetExceptionCode();
00636 }
00637
00638
00639
SepReleaseTokenReadLock(
Token );
00640
ObDereferenceObject(
Token );
00641
return STATUS_SUCCESS;
00642
00643
case TokenPrimaryGroup:
00644
00645 LocalPrimaryGroup = (PTOKEN_PRIMARY_GROUP)TokenInformation;
00646
00647
Status =
ObReferenceObjectByHandle(
00648 TokenHandle,
00649 TOKEN_QUERY,
00650
SepTokenObjectType,
00651 PreviousMode,
00652 (PVOID *)&
Token,
00653
NULL
00654 );
00655
00656
if ( !
NT_SUCCESS(
Status) ) {
00657
return Status;
00658 }
00659
00660
00661
00662
00663
00664
00665
SepAcquireTokenReadLock(
Token );
00666
00667
00668
00669
00670
00671
00672 RequiredLength = (ULONG)
sizeof(TOKEN_PRIMARY_GROUP) +
00673
SeLengthSid(
Token->PrimaryGroup );
00674
00675
try {
00676
00677 *ReturnLength = RequiredLength;
00678
00679 } except(
EXCEPTION_EXECUTE_HANDLER) {
00680
00681
SepReleaseTokenReadLock(
Token );
00682
ObDereferenceObject(
Token );
00683
return GetExceptionCode();
00684 }
00685
00686
if ( TokenInformationLength < RequiredLength ) {
00687
00688
SepReleaseTokenReadLock(
Token );
00689
ObDereferenceObject(
Token );
00690
return STATUS_BUFFER_TOO_SMALL;
00691
00692 }
00693
00694
00695
00696
00697
00698 PSid = (PSID)((ULONG_PTR)LocalPrimaryGroup +
00699 (ULONG)
sizeof(TOKEN_PRIMARY_GROUP));
00700
00701
try {
00702
00703 LocalPrimaryGroup->PrimaryGroup = PSid;
00704
00705
Status =
RtlCopySid( (RequiredLength - (ULONG)
sizeof(TOKEN_PRIMARY_GROUP)),
00706 PSid,
00707
Token->PrimaryGroup
00708 );
00709
00710
ASSERT(
NT_SUCCESS(
Status) );
00711
00712 } except(
EXCEPTION_EXECUTE_HANDLER) {
00713
00714
SepReleaseTokenReadLock(
Token );
00715
ObDereferenceObject(
Token );
00716
return GetExceptionCode();
00717 }
00718
00719
00720
SepReleaseTokenReadLock(
Token );
00721
ObDereferenceObject(
Token );
00722
return STATUS_SUCCESS;
00723
00724
case TokenDefaultDacl:
00725
00726 LocalDefaultDacl = (PTOKEN_DEFAULT_DACL)TokenInformation;
00727
00728
Status =
ObReferenceObjectByHandle(
00729 TokenHandle,
00730 TOKEN_QUERY,
00731
SepTokenObjectType,
00732 PreviousMode,
00733 (PVOID *)&
Token,
00734
NULL
00735 );
00736
00737
if ( !
NT_SUCCESS(
Status) ) {
00738
return Status;
00739 }
00740
00741
00742
00743
00744
00745
00746
SepAcquireTokenReadLock(
Token );
00747
00748
00749
00750
00751
00752
00753
00754 RequiredLength = (ULONG)
sizeof(TOKEN_DEFAULT_DACL);
00755
00756
if (ARGUMENT_PRESENT(
Token->DefaultDacl)) {
00757
00758 RequiredLength +=
Token->DefaultDacl->AclSize;
00759
00760 }
00761
00762
try {
00763
00764 *ReturnLength = RequiredLength;
00765
00766 } except(
EXCEPTION_EXECUTE_HANDLER) {
00767
00768
SepReleaseTokenReadLock(
Token );
00769
ObDereferenceObject(
Token );
00770
return GetExceptionCode();
00771 }
00772
00773
if ( TokenInformationLength < RequiredLength ) {
00774
00775
SepReleaseTokenReadLock(
Token );
00776
ObDereferenceObject(
Token );
00777
return STATUS_BUFFER_TOO_SMALL;
00778
00779 }
00780
00781
00782
00783
00784
00785 PAcl = (PACL)((ULONG_PTR)LocalDefaultDacl +
00786 (ULONG)
sizeof(TOKEN_DEFAULT_DACL));
00787
00788
try {
00789
00790
if (ARGUMENT_PRESENT(
Token->DefaultDacl)) {
00791
00792 LocalDefaultDacl->DefaultDacl = PAcl;
00793
00794 RtlCopyMemory( (PVOID)PAcl,
00795 (PVOID)
Token->DefaultDacl,
00796
Token->DefaultDacl->AclSize
00797 );
00798 }
else {
00799
00800 LocalDefaultDacl->DefaultDacl =
NULL;
00801
00802 }
00803
00804 } except(
EXCEPTION_EXECUTE_HANDLER) {
00805
00806
SepReleaseTokenReadLock(
Token );
00807
ObDereferenceObject(
Token );
00808
return GetExceptionCode();
00809 }
00810
00811
00812
SepReleaseTokenReadLock(
Token );
00813
ObDereferenceObject(
Token );
00814
return STATUS_SUCCESS;
00815
00816
00817
00818
case TokenSource:
00819
00820 LocalSource = (PTOKEN_SOURCE)TokenInformation;
00821
00822
Status =
ObReferenceObjectByHandle(
00823 TokenHandle,
00824 TOKEN_QUERY_SOURCE,
00825
SepTokenObjectType,
00826 PreviousMode,
00827 (PVOID *)&
Token,
00828
NULL
00829 );
00830
00831
if ( !
NT_SUCCESS(
Status) ) {
00832
return Status;
00833 }
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845 RequiredLength = (ULONG)
sizeof(TOKEN_SOURCE);
00846
00847
try {
00848
00849 *ReturnLength = RequiredLength;
00850
00851 } except(
EXCEPTION_EXECUTE_HANDLER) {
00852
00853
ObDereferenceObject(
Token );
00854
return GetExceptionCode();
00855 }
00856
00857
if ( TokenInformationLength < RequiredLength ) {
00858
00859
ObDereferenceObject(
Token );
00860
return STATUS_BUFFER_TOO_SMALL;
00861
00862 }
00863
00864
00865
00866
00867
00868
00869
try {
00870
00871 (*LocalSource) =
Token->TokenSource;
00872
00873 } except(
EXCEPTION_EXECUTE_HANDLER) {
00874
00875
ObDereferenceObject(
Token );
00876
return GetExceptionCode();
00877 }
00878
00879
00880
ObDereferenceObject(
Token );
00881
return STATUS_SUCCESS;
00882
00883
case TokenType:
00884
00885 LocalType = (PTOKEN_TYPE)TokenInformation;
00886
00887
Status =
ObReferenceObjectByHandle(
00888 TokenHandle,
00889 TOKEN_QUERY,
00890
SepTokenObjectType,
00891 PreviousMode,
00892 (PVOID *)&
Token,
00893
NULL
00894 );
00895
00896
if ( !
NT_SUCCESS(
Status) ) {
00897
return Status;
00898 }
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910 RequiredLength = (ULONG)
sizeof(TOKEN_TYPE);
00911
00912
try {
00913
00914 *ReturnLength = RequiredLength;
00915
00916 } except(
EXCEPTION_EXECUTE_HANDLER) {
00917
00918
ObDereferenceObject(
Token );
00919
return GetExceptionCode();
00920 }
00921
00922
if ( TokenInformationLength < RequiredLength ) {
00923
00924
ObDereferenceObject(
Token );
00925
return STATUS_BUFFER_TOO_SMALL;
00926
00927 }
00928
00929
00930
00931
00932
00933
00934
try {
00935
00936 (*LocalType) =
Token->TokenType;
00937
00938 } except(
EXCEPTION_EXECUTE_HANDLER) {
00939
00940
ObDereferenceObject(
Token );
00941
return GetExceptionCode();
00942 }
00943
00944
00945
ObDereferenceObject(
Token );
00946
return STATUS_SUCCESS;
00947
00948
00949
case TokenImpersonationLevel:
00950
00951 LocalImpersonationLevel = (PSECURITY_IMPERSONATION_LEVEL)TokenInformation;
00952
00953
Status =
ObReferenceObjectByHandle(
00954 TokenHandle,
00955 TOKEN_QUERY,
00956
SepTokenObjectType,
00957 PreviousMode,
00958 (PVOID *)&
Token,
00959
NULL
00960 );
00961
00962
if ( !
NT_SUCCESS(
Status) ) {
00963
return Status;
00964 }
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
if (
Token->TokenType != TokenImpersonation) {
00977
00978
ObDereferenceObject(
Token );
00979
return STATUS_INVALID_INFO_CLASS;
00980
00981 }
00982
00983
00984
00985
00986
00987
00988 RequiredLength = (ULONG)
sizeof(SECURITY_IMPERSONATION_LEVEL);
00989
00990
try {
00991
00992 *ReturnLength = RequiredLength;
00993
00994 } except(
EXCEPTION_EXECUTE_HANDLER) {
00995
00996
ObDereferenceObject(
Token );
00997
return GetExceptionCode();
00998 }
00999
01000
if ( TokenInformationLength < RequiredLength ) {
01001
01002
ObDereferenceObject(
Token );
01003
return STATUS_BUFFER_TOO_SMALL;
01004
01005 }
01006
01007
01008
01009
01010
01011
01012
try {
01013
01014 (*LocalImpersonationLevel) =
Token->ImpersonationLevel;
01015
01016 } except(
EXCEPTION_EXECUTE_HANDLER) {
01017
01018
ObDereferenceObject(
Token );
01019
return GetExceptionCode();
01020 }
01021
01022
01023
ObDereferenceObject(
Token );
01024
return STATUS_SUCCESS;
01025
01026
01027
case TokenStatistics:
01028
01029 LocalStatistics = (PTOKEN_STATISTICS)TokenInformation;
01030
01031
Status =
ObReferenceObjectByHandle(
01032 TokenHandle,
01033 TOKEN_QUERY,
01034
SepTokenObjectType,
01035 PreviousMode,
01036 (PVOID *)&
Token,
01037
NULL
01038 );
01039
01040
if ( !
NT_SUCCESS(
Status) ) {
01041
return Status;
01042 }
01043
01044
01045
01046
01047
01048
SepAcquireTokenReadLock(
Token );
01049
01050
01051
01052
01053
01054
01055
01056
01057 RequiredLength = (ULONG)
sizeof( TOKEN_STATISTICS );
01058
01059
try {
01060
01061 *ReturnLength = RequiredLength;
01062
01063 } except(
EXCEPTION_EXECUTE_HANDLER) {
01064
01065
SepReleaseTokenReadLock(
Token );
01066
ObDereferenceObject(
Token );
01067
return GetExceptionCode();
01068 }
01069
01070
if ( TokenInformationLength < RequiredLength ) {
01071
01072
SepReleaseTokenReadLock(
Token );
01073
ObDereferenceObject(
Token );
01074
return STATUS_BUFFER_TOO_SMALL;
01075
01076 }
01077
01078
01079
01080
01081
01082
try {
01083
01084 LocalStatistics->TokenId =
Token->TokenId;
01085 LocalStatistics->AuthenticationId =
Token->AuthenticationId;
01086 LocalStatistics->ExpirationTime =
Token->ExpirationTime;
01087 LocalStatistics->TokenType =
Token->TokenType;
01088 LocalStatistics->ImpersonationLevel =
Token->ImpersonationLevel;
01089 LocalStatistics->DynamicCharged =
Token->DynamicCharged;
01090 LocalStatistics->DynamicAvailable =
Token->DynamicAvailable;
01091 LocalStatistics->GroupCount =
Token->UserAndGroupCount-1;
01092 LocalStatistics->PrivilegeCount =
Token->PrivilegeCount;
01093 LocalStatistics->ModifiedId =
Token->ModifiedId;
01094
01095 } except(
EXCEPTION_EXECUTE_HANDLER) {
01096
01097
SepReleaseTokenReadLock(
Token );
01098
ObDereferenceObject(
Token );
01099
return GetExceptionCode();
01100 }
01101
01102
01103
SepReleaseTokenReadLock(
Token );
01104
ObDereferenceObject(
Token );
01105
return STATUS_SUCCESS;
01106
01107
case TokenSessionId:
01108
01109
if ( TokenInformationLength !=
sizeof(ULONG) )
01110
return( STATUS_INFO_LENGTH_MISMATCH );
01111
01112
Status =
ObReferenceObjectByHandle(
01113 TokenHandle,
01114 TOKEN_QUERY,
01115
SepTokenObjectType,
01116 PreviousMode,
01117 (PVOID *)&
Token,
01118
NULL
01119 );
01120
01121
if ( !
NT_SUCCESS(
Status) ) {
01122
return Status;
01123 }
01124
01125
01126
01127
01128
SeQuerySessionIdToken( (PACCESS_TOKEN)
Token,
01129 &SessionId);
01130
01131
try {
01132
01133 *(PULONG)TokenInformation = SessionId;
01134 *ReturnLength =
sizeof(ULONG);
01135
01136 } except(
EXCEPTION_EXECUTE_HANDLER) {
01137
ObDereferenceObject(
Token );
01138
return GetExceptionCode();
01139 }
01140
01141
ObDereferenceObject(
Token );
01142
return( STATUS_SUCCESS );
01143
01144
default:
01145
01146
return STATUS_INVALID_INFO_CLASS;
01147 }
01148 }
01149
01150
01151
NTSTATUS
01152 SeQueryAuthenticationIdToken(
01153 IN PACCESS_TOKEN Token,
01154 OUT PLUID AuthenticationId
01155 )
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177 {
01178
PAGED_CODE();
01179
01180
SepAcquireTokenReadLock( ((
PTOKEN)
Token) );
01181 (*AuthenticationId) = ((
PTOKEN)
Token)->AuthenticationId;
01182
SepReleaseTokenReadLock( ((
PTOKEN)
Token) );
01183
return(STATUS_SUCCESS);
01184 }
01185
01186
01187
01188
NTSTATUS
01189 SeQueryInformationToken (
01190 IN PACCESS_TOKEN AccessToken,
01191 IN TOKEN_INFORMATION_CLASS TokenInformationClass,
01192 OUT PVOID *TokenInformation
01193 )
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257 {
01258
01259
NTSTATUS Status;
01260
01261 ULONG RequiredLength;
01262 ULONG
Index;
01263
01264 PSID PSid;
01265 PACL PAcl;
01266
01267 PVOID Ignore;
01268
PTOKEN Token = (
PTOKEN)AccessToken;
01269
01270
PAGED_CODE();
01271
01272
01273
01274
01275
01276
switch ( TokenInformationClass ) {
01277
01278
case TokenUser:
01279 {
01280 PTOKEN_USER LocalUser;
01281
01282
01283
01284
01285
01286
SepAcquireTokenReadLock(
Token );
01287
01288
01289
01290
01291
01292
01293 RequiredLength =
SeLengthSid(
Token->UserAndGroups[0].Sid) +
01294 (ULONG)
sizeof( TOKEN_USER );
01295
01296 LocalUser =
ExAllocatePool(
PagedPool, RequiredLength );
01297
01298
if (LocalUser ==
NULL) {
01299
SepReleaseTokenReadLock(
Token );
01300
return( STATUS_INSUFFICIENT_RESOURCES );
01301 }
01302
01303
01304
01305
01306
01307
01308
01309 PSid = (PSID)( (ULONG_PTR)LocalUser + (ULONG)
sizeof(TOKEN_USER) );
01310
01311
RtlCopySidAndAttributesArray(
01312 1,
01313
Token->UserAndGroups,
01314 RequiredLength,
01315 &(LocalUser->User),
01316 PSid,
01317 ((PSID *)&Ignore),
01318 ((PULONG)&Ignore)
01319 );
01320
01321
SepReleaseTokenReadLock(
Token );
01322 *TokenInformation = LocalUser;
01323
return STATUS_SUCCESS;
01324 }
01325
01326
01327
case TokenGroups:
01328 {
01329 PTOKEN_GROUPS LocalGroups;
01330
01331
01332
01333
01334
01335
SepAcquireTokenReadLock(
Token );
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346 RequiredLength = (ULONG)
sizeof(TOKEN_GROUPS) +
01347 ((
Token->UserAndGroupCount -
ANYSIZE_ARRAY - 1) *
01348 ((ULONG)
sizeof(SID_AND_ATTRIBUTES)) );
01349
01350
Index = 1;
01351
while (
Index <
Token->UserAndGroupCount) {
01352
01353 RequiredLength +=
SeLengthSid(
Token->UserAndGroups[
Index].Sid );
01354
01355
Index += 1;
01356
01357 }
01358
01359 LocalGroups =
ExAllocatePool(
PagedPool, RequiredLength );
01360
01361
if (LocalGroups ==
NULL) {
01362
SepReleaseTokenReadLock(
Token );
01363
return( STATUS_INSUFFICIENT_RESOURCES );
01364 }
01365
01366
01367
01368
01369
01370 LocalGroups->GroupCount =
Token->UserAndGroupCount - 1;
01371
01372 PSid = (PSID)( (ULONG_PTR)LocalGroups +
01373 (ULONG)
sizeof(TOKEN_GROUPS) +
01374 ( (
Token->UserAndGroupCount -
ANYSIZE_ARRAY - 1) *
01375 (ULONG)
sizeof(SID_AND_ATTRIBUTES) )
01376 );
01377
01378
RtlCopySidAndAttributesArray(
01379 (ULONG)(
Token->UserAndGroupCount - 1),
01380 &(
Token->UserAndGroups[1]),
01381 RequiredLength,
01382 LocalGroups->Groups,
01383 PSid,
01384 ((PSID *)&Ignore),
01385 ((PULONG)&Ignore)
01386 );
01387
01388
SepReleaseTokenReadLock(
Token );
01389 *TokenInformation = LocalGroups;
01390
return STATUS_SUCCESS;
01391 }
01392
01393
01394
case TokenPrivileges:
01395 {
01396 PTOKEN_PRIVILEGES LocalPrivileges;
01397
01398
01399
01400
01401
01402
01403
SepAcquireTokenReadLock(
Token );
01404
01405
01406
01407
01408
01409
01410 RequiredLength = (ULONG)
sizeof(TOKEN_PRIVILEGES) +
01411 ((
Token->PrivilegeCount -
ANYSIZE_ARRAY) *
01412 ((ULONG)
sizeof(LUID_AND_ATTRIBUTES)) );
01413
01414 LocalPrivileges =
ExAllocatePool(
PagedPool, RequiredLength );
01415
01416
if (LocalPrivileges ==
NULL) {
01417
SepReleaseTokenReadLock(
Token );
01418
return( STATUS_INSUFFICIENT_RESOURCES );
01419 }
01420
01421
01422
01423
01424
01425 LocalPrivileges->PrivilegeCount =
Token->PrivilegeCount;
01426
01427
RtlCopyLuidAndAttributesArray(
01428
Token->PrivilegeCount,
01429
Token->Privileges,
01430 LocalPrivileges->Privileges
01431 );
01432
01433
SepReleaseTokenReadLock(
Token );
01434 *TokenInformation = LocalPrivileges;
01435
return STATUS_SUCCESS;
01436 }
01437
01438
01439
case TokenOwner:
01440 {
01441 PTOKEN_OWNER LocalOwner;
01442
01443
01444
01445
01446
01447
01448
SepAcquireTokenReadLock(
Token );
01449
01450
01451
01452
01453
01454
01455 PSid =
Token->UserAndGroups[
Token->DefaultOwnerIndex].Sid;
01456 RequiredLength = (ULONG)
sizeof(TOKEN_OWNER) +
01457
SeLengthSid( PSid );
01458
01459 LocalOwner =
ExAllocatePool(
PagedPool, RequiredLength );
01460
01461
if (LocalOwner ==
NULL) {
01462
SepReleaseTokenReadLock(
Token );
01463
return( STATUS_INSUFFICIENT_RESOURCES );
01464 }
01465
01466
01467
01468
01469
01470 PSid = (PSID)((ULONG_PTR)LocalOwner +
01471 (ULONG)
sizeof(TOKEN_OWNER));
01472
01473 LocalOwner->Owner = PSid;
01474
01475
Status =
RtlCopySid(
01476 (RequiredLength - (ULONG)
sizeof(TOKEN_OWNER)),
01477 PSid,
01478
Token->UserAndGroups[
Token->DefaultOwnerIndex].Sid
01479 );
01480
01481
ASSERT(
NT_SUCCESS(
Status) );
01482
01483
SepReleaseTokenReadLock(
Token );
01484 *TokenInformation = LocalOwner;
01485
return STATUS_SUCCESS;
01486 }
01487
01488
01489
case TokenPrimaryGroup:
01490 {
01491 PTOKEN_PRIMARY_GROUP LocalPrimaryGroup;
01492
01493
01494
01495
01496
01497
01498
SepAcquireTokenReadLock(
Token );
01499
01500
01501
01502
01503
01504
01505 RequiredLength = (ULONG)
sizeof(TOKEN_PRIMARY_GROUP) +
01506
SeLengthSid(
Token->PrimaryGroup );
01507
01508 LocalPrimaryGroup =
ExAllocatePool(
PagedPool, RequiredLength );
01509
01510
if (LocalPrimaryGroup ==
NULL) {
01511
SepReleaseTokenReadLock(
Token );
01512
return( STATUS_INSUFFICIENT_RESOURCES );
01513 }
01514
01515
01516
01517
01518
01519 PSid = (PSID)((ULONG_PTR)LocalPrimaryGroup +
01520 (ULONG)
sizeof(TOKEN_PRIMARY_GROUP));
01521
01522 LocalPrimaryGroup->PrimaryGroup = PSid;
01523
01524
Status =
RtlCopySid( (RequiredLength - (ULONG)
sizeof(TOKEN_PRIMARY_GROUP)),
01525 PSid,
01526
Token->PrimaryGroup
01527 );
01528
01529
ASSERT(
NT_SUCCESS(
Status) );
01530
01531
SepReleaseTokenReadLock(
Token );
01532 *TokenInformation = LocalPrimaryGroup;
01533
return STATUS_SUCCESS;
01534 }
01535
01536
01537
case TokenDefaultDacl:
01538 {
01539 PTOKEN_DEFAULT_DACL LocalDefaultDacl;
01540
01541
01542
01543
01544
01545
01546
SepAcquireTokenReadLock(
Token );
01547
01548
01549
01550
01551
01552
01553 RequiredLength = (ULONG)
sizeof(TOKEN_DEFAULT_DACL);
01554
01555
if (ARGUMENT_PRESENT(
Token->DefaultDacl)) {
01556
01557 RequiredLength +=
Token->DefaultDacl->AclSize;
01558 }
01559
01560 LocalDefaultDacl =
ExAllocatePool(
PagedPool, RequiredLength );
01561
01562
if (LocalDefaultDacl ==
NULL) {
01563
SepReleaseTokenReadLock(
Token );
01564
return( STATUS_INSUFFICIENT_RESOURCES );
01565 }
01566
01567
01568
01569
01570
01571 PAcl = (PACL)((ULONG_PTR)LocalDefaultDacl +
01572 (ULONG)
sizeof(TOKEN_DEFAULT_DACL));
01573
01574
if (ARGUMENT_PRESENT(
Token->DefaultDacl)) {
01575
01576 LocalDefaultDacl->DefaultDacl = PAcl;
01577
01578 RtlCopyMemory( (PVOID)PAcl,
01579 (PVOID)
Token->DefaultDacl,
01580
Token->DefaultDacl->AclSize
01581 );
01582 }
else {
01583
01584 LocalDefaultDacl->DefaultDacl =
NULL;
01585 }
01586
01587
SepReleaseTokenReadLock(
Token );
01588 *TokenInformation = LocalDefaultDacl;
01589
return STATUS_SUCCESS;
01590 }
01591
01592
01593
case TokenSource:
01594 {
01595 PTOKEN_SOURCE LocalSource;
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607 RequiredLength = (ULONG)
sizeof(TOKEN_SOURCE);
01608
01609 LocalSource =
ExAllocatePool(
PagedPool, RequiredLength );
01610
01611
if (LocalSource ==
NULL) {
01612
return( STATUS_INSUFFICIENT_RESOURCES );
01613 }
01614
01615
01616
01617
01618
01619 (*LocalSource) =
Token->TokenSource;
01620 *TokenInformation = LocalSource;
01621
01622
return STATUS_SUCCESS;
01623 }
01624
01625
01626
case TokenType:
01627 {
01628 PTOKEN_TYPE LocalType;
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640 RequiredLength = (ULONG)
sizeof(TOKEN_TYPE);
01641
01642 LocalType =
ExAllocatePool(
PagedPool, RequiredLength );
01643
01644
if (LocalType ==
NULL) {
01645
return( STATUS_INSUFFICIENT_RESOURCES );
01646 }
01647
01648
01649
01650
01651
01652 (*LocalType) =
Token->TokenType;
01653 *TokenInformation = LocalType;
01654
return STATUS_SUCCESS;
01655 }
01656
01657
01658
case TokenImpersonationLevel:
01659 {
01660 PSECURITY_IMPERSONATION_LEVEL LocalImpersonationLevel;
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
if (
Token->TokenType != TokenImpersonation) {
01673
01674
return STATUS_INVALID_INFO_CLASS;
01675 }
01676
01677
01678
01679
01680
01681
01682 RequiredLength = (ULONG)
sizeof(SECURITY_IMPERSONATION_LEVEL);
01683
01684 LocalImpersonationLevel =
ExAllocatePool(
PagedPool, RequiredLength );
01685
01686
if (LocalImpersonationLevel ==
NULL) {
01687
return( STATUS_INSUFFICIENT_RESOURCES );
01688 }
01689
01690
01691
01692
01693
01694 (*LocalImpersonationLevel) =
Token->ImpersonationLevel;
01695 *TokenInformation = LocalImpersonationLevel;
01696
return STATUS_SUCCESS;
01697 }
01698
01699
01700
case TokenStatistics:
01701 {
01702 PTOKEN_STATISTICS LocalStatistics;
01703
01704
01705
01706
01707
01708
SepAcquireTokenReadLock(
Token );
01709
01710
01711
01712
01713
01714
01715 RequiredLength = (ULONG)
sizeof( TOKEN_STATISTICS );
01716
01717 LocalStatistics =
ExAllocatePool(
PagedPool, RequiredLength );
01718
01719
if (LocalStatistics ==
NULL) {
01720
SepReleaseTokenReadLock(
Token );
01721
return( STATUS_INSUFFICIENT_RESOURCES );
01722 }
01723
01724
01725
01726
01727
01728 LocalStatistics->TokenId =
Token->TokenId;
01729 LocalStatistics->AuthenticationId =
Token->AuthenticationId;
01730 LocalStatistics->ExpirationTime =
Token->ExpirationTime;
01731 LocalStatistics->TokenType =
Token->TokenType;
01732 LocalStatistics->ImpersonationLevel =
Token->ImpersonationLevel;
01733 LocalStatistics->DynamicCharged =
Token->DynamicCharged;
01734 LocalStatistics->DynamicAvailable =
Token->DynamicAvailable;
01735 LocalStatistics->GroupCount =
Token->UserAndGroupCount-1;
01736 LocalStatistics->PrivilegeCount =
Token->PrivilegeCount;
01737 LocalStatistics->ModifiedId =
Token->ModifiedId;
01738
01739
SepReleaseTokenReadLock(
Token );
01740 *TokenInformation = LocalStatistics;
01741
return STATUS_SUCCESS;
01742 }
01743
01744
case TokenSessionId:
01745
01746
01747
01748
01749
SeQuerySessionIdToken( (PACCESS_TOKEN)
Token,
01750 (PULONG)TokenInformation );
01751
01752
return( STATUS_SUCCESS );
01753
01754
default:
01755
01756
return STATUS_INVALID_INFO_CLASS;
01757 }
01758 }
01759
01760
01761
01762
NTSTATUS
01763 SeQuerySessionIdToken(
01764 PACCESS_TOKEN Token,
01765 PULONG SessionId
01766 )
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787 {
01788
01789
01790
01791
01792
SepAcquireTokenReadLock( ((
PTOKEN)
Token) );
01793 (*SessionId) = ((
PTOKEN)
Token)->SessionId;
01794
SepReleaseTokenReadLock( ((
PTOKEN)
Token) );
01795
return( STATUS_SUCCESS );
01796 }
01797
01798