Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
6.3 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. token.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Ramon J San Andres (ramonsa) 8-Nov-1993
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. BOOL
  16. DumpToken (
  17. IN char *Pad,
  18. IN ULONG64 RealTokenBase,
  19. IN ULONG Flags
  20. );
  21. DECLARE_API( token )
  22. /*++
  23. Routine Description:
  24. Dump token at specified address
  25. Arguments:
  26. args - Address Flags
  27. Return Value:
  28. None
  29. --*/
  30. {
  31. ULONG64 Address;
  32. ULONG Flags;
  33. ULONG result;
  34. Address = 0;
  35. Flags = 6;
  36. if (GetExpressionEx(args,&Address,&args)) {
  37. if (args && *args) {
  38. Flags = (ULONG) GetExpression(args);
  39. }
  40. }
  41. if (Address == 0) {
  42. dprintf("usage: !token <token-address>\n");
  43. return E_INVALIDARG;
  44. }
  45. //
  46. // Dump token with no pad
  47. //
  48. DumpToken ("", Address, Flags);
  49. EXPRLastDump = Address;
  50. return S_OK;
  51. }
  52. DECLARE_API( tokenfields )
  53. /*++
  54. Routine Description:
  55. Displays the field offsets for TOKEN type.
  56. Arguments:
  57. args -
  58. Return Value:
  59. None
  60. --*/
  61. {
  62. dprintf("Use : dt TOKEN\n");
  63. return S_OK;
  64. /*
  65. dprintf(" TOKEN structure offsets:\n");
  66. dprintf(" TokenSource: 0x%lx\n", FIELD_OFFSET(TOKEN, TokenSource) );
  67. dprintf(" AuthenticationId: 0x%lx\n", FIELD_OFFSET(TOKEN, AuthenticationId) );
  68. dprintf(" ExpirationTime: 0x%lx\n", FIELD_OFFSET(TOKEN, ExpirationTime) );
  69. dprintf(" ModifiedId: 0x%lx\n", FIELD_OFFSET(TOKEN, ModifiedId) );
  70. dprintf(" UserAndGroupCount: 0x%lx\n", FIELD_OFFSET(TOKEN, UserAndGroupCount) );
  71. dprintf(" PrivilegeCount: 0x%lx\n", FIELD_OFFSET(TOKEN, PrivilegeCount) );
  72. dprintf(" VariableLength: 0x%lx\n", FIELD_OFFSET(TOKEN, VariableLength) );
  73. dprintf(" DynamicCharged: 0x%lx\n", FIELD_OFFSET(TOKEN, DynamicCharged) );
  74. dprintf(" DynamicAvailable: 0x%lx\n", FIELD_OFFSET(TOKEN, DynamicAvailable) );
  75. dprintf(" DefaultOwnerIndex: 0x%lx\n", FIELD_OFFSET(TOKEN, DefaultOwnerIndex) );
  76. dprintf(" DefaultDacl: 0x%lx\n", FIELD_OFFSET(TOKEN, DefaultDacl) );
  77. dprintf(" TokenType: 0x%lx\n", FIELD_OFFSET(TOKEN, TokenType) );
  78. dprintf(" ImpersonationLevel: 0x%lx\n", FIELD_OFFSET(TOKEN, ImpersonationLevel) );
  79. dprintf(" TokenFlags: 0x%lx\n", FIELD_OFFSET(TOKEN, TokenFlags) );
  80. dprintf(" TokenInUse: 0x%lx\n", FIELD_OFFSET(TOKEN, TokenInUse) );
  81. dprintf(" ProxyData: 0x%lx\n", FIELD_OFFSET(TOKEN, ProxyData) );
  82. dprintf(" AuditData: 0x%lx\n", FIELD_OFFSET(TOKEN, AuditData) );
  83. dprintf(" VariablePart: 0x%lx\n", FIELD_OFFSET(TOKEN, VariablePart) );
  84. return;
  85. */
  86. }
  87. BOOL
  88. DumpToken (
  89. IN char *Pad,
  90. IN ULONG64 RealTokenBase,
  91. IN ULONG Flags
  92. )
  93. {
  94. ULONG TokenType, TokenFlags, TokenInUse, UserAndGroupCount;
  95. ULONG RestrictedSidCount, PrivilegeCount;
  96. ULONG64 AuthenticationId, TokenId, ParentTokenId, ModifiedId, UserAndGroups;
  97. ULONG64 RestrictedSids, Privileges, ImpersonationLevel;
  98. CHAR SourceName[16];
  99. #define TokFld(F) GetFieldValue(RealTokenBase, "TOKEN", #F, F)
  100. #define TokSubFld(F,N) GetFieldValue(RealTokenBase, "TOKEN", #F, N)
  101. if (TokFld(TokenType)) {
  102. dprintf("%sUnable to read TOKEN at %p.\n", Pad, RealTokenBase);
  103. return FALSE;
  104. }
  105. //
  106. // It would be worth sticking a check in here to see if we
  107. // are really being asked to dump a token, but I don't have
  108. // time just now.
  109. //
  110. if (TokenType != TokenPrimary &&
  111. TokenType != TokenImpersonation) {
  112. dprintf("%sUNKNOWN token type - probably is not a token\n", Pad);
  113. return FALSE;
  114. }
  115. TokSubFld(TokenSource.SourceName, SourceName);
  116. TokFld(TokenFlags); TokFld(AuthenticationId); TokFld(TokenInUse);
  117. TokFld(ImpersonationLevel); TokFld(TokenId), TokFld(ParentTokenId);
  118. TokFld(ModifiedId); TokFld(RestrictedSids); TokFld(RestrictedSidCount);
  119. TokFld(PrivilegeCount); TokFld(Privileges); TokFld(UserAndGroupCount);
  120. TokFld(UserAndGroups);
  121. dprintf("%sTOKEN %p Flags: %x Source %8s AuthentId (%lx, %lx)\n",
  122. Pad,
  123. RealTokenBase,
  124. TokenFlags,
  125. &(SourceName[0]),
  126. (ULONG) ((AuthenticationId >> 32) & 0xffffffff),
  127. (ULONG) AuthenticationId & 0xffffffff
  128. );
  129. //
  130. // Token type
  131. //
  132. if (TokenType == TokenPrimary) {
  133. dprintf("%s Type: Primary", Pad);
  134. if (TokenInUse) {
  135. dprintf(" (IN USE)\n");
  136. } else {
  137. dprintf(" (NOT in use)\n");
  138. }
  139. } else {
  140. dprintf("%s Type: Impersonation (level: ", Pad);
  141. switch (ImpersonationLevel) {
  142. case SecurityAnonymous:
  143. dprintf(" Anonymous)\n");
  144. break;
  145. case SecurityIdentification:
  146. dprintf(" Identification)\n");
  147. break;
  148. case SecurityImpersonation:
  149. dprintf(" Impersonation)\n");
  150. break;
  151. case SecurityDelegation:
  152. dprintf(" Delegation)\n");
  153. break;
  154. default:
  155. dprintf(" UNKNOWN)\n");
  156. break;
  157. }
  158. }
  159. //
  160. // Token ID and modified ID
  161. //
  162. dprintf("%s Token ID: %I64lx\n",
  163. Pad, TokenId );
  164. dprintf("%s ParentToken ID: %I64lx\n",
  165. Pad, ParentTokenId );
  166. dprintf("%s Modified ID: (%lx, %lx)\n",
  167. Pad, (ULONG) (ModifiedId >> 32) & 0xffffffff, (ULONG) (ModifiedId & 0xffffffff));
  168. dprintf("%s TokenFlags: 0x%x\n",
  169. Pad, TokenFlags );
  170. dprintf("%s SidCount: %d\n",
  171. Pad, UserAndGroupCount );
  172. dprintf("%s Sids: %p\n",
  173. Pad, UserAndGroups );
  174. dprintf("%s RestrictedSidCount: %d\n",
  175. Pad, RestrictedSidCount );
  176. dprintf("%s RestrictedSids: %p\n",
  177. Pad, RestrictedSids );
  178. dprintf("%s PrivilegeCount: %d\n",
  179. Pad, PrivilegeCount );
  180. dprintf("%s Privileges: %p\n",
  181. Pad, Privileges );
  182. dprintf("\n");
  183. #undef TokFld
  184. #undef TokSubFld
  185. return TRUE;
  186. }