Leaked source code of windows server 2003
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.

328 lines
7.8 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 2000
  6. //
  7. // File: N E W E X T . C
  8. //
  9. // Contents: LSA debugger extensions that use the new style
  10. // extension API.
  11. //
  12. //
  13. // History:
  14. // 07-January-2000 kumarp created
  15. //
  16. // Note:
  17. //
  18. // If you want to add extensions to this file, read the following
  19. // guidelines from andreva first:
  20. //
  21. // Everyone who debugs or runs stress will expect debugger extensions
  22. // to work on both 32 bit and 64 bit TARGETS. The Debugger extensions must
  23. // therefore be TARGET independent. We the only viable solution to this is to
  24. // get structure definitions from the symbol information, instead of
  25. // from the header file. So the way we solve this problem is:
  26. //
  27. // - A debugger extension can only include windows.h and wdbgexts.h
  28. // - A debugger extensions NEVER includes header files from
  29. // the component it tries to analyze\debug.
  30. // - Debugger extensions use the new routines we provide to query
  31. // type information.
  32. //
  33. //------------------------------------------------------------------------
  34. #include <windows.h>
  35. #include <dbghelp.h>
  36. #define KDEXT_64BIT
  37. #include <wdbgexts.h>
  38. #include <ntverp.h>
  39. // ----------------------------------------------------------------------
  40. //
  41. // globals
  42. //
  43. WINDBG_EXTENSION_APIS ExtensionApis;
  44. EXT_API_VERSION ApiVersion =
  45. {
  46. (VER_PRODUCTVERSION_W >> 8),
  47. (VER_PRODUCTVERSION_W & 0xff),
  48. EXT_API_VERSION_NUMBER64,
  49. 0
  50. };
  51. USHORT SavedMajorVersion;
  52. USHORT SavedMinorVersion;
  53. // ----------------------------------------------------------------------
  54. //
  55. // The following 3 functions must be present in the extension dll.
  56. // They were lifted straight from base\tools\kdexts\kdexts.c
  57. //
  58. VOID
  59. WinDbgExtensionDllInit(
  60. PWINDBG_EXTENSION_APIS64 lpExtensionApis, // 64Bit Change
  61. USHORT MajorVersion,
  62. USHORT MinorVersion
  63. )
  64. {
  65. ExtensionApis = *lpExtensionApis;
  66. SavedMajorVersion = MajorVersion;
  67. SavedMinorVersion = MinorVersion;
  68. return;
  69. }
  70. VOID
  71. CheckVersion(
  72. VOID
  73. )
  74. {
  75. }
  76. LPEXT_API_VERSION
  77. ExtensionApiVersion(
  78. VOID
  79. )
  80. {
  81. return &ApiVersion;
  82. }
  83. // ----------------------------------------------------------------------
  84. BOOL
  85. GetGlobalVar (
  86. IN PUCHAR Name,
  87. IN USHORT Size,
  88. OUT PVOID pOutValue
  89. )
  90. /*++
  91. Routine Description:
  92. Get value of global vars of primitive type OR
  93. Get the address instead for non-primitive global vars.
  94. Primitive type is defined as the one not-involving any struct/union
  95. in its type definition. Pointer to struct/unions are ok.
  96. for example: USHORT, ULONG, PVOID etc.
  97. Arguments:
  98. Name - global var name
  99. (for example: "lsasrv!LsapAdtContextList")
  100. Size - size in bytes for primitive types, 0 otherwise
  101. pOutValue - pointer to return val.
  102. Return Value:
  103. TRUE on success, FALSE otherwise
  104. Notes:
  105. --*/
  106. {
  107. ULONG64 Temp=0;
  108. SYM_DUMP_PARAM Sym =
  109. {
  110. sizeof (SYM_DUMP_PARAM),
  111. Name,
  112. DBG_DUMP_NO_PRINT | DBG_DUMP_COPY_TYPE_DATA,
  113. 0,
  114. NULL,
  115. &Temp,
  116. NULL,
  117. 0,
  118. NULL
  119. };
  120. ULONG RetVal;
  121. RetVal = Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size );
  122. //
  123. // store only the correct number of bytes from the value read
  124. //
  125. switch(Size)
  126. {
  127. default:
  128. case 0:
  129. *((PUCHAR*) pOutValue) = (PUCHAR) Sym.addr;
  130. break;
  131. case 1:
  132. *((UCHAR*) pOutValue) = (UCHAR) Temp;
  133. break;
  134. case 2:
  135. *((USHORT*) pOutValue) = (USHORT) Temp;
  136. break;
  137. case 4:
  138. *((DWORD*) pOutValue) = (DWORD) Temp;
  139. break;
  140. case 8:
  141. *((ULONG64*) pOutValue) = Temp;
  142. break;
  143. }
  144. return (RetVal == NO_ERROR);
  145. }
  146. //
  147. // helper macro to get field of AUDIT_CONTEXT struct
  148. //
  149. #define GetAuditContextField(addr,f) \
  150. GetFieldData( (ULONG64) addr, \
  151. "AUDIT_CONTEXT",\
  152. #f, \
  153. sizeof(f), \
  154. &f )
  155. //
  156. // helper macro to get LIST_ENTRY.Flink
  157. //
  158. #define GetFlink(addr,pflink) \
  159. GetFieldData( addr,\
  160. "LIST_ENTRY", \
  161. "Flink",\
  162. sizeof(ULONG64),\
  163. pflink )
  164. void
  165. DumpAuditContextList(
  166. )
  167. /*++
  168. Routine Description:
  169. Dump the audit context list.
  170. Arguments:
  171. None
  172. Return Value:
  173. None
  174. Notes:
  175. It appears that there is a built in support for dumping
  176. lists using SYM_DUMP_PARAM.listLink but I came to know about it too late.
  177. --*/
  178. {
  179. LIST_ENTRY LsapAdtContextList = { (PLIST_ENTRY) 22, (PLIST_ENTRY) 33 };
  180. ULONG64 pLsapAdtContextList=0;
  181. ULONG LsapAdtContextListCount=0;
  182. ULONG64 Temp=0;
  183. ULONG64 Scan=0;
  184. ULONG64 Link=0;
  185. USHORT CategoryId;
  186. USHORT AuditId;
  187. USHORT ParameterCount;
  188. ULONG Status=NO_ERROR;
  189. ULONG i;
  190. if (!GetGlobalVar( "lsasrv!LsapAdtContextListCount",
  191. sizeof(LsapAdtContextListCount),
  192. &LsapAdtContextListCount ))
  193. {
  194. goto Cleanup;
  195. }
  196. dprintf( "# contexts: %ld\n", LsapAdtContextListCount );
  197. if ( ((LONG) LsapAdtContextListCount) < 0 )
  198. {
  199. dprintf("...List/ListCount may be corrupt\n");
  200. goto Cleanup;
  201. }
  202. if ( LsapAdtContextListCount == 0 )
  203. {
  204. goto Cleanup;
  205. }
  206. if (!GetGlobalVar( "lsasrv!LsapAdtContextList",
  207. 0,
  208. &pLsapAdtContextList ))
  209. {
  210. dprintf("...error reading lsasrv!LsapAdtContextList\n");
  211. goto Cleanup;
  212. }
  213. Status = GetFlink( pLsapAdtContextList, &Scan );
  214. if ( Status != NO_ERROR )
  215. {
  216. dprintf("...error reading lsasrv!LsapAdtContextList.Flink\n");
  217. goto Cleanup;
  218. }
  219. dprintf("LsapAdtContextList @ %p\n", pLsapAdtContextList);
  220. for (i=0; i < LsapAdtContextListCount; i++)
  221. {
  222. dprintf("%02d) [%p]: ", i, Scan);
  223. if ( Scan == pLsapAdtContextList )
  224. {
  225. dprintf("...pre-mature end of list\nList/ListCount may be corrupt\n");
  226. break;
  227. }
  228. else if ( Scan == 0 )
  229. {
  230. dprintf("...NULL list element found!\nList/ListCount may be corrupt\n");
  231. break;
  232. }
  233. Status = GetAuditContextField( Scan, CategoryId );
  234. if ( Status != NO_ERROR )
  235. {
  236. dprintf("...error reading AUDIT_CONTEXT.CategoryId\n");
  237. break;
  238. }
  239. dprintf("Category: %03x\t", CategoryId);
  240. Status = GetAuditContextField( Scan, AuditId );
  241. if ( Status != NO_ERROR )
  242. {
  243. dprintf("...error reading AUDIT_CONTEXT.AuditId\n");
  244. break;
  245. }
  246. dprintf("AuditId: %03x\t", AuditId);
  247. Status = GetAuditContextField( Scan, Link );
  248. if ( Status != NO_ERROR )
  249. {
  250. dprintf("...error reading AUDIT_CONTEXT.Link\n");
  251. break;
  252. }
  253. Status = GetFlink( Link, &Scan );
  254. if ( Status != NO_ERROR )
  255. {
  256. goto Cleanup;
  257. }
  258. dprintf("\n");
  259. }
  260. Cleanup:
  261. if ( Status != NO_ERROR )
  262. {
  263. dprintf("...failed\n");
  264. }
  265. }
  266. DECLARE_API(AuditContexts)
  267. {
  268. DumpAuditContextList();
  269. }