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.

423 lines
11 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. dbgsec.c
  5. Abstract:
  6. Argus debugging extensions. The routines here dump out Security Descriptors
  7. and allow you to examine them.
  8. Author:
  9. Krishna Ganugapati (KrishnaG) 1-July-1993
  10. Revision History:
  11. KrishnaG: Created: 1-July-1993 (imported most of IanJa's stuff)
  12. KrishnaG: Added: 7-July-1993 (added AndrewBe's UnicodeAnsi conversion
  13. KrishnaG Added: 3-Aug-1993 (added DevMode/SecurityDescriptor dumps)
  14. t-blakej Added: 1-July-1997 (added single-address dump, PID)
  15. To do:
  16. --*/
  17. #define NOMINMAX
  18. #define SECURITY_WIN32
  19. #include <nt.h>
  20. #include <ntrtl.h>
  21. #include <nturtl.h>
  22. #include <windows.h>
  23. #include <stdlib.h>
  24. #include <math.h>
  25. #include <ntsdexts.h>
  26. #include <windows.h>
  27. #include <winspool.h>
  28. #include <security.h>
  29. #include <wchar.h>
  30. #include <winldap.h>
  31. #include "dbglocal.h"
  32. #define NULL_TERMINATED 0
  33. #define MAXDEPTH 10
  34. typedef struct _ADSMEMTAG {
  35. DWORD Tag ;
  36. DWORD Size ;
  37. PVOID pvBackTrace[MAXDEPTH+1];
  38. LPSTR pszSymbol[MAXDEPTH+1];
  39. DWORD uDepth;
  40. LIST_ENTRY List ;
  41. } ADSMEMTAG, *PADSMEMTAG ;
  42. typedef struct _ADS_LDP {
  43. LIST_ENTRY List ;
  44. LPWSTR Server ;
  45. ULONG RefCount ;
  46. LUID Luid ;
  47. DWORD Flags ;
  48. LDAP *LdapHandle ;
  49. PVOID *pCredentials;
  50. DWORD PortNumber;
  51. DWORD TickCount ;
  52. PVOID **ReferralEntries;
  53. DWORD nReferralEntries;
  54. } ADS_LDP, *PADS_LDP ;
  55. ULONG
  56. TranslateAddress (
  57. IN DWORD dwProcessId,
  58. IN ULONG Address,
  59. OUT LPSTR Name,
  60. IN ULONG MaxNameLength
  61. );
  62. void print_struct_ldap(
  63. HANDLE hCurrentProcess,
  64. HANDLE hCurrentThread,
  65. DWORD dwCurrentPc,
  66. PNTSD_EXTENSION_APIS lpExtensionApis,
  67. LDAP ldap_struct);
  68. DWORD
  69. SimpleAToI(LPSTR *lppStr)
  70. {
  71. DWORD dwResult = 0;
  72. while (isspace(**lppStr)) (*lppStr)++;
  73. while (isdigit(**lppStr))
  74. {
  75. dwResult = dwResult * 10 + (**lppStr - '0');
  76. (*lppStr)++;
  77. }
  78. return dwResult;
  79. }
  80. BOOL
  81. dmem(
  82. HANDLE hCurrentProcess,
  83. HANDLE hCurrentThread,
  84. DWORD dwCurrentPc,
  85. PNTSD_EXTENSION_APIS lpExtensionApis,
  86. LPSTR lpArgumentString)
  87. {
  88. PNTSD_OUTPUT_ROUTINE Print;
  89. PNTSD_GET_EXPRESSION EvalExpression;
  90. PNTSD_GET_SYMBOL GetSymbol;
  91. DWORD Address = (DWORD)NULL;
  92. DWORD dwProcessId = 0;
  93. BOOL bThereAreOptions = TRUE;
  94. BOOL bDoOneAddress = FALSE;
  95. LIST_ENTRY ListEntry;
  96. LIST_ENTRY AdsMemHeader;
  97. ADSMEMTAG AdsMemTag;
  98. DWORD pEntry = 0;
  99. DWORD pTemp = 0;
  100. DWORD pMem = 0;
  101. CHAR szSymbolName[MAX_PATH];
  102. DWORD i = 0;
  103. UNREFERENCED_PARAMETER(hCurrentProcess);
  104. UNREFERENCED_PARAMETER(hCurrentThread);
  105. UNREFERENCED_PARAMETER(dwCurrentPc);
  106. Print = lpExtensionApis->lpOutputRoutine;
  107. EvalExpression = lpExtensionApis->lpGetExpressionRoutine;
  108. GetSymbol = lpExtensionApis->lpGetSymbolRoutine;
  109. dwProcessId = GetCurrentProcessId();
  110. while (bThereAreOptions) {
  111. while (isspace(*lpArgumentString)) {
  112. lpArgumentString++;
  113. }
  114. switch (*lpArgumentString) {
  115. //
  116. // Read symbols from the process whose PID is an arg to "p".
  117. //
  118. case 'p':
  119. lpArgumentString++;
  120. // EvalValue uses hex, and I don't want to bother fiddling with
  121. // it enough to make it do decimal.
  122. dwProcessId = SimpleAToI(&lpArgumentString);
  123. break;
  124. //
  125. // Dump the single address given as an arg to "a".
  126. //
  127. case 'a':
  128. lpArgumentString++;
  129. Address = EvalValue(&lpArgumentString, EvalExpression, Print);
  130. bDoOneAddress = TRUE;
  131. break;
  132. default: // go get the address because there's nothing else
  133. bThereAreOptions = FALSE;
  134. break;
  135. }
  136. }
  137. if (!bDoOneAddress) {
  138. if (*lpArgumentString != 0) {
  139. Address = EvalValue(&lpArgumentString, EvalExpression, Print);
  140. }
  141. // if we've got no address, then quit now - nothing we can do
  142. if (Address == (DWORD)NULL) {
  143. Print("We have a Null address\n");
  144. return(0);
  145. }
  146. movestruct(Address, &AdsMemHeader, LIST_ENTRY);
  147. pEntry = AdsMemHeader.Flink;
  148. while(pEntry != Address) {
  149. movestruct(pEntry, &ListEntry, LIST_ENTRY);
  150. pTemp = (BYTE*)pEntry;
  151. pTemp = pTemp - sizeof(DWORD) - sizeof(DWORD)
  152. - sizeof(DWORD) -
  153. (sizeof(CHAR*) + sizeof(LPVOID))*( MAXDEPTH +1);
  154. pMem = (ADSMEMTAG*)pTemp;
  155. movestruct(pMem, &AdsMemTag, ADSMEMTAG);
  156. Print("[oleds] Memory leak!!! size = %ld\n", AdsMemTag.Size);
  157. for (i = 0; i < AdsMemTag.uDepth; i++) {
  158. TranslateAddress(dwProcessId, AdsMemTag.pvBackTrace[i],
  159. szSymbolName, 256);
  160. Print("%.8x %s\n", AdsMemTag.pvBackTrace[i], szSymbolName);
  161. }
  162. Print("\n");
  163. pEntry = ListEntry.Flink;
  164. }
  165. }
  166. else {
  167. TranslateAddress(dwProcessId, Address, szSymbolName, 256);
  168. Print("%.8x %s\n", Address, szSymbolName);
  169. }
  170. return 0;
  171. DBG_UNREFERENCED_PARAMETER(hCurrentProcess);
  172. DBG_UNREFERENCED_PARAMETER(hCurrentThread);
  173. DBG_UNREFERENCED_PARAMETER(dwCurrentPc);
  174. }
  175. //
  176. // Give it the adsldpc!BindCache address and it will give
  177. // the BindCache info.
  178. //
  179. BOOL
  180. dcache(
  181. HANDLE hCurrentProcess,
  182. HANDLE hCurrentThread,
  183. DWORD dwCurrentPc,
  184. PNTSD_EXTENSION_APIS lpExtensionApis,
  185. LPSTR lpArgumentString)
  186. {
  187. PNTSD_OUTPUT_ROUTINE Print;
  188. PNTSD_GET_EXPRESSION EvalExpression;
  189. PNTSD_GET_SYMBOL GetSymbol;
  190. DWORD Address = (DWORD)NULL;
  191. DWORD dwProcessId = 0;
  192. BOOL bThereAreOptions = TRUE;
  193. BOOL bDoOneAddress = FALSE;
  194. ADS_LDP BindCacheEntry;
  195. ADS_LDP ads_ldp_struct;
  196. DWORD pEntry = 0;
  197. DWORD pTemp = 0;
  198. ADS_LDP *pMem = NULL;
  199. CHAR szSymbolName[MAX_PATH];
  200. LDAP LDAPStruct;
  201. DWORD i = 0;
  202. WCHAR serverName[250];
  203. //DebugBreak();
  204. UNREFERENCED_PARAMETER(hCurrentProcess);
  205. UNREFERENCED_PARAMETER(hCurrentThread);
  206. UNREFERENCED_PARAMETER(dwCurrentPc);
  207. Print = lpExtensionApis->lpOutputRoutine;
  208. EvalExpression = lpExtensionApis->lpGetExpressionRoutine;
  209. GetSymbol = lpExtensionApis->lpGetSymbolRoutine;
  210. dwProcessId = GetCurrentProcessId();
  211. while (bThereAreOptions) {
  212. while (isspace(*lpArgumentString)) {
  213. lpArgumentString++;
  214. }
  215. switch (*lpArgumentString) {
  216. //
  217. // Read symbols from the process whose PID is an arg to "p".
  218. //
  219. case 'p':
  220. lpArgumentString++;
  221. // EvalValue uses hex, and I don't want to bother fiddling with
  222. // it enough to make it do decimal.
  223. dwProcessId = SimpleAToI(&lpArgumentString);
  224. break;
  225. //
  226. // Dump the single address given as an arg to "a".
  227. //
  228. case 'a':
  229. lpArgumentString++;
  230. Address = EvalValue(&lpArgumentString, EvalExpression, Print);
  231. bDoOneAddress = TRUE;
  232. break;
  233. default: // go get the address because there's nothing else
  234. bThereAreOptions = FALSE;
  235. break;
  236. }
  237. }
  238. if (!bDoOneAddress) {
  239. if (*lpArgumentString != 0) {
  240. Address = EvalValue(&lpArgumentString, EvalExpression, Print);
  241. }
  242. // if we've got no address, then quit now - nothing we can do
  243. if (Address == (DWORD)NULL) {
  244. Print("We have a Null address\n");
  245. return(0);
  246. }
  247. movestruct(Address, &BindCacheEntry, LIST_ENTRY);
  248. pEntry = BindCacheEntry.List.Flink;
  249. Print("Bind Cache Address passed is 0x%x\n", pEntry);
  250. while(pEntry != Address) {
  251. movestruct(pEntry, &BindCacheEntry, ADS_LDP);
  252. movemem(BindCacheEntry.Server, serverName, 250);
  253. // get the LDAP struct also now
  254. movestruct(BindCacheEntry.LdapHandle, &LDAPStruct, LDAP);
  255. Print("BindCache Information :\n");
  256. Print(" Server : %S\n", serverName);
  257. Print(" RefCount : %lu\n", BindCacheEntry.RefCount);
  258. Print(" LUID.High : %ld\n", BindCacheEntry.Luid.HighPart);
  259. Print(" LUID.Low : %ld\n", BindCacheEntry.Luid.LowPart);
  260. Print(" FLAGS : %ld\n", BindCacheEntry.Flags);
  261. Print(" LDAPHandle :0x%X\n", BindCacheEntry.LdapHandle);
  262. print_struct_ldap(
  263. hCurrentProcess,
  264. hCurrentThread,
  265. dwCurrentPc,
  266. lpExtensionApis,
  267. LDAPStruct);
  268. Print(" pCredenti : 0x%X\n", BindCacheEntry.pCredentials);
  269. Print(" PortNo : %ld\n", BindCacheEntry.PortNumber);
  270. Print(" Referrals : %ld\n", BindCacheEntry.nReferralEntries);
  271. pEntry = BindCacheEntry.List.Flink;
  272. }
  273. }
  274. else {
  275. TranslateAddress(dwProcessId, Address, szSymbolName, 256);
  276. Print("%.8x %s\n", Address, szSymbolName);
  277. }
  278. return 0;
  279. DBG_UNREFERENCED_PARAMETER(hCurrentProcess);
  280. DBG_UNREFERENCED_PARAMETER(hCurrentThread);
  281. DBG_UNREFERENCED_PARAMETER(dwCurrentPc);
  282. }
  283. void print_struct_ldap(
  284. HANDLE hCurrentProcess,
  285. HANDLE hCurrentThread,
  286. DWORD dwCurrentPc,
  287. PNTSD_EXTENSION_APIS lpExtensionApis,
  288. LDAP ldap_struct)
  289. {
  290. PNTSD_OUTPUT_ROUTINE Print;
  291. UCHAR u_char_string[250];
  292. Print = lpExtensionApis->lpOutputRoutine;
  293. if (ldap_struct.ld_host) {
  294. movemem(ldap_struct.ld_host, u_char_string, 250);
  295. Print(" ld_host, address : 0x%X, string value: %s\n",
  296. ldap_struct.ld_host, u_char_string);
  297. }
  298. Print(" ld_version : %lu\n", ldap_struct.ld_version);
  299. Print(" ld_lberoptions (UCHAR) : %c\n",
  300. ldap_struct.ld_lberoptions);
  301. Print(" ld_deref : %lu\n", ldap_struct.ld_deref);
  302. Print(" ld_timelimit : %lu\n", ldap_struct.ld_timelimit);
  303. Print(" ld_sizelimit : %lu\n", ldap_struct.ld_sizelimit);
  304. Print(" ld_errno : %lu\n", ldap_struct.ld_errno);
  305. if (ldap_struct.ld_matched) {
  306. movemem(ldap_struct.ld_matched, u_char_string, 250);
  307. Print(" ld_matched address : 0x%X, string value: %s\n",
  308. ldap_struct.ld_matched, u_char_string);
  309. }
  310. if (ldap_struct.ld_error) {
  311. movemem(ldap_struct.ld_error, u_char_string, 250);
  312. Print(" ld_error address : 0x%X, string value: %s\n",
  313. ldap_struct.ld_error, u_char_string);
  314. }
  315. Print(" ld_msgid : %lu\n", ldap_struct.ld_msgid);
  316. Print(" ld_cldaptries : %lu\n", ldap_struct.ld_cldaptries);
  317. Print(" ld_cldaptimeout : %lu\n", ldap_struct.ld_cldaptimeout);
  318. Print(" ld_refhoplimit : %lu\n", ldap_struct.ld_refhoplimit);
  319. Print(" ld_options : %lu\n", ldap_struct.ld_options);
  320. }
  321.