00045 :
00046
00047 Retrieve information about a specified token.
00048
00049 Arguments:
00050
00051 TokenHandle - Provides a handle to
the token to operate on.
00052
00053 TokenInformationClass - The token information
class about which
00054 to retrieve information.
00055
00056 TokenInformation - The buffer to receive
the requested class of
00057 information. The buffer must be aligned on at least a
00058 longword boundary. The actual structures returned are
00059 dependent upon
the information class requested, as defined in
00060
the TokenInformationClass parameter description.
00061
00062 TokenInformation Format By Information Class:
00063
00064 TokenUser => TOKEN_USER data structure. TOKEN_QUERY
00065 access
is needed to retrieve this information about a
00066 token.
00067
00068 TokenGroups => TOKEN_GROUPS data structure. TOKEN_QUERY
00069 access
is needed to retrieve this information about a
00070 token.
00071
00072 TokenPrivileges => TOKEN_PRIVILEGES data structure.
00073 TOKEN_QUERY access
is needed to retrieve this information
00074 about a token.
00075
00076 TokenOwner => TOKEN_OWNER data structure. TOKEN_QUERY
00077 access
is needed to retrieve this information about a
00078 token.
00079
00080 TokenPrimaryGroup => TOKEN_PRIMARY_GROUP data structure.
00081 TOKEN_QUERY access
is needed to retrieve this information
00082 about a token.
00083
00084 TokenDefaultDacl => TOKEN_DEFAULT_DACL data structure.
00085 TOKEN_QUERY access
is needed to retrieve this information
00086 about a token.
00087
00088 TokenSource => TOKEN_SOURCE data structure.
00089 TOKEN_QUERY_SOURCE access
is needed to retrieve this
00090 information about a token.
00091
00092 TokenType => TOKEN_TYPE data structure.
00093 TOKEN_QUERY access
is needed to retrieve this information
00094 about a token.
00095
00096 TokenStatistics => TOKEN_STATISTICS data structure.
00097 TOKEN_QUERY access
is needed to retrieve this
00098 information about a token.
00099
00100 TokenGroups => TOKEN_GROUPS data structure. TOKEN_QUERY
00101 access
is needed to retrieve this information about a
00102 token.
00103
00104 TokenInformationLength - Indicates
the length, in bytes, of
the
00105 TokenInformation buffer.
00106
00107 ReturnLength - This OUT parameter receives
the actual length of
00108
the requested information. If this value
is larger than that
00109 provided by
the TokenInformationLength parameter, then
the
00110 buffer provided to receive
the requested information
is not
00111 large enough to hold that data and no data
is returned.
00112
00113 If
the queried class
is TokenDefaultDacl and there
is no
00114 default
Dacl established for
the token, then
the return
00115 length will be returned as zero, and no data will be returned.
00116
00117 Return Value:
00118
00119 STATUS_SUCCESS - Indicates
the operation was successful.
00120
00121 STATUS_BUFFER_TOO_SMALL - if
the requested information did not
00122 fit in
the provided output buffer. In this case,
the
00123 ReturnLength OUT parameter contains
the number of bytes
00124 actually needed to store
the requested information.
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 }