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.

440 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. logging.c
  5. Abstract:
  6. Commands to control how logging information is performed.
  7. Revision History:
  8. --*/
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. static const WCHAR g_pszRegValTracingFile[] = L"EnableFileTracing";
  12. static const WCHAR g_pszRegKeyTracing[] = L"SOFTWARE\\Microsoft\\Tracing";
  13. typedef struct _TRACING_DATA
  14. {
  15. HKEY hkMachine;
  16. HKEY hkFlags;
  17. DWORD dwServerFlags;
  18. } TRACING_DATA;
  19. //
  20. // Opens the root tracing registry key
  21. //
  22. DWORD
  23. TraceOpenRoot(
  24. OUT PHKEY phKey)
  25. {
  26. DWORD dwErr = NO_ERROR;
  27. dwErr = RegOpenKeyExW(
  28. g_pServerInfo->hkMachine,
  29. g_pszRegKeyTracing,
  30. 0,
  31. KEY_ALL_ACCESS,
  32. phKey);
  33. return dwErr;
  34. }
  35. DWORD
  36. TraceOpenKey(
  37. IN HKEY hkRoot,
  38. IN LPCWSTR pszKey,
  39. OUT PHKEY phKey)
  40. {
  41. return RegOpenKeyExW(
  42. hkRoot,
  43. pszKey,
  44. 0,
  45. KEY_ALL_ACCESS,
  46. phKey);
  47. }
  48. DWORD
  49. TraceCloseKey(
  50. IN HKEY hKey)
  51. {
  52. return RegCloseKey(hKey);
  53. }
  54. DWORD
  55. TraceWrite(
  56. IN HKEY hkComp,
  57. IN DWORD dwEnable)
  58. {
  59. return RutlRegWriteDword(
  60. hkComp,
  61. (PWCHAR)g_pszRegValTracingFile,
  62. dwEnable);
  63. }
  64. DWORD
  65. TraceRead(
  66. IN HKEY hkComp,
  67. IN LPDWORD lpdwEnable)
  68. {
  69. return RutlRegReadDword(
  70. hkComp,
  71. (PWCHAR)g_pszRegValTracingFile,
  72. lpdwEnable);
  73. }
  74. DWORD
  75. TraceShow(
  76. IN LPCWSTR pszName,
  77. IN HKEY hKey,
  78. IN HANDLE hData)
  79. {
  80. DWORD dwErr = NO_ERROR, dwEnabled = 0;
  81. do
  82. {
  83. // Get the enabling of the current component
  84. //
  85. dwErr = TraceRead(hKey, &dwEnabled);
  86. BREAK_ON_DWERR(dwErr);
  87. // Display the status
  88. //
  89. DisplayMessage(
  90. g_hModule,
  91. MSG_TRACE_SHOW,
  92. pszName,
  93. (dwEnabled) ? TOKEN_ENABLED : TOKEN_DISABLED);
  94. } while (FALSE);
  95. // Cleanup
  96. {
  97. }
  98. return dwErr;
  99. }
  100. DWORD
  101. TraceDumpComponent(
  102. IN LPCWSTR pszName,
  103. IN HKEY hKey,
  104. IN HANDLE hData)
  105. {
  106. PWCHAR pszComp = NULL, pszEnable = NULL, pszQuote = NULL;
  107. DWORD dwErr = NO_ERROR, dwEnabled = 0;
  108. DWORD* pdwShowDisable = (DWORD*)hData;
  109. do
  110. {
  111. dwErr = TraceRead(hKey, &dwEnabled);
  112. BREAK_ON_DWERR(dwErr);
  113. pszQuote = MakeQuotedString(pszName);
  114. pszComp = RutlAssignmentFromTokens(
  115. g_hModule,
  116. TOKEN_COMPONENT,
  117. pszQuote);
  118. pszEnable = RutlAssignmentFromTokens(
  119. g_hModule,
  120. TOKEN_STATE,
  121. (dwEnabled) ? TOKEN_ENABLED : TOKEN_DISABLED);
  122. if (pszQuote == NULL || pszComp == NULL || pszEnable == NULL)
  123. {
  124. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  125. break;
  126. }
  127. if (dwEnabled || (pdwShowDisable && *pdwShowDisable))
  128. {
  129. DisplayMessage(
  130. g_hModule,
  131. MSG_TRACE_DUMP,
  132. DMP_TRACE_SET,
  133. pszComp,
  134. pszEnable);
  135. }
  136. } while (FALSE);
  137. // Cleanup
  138. {
  139. RutlFree(pszComp);
  140. RutlFree(pszEnable);
  141. RutlFree(pszQuote);
  142. }
  143. return dwErr;
  144. }
  145. DWORD
  146. TraceEnableDisable(
  147. IN LPCWSTR pszName,
  148. IN HKEY hKey,
  149. IN HANDLE hData)
  150. {
  151. DWORD dwErr = NO_ERROR, dwEnabled = 0;
  152. DWORD* pdwEnable = (DWORD*)hData;
  153. do
  154. {
  155. // Get the enabling of the current component
  156. //
  157. dwErr = TraceWrite(hKey, *pdwEnable);
  158. BREAK_ON_DWERR(dwErr);
  159. } while (FALSE);
  160. // Cleanup
  161. {
  162. }
  163. return dwErr;
  164. }
  165. //
  166. // Dumps configuration
  167. //
  168. DWORD
  169. TraceDumpConfig(
  170. IN HANDLE hFile
  171. )
  172. {
  173. PWCHAR pszComp = NULL, pszEnable = NULL;
  174. DWORD dwErr = NO_ERROR;
  175. HKEY hkRoot = NULL;
  176. do
  177. {
  178. pszComp = RutlAssignmentFromTokens(
  179. g_hModule,
  180. TOKEN_COMPONENT,
  181. L"*");
  182. pszEnable = RutlAssignmentFromTokens(
  183. g_hModule,
  184. TOKEN_STATE,
  185. TOKEN_DISABLED);
  186. if (pszComp == NULL || pszEnable == NULL)
  187. {
  188. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  189. break;
  190. }
  191. DisplayMessage(
  192. g_hModule,
  193. MSG_TRACE_DUMP,
  194. DMP_TRACE_SET,
  195. pszComp,
  196. pszEnable);
  197. dwErr = TraceOpenRoot(&hkRoot);
  198. BREAK_ON_DWERR(dwErr);
  199. dwErr = RutlRegEnumKeys(
  200. hkRoot,
  201. TraceDumpComponent,
  202. NULL);
  203. BREAK_ON_DWERR(dwErr);
  204. } while (FALSE);
  205. // Cleanup
  206. {
  207. RutlFree(pszComp);
  208. RutlFree(pszEnable);
  209. if (hkRoot)
  210. {
  211. RegCloseKey(hkRoot);
  212. }
  213. }
  214. return NO_ERROR;
  215. }
  216. DWORD
  217. HandleTraceSet(
  218. IN LPCWSTR pwszMachine,
  219. IN OUT LPWSTR *ppwcArguments,
  220. IN DWORD dwCurrentIndex,
  221. IN DWORD dwArgCount,
  222. IN DWORD dwFlags,
  223. IN LPCVOID pvData,
  224. OUT BOOL *pbDone
  225. )
  226. {
  227. DWORD dwErr = NO_ERROR, dwEnable;
  228. PWCHAR pszComponent = NULL;
  229. HKEY hkRoot = NULL, hkComp = NULL;
  230. TOKEN_VALUE rgEnumState[] =
  231. {
  232. {TOKEN_ENABLED, 1},
  233. {TOKEN_DISABLED, 0}
  234. };
  235. RASMON_CMD_ARG pArgs[] =
  236. {
  237. {
  238. RASMONTR_CMD_TYPE_STRING,
  239. {TOKEN_COMPONENT, TRUE, FALSE},
  240. NULL,
  241. 0,
  242. NULL
  243. },
  244. {
  245. RASMONTR_CMD_TYPE_ENUM,
  246. {TOKEN_STATE, TRUE, FALSE},
  247. rgEnumState,
  248. sizeof(rgEnumState)/sizeof(*rgEnumState),
  249. NULL
  250. }
  251. };
  252. do
  253. {
  254. // Parse the command line
  255. //
  256. dwErr = RutlParse(
  257. ppwcArguments,
  258. dwCurrentIndex,
  259. dwArgCount,
  260. pbDone,
  261. pArgs,
  262. sizeof(pArgs)/sizeof(*pArgs));
  263. BREAK_ON_DWERR( dwErr );
  264. pszComponent = RASMON_CMD_ARG_GetPsz(&pArgs[0]);
  265. dwEnable = RASMON_CMD_ARG_GetDword(&pArgs[1]);
  266. // Whistler bug 259800 PREFIX
  267. //
  268. if(pszComponent == NULL)
  269. {
  270. dwErr = ERROR_INVALID_SYNTAX;
  271. break;
  272. }
  273. dwErr = TraceOpenRoot(&hkRoot);
  274. BREAK_ON_DWERR(dwErr);
  275. if (wcscmp(pszComponent, L"*") == 0)
  276. {
  277. dwErr = RutlRegEnumKeys(
  278. hkRoot,
  279. TraceEnableDisable,
  280. (HANDLE)&dwEnable);
  281. BREAK_ON_DWERR(dwErr);
  282. }
  283. else
  284. {
  285. dwErr = TraceOpenKey(hkRoot, pszComponent, &hkComp);
  286. BREAK_ON_DWERR(dwErr);
  287. TraceWrite(hkComp, dwEnable);
  288. BREAK_ON_DWERR(dwErr);
  289. }
  290. } while (FALSE);
  291. // Cleanup
  292. {
  293. RutlFree(pszComponent);
  294. if (hkRoot)
  295. {
  296. RegCloseKey(hkRoot);
  297. }
  298. if (hkComp)
  299. {
  300. RegCloseKey(hkComp);
  301. }
  302. }
  303. return dwErr;
  304. }
  305. DWORD
  306. HandleTraceShow(
  307. IN LPCWSTR pwszMachine,
  308. IN OUT LPWSTR *ppwcArguments,
  309. IN DWORD dwCurrentIndex,
  310. IN DWORD dwArgCount,
  311. IN DWORD dwFlags,
  312. IN LPCVOID pvData,
  313. OUT BOOL *pbDone
  314. )
  315. {
  316. DWORD dwErr = NO_ERROR;
  317. PWCHAR pszComponent = NULL;
  318. HKEY hkRoot = NULL, hkComp = NULL;
  319. RASMON_CMD_ARG pArgs[] =
  320. {
  321. {
  322. RASMONTR_CMD_TYPE_STRING,
  323. {TOKEN_COMPONENT, FALSE, FALSE},
  324. NULL,
  325. 0,
  326. NULL
  327. }
  328. };
  329. do
  330. {
  331. // Parse the command line
  332. //
  333. dwErr = RutlParse(
  334. ppwcArguments,
  335. dwCurrentIndex,
  336. dwArgCount,
  337. pbDone,
  338. pArgs,
  339. sizeof(pArgs)/sizeof(*pArgs));
  340. BREAK_ON_DWERR( dwErr );
  341. pszComponent = RASMON_CMD_ARG_GetPsz(&pArgs[0]);
  342. dwErr = TraceOpenRoot(&hkRoot);
  343. BREAK_ON_DWERR(dwErr);
  344. if (pszComponent)
  345. {
  346. dwErr = TraceOpenKey(hkRoot, pszComponent, &hkComp);
  347. BREAK_ON_DWERR(dwErr);
  348. TraceShow(pszComponent, hkComp, NULL);
  349. BREAK_ON_DWERR(dwErr);
  350. }
  351. else
  352. {
  353. dwErr = RutlRegEnumKeys(
  354. hkRoot,
  355. TraceShow,
  356. NULL);
  357. BREAK_ON_DWERR(dwErr);
  358. }
  359. } while (FALSE);
  360. // Cleanup
  361. {
  362. RutlFree(pszComponent);
  363. if (hkRoot)
  364. {
  365. RegCloseKey(hkRoot);
  366. }
  367. if (hkComp)
  368. {
  369. RegCloseKey(hkComp);
  370. }
  371. }
  372. return dwErr;
  373. }