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.

3413 lines
71 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. static CONST WCHAR g_pwszAll[] = L"*";
  14. static CONST WCHAR g_pwszLogPath[] = L"LoggingPath";
  15. static CONST WCHAR g_pwszEnableLog[] = L"EnableLogging";
  16. static CONST WCHAR g_pwszSecurity[] = L"Security";
  17. static CONST WCHAR g_pwszOakleyPath[] = L"\\debug\\oakley.log";
  18. static CONST WCHAR g_pwszWppActive[] = L"Active";
  19. static CONST WCHAR g_pwszWppControlFlags[] = L"ControlFlags";
  20. static CONST WCHAR g_pwszWppControlLevel[] = L"ControlLevel";
  21. static CONST WCHAR g_pwszWppGuid[] = L"Guid";
  22. static CONST WCHAR g_pwszWppLogFileName[] = L"LogFileName";
  23. static CONST WCHAR g_pwszWppPath[] =
  24. L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Tracing\\Microsoft\\RemoteAccess\\";
  25. static CONST WCHAR g_pwszModemSubkey[] =
  26. L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E96D-E325-11CE-BFC1-08002BE10318}";
  27. static CONST WCHAR g_pwszCmLogAllKey[] =
  28. L"Software\\Microsoft\\Connection Manager\\UserInfo";
  29. static CONST WCHAR g_pwszCmLogCurKey[] =
  30. L"Software\\Microsoft\\Connection Manager\\SingleUserInfo";
  31. DWORD
  32. TraceOpenRoot(
  33. OUT PHKEY phKey);
  34. DWORD
  35. TraceOpenKey(
  36. IN HKEY hkRoot,
  37. IN LPCWSTR pszKey,
  38. OUT PHKEY phKey);
  39. DWORD
  40. TraceCloseKey(
  41. IN HKEY hKey);
  42. DWORD
  43. TraceWrite(
  44. IN HKEY hkComp,
  45. IN DWORD dwEnable);
  46. DWORD
  47. TraceRead(
  48. IN HKEY hkComp,
  49. IN LPDWORD lpdwEnable);
  50. DWORD
  51. TraceShow(
  52. IN LPCWSTR pszName,
  53. IN HKEY hKey,
  54. IN HANDLE hData);
  55. DWORD
  56. TraceDumpComponent(
  57. IN LPCWSTR pszName,
  58. IN HKEY hKey,
  59. IN HANDLE hData);
  60. DWORD
  61. TraceEnableDisable(
  62. IN LPCWSTR pszName,
  63. IN HKEY hKey,
  64. IN HANDLE hData);
  65. DWORD
  66. TraceClearTracingCb(
  67. IN LPCWSTR pwszFQFileName,
  68. IN LPCWSTR pwszFileName,
  69. IN HANDLE hData);
  70. BOOL
  71. TraceClearTracing();
  72. DWORD
  73. TraceCollectTracingLogsCb(
  74. IN LPCWSTR pwszFQFileName,
  75. IN LPCWSTR pwszFileName,
  76. IN HANDLE hData);
  77. BOOL
  78. TraceCollectTracingLogs(
  79. IN REPORT_INFO* pInfo,
  80. IN BOOL fEnable);
  81. DWORD
  82. WriteTracingLogsTocCb(
  83. IN LPCWSTR pwszFQFileName,
  84. IN LPCWSTR pwszFileName,
  85. IN HANDLE hData);
  86. BOOL
  87. TraceEnableDisableTracing(
  88. IN BOOL fEnable);
  89. BOOL
  90. TraceShowTracing();
  91. DWORD
  92. TraceClearModemCb(
  93. IN LPCWSTR pszName,
  94. IN HKEY hKey,
  95. IN HANDLE hData);
  96. BOOL
  97. TraceClearModem(
  98. IN BOOL fEnable);
  99. DWORD
  100. TraceCollectModemLogsCb(
  101. IN LPCWSTR pszName,
  102. IN HKEY hKey,
  103. IN HANDLE hData);
  104. BOOL
  105. TraceCollectModemLogs(
  106. IN REPORT_INFO* pInfo,
  107. IN BOOL fEnable);
  108. DWORD
  109. TraceEnableDisableModemCb(
  110. IN LPCWSTR pszName,
  111. IN HKEY hKey,
  112. IN HANDLE hData);
  113. DWORD
  114. TraceShowModemCb(
  115. IN LPCWSTR pszName,
  116. IN HKEY hKey,
  117. IN HANDLE hData);
  118. DWORD
  119. TraceClearCmCb(
  120. IN LPCWSTR pwszName,
  121. IN HKEY hKey,
  122. IN HANDLE hData);
  123. BOOL
  124. TraceClearCm(
  125. IN BOOL fEnable);
  126. DWORD
  127. TraceCollectCmLogsEnumCb(
  128. IN LPCWSTR pwszFQFileName,
  129. IN LPCWSTR pwszFileName,
  130. IN HANDLE hData);
  131. DWORD
  132. TraceCollectCmLogsCb(
  133. IN LPCWSTR pwszName,
  134. IN HKEY hKey,
  135. IN HANDLE hData);
  136. BOOL
  137. TraceCollectCmLogs(
  138. IN REPORT_INFO* pInfo,
  139. IN BOOL fEnable);
  140. DWORD
  141. TraceEnableDisableCmCb(
  142. IN LPCWSTR pszName,
  143. IN HKEY hKey,
  144. IN HANDLE hData);
  145. DWORD
  146. TraceShowCmCb(
  147. IN LPCWSTR pszName,
  148. IN HKEY hKey,
  149. IN HANDLE hData);
  150. BOOL
  151. TraceClearIpsecLogs(
  152. IN BOOL fEnable);
  153. BOOL
  154. TraceCollectIpsecLogs(
  155. IN REPORT_INFO* pInfo);
  156. BOOL
  157. TraceEnableDisableIpsec(
  158. IN BOOL fEnable);
  159. BOOL
  160. TraceClearAuditing(
  161. IN BOOL fEnable);
  162. BOOL
  163. WriteWppTracingState(
  164. IN WPP_LOG_INFO* pWppLog);
  165. BOOL
  166. ReadWppTracingState(
  167. IN WPP_LOG_INFO* pWppLog);
  168. BOOL
  169. StartWppTracing(
  170. IN WPP_LOG_INFO* pWppLog);
  171. BOOL
  172. TraceEnableDisableRasL2tp(
  173. IN BOOL fEnable);
  174. BOOL
  175. TraceEnableDisableRasPptp(
  176. IN BOOL fEnable);
  177. BOOL
  178. PrintRasEventLogsCb(
  179. IN PEVENTLOGRECORD pevlr,
  180. IN HANDLE hModule,
  181. IN HANDLE hData);
  182. VOID
  183. PrintRasEventLogs(
  184. IN REPORT_INFO* pInfo);
  185. BOOL
  186. PrintSecurityEventLogsCb(
  187. IN PEVENTLOGRECORD pevlr,
  188. IN HANDLE hModule,
  189. IN HANDLE hData);
  190. VOID
  191. PrintSecurityEventLogs(
  192. IN REPORT_INFO* pInfo);
  193. DWORD
  194. DiagGetStateCb(
  195. IN LPCWSTR pszName,
  196. IN HKEY hKey,
  197. IN HANDLE hData);
  198. //
  199. // Opens the root tracing registry key
  200. //
  201. DWORD
  202. TraceOpenRoot(
  203. OUT PHKEY phKey)
  204. {
  205. DWORD dwErr = NO_ERROR;
  206. dwErr = RegOpenKeyExW(
  207. g_pServerInfo->hkMachine,
  208. g_pszRegKeyTracing,
  209. 0,
  210. KEY_ALL_ACCESS,
  211. phKey);
  212. return dwErr;
  213. }
  214. DWORD
  215. TraceOpenKey(
  216. IN HKEY hkRoot,
  217. IN LPCWSTR pszKey,
  218. OUT PHKEY phKey)
  219. {
  220. return RegOpenKeyExW(
  221. hkRoot,
  222. pszKey,
  223. 0,
  224. KEY_ALL_ACCESS,
  225. phKey);
  226. }
  227. DWORD
  228. TraceCloseKey(
  229. IN HKEY hKey)
  230. {
  231. return RegCloseKey(hKey);
  232. }
  233. DWORD
  234. TraceWrite(
  235. IN HKEY hkComp,
  236. IN DWORD dwEnable)
  237. {
  238. return RutlRegWriteDword(
  239. hkComp,
  240. (PWCHAR)g_pszRegValTracingFile,
  241. dwEnable);
  242. }
  243. DWORD
  244. TraceRead(
  245. IN HKEY hkComp,
  246. IN LPDWORD lpdwEnable)
  247. {
  248. return RutlRegReadDword(
  249. hkComp,
  250. (PWCHAR)g_pszRegValTracingFile,
  251. lpdwEnable);
  252. }
  253. DWORD
  254. TraceShow(
  255. IN LPCWSTR pszName,
  256. IN HKEY hKey,
  257. IN HANDLE hData)
  258. {
  259. DWORD dwErr = NO_ERROR, dwEnabled = 0;
  260. do
  261. {
  262. // Get the enabling of the current component
  263. //
  264. dwErr = TraceRead(hKey, &dwEnabled);
  265. BREAK_ON_DWERR(dwErr);
  266. // Display the status
  267. //
  268. DisplayMessage(
  269. g_hModule,
  270. MSG_TRACE_SHOW,
  271. pszName,
  272. (dwEnabled) ? TOKEN_ENABLED : TOKEN_DISABLED);
  273. } while (FALSE);
  274. return dwErr;
  275. }
  276. DWORD
  277. TraceDumpComponent(
  278. IN LPCWSTR pszName,
  279. IN HKEY hKey,
  280. IN HANDLE hData)
  281. {
  282. PWCHAR pszComp = NULL, pszEnable = NULL, pszQuote = NULL;
  283. DWORD dwErr = NO_ERROR, dwEnabled = 0;
  284. DWORD* pdwShowDisable = (DWORD*)hData;
  285. do
  286. {
  287. dwErr = TraceRead(hKey, &dwEnabled);
  288. BREAK_ON_DWERR(dwErr);
  289. pszQuote = MakeQuotedString(pszName);
  290. pszComp = RutlAssignmentFromTokens(
  291. g_hModule,
  292. TOKEN_COMPONENT,
  293. pszQuote);
  294. pszEnable = RutlAssignmentFromTokens(
  295. g_hModule,
  296. TOKEN_STATE,
  297. (dwEnabled) ? TOKEN_ENABLED : TOKEN_DISABLED);
  298. if (pszQuote == NULL || pszComp == NULL || pszEnable == NULL)
  299. {
  300. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  301. break;
  302. }
  303. if (dwEnabled || (pdwShowDisable && *pdwShowDisable))
  304. {
  305. DisplayMessage(
  306. g_hModule,
  307. MSG_TRACE_DUMP,
  308. DMP_TRACE_SET,
  309. pszComp,
  310. pszEnable);
  311. }
  312. } while (FALSE);
  313. //
  314. // Cleanup
  315. //
  316. {
  317. RutlFree(pszComp);
  318. RutlFree(pszEnable);
  319. RutlFree(pszQuote);
  320. }
  321. return dwErr;
  322. }
  323. //
  324. // Dumps configuration
  325. //
  326. DWORD
  327. TraceDumpConfig()
  328. {
  329. PWCHAR pszComp = NULL, pszEnable = NULL;
  330. DWORD dwErr = NO_ERROR;
  331. HKEY hkRoot = NULL;
  332. do
  333. {
  334. pszComp = RutlAssignmentFromTokens(
  335. g_hModule,
  336. TOKEN_COMPONENT,
  337. g_pwszAll);
  338. pszEnable = RutlAssignmentFromTokens(
  339. g_hModule,
  340. TOKEN_STATE,
  341. TOKEN_DISABLED);
  342. if (pszComp == NULL || pszEnable == NULL)
  343. {
  344. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  345. break;
  346. }
  347. DisplayMessage(
  348. g_hModule,
  349. MSG_TRACE_DUMP,
  350. DMP_TRACE_SET,
  351. pszComp,
  352. pszEnable);
  353. dwErr = TraceOpenRoot(&hkRoot);
  354. BREAK_ON_DWERR(dwErr);
  355. dwErr = RutlRegEnumKeys(
  356. hkRoot,
  357. TraceDumpComponent,
  358. NULL);
  359. BREAK_ON_DWERR(dwErr);
  360. } while (FALSE);
  361. //
  362. // Cleanup
  363. //
  364. {
  365. RutlFree(pszComp);
  366. RutlFree(pszEnable);
  367. if (hkRoot)
  368. {
  369. RegCloseKey(hkRoot);
  370. }
  371. }
  372. return NO_ERROR;
  373. }
  374. DWORD
  375. TraceEnableDisable(
  376. IN LPCWSTR pszName,
  377. IN HKEY hKey,
  378. IN HANDLE hData)
  379. {
  380. DWORD dwErr = NO_ERROR, dwEnabled = 0;
  381. PDWORD pdwEnable = (PDWORD)hData;
  382. do
  383. {
  384. if (!pdwEnable)
  385. {
  386. dwErr = ERROR_INVALID_PARAMETER;
  387. break;
  388. }
  389. //
  390. // Get the enabling of the current component
  391. //
  392. dwErr = TraceWrite(hKey, *pdwEnable);
  393. BREAK_ON_DWERR(dwErr);
  394. } while (FALSE);
  395. return dwErr;
  396. }
  397. DWORD
  398. HandleTraceSet(
  399. IN LPCWSTR pwszMachine,
  400. IN OUT LPWSTR* ppwcArguments,
  401. IN DWORD dwCurrentIndex,
  402. IN DWORD dwArgCount,
  403. IN DWORD dwFlags,
  404. IN LPCVOID pvData,
  405. OUT BOOL* pbDone)
  406. {
  407. DWORD dwErr = NO_ERROR, dwEnable;
  408. PWCHAR pszComponent = NULL;
  409. HKEY hkRoot = NULL, hkComp = NULL;
  410. TOKEN_VALUE rgEnumState[] =
  411. {
  412. {TOKEN_ENABLED, 1},
  413. {TOKEN_DISABLED, 0}
  414. };
  415. RASMON_CMD_ARG pArgs[] =
  416. {
  417. {
  418. RASMONTR_CMD_TYPE_STRING,
  419. {TOKEN_COMPONENT, TRUE, FALSE},
  420. NULL,
  421. 0,
  422. NULL
  423. },
  424. {
  425. RASMONTR_CMD_TYPE_ENUM,
  426. {TOKEN_STATE, TRUE, FALSE},
  427. rgEnumState,
  428. sizeof(rgEnumState)/sizeof(*rgEnumState),
  429. NULL
  430. }
  431. };
  432. do
  433. {
  434. // Parse the command line
  435. //
  436. dwErr = RutlParse(
  437. ppwcArguments,
  438. dwCurrentIndex,
  439. dwArgCount,
  440. pbDone,
  441. pArgs,
  442. sizeof(pArgs)/sizeof(*pArgs));
  443. BREAK_ON_DWERR( dwErr );
  444. pszComponent = RASMON_CMD_ARG_GetPsz(&pArgs[0]);
  445. if (!pszComponent)
  446. {
  447. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  448. break;
  449. }
  450. dwEnable = RASMON_CMD_ARG_GetDword(&pArgs[1]);
  451. dwErr = TraceOpenRoot(&hkRoot);
  452. BREAK_ON_DWERR(dwErr);
  453. if (wcscmp(pszComponent, g_pwszAll) == 0)
  454. {
  455. dwErr = RutlRegEnumKeys(
  456. hkRoot,
  457. TraceEnableDisable,
  458. (HANDLE)&dwEnable);
  459. BREAK_ON_DWERR(dwErr);
  460. }
  461. else
  462. {
  463. dwErr = TraceOpenKey(hkRoot, pszComponent, &hkComp);
  464. if (dwErr)
  465. {
  466. dwErr = ERROR_INVALID_SYNTAX;
  467. break;
  468. }
  469. TraceWrite(hkComp, dwEnable);
  470. BREAK_ON_DWERR(dwErr);
  471. }
  472. } while (FALSE);
  473. //
  474. // Cleanup
  475. //
  476. {
  477. RutlFree(pszComponent);
  478. if (hkRoot)
  479. {
  480. RegCloseKey(hkRoot);
  481. }
  482. if (hkComp)
  483. {
  484. RegCloseKey(hkComp);
  485. }
  486. }
  487. return dwErr;
  488. }
  489. DWORD
  490. HandleTraceShow(
  491. IN LPCWSTR pwszMachine,
  492. IN OUT LPWSTR* ppwcArguments,
  493. IN DWORD dwCurrentIndex,
  494. IN DWORD dwArgCount,
  495. IN DWORD dwFlags,
  496. IN LPCVOID pvData,
  497. OUT BOOL* pbDone)
  498. {
  499. DWORD dwErr = NO_ERROR;
  500. PWCHAR pszComponent = NULL;
  501. HKEY hkRoot = NULL, hkComp = NULL;
  502. RASMON_CMD_ARG pArgs[] =
  503. {
  504. {
  505. RASMONTR_CMD_TYPE_STRING,
  506. {TOKEN_COMPONENT, FALSE, FALSE},
  507. NULL,
  508. 0,
  509. NULL
  510. }
  511. };
  512. do
  513. {
  514. // Parse the command line
  515. //
  516. dwErr = RutlParse(
  517. ppwcArguments,
  518. dwCurrentIndex,
  519. dwArgCount,
  520. pbDone,
  521. pArgs,
  522. sizeof(pArgs)/sizeof(*pArgs));
  523. BREAK_ON_DWERR( dwErr );
  524. pszComponent = RASMON_CMD_ARG_GetPsz(&pArgs[0]);
  525. dwErr = TraceOpenRoot(&hkRoot);
  526. BREAK_ON_DWERR(dwErr);
  527. if (pszComponent)
  528. {
  529. dwErr = TraceOpenKey(hkRoot, pszComponent, &hkComp);
  530. if (dwErr)
  531. {
  532. dwErr = ERROR_INVALID_SYNTAX;
  533. break;
  534. }
  535. TraceShow(pszComponent, hkComp, NULL);
  536. BREAK_ON_DWERR(dwErr);
  537. }
  538. else
  539. {
  540. dwErr = RutlRegEnumKeys(
  541. hkRoot,
  542. TraceShow,
  543. NULL);
  544. BREAK_ON_DWERR(dwErr);
  545. }
  546. } while (FALSE);
  547. //
  548. // Cleanup
  549. //
  550. {
  551. RutlFree(pszComponent);
  552. if (hkRoot)
  553. {
  554. RegCloseKey(hkRoot);
  555. }
  556. if (hkComp)
  557. {
  558. RegCloseKey(hkComp);
  559. }
  560. }
  561. return dwErr;
  562. }
  563. DWORD
  564. TraceClearTracingCb(
  565. IN LPCWSTR pwszFQFileName,
  566. IN LPCWSTR pwszFileName,
  567. IN HANDLE hData)
  568. {
  569. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  570. if (pTrace)
  571. {
  572. UINT ulTry = 0;
  573. while (ulTry++ < 10)
  574. {
  575. if (DeleteFile(pwszFQFileName))
  576. {
  577. pTrace->fOneOk = TRUE;
  578. break;
  579. }
  580. else if (GetLastError() == ERROR_SHARING_VIOLATION)
  581. {
  582. //
  583. // Wait a little for logging to get disabled
  584. //
  585. Sleep(10);
  586. }
  587. }
  588. }
  589. return NO_ERROR;
  590. }
  591. BOOL
  592. TraceClearTracing(
  593. IN BOOL fEnable)
  594. {
  595. BOOL fRet = FALSE;
  596. PWCHAR pwszTracingPath = NULL;
  597. TRACING_DATA Trace;
  598. do
  599. {
  600. //
  601. // Disable tracing
  602. //
  603. TraceEnableDisableTracing(FALSE);
  604. pwszTracingPath = GetTracingDir();
  605. if (!pwszTracingPath)
  606. {
  607. break;
  608. }
  609. Trace.fOneOk = FALSE;
  610. RutlEnumFiles(
  611. pwszTracingPath,
  612. (PWCHAR)g_pwszLogSrchStr,
  613. TraceClearTracingCb,
  614. &Trace);
  615. fRet = Trace.fOneOk;
  616. //
  617. // Enable tracing
  618. //
  619. if (fEnable)
  620. {
  621. TraceEnableDisableTracing(TRUE);
  622. }
  623. } while (FALSE);
  624. //
  625. // Clean up
  626. //
  627. RutlFree(pwszTracingPath);
  628. return fRet;
  629. }
  630. DWORD
  631. TraceCollectTracingLogsCb(
  632. IN LPCWSTR pwszFQFileName,
  633. IN LPCWSTR pwszFileName,
  634. IN HANDLE hData)
  635. {
  636. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  637. if (pTrace)
  638. {
  639. REPORT_INFO* pInfo = pTrace->pInfo;
  640. if (pInfo)
  641. {
  642. UINT ulTry = 0;
  643. DWORD dwErr = NO_ERROR;
  644. BufferWriteFileStrW(pInfo->pBuff, g_pwszAnNameStart);
  645. BufferWriteFileStrW(pInfo->pBuff, pwszFileName);
  646. BufferWriteFileStrW(pInfo->pBuff, g_pwszAnNameMiddle);
  647. BufferWriteFileStrW(pInfo->pBuff, pwszFileName);
  648. WriteLinkBackToToc(pInfo->pBuff);
  649. BufferWriteFileStrW(pInfo->pBuff, g_pwszAnNameEnd);
  650. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreStart);
  651. while (ulTry++ < 10)
  652. {
  653. dwErr = PrintFile(
  654. pInfo,
  655. pwszFQFileName,
  656. TRUE,
  657. ParseRasLogForTime);
  658. if (!dwErr)
  659. {
  660. pTrace->fOneOk = TRUE;
  661. break;
  662. }
  663. else if (ERROR_SHARING_VIOLATION == dwErr)
  664. {
  665. //
  666. // Wait a little for logging to get disabled
  667. //
  668. Sleep(10);
  669. }
  670. }
  671. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreEnd);
  672. }
  673. }
  674. return NO_ERROR;
  675. }
  676. BOOL
  677. TraceCollectTracingLogs(
  678. IN REPORT_INFO* pInfo,
  679. IN BOOL fEnable)
  680. {
  681. BOOL fRet = FALSE;
  682. PWCHAR pwszTracingPath = NULL;
  683. TRACING_DATA Trace;
  684. do
  685. {
  686. //
  687. // Disable tracing
  688. //
  689. TraceEnableDisableTracing(FALSE);
  690. pwszTracingPath = GetTracingDir();
  691. if (!pwszTracingPath)
  692. {
  693. break;
  694. }
  695. Trace.fOneOk = FALSE;
  696. Trace.pInfo = pInfo;
  697. RutlEnumFiles(
  698. pwszTracingPath,
  699. (PWCHAR)g_pwszLogSrchStr,
  700. TraceCollectTracingLogsCb,
  701. &Trace);
  702. fRet = Trace.fOneOk;
  703. //
  704. // Enable tracing
  705. //
  706. if (fEnable)
  707. {
  708. TraceEnableDisableTracing(TRUE);
  709. }
  710. } while (FALSE);
  711. //
  712. // Clean up
  713. //
  714. RutlFree(pwszTracingPath);
  715. return fRet;
  716. }
  717. DWORD
  718. WriteTracingLogsTocCb(
  719. IN LPCWSTR pwszFQFileName,
  720. IN LPCWSTR pwszFileName,
  721. IN HANDLE hData)
  722. {
  723. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  724. if (pTrace)
  725. {
  726. REPORT_INFO* pInfo = pTrace->pInfo;
  727. if (pInfo)
  728. {
  729. BufferWriteFileStrW(pInfo->pBuff, g_pwszLiStart);
  730. BufferWriteFileStrW(pInfo->pBuff, g_pwszAnStart);
  731. BufferWriteFileStrW(pInfo->pBuff, pwszFileName);
  732. BufferWriteFileStrW(pInfo->pBuff, g_pwszAnMiddle);
  733. BufferWriteFileStrW(pInfo->pBuff, pwszFileName);
  734. BufferWriteFileStrW(pInfo->pBuff, g_pwszAnEnd);
  735. BufferWriteFileStrW(pInfo->pBuff, g_pwszLiEnd);
  736. pTrace->fOneOk = TRUE;
  737. }
  738. }
  739. return NO_ERROR;
  740. }
  741. BOOL
  742. WriteTracingLogsToc(
  743. IN REPORT_INFO* pInfo)
  744. {
  745. BOOL fRet = FALSE;
  746. PWCHAR pwszTracingPath = NULL;
  747. TRACING_DATA Trace;
  748. do
  749. {
  750. pwszTracingPath = GetTracingDir();
  751. if (!pwszTracingPath)
  752. {
  753. break;
  754. }
  755. Trace.fOneOk = FALSE;
  756. Trace.pInfo = pInfo;
  757. RutlEnumFiles(
  758. pwszTracingPath,
  759. (PWCHAR)g_pwszLogSrchStr,
  760. WriteTracingLogsTocCb,
  761. &Trace);
  762. fRet = Trace.fOneOk;
  763. } while (FALSE);
  764. //
  765. // Clean up
  766. //
  767. RutlFree(pwszTracingPath);
  768. return fRet;
  769. }
  770. BOOL
  771. TraceEnableDisableTracing(
  772. IN BOOL fEnable)
  773. {
  774. BOOL fRet = FALSE;
  775. HKEY hkRoot = NULL;
  776. DWORD dwEnable = fEnable ? 1 : 0;
  777. if (!TraceOpenRoot(&hkRoot) &&
  778. !RutlRegEnumKeys(hkRoot, TraceEnableDisable, &dwEnable)
  779. )
  780. {
  781. fRet = TRUE;
  782. }
  783. //
  784. // Clean up
  785. //
  786. if (hkRoot)
  787. {
  788. RegCloseKey(hkRoot);
  789. }
  790. return fRet;
  791. }
  792. BOOL
  793. TraceShowTracing()
  794. {
  795. BOOL fRet = FALSE;
  796. HKEY hkRoot = NULL;
  797. if (!TraceOpenRoot(&hkRoot) &&
  798. !RutlRegEnumKeys(hkRoot, TraceShow, NULL))
  799. {
  800. fRet = TRUE;
  801. }
  802. //
  803. // Clean up
  804. //
  805. if (hkRoot)
  806. {
  807. RegCloseKey(hkRoot);
  808. }
  809. return fRet;
  810. }
  811. DWORD
  812. TraceClearModemCb(
  813. IN LPCWSTR pszName,
  814. IN HKEY hKey,
  815. IN HANDLE hData)
  816. {
  817. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  818. if (pTrace)
  819. {
  820. PWCHAR pwszPath = NULL;
  821. if (!RutlRegReadString(hKey, g_pwszLogPath, &pwszPath) &&
  822. DeleteFile(pwszPath))
  823. {
  824. pTrace->fOneOk = TRUE;
  825. }
  826. RutlFree(pwszPath);
  827. }
  828. return NO_ERROR;
  829. }
  830. BOOL
  831. TraceClearModem(
  832. IN BOOL fEnable)
  833. {
  834. BOOL fRet = FALSE;
  835. HKEY hKey = NULL;
  836. TRACING_DATA Trace;
  837. do
  838. {
  839. if (RegOpenKeyEx(
  840. HKEY_LOCAL_MACHINE,
  841. g_pwszModemSubkey,
  842. 0,
  843. KEY_READ,
  844. &hKey)
  845. )
  846. {
  847. break;
  848. }
  849. //
  850. // Disable all modem logging
  851. //
  852. TraceEnableDisableModem(FALSE);
  853. Trace.fOneOk = FALSE;
  854. RutlRegEnumKeys(hKey, TraceClearModemCb, &Trace);
  855. fRet = Trace.fOneOk;
  856. //
  857. // Enable all modem logging
  858. //
  859. if (fEnable)
  860. {
  861. TraceEnableDisableModem(TRUE);
  862. }
  863. } while (FALSE);
  864. //
  865. // Clean up
  866. //
  867. if (hKey)
  868. {
  869. RegCloseKey(hKey);
  870. }
  871. return fRet;
  872. }
  873. DWORD
  874. TraceCollectModemLogsCb(
  875. IN LPCWSTR pszName,
  876. IN HKEY hKey,
  877. IN HANDLE hData)
  878. {
  879. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  880. if (pTrace)
  881. {
  882. REPORT_INFO* pInfo = pTrace->pInfo;
  883. if (pInfo)
  884. {
  885. PWCHAR pwszPath = NULL;
  886. if (!RutlRegReadString(hKey, g_pwszLogPath, &pwszPath) &&
  887. !PrintFile(pInfo, pwszPath, TRUE, ParseModemLogForTime))
  888. {
  889. pTrace->fOneOk = TRUE;
  890. }
  891. RutlFree(pwszPath);
  892. }
  893. }
  894. return NO_ERROR;
  895. }
  896. BOOL
  897. TraceCollectModemLogs(
  898. IN REPORT_INFO* pInfo,
  899. IN BOOL fEnable)
  900. {
  901. BOOL fRet = FALSE;
  902. HKEY hKey = NULL;
  903. TRACING_DATA Trace;
  904. do
  905. {
  906. if (RegOpenKeyEx(
  907. HKEY_LOCAL_MACHINE,
  908. g_pwszModemSubkey,
  909. 0,
  910. KEY_READ,
  911. &hKey)
  912. )
  913. {
  914. break;
  915. }
  916. //
  917. // Disable all modem logging
  918. //
  919. TraceEnableDisableModem(FALSE);
  920. Trace.fOneOk = FALSE;
  921. Trace.pInfo = pInfo;
  922. RutlRegEnumKeys(hKey, TraceCollectModemLogsCb, &Trace);
  923. fRet = Trace.fOneOk;
  924. //
  925. // Enable all modem logging
  926. //
  927. if (fEnable)
  928. {
  929. TraceEnableDisableModem(TRUE);
  930. }
  931. } while (FALSE);
  932. //
  933. // Clean up
  934. //
  935. if (hKey)
  936. {
  937. RegCloseKey(hKey);
  938. }
  939. return fRet;
  940. }
  941. DWORD
  942. TraceEnableDisableModemCb(
  943. IN LPCWSTR pszName,
  944. IN HKEY hKey,
  945. IN HANDLE hData)
  946. {
  947. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  948. if (pTrace)
  949. {
  950. DWORD dwEnable = pTrace->fData ? 1 : 0;
  951. if (!RegSetValueEx(
  952. hKey,
  953. g_pwszLogging,
  954. 0,
  955. REG_BINARY,
  956. (LPBYTE)&dwEnable,
  957. 1)
  958. )
  959. {
  960. pTrace->fOneOk = TRUE;
  961. }
  962. }
  963. return NO_ERROR;
  964. }
  965. BOOL
  966. TraceEnableDisableModem(
  967. IN BOOL fEnable)
  968. {
  969. BOOL fRet = FALSE;
  970. HKEY hKey = NULL;
  971. TRACING_DATA Trace;
  972. do
  973. {
  974. if (RegOpenKeyEx(
  975. HKEY_LOCAL_MACHINE,
  976. g_pwszModemSubkey,
  977. 0,
  978. KEY_READ | KEY_WRITE,
  979. &hKey)
  980. )
  981. {
  982. break;
  983. }
  984. Trace.fOneOk = FALSE;
  985. Trace.fData = fEnable;
  986. RutlRegEnumKeys(hKey, TraceEnableDisableModemCb, &Trace);
  987. fRet = Trace.fOneOk;
  988. } while (FALSE);
  989. //
  990. // Clean up
  991. //
  992. if (hKey)
  993. {
  994. RegCloseKey(hKey);
  995. }
  996. return fRet;
  997. }
  998. DWORD
  999. TraceShowModemCb(
  1000. IN LPCWSTR pszName,
  1001. IN HKEY hKey,
  1002. IN HANDLE hData)
  1003. {
  1004. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  1005. if (pTrace)
  1006. {
  1007. DWORD dwEnabled = 0;
  1008. if (!RutlRegReadDword(
  1009. hKey,
  1010. g_pwszLogging,
  1011. &dwEnabled) && dwEnabled
  1012. )
  1013. {
  1014. pTrace->fOneOk = TRUE;
  1015. }
  1016. }
  1017. return NO_ERROR;
  1018. }
  1019. BOOL
  1020. TraceShowModem()
  1021. {
  1022. BOOL fRet = FALSE;
  1023. HKEY hKey = NULL;
  1024. TRACING_DATA Trace;
  1025. do
  1026. {
  1027. if (RegOpenKeyEx(
  1028. HKEY_LOCAL_MACHINE,
  1029. g_pwszModemSubkey,
  1030. 0,
  1031. KEY_READ,
  1032. &hKey)
  1033. )
  1034. {
  1035. break;
  1036. }
  1037. Trace.fOneOk = FALSE;
  1038. RutlRegEnumKeys(hKey, TraceShowModemCb, &Trace);
  1039. fRet = Trace.fOneOk;
  1040. } while (FALSE);
  1041. //
  1042. // Clean up
  1043. //
  1044. if (hKey)
  1045. {
  1046. RegCloseKey(hKey);
  1047. }
  1048. return fRet;
  1049. }
  1050. DWORD
  1051. TraceDumpModem()
  1052. {
  1053. BOOL fEnabled;
  1054. DWORD dwErr = NO_ERROR;
  1055. PWCHAR pwszEnable = NULL;
  1056. do
  1057. {
  1058. fEnabled = TraceShowModem();
  1059. pwszEnable = RutlAssignmentFromTokens(
  1060. g_hModule,
  1061. TOKEN_STATE,
  1062. (fEnabled) ? TOKEN_ENABLED : TOKEN_DISABLED);
  1063. if (!pwszEnable)
  1064. {
  1065. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  1066. break;
  1067. }
  1068. DisplayMessage(
  1069. g_hModule,
  1070. MSG_TRACE_DUMP2,
  1071. DMP_RASDIAG_SET_MODEMTRACE,
  1072. pwszEnable);
  1073. } while (FALSE);
  1074. //
  1075. // Cleanup
  1076. //
  1077. RutlFree(pwszEnable);
  1078. return dwErr;
  1079. }
  1080. DWORD
  1081. TraceClearCmCb(
  1082. IN LPCWSTR pwszName,
  1083. IN HKEY hKey,
  1084. IN HANDLE hData)
  1085. {
  1086. PWCHAR pwszSearch = NULL, pwszLoggingPath = NULL;
  1087. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  1088. do
  1089. {
  1090. if (!pTrace)
  1091. {
  1092. break;
  1093. }
  1094. if (GetCMLoggingSearchPath(
  1095. pTrace->hKey,
  1096. pwszName,
  1097. &pwszLoggingPath,
  1098. &pwszSearch))
  1099. {
  1100. RutlEnumFiles(
  1101. pwszLoggingPath,
  1102. pwszSearch,
  1103. TraceClearTracingCb,
  1104. pTrace);
  1105. }
  1106. } while (FALSE);
  1107. //
  1108. // Clean up
  1109. //
  1110. RutlFree(pwszSearch);
  1111. RutlFree(pwszLoggingPath);
  1112. return NO_ERROR;
  1113. }
  1114. BOOL
  1115. TraceClearCm(
  1116. IN BOOL fEnable)
  1117. {
  1118. BOOL fRet = FALSE;
  1119. HKEY hKey = NULL;
  1120. TRACING_DATA Trace;
  1121. do
  1122. {
  1123. //
  1124. // Disable CM logging
  1125. //
  1126. TraceEnableDisableCm(FALSE);
  1127. //
  1128. // Open for ALLUSERS
  1129. //
  1130. Trace.hKey = HKEY_LOCAL_MACHINE;
  1131. Trace.fOneOk = FALSE;
  1132. if (RegOpenKeyEx(
  1133. HKEY_CURRENT_USER,
  1134. g_pwszCmLogAllKey,
  1135. 0,
  1136. KEY_READ,
  1137. &hKey) ||
  1138. RutlRegEnumKeys(
  1139. hKey,
  1140. TraceClearCmCb,
  1141. &Trace)
  1142. )
  1143. {
  1144. break;
  1145. }
  1146. fRet = Trace.fOneOk;
  1147. RegCloseKey(hKey);
  1148. hKey = NULL;
  1149. //
  1150. // Open for CurrentUser
  1151. //
  1152. Trace.hKey = HKEY_CURRENT_USER;
  1153. if (RegOpenKeyEx(
  1154. HKEY_CURRENT_USER,
  1155. g_pwszCmLogCurKey,
  1156. 0,
  1157. KEY_READ,
  1158. &hKey) ||
  1159. RutlRegEnumKeys(
  1160. hKey,
  1161. TraceClearCmCb,
  1162. &Trace)
  1163. )
  1164. {
  1165. break;
  1166. }
  1167. fRet = Trace.fOneOk;
  1168. //
  1169. // Enable CM logging
  1170. //
  1171. if (fEnable)
  1172. {
  1173. TraceEnableDisableCm(TRUE);
  1174. }
  1175. } while (FALSE);
  1176. //
  1177. // Clean up
  1178. //
  1179. if (hKey)
  1180. {
  1181. RegCloseKey(hKey);
  1182. }
  1183. return fRet;
  1184. }
  1185. DWORD
  1186. TraceCollectCmLogsEnumCb(
  1187. IN LPCWSTR pwszFQFileName,
  1188. IN LPCWSTR pwszFileName,
  1189. IN HANDLE hData)
  1190. {
  1191. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  1192. if (pTrace)
  1193. {
  1194. REPORT_INFO* pInfo = pTrace->pInfo;
  1195. if (pInfo)
  1196. {
  1197. if (!PrintFile(pInfo, pwszFQFileName, TRUE, ParseCmLogForTime))
  1198. {
  1199. pTrace->fOneOk = TRUE;
  1200. }
  1201. }
  1202. }
  1203. return NO_ERROR;
  1204. }
  1205. DWORD
  1206. TraceCollectCmLogsCb(
  1207. IN LPCWSTR pwszName,
  1208. IN HKEY hKey,
  1209. IN HANDLE hData)
  1210. {
  1211. PWCHAR pwszSearch = NULL, pwszLoggingPath = NULL;
  1212. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  1213. if (pTrace &&
  1214. GetCMLoggingSearchPath(
  1215. pTrace->hKey,
  1216. pwszName,
  1217. &pwszLoggingPath,
  1218. &pwszSearch))
  1219. {
  1220. RutlEnumFiles(
  1221. pwszLoggingPath,
  1222. pwszSearch,
  1223. TraceCollectCmLogsEnumCb,
  1224. pTrace);
  1225. }
  1226. //
  1227. // Clean up
  1228. //
  1229. RutlFree(pwszSearch);
  1230. RutlFree(pwszLoggingPath);
  1231. return NO_ERROR;
  1232. }
  1233. BOOL
  1234. TraceCollectCmLogs(
  1235. IN REPORT_INFO* pInfo,
  1236. IN BOOL fEnable)
  1237. {
  1238. BOOL fRet = FALSE;
  1239. HKEY hKey = NULL;
  1240. TRACING_DATA Trace;
  1241. do
  1242. {
  1243. //
  1244. // Disable CM logging
  1245. //
  1246. TraceEnableDisableCm(FALSE);
  1247. Trace.fOneOk = FALSE;
  1248. Trace.hKey = HKEY_LOCAL_MACHINE;
  1249. Trace.pInfo = pInfo;
  1250. //
  1251. // Open for ALLUSERS
  1252. //
  1253. if (RegOpenKeyEx(
  1254. HKEY_CURRENT_USER,
  1255. g_pwszCmLogAllKey,
  1256. 0,
  1257. KEY_READ,
  1258. &hKey) ||
  1259. RutlRegEnumKeys(
  1260. hKey,
  1261. TraceCollectCmLogsCb,
  1262. &Trace)
  1263. )
  1264. {
  1265. break;
  1266. }
  1267. fRet = Trace.fOneOk;
  1268. RegCloseKey(hKey);
  1269. hKey = NULL;
  1270. //
  1271. // Open for CurrentUser
  1272. //
  1273. Trace.hKey = HKEY_CURRENT_USER;
  1274. if (RegOpenKeyEx(
  1275. HKEY_CURRENT_USER,
  1276. g_pwszCmLogCurKey,
  1277. 0,
  1278. KEY_READ,
  1279. &hKey) ||
  1280. RutlRegEnumKeys(
  1281. hKey,
  1282. TraceCollectCmLogsCb,
  1283. &Trace)
  1284. )
  1285. {
  1286. break;
  1287. }
  1288. fRet = Trace.fOneOk;
  1289. //
  1290. // Enable CM logging
  1291. //
  1292. if (fEnable)
  1293. {
  1294. TraceEnableDisableCm(TRUE);
  1295. }
  1296. } while (FALSE);
  1297. //
  1298. // Clean up
  1299. //
  1300. if (hKey)
  1301. {
  1302. RegCloseKey(hKey);
  1303. }
  1304. return fRet;
  1305. }
  1306. DWORD
  1307. TraceEnableDisableCmCb(
  1308. IN LPCWSTR pszName,
  1309. IN HKEY hKey,
  1310. IN HANDLE hData)
  1311. {
  1312. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  1313. if (pTrace)
  1314. {
  1315. DWORD dwEnable = pTrace->fData ? 1 : 0;
  1316. if (!RutlRegWriteDword(
  1317. hKey,
  1318. g_pwszEnableLog,
  1319. dwEnable))
  1320. {
  1321. pTrace->fOneOk = TRUE;
  1322. }
  1323. }
  1324. return NO_ERROR;
  1325. }
  1326. BOOL
  1327. TraceEnableDisableCm(
  1328. IN BOOL fEnable)
  1329. {
  1330. BOOL fRet = FALSE;
  1331. HKEY hKey = NULL;
  1332. TRACING_DATA Trace;
  1333. do
  1334. {
  1335. Trace.fOneOk = FALSE;
  1336. Trace.fData = fEnable;
  1337. if (RegOpenKeyEx(
  1338. HKEY_CURRENT_USER,
  1339. g_pwszCmLogAllKey,
  1340. 0,
  1341. KEY_READ | KEY_WRITE,
  1342. &hKey) ||
  1343. RutlRegEnumKeys(
  1344. hKey,
  1345. TraceEnableDisableCmCb,
  1346. &Trace)
  1347. )
  1348. {
  1349. break;
  1350. }
  1351. fRet = Trace.fOneOk;
  1352. RegCloseKey(hKey);
  1353. hKey = NULL;
  1354. if (RegOpenKeyEx(
  1355. HKEY_CURRENT_USER,
  1356. g_pwszCmLogCurKey,
  1357. 0,
  1358. KEY_READ | KEY_WRITE,
  1359. &hKey) ||
  1360. RutlRegEnumKeys(
  1361. hKey,
  1362. TraceEnableDisableCmCb,
  1363. &Trace)
  1364. )
  1365. {
  1366. break;
  1367. }
  1368. fRet = Trace.fOneOk;
  1369. } while (FALSE);
  1370. //
  1371. // Clean up
  1372. //
  1373. if (hKey)
  1374. {
  1375. RegCloseKey(hKey);
  1376. }
  1377. return fRet;
  1378. }
  1379. //
  1380. //
  1381. //
  1382. DWORD
  1383. TraceShowCmCb(
  1384. IN LPCWSTR pszName,
  1385. IN HKEY hKey,
  1386. IN HANDLE hData)
  1387. {
  1388. DWORD dwValueData = 0;
  1389. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  1390. if (pTrace &&
  1391. !RutlRegReadDword(
  1392. hKey,
  1393. g_pwszEnableLog,
  1394. &dwValueData) &&
  1395. dwValueData
  1396. )
  1397. {
  1398. //
  1399. // Success
  1400. //
  1401. pTrace->fOneOk = TRUE;
  1402. }
  1403. return NO_ERROR;
  1404. }
  1405. //
  1406. //
  1407. //
  1408. BOOL
  1409. TraceShowCm()
  1410. {
  1411. BOOL fRet = FALSE;
  1412. HKEY hKey = NULL;
  1413. TRACING_DATA Trace;
  1414. do
  1415. {
  1416. Trace.fOneOk = FALSE;
  1417. if (RegOpenKeyEx(
  1418. HKEY_CURRENT_USER,
  1419. g_pwszCmLogAllKey,
  1420. 0,
  1421. KEY_READ,
  1422. &hKey) ||
  1423. RutlRegEnumKeys(
  1424. hKey,
  1425. TraceShowCmCb,
  1426. &Trace)
  1427. )
  1428. {
  1429. break;
  1430. }
  1431. fRet = Trace.fOneOk;
  1432. RegCloseKey(hKey);
  1433. hKey = NULL;
  1434. if (RegOpenKeyEx(
  1435. HKEY_CURRENT_USER,
  1436. g_pwszCmLogCurKey,
  1437. 0,
  1438. KEY_READ,
  1439. &hKey) ||
  1440. RutlRegEnumKeys(
  1441. hKey,
  1442. TraceShowCmCb,
  1443. &Trace)
  1444. )
  1445. {
  1446. break;
  1447. }
  1448. fRet = Trace.fOneOk;
  1449. } while (FALSE);
  1450. //
  1451. // Clean up
  1452. //
  1453. if (hKey)
  1454. {
  1455. RegCloseKey(hKey);
  1456. }
  1457. return fRet;
  1458. }
  1459. //
  1460. //
  1461. //
  1462. DWORD
  1463. TraceDumpCm()
  1464. {
  1465. BOOL fEnabled;
  1466. DWORD dwErr = NO_ERROR;
  1467. PWCHAR pwszEnable = NULL;
  1468. do
  1469. {
  1470. fEnabled = TraceShowCm();
  1471. pwszEnable = RutlAssignmentFromTokens(
  1472. g_hModule,
  1473. TOKEN_STATE,
  1474. (fEnabled) ? TOKEN_ENABLED : TOKEN_DISABLED);
  1475. if (!pwszEnable)
  1476. {
  1477. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  1478. break;
  1479. }
  1480. DisplayMessage(
  1481. g_hModule,
  1482. MSG_TRACE_DUMP2,
  1483. DMP_RASDIAG_SET_CMTRACE,
  1484. pwszEnable);
  1485. } while (FALSE);
  1486. //
  1487. // Cleanup
  1488. //
  1489. RutlFree(pwszEnable);
  1490. return dwErr;
  1491. }
  1492. //
  1493. // Clear the IPSec logs of any data
  1494. //
  1495. // .Net bug# 509365 No option to delete Oakley Log via RAS Diagnostics U.I.
  1496. //
  1497. BOOL
  1498. TraceClearIpsecLogs(
  1499. IN BOOL fEnable)
  1500. {
  1501. BOOL fRet = FALSE;
  1502. WCHAR wszWindir[MAX_PATH + 1] = L"\0", wszPath[MAX_PATH + 1] = L"\0";
  1503. do
  1504. {
  1505. //
  1506. // Disable IPSec logging
  1507. //
  1508. TraceEnableDisableIpsec(FALSE);
  1509. if (!GetSystemWindowsDirectory(wszWindir, MAX_PATH))
  1510. {
  1511. break;
  1512. }
  1513. _snwprintf(wszPath, MAX_PATH, L"%s%s", wszWindir, g_pwszOakleyPath);
  1514. {
  1515. UINT ulTry = 0;
  1516. while (ulTry++ < 10)
  1517. {
  1518. if (DeleteFile(wszPath))
  1519. {
  1520. fRet = TRUE;
  1521. break;
  1522. }
  1523. else if (GetLastError() == ERROR_SHARING_VIOLATION)
  1524. {
  1525. //
  1526. // Wait a little for logging to get disabled
  1527. //
  1528. Sleep(10);
  1529. }
  1530. }
  1531. }
  1532. } while (FALSE);
  1533. if (fEnable)
  1534. {
  1535. //
  1536. // Re-enable IPSec logging
  1537. //
  1538. TraceEnableDisableIpsec(TRUE);
  1539. }
  1540. return fRet;
  1541. }
  1542. //
  1543. //
  1544. //
  1545. BOOL
  1546. TraceCollectIpsecLogs(
  1547. IN REPORT_INFO* pInfo)
  1548. {
  1549. BOOL fRet = FALSE;
  1550. DWORD dwWindir = 0, dwIpsec = 0;
  1551. WCHAR wszWindir[MAX_PATH + 1] = L"\0";
  1552. PWCHAR pwszIpsecLog = NULL;
  1553. do
  1554. {
  1555. //
  1556. // Whistler .NET BUG: 492081
  1557. //
  1558. if (!GetSystemWindowsDirectory(wszWindir, MAX_PATH))
  1559. {
  1560. break;
  1561. }
  1562. dwWindir = lstrlen(wszWindir);
  1563. if (!dwWindir)
  1564. {
  1565. break;
  1566. }
  1567. dwIpsec = lstrlen(g_pwszOakleyPath);
  1568. pwszIpsecLog = RutlAlloc(
  1569. (dwWindir + dwIpsec + 1) * sizeof(WCHAR),
  1570. FALSE);
  1571. if (!pwszIpsecLog)
  1572. {
  1573. break;
  1574. }
  1575. lstrcpyn(pwszIpsecLog, wszWindir, dwWindir + 1);
  1576. wcsncat(pwszIpsecLog, g_pwszOakleyPath, dwIpsec + 1);
  1577. if (!PrintFile(pInfo, pwszIpsecLog, TRUE, ParseIpsecLogForTime))
  1578. {
  1579. fRet = TRUE;
  1580. }
  1581. } while (FALSE);
  1582. //
  1583. // Clean up
  1584. //
  1585. RutlFree(pwszIpsecLog);
  1586. return fRet;
  1587. }
  1588. //
  1589. //
  1590. //
  1591. BOOL
  1592. TraceEnableDisableIpsec(
  1593. IN BOOL fEnable)
  1594. {
  1595. BOOL fRet = FALSE;
  1596. IKE_CONFIG IKEConfig;
  1597. WPP_LOG_INFO WppLog;
  1598. static GUID c_RasIpsecGuid = IPSEC_GUID;
  1599. static CONST WCHAR c_pwszIpsecPath[] = L"\\TRACING\\IPSEC.BIN";
  1600. static CONST WCHAR c_pwszIpsecSession[] = L"IPSEC";
  1601. do
  1602. {
  1603. //
  1604. // .Net bug# 515191 RAS Diag clears all oakley regkeys when
  1605. // enabling/disabling IPSec Logging
  1606. //
  1607. if (!GetConfigurationVariables(NULL, &IKEConfig))
  1608. {
  1609. IKEConfig.dwEnableLogging = fEnable ? 1 : 0;
  1610. if (!SetConfigurationVariables(NULL, IKEConfig))
  1611. {
  1612. fRet = TRUE;
  1613. }
  1614. }
  1615. //
  1616. // Enable or disable IPSEC WPP tracing
  1617. //
  1618. ZeroMemory(&WppLog, sizeof(WPP_LOG_INFO));
  1619. WppLog.dwEnableFlag = 0x2ff;
  1620. WppLog.dwEnableLevel = 2;
  1621. WppLog.ControlGuid = c_RasIpsecGuid;
  1622. lstrcpyn(WppLog.wszLogFileName, c_pwszIpsecPath, MAX_PATH + 1);
  1623. lstrcpyn(WppLog.wszSessionName, c_pwszIpsecSession, MAX_PATH + 1);
  1624. if (!InitWppData(&WppLog))
  1625. {
  1626. break;
  1627. }
  1628. if (fEnable)
  1629. {
  1630. if (!StartWppTracing(&WppLog))
  1631. {
  1632. break;
  1633. }
  1634. }
  1635. else
  1636. {
  1637. if (!StopWppTracing(&WppLog))
  1638. {
  1639. break;
  1640. }
  1641. }
  1642. fRet = TRUE;
  1643. } while (FALSE);
  1644. //
  1645. // Clean up
  1646. //
  1647. CleanupWppData(&WppLog);
  1648. return fRet;
  1649. }
  1650. //
  1651. //
  1652. //
  1653. BOOL
  1654. TraceClearAuditing(
  1655. IN BOOL fEnable)
  1656. {
  1657. BOOL fRet = FALSE;
  1658. HANDLE hLog = NULL;
  1659. do
  1660. {
  1661. hLog = OpenEventLog(NULL, g_pwszSecurity);
  1662. if (!hLog)
  1663. {
  1664. break;
  1665. }
  1666. if (ClearEventLog(hLog, NULL))
  1667. {
  1668. fRet = TRUE;
  1669. }
  1670. //
  1671. // Enable auditing with no feedback
  1672. //
  1673. if (fEnable)
  1674. {
  1675. TraceEnableDisableAuditing(FALSE, fEnable);
  1676. }
  1677. } while (FALSE);
  1678. //
  1679. // Clean up
  1680. //
  1681. if (hLog)
  1682. {
  1683. CloseEventLog(hLog);
  1684. }
  1685. return fRet;
  1686. }
  1687. //
  1688. //
  1689. //
  1690. BOOL
  1691. TraceEnableDisableAuditing(
  1692. IN BOOL fShowOnly,
  1693. IN BOOL fEnable)
  1694. {
  1695. BOOL fRet = FALSE;
  1696. UINT i;
  1697. NTSTATUS ntstatus;
  1698. LSA_HANDLE policy_handle = NULL;
  1699. OBJECT_ATTRIBUTES obj_attr;
  1700. PPOLICY_AUDIT_EVENTS_INFO info = NULL;
  1701. SECURITY_QUALITY_OF_SERVICE sqos;
  1702. do
  1703. {
  1704. InitializeObjectAttributes(&obj_attr, NULL, 0L, 0L, NULL);
  1705. sqos.Length = sizeof(sqos);
  1706. sqos.ImpersonationLevel = SecurityIdentification;
  1707. sqos.ContextTrackingMode = SECURITY_STATIC_TRACKING;
  1708. sqos.EffectiveOnly = FALSE;
  1709. obj_attr.SecurityQualityOfService = &sqos;
  1710. ntstatus = LsaOpenPolicy(
  1711. NULL,
  1712. &obj_attr,
  1713. POLICY_VIEW_AUDIT_INFORMATION |
  1714. POLICY_SET_AUDIT_REQUIREMENTS |
  1715. POLICY_AUDIT_LOG_ADMIN,
  1716. &policy_handle);
  1717. if (!NT_SUCCESS(ntstatus))
  1718. {
  1719. break;
  1720. }
  1721. ntstatus = LsaQueryInformationPolicy(
  1722. policy_handle,
  1723. PolicyAuditEventsInformation,
  1724. (PVOID*)&info);
  1725. if (!NT_SUCCESS(ntstatus) || (!info))
  1726. {
  1727. break;
  1728. }
  1729. for (i = 0; i < info->MaximumAuditEventCount; i++)
  1730. {
  1731. if(i == AuditCategoryAccountLogon ||
  1732. i == AuditCategoryLogon)
  1733. {
  1734. if (fShowOnly)
  1735. {
  1736. if(i == AuditCategoryAccountLogon ||
  1737. i == AuditCategoryLogon)
  1738. {
  1739. if ((info->EventAuditingOptions[i] &
  1740. POLICY_AUDIT_EVENT_FAILURE) &&
  1741. (info->EventAuditingOptions[i] &
  1742. POLICY_AUDIT_EVENT_SUCCESS)
  1743. )
  1744. {
  1745. fRet = TRUE;
  1746. }
  1747. }
  1748. }
  1749. else
  1750. {
  1751. if(fEnable)
  1752. {
  1753. info->EventAuditingOptions[i] = POLICY_AUDIT_EVENT_FAILURE|
  1754. POLICY_AUDIT_EVENT_SUCCESS;
  1755. } else
  1756. {
  1757. info->EventAuditingOptions[i] = POLICY_AUDIT_EVENT_NONE;
  1758. }
  1759. }
  1760. }
  1761. }
  1762. //
  1763. // See if we are only trying to detect what is enabled
  1764. //
  1765. if (fShowOnly)
  1766. {
  1767. break;
  1768. }
  1769. ntstatus = LsaSetInformationPolicy(
  1770. policy_handle,
  1771. PolicyAuditEventsInformation,
  1772. (PVOID)info);
  1773. if (NT_SUCCESS(ntstatus))
  1774. {
  1775. fRet = TRUE;
  1776. }
  1777. else
  1778. {
  1779. fRet = FALSE;
  1780. }
  1781. } while (FALSE);
  1782. //
  1783. // Clean up
  1784. //
  1785. if (info)
  1786. {
  1787. LsaFreeMemory(info);
  1788. }
  1789. if (policy_handle)
  1790. {
  1791. LsaClose(policy_handle);
  1792. }
  1793. return fRet;
  1794. }
  1795. //
  1796. //
  1797. //
  1798. DWORD
  1799. TraceDumpAuditing()
  1800. {
  1801. BOOL fEnabled;
  1802. DWORD dwErr = NO_ERROR;
  1803. PWCHAR pwszEnable = NULL;
  1804. do
  1805. {
  1806. fEnabled = TraceEnableDisableAuditing(TRUE, FALSE);
  1807. pwszEnable = RutlAssignmentFromTokens(
  1808. g_hModule,
  1809. TOKEN_STATE,
  1810. (fEnabled) ? TOKEN_ENABLED : TOKEN_DISABLED);
  1811. if (!pwszEnable)
  1812. {
  1813. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  1814. break;
  1815. }
  1816. DisplayMessage(
  1817. g_hModule,
  1818. MSG_TRACE_DUMP2,
  1819. DMP_RASDIAG_SET_AUDITING,
  1820. pwszEnable);
  1821. } while (FALSE);
  1822. //
  1823. // Cleanup
  1824. //
  1825. RutlFree(pwszEnable);
  1826. return dwErr;
  1827. }
  1828. //
  1829. // .Net bug# 522035 RAS Diag: include new WPP tracing logs from RASL2TP and
  1830. // RASPPTP
  1831. //
  1832. // Init the EVENT_TRACE_PROPERTIES struct
  1833. //
  1834. BOOL
  1835. InitWppData(
  1836. IN WPP_LOG_INFO* pWppLog)
  1837. {
  1838. BOOL fRet = FALSE;
  1839. ULONG ulSize = sizeof(EVENT_TRACE_PROPERTIES) +
  1840. ((MAX_PATH + 1) * 2 * sizeof(WCHAR));
  1841. do
  1842. {
  1843. if (!pWppLog)
  1844. {
  1845. break;
  1846. }
  1847. //
  1848. // Allocate and init the WPP structure
  1849. //
  1850. pWppLog->pProperties = RutlAlloc(ulSize, TRUE);
  1851. if (!pWppLog->pProperties)
  1852. {
  1853. break;
  1854. }
  1855. pWppLog->pProperties->Wnode.BufferSize = ulSize;
  1856. pWppLog->pProperties->Wnode.Flags = WNODE_FLAG_TRACED_GUID;
  1857. pWppLog->pProperties->MaximumFileSize = 5;
  1858. pWppLog->pProperties->LogFileMode = EVENT_TRACE_FILE_MODE_SEQUENTIAL;
  1859. pWppLog->pProperties->LogFileNameOffset =
  1860. sizeof(EVENT_TRACE_PROPERTIES);
  1861. pWppLog->pProperties->LoggerNameOffset =
  1862. sizeof(EVENT_TRACE_PROPERTIES) + ((MAX_PATH + 1) * sizeof(WCHAR));
  1863. lstrcpyn(
  1864. (PWCHAR )((PBYTE )pWppLog->pProperties +
  1865. pWppLog->pProperties->LoggerNameOffset),
  1866. pWppLog->wszSessionName,
  1867. MAX_PATH + 1);
  1868. if ((pWppLog->wszLogFileName)[0] != L'\0')
  1869. {
  1870. WCHAR wszWindir[MAX_PATH + 1] = L"\0", wszPath[MAX_PATH + 1] = L"\0";
  1871. //
  1872. // Get the name of the tracing directory
  1873. //
  1874. if (!GetSystemWindowsDirectory(wszWindir, MAX_PATH))
  1875. {
  1876. break;
  1877. }
  1878. _snwprintf(
  1879. wszPath,
  1880. MAX_PATH,
  1881. L"%s%s",
  1882. wszWindir,
  1883. pWppLog->wszLogFileName);
  1884. lstrcpyn(
  1885. (PWCHAR )((PBYTE )pWppLog->pProperties +
  1886. pWppLog->pProperties->LogFileNameOffset),
  1887. wszPath,
  1888. MAX_PATH + 1);
  1889. }
  1890. //
  1891. // Attempt to read in any existing settings from the registry, this
  1892. // could overwrite some of the defaults above.
  1893. //
  1894. ReadWppTracingState(pWppLog);
  1895. fRet = TRUE;
  1896. } while (FALSE);
  1897. return fRet;
  1898. }
  1899. //
  1900. // Free the Wpp data struct
  1901. //
  1902. VOID
  1903. CleanupWppData(
  1904. IN WPP_LOG_INFO* pWppLog)
  1905. {
  1906. if (pWppLog)
  1907. {
  1908. RutlFree(pWppLog->pProperties);
  1909. ZeroMemory(pWppLog, sizeof(WPP_LOG_INFO));
  1910. }
  1911. return;
  1912. }
  1913. DWORD
  1914. ClearWppTracingCb(
  1915. IN LPCWSTR pwszFQFileName,
  1916. IN LPCWSTR pwszFileName,
  1917. IN HANDLE hData)
  1918. {
  1919. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  1920. if (pTrace)
  1921. {
  1922. UINT ulTry = 0;
  1923. while (ulTry++ < 10)
  1924. {
  1925. if (DeleteFile(pwszFQFileName))
  1926. {
  1927. pTrace->fOneOk = TRUE;
  1928. break;
  1929. }
  1930. else if (GetLastError() == ERROR_SHARING_VIOLATION)
  1931. {
  1932. //
  1933. // Wait a little for logging to get disabled
  1934. //
  1935. Sleep(10);
  1936. }
  1937. }
  1938. }
  1939. return NO_ERROR;
  1940. }
  1941. BOOL
  1942. ClearWppTracing(
  1943. IN BOOL fEnable)
  1944. {
  1945. BOOL fRet = FALSE;
  1946. PWCHAR pwszTracingPath = NULL;
  1947. TRACING_DATA Trace;
  1948. static CONST WCHAR pwszWppExt[] = L".BIN";
  1949. do
  1950. {
  1951. //
  1952. // Disable tracing
  1953. //
  1954. TraceEnableDisableAllWpp(FALSE);
  1955. pwszTracingPath = GetTracingDir();
  1956. if (!pwszTracingPath)
  1957. {
  1958. break;
  1959. }
  1960. Trace.fOneOk = FALSE;
  1961. RutlEnumFiles(
  1962. pwszTracingPath,
  1963. (PWCHAR)pwszWppExt,
  1964. ClearWppTracingCb,
  1965. &Trace);
  1966. fRet = Trace.fOneOk;
  1967. //
  1968. // Enable tracing
  1969. //
  1970. if (fEnable)
  1971. {
  1972. TraceEnableDisableAllWpp(TRUE);
  1973. }
  1974. } while (FALSE);
  1975. //
  1976. // Clean up
  1977. //
  1978. RutlFree(pwszTracingPath);
  1979. return fRet;
  1980. }
  1981. //
  1982. // Wpp does not currently (01/26/02) persist tracing state across a reboot.
  1983. // When a machine comes back up, even if it was enabled before the reboot,
  1984. // it returns to a disabled state. Thus we must track the state ourselves in
  1985. // the registry.
  1986. //
  1987. BOOL
  1988. WriteWppTracingState(
  1989. IN WPP_LOG_INFO* pWppLog)
  1990. {
  1991. BOOL fRet = FALSE;
  1992. HKEY hkKey = NULL;
  1993. WCHAR wszPath[MAX_PATH + 1] = L"\0", wszGuid[MAX_PATH + 1] = L"\0";
  1994. do
  1995. {
  1996. if ((!pWppLog) || (!pWppLog->pProperties))
  1997. {
  1998. break;
  1999. }
  2000. _snwprintf(
  2001. wszPath,
  2002. MAX_PATH,
  2003. L"%s%s",
  2004. g_pwszWppPath,
  2005. pWppLog->wszSessionName);
  2006. //
  2007. // Create the new key if need be
  2008. //
  2009. if (RegCreateKeyExW(
  2010. HKEY_LOCAL_MACHINE,
  2011. wszPath,
  2012. 0,
  2013. NULL,
  2014. 0,
  2015. KEY_WRITE,
  2016. NULL,
  2017. &hkKey,
  2018. NULL)
  2019. )
  2020. {
  2021. break;
  2022. }
  2023. //
  2024. // Write out the tracing data
  2025. //
  2026. RutlRegWriteDword(hkKey, g_pwszWppActive, pWppLog->dwActive);
  2027. RutlRegWriteDword(hkKey, g_pwszWppControlFlags, pWppLog->dwEnableFlag);
  2028. RutlRegWriteDword(hkKey, g_pwszWppControlLevel, pWppLog->dwEnableLevel);
  2029. RutlConvertGuidToString(&(pWppLog->ControlGuid), wszGuid);
  2030. RutlRegWriteString(hkKey, g_pwszWppGuid, wszGuid);
  2031. RutlRegWriteString(
  2032. hkKey,
  2033. g_pwszWppLogFileName,
  2034. (PWCHAR )((PBYTE )pWppLog->pProperties +
  2035. pWppLog->pProperties->LogFileNameOffset));
  2036. fRet = TRUE;
  2037. } while (FALSE);
  2038. //
  2039. // Clean up
  2040. //
  2041. if (hkKey)
  2042. {
  2043. RegCloseKey(hkKey);
  2044. }
  2045. return fRet;
  2046. }
  2047. //
  2048. // Open the WPP registry location and read out any config values
  2049. //
  2050. BOOL
  2051. ReadWppTracingState(
  2052. IN WPP_LOG_INFO* pWppLog)
  2053. {
  2054. BOOL fRet = FALSE;
  2055. HKEY hkKey = NULL;
  2056. WCHAR wszPath[MAX_PATH + 1] = L"\0";
  2057. PWCHAR pwszGuid = NULL, pwszLogFileName = NULL;
  2058. do
  2059. {
  2060. if ((!pWppLog) || (!pWppLog->pProperties))
  2061. {
  2062. break;
  2063. }
  2064. _snwprintf(
  2065. wszPath,
  2066. MAX_PATH,
  2067. L"%s%s",
  2068. g_pwszWppPath,
  2069. pWppLog->wszSessionName);
  2070. //
  2071. // Open the key
  2072. //
  2073. if (RegOpenKeyEx(
  2074. HKEY_LOCAL_MACHINE,
  2075. wszPath,
  2076. 0,
  2077. KEY_READ,
  2078. &hkKey)
  2079. )
  2080. {
  2081. break;
  2082. }
  2083. //
  2084. // Read in the tracing data
  2085. //
  2086. RutlRegReadDword(hkKey, g_pwszWppActive, &(pWppLog->dwActive));
  2087. RutlRegReadDword(
  2088. hkKey,
  2089. g_pwszWppControlFlags,
  2090. &(pWppLog->dwEnableFlag));
  2091. RutlRegReadDword(
  2092. hkKey,
  2093. g_pwszWppControlLevel,
  2094. &(pWppLog->dwEnableLevel));
  2095. if (!RutlRegReadString(hkKey, g_pwszWppGuid, &pwszGuid))
  2096. {
  2097. RutlConvertStringToGuid(
  2098. pwszGuid,
  2099. lstrlen(pwszGuid) * sizeof(WCHAR),
  2100. &(pWppLog->ControlGuid));
  2101. }
  2102. if (!RutlRegReadString(hkKey, g_pwszWppLogFileName, &pwszLogFileName))
  2103. {
  2104. lstrcpyn(
  2105. (PWCHAR )((PBYTE )pWppLog->pProperties +
  2106. pWppLog->pProperties->LogFileNameOffset),
  2107. pwszLogFileName,
  2108. MAX_PATH + 1);
  2109. }
  2110. fRet = TRUE;
  2111. } while (FALSE);
  2112. //
  2113. // Clean up
  2114. //
  2115. RutlFree(pwszLogFileName);
  2116. RutlFree(pwszGuid);
  2117. if (hkKey)
  2118. {
  2119. RegCloseKey(hkKey);
  2120. }
  2121. return fRet;
  2122. }
  2123. //
  2124. // Start a Wpp tracing session
  2125. //
  2126. BOOL
  2127. StartWppTracing(
  2128. IN WPP_LOG_INFO* pWppLog)
  2129. {
  2130. DWORD dwErr;
  2131. TRACEHANDLE hSession = 0;
  2132. if ((!pWppLog) || (!pWppLog->pProperties))
  2133. {
  2134. return FALSE;
  2135. }
  2136. //
  2137. // Start a tracing session
  2138. //
  2139. if (StartTrace(&hSession, pWppLog->wszSessionName, pWppLog->pProperties))
  2140. {
  2141. return FALSE;
  2142. }
  2143. //
  2144. // Enable a tracing session
  2145. //
  2146. if (EnableTrace(
  2147. TRUE,
  2148. pWppLog->dwEnableFlag,
  2149. pWppLog->dwEnableLevel,
  2150. &(pWppLog->ControlGuid),
  2151. hSession)
  2152. )
  2153. {
  2154. return FALSE;
  2155. }
  2156. //
  2157. // Save off the state in the registry
  2158. //
  2159. pWppLog->dwActive = 1;
  2160. if (!WriteWppTracingState(pWppLog))
  2161. {
  2162. return FALSE;
  2163. }
  2164. return TRUE;
  2165. }
  2166. //
  2167. // Stop a Wpp tracing session
  2168. //
  2169. BOOL
  2170. StopWppTracing(
  2171. IN WPP_LOG_INFO* pWppLog)
  2172. {
  2173. TRACEHANDLE hSession = 0;
  2174. if ((!pWppLog) || (!pWppLog->pProperties))
  2175. {
  2176. return FALSE;
  2177. }
  2178. //
  2179. // Query WPP to see if a tracing session is active
  2180. //
  2181. if (ControlTrace(
  2182. hSession,
  2183. pWppLog->wszSessionName,
  2184. pWppLog->pProperties,
  2185. EVENT_TRACE_CONTROL_QUERY)
  2186. )
  2187. {
  2188. return FALSE;
  2189. }
  2190. //
  2191. // One is active, get it's handle
  2192. //
  2193. hSession = pWppLog->pProperties->Wnode.HistoricalContext;
  2194. //
  2195. // Disable the session
  2196. //
  2197. if (EnableTrace(FALSE, 0, 0, &(pWppLog->ControlGuid), hSession))
  2198. {
  2199. return FALSE;
  2200. }
  2201. //
  2202. // Stop the tracing
  2203. //
  2204. if (ControlTrace(
  2205. hSession,
  2206. pWppLog->wszSessionName,
  2207. pWppLog->pProperties,
  2208. EVENT_TRACE_CONTROL_STOP)
  2209. )
  2210. {
  2211. return FALSE;
  2212. }
  2213. //
  2214. // Save off the state in the registry
  2215. //
  2216. pWppLog->dwActive = 0;
  2217. if (!WriteWppTracingState(pWppLog))
  2218. {
  2219. return FALSE;
  2220. }
  2221. return TRUE;
  2222. }
  2223. //
  2224. // Enum any existing RAS WPP registry entries
  2225. //
  2226. DWORD
  2227. EnumWppTracing(
  2228. IN RAS_REGKEY_ENUM_FUNC_CB pCallback,
  2229. IN HANDLE hData)
  2230. {
  2231. HKEY hKey = NULL;
  2232. DWORD dwErr = NO_ERROR;
  2233. if (!pCallback)
  2234. {
  2235. return ERROR_INVALID_PARAMETER;
  2236. }
  2237. dwErr = RegOpenKeyEx(
  2238. HKEY_LOCAL_MACHINE,
  2239. g_pwszWppPath,
  2240. 0,
  2241. KEY_READ,
  2242. &hKey);
  2243. if (!dwErr)
  2244. {
  2245. dwErr = RutlRegEnumKeys(hKey, pCallback, hData);
  2246. RegCloseKey(hKey);
  2247. }
  2248. return dwErr;
  2249. }
  2250. //
  2251. // Enable or disable RASL2TP WPP tracing
  2252. //
  2253. BOOL
  2254. TraceEnableDisableRasL2tp(
  2255. IN BOOL fEnable)
  2256. {
  2257. BOOL fRet = FALSE;
  2258. WPP_LOG_INFO WppLog;
  2259. static GUID c_RasL2tpGuid = RASL2TP_GUID;
  2260. static CONST WCHAR c_pwszL2tpPath[] = L"\\TRACING\\RASL2TP.BIN";
  2261. static CONST WCHAR c_pwszL2tpSession[] = L"RASL2TP";
  2262. do
  2263. {
  2264. ZeroMemory(&WppLog, sizeof(WPP_LOG_INFO));
  2265. WppLog.dwEnableFlag = 0x2ff;
  2266. WppLog.dwEnableLevel = 2;
  2267. WppLog.ControlGuid = c_RasL2tpGuid;
  2268. lstrcpyn(WppLog.wszLogFileName, c_pwszL2tpPath, MAX_PATH + 1);
  2269. lstrcpyn(WppLog.wszSessionName, c_pwszL2tpSession, MAX_PATH + 1);
  2270. if (!InitWppData(&WppLog))
  2271. {
  2272. break;
  2273. }
  2274. if (fEnable)
  2275. {
  2276. if (!StartWppTracing(&WppLog))
  2277. {
  2278. break;
  2279. }
  2280. }
  2281. else
  2282. {
  2283. if (!StopWppTracing(&WppLog))
  2284. {
  2285. break;
  2286. }
  2287. }
  2288. fRet = TRUE;
  2289. } while (FALSE);
  2290. //
  2291. // Clean up
  2292. //
  2293. CleanupWppData(&WppLog);
  2294. return fRet;
  2295. }
  2296. //
  2297. // Enable or disable RASPPTP WPP tracing
  2298. //
  2299. BOOL
  2300. TraceEnableDisableRasPptp(
  2301. IN BOOL fEnable)
  2302. {
  2303. BOOL fRet = FALSE;
  2304. WPP_LOG_INFO WppLog;
  2305. static GUID c_RasPptpGuid = RASPPTP_GUID;
  2306. static CONST WCHAR c_pwszPptpPath[] = L"\\TRACING\\RASPPTP.BIN";
  2307. static CONST WCHAR c_pwszPptpSession[] = L"RASPPTP";
  2308. do
  2309. {
  2310. ZeroMemory(&WppLog, sizeof(WPP_LOG_INFO));
  2311. WppLog.dwEnableFlag = 0x2ff;
  2312. WppLog.dwEnableLevel = 2;
  2313. WppLog.ControlGuid = c_RasPptpGuid;
  2314. lstrcpyn(WppLog.wszLogFileName, c_pwszPptpPath, MAX_PATH + 1);
  2315. lstrcpyn(WppLog.wszSessionName, c_pwszPptpSession, MAX_PATH + 1);
  2316. if (!InitWppData(&WppLog))
  2317. {
  2318. break;
  2319. }
  2320. if (fEnable)
  2321. {
  2322. if (!StartWppTracing(&WppLog))
  2323. {
  2324. break;
  2325. }
  2326. }
  2327. else
  2328. {
  2329. if (!StopWppTracing(&WppLog))
  2330. {
  2331. break;
  2332. }
  2333. }
  2334. fRet = TRUE;
  2335. } while (FALSE);
  2336. //
  2337. // Clean up
  2338. //
  2339. CleanupWppData(&WppLog);
  2340. return fRet;
  2341. }
  2342. //
  2343. // Enable or disable All WPP tracing
  2344. //
  2345. BOOL
  2346. TraceEnableDisableAllWpp(
  2347. IN BOOL fEnable)
  2348. {
  2349. BOOL fRet = FALSE;
  2350. if (TraceEnableDisableRasL2tp(fEnable))
  2351. {
  2352. fRet = TRUE;
  2353. }
  2354. if (TraceEnableDisableRasPptp(fEnable))
  2355. {
  2356. fRet = TRUE;
  2357. }
  2358. if (TraceEnableDisableIpsec(fEnable))
  2359. {
  2360. fRet = TRUE;
  2361. }
  2362. return fRet;
  2363. }
  2364. //
  2365. // Enable any WPP tracing sessions that were disabled because of reboot
  2366. //
  2367. DWORD
  2368. DiagInitWppTracingCb(
  2369. IN LPCWSTR pszName,
  2370. IN HKEY hKey,
  2371. IN HANDLE hData)
  2372. {
  2373. WPP_LOG_INFO WppLog;
  2374. ZeroMemory(&WppLog, sizeof(WPP_LOG_INFO));
  2375. WppLog.dwEnableFlag = 0x2ff;
  2376. WppLog.dwEnableLevel = 2;
  2377. lstrcpyn(WppLog.wszSessionName, pszName, MAX_PATH + 1);
  2378. if ((InitWppData(&WppLog)) &&
  2379. (WppLog.dwActive)
  2380. )
  2381. {
  2382. StartWppTracing(&WppLog);
  2383. }
  2384. //
  2385. // Clean up
  2386. //
  2387. CleanupWppData(&WppLog);
  2388. return NO_ERROR;
  2389. }
  2390. //
  2391. // NON-NETSH function - allow someone to turn on all of our WPP tracing based
  2392. // on our saved state in the registry
  2393. //
  2394. VOID
  2395. DiagInitWppTracing()
  2396. {
  2397. EnumWppTracing(DiagInitWppTracingCb, NULL);
  2398. return;
  2399. }
  2400. //
  2401. //
  2402. //
  2403. BOOL
  2404. PrintRasEventLogsCb(
  2405. IN PEVENTLOGRECORD pevlr,
  2406. IN HANDLE hModule,
  2407. IN HANDLE hData)
  2408. {
  2409. BOOL fRet = FALSE;
  2410. DWORD dwId = pevlr->EventID;
  2411. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  2412. if (pTrace)
  2413. {
  2414. REPORT_INFO* pInfo = pTrace->pInfo;
  2415. if (pInfo && (((dwId >= RASBASE ) && (dwId <= RASBASEEND)) ||
  2416. ((dwId >= ROUTEBASE ) && ( dwId <= ROUTEBASEEND)) ||
  2417. ((dwId >= ROUTER_LOG_BASE) && (dwId <= ROUTER_LOG_BASEEND)))
  2418. )
  2419. {
  2420. PWCHAR pwszErrorMsg = NULL;
  2421. pwszErrorMsg = FormatMessageFromMod(hModule, dwId);
  2422. if (pwszErrorMsg)
  2423. {
  2424. PWCHAR pwszCategory = NULL, pwszExpanded = NULL;
  2425. pwszExpanded = CreateErrorString(
  2426. pevlr->NumStrings,
  2427. (PWCHAR)((LPBYTE)pevlr + pevlr->StringOffset),
  2428. pwszErrorMsg);
  2429. if (pwszExpanded)
  2430. {
  2431. WriteEventLogEntry(pInfo->pBuff, pevlr, pwszExpanded, NULL);
  2432. RutlFree(pwszExpanded);
  2433. pTrace->fOneOk = TRUE;
  2434. }
  2435. FreeFormatMessageFromMod(pwszErrorMsg);
  2436. fRet = TRUE;
  2437. }
  2438. }
  2439. }
  2440. return fRet;
  2441. }
  2442. //
  2443. //
  2444. //
  2445. VOID
  2446. PrintRasEventLogs(
  2447. IN REPORT_INFO* pInfo)
  2448. {
  2449. TRACING_DATA Trace;
  2450. static CONST WCHAR pwszSystem[] = L"System";
  2451. static CONST WCHAR pwszMsgDll[] = L"mprmsg.dll";
  2452. Trace.fOneOk = FALSE;
  2453. Trace.pInfo = pInfo;
  2454. RutlEnumEventLogs(
  2455. pwszSystem,
  2456. pwszMsgDll,
  2457. MAX_NUMBER_OF_LOGS,
  2458. PrintRasEventLogsCb,
  2459. &Trace);
  2460. if (!Trace.fOneOk)
  2461. {
  2462. BufferWriteMessage(
  2463. pInfo->pBuff,
  2464. g_hModule,
  2465. EMSG_RASDIAG_SHOW_CONFIG_EVENTLOG);
  2466. }
  2467. return;
  2468. }
  2469. //
  2470. //
  2471. //
  2472. BOOL
  2473. PrintSecurityEventLogsCb(
  2474. IN PEVENTLOGRECORD pevlr,
  2475. IN HANDLE hModule,
  2476. IN HANDLE hData)
  2477. {
  2478. BOOL fRet = FALSE;
  2479. PWCHAR pwszErrorMsg = NULL, pwszCategory = NULL, pwszExpanded = NULL;
  2480. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  2481. if (pTrace)
  2482. {
  2483. REPORT_INFO* pInfo = pTrace->pInfo;
  2484. pwszErrorMsg = FormatMessageFromMod(hModule, pevlr->EventID);
  2485. if (pInfo && pwszErrorMsg)
  2486. {
  2487. if (pevlr->EventCategory)
  2488. {
  2489. pwszCategory = FormatMessageFromMod(
  2490. hModule,
  2491. (DWORD)pevlr->EventCategory);
  2492. }
  2493. pwszExpanded = CreateErrorString(
  2494. pevlr->NumStrings,
  2495. (PWCHAR)((LPBYTE)pevlr + pevlr->StringOffset),
  2496. pwszErrorMsg);
  2497. if (pwszExpanded)
  2498. {
  2499. WriteEventLogEntry(
  2500. pInfo->pBuff,
  2501. pevlr,
  2502. pwszExpanded,
  2503. pwszCategory);
  2504. RutlFree(pwszExpanded);
  2505. pTrace->fOneOk = TRUE;
  2506. }
  2507. FreeFormatMessageFromMod(pwszCategory);
  2508. fRet = TRUE;
  2509. }
  2510. FreeFormatMessageFromMod(pwszErrorMsg);
  2511. }
  2512. return fRet;
  2513. }
  2514. //
  2515. //
  2516. //
  2517. VOID
  2518. PrintSecurityEventLogs(
  2519. IN REPORT_INFO* pInfo)
  2520. {
  2521. TRACING_DATA Trace;
  2522. static CONST WCHAR pwszMsgDll[] = L"msaudite.dll";
  2523. Trace.fOneOk = FALSE;
  2524. Trace.pInfo = pInfo;
  2525. RutlEnumEventLogs(
  2526. g_pwszSecurity,
  2527. pwszMsgDll,
  2528. MAX_NUMBER_OF_LOGS,
  2529. PrintSecurityEventLogsCb,
  2530. &Trace);
  2531. if (!Trace.fOneOk)
  2532. {
  2533. BufferWriteMessage(
  2534. pInfo->pBuff,
  2535. g_hModule,
  2536. EMSG_RASDIAG_SHOW_CONFIG_SECEVENTLOG);
  2537. }
  2538. return;
  2539. }
  2540. //
  2541. //
  2542. //
  2543. DWORD
  2544. TraceCollectAll(
  2545. IN REPORT_INFO* pInfo)
  2546. {
  2547. BOOL fEnabled;
  2548. DWORD dwErr = NO_ERROR;
  2549. do
  2550. {
  2551. fEnabled = DiagGetState();
  2552. //
  2553. // Collect RAS tracing logs into report
  2554. //
  2555. WriteHtmlSection(
  2556. pInfo->pBuff,
  2557. g_pwszTraceCollectTracingLogs,
  2558. MSG_RASDIAG_REPORT_TRACE);
  2559. if (pInfo->fDisplay)
  2560. {
  2561. DisplayMessage(g_hModule, MSG_RASDIAG_REPORT_TRACE);
  2562. PrintMessage(g_pwszDispNewLine);
  2563. }
  2564. else if (pInfo->pCallback)
  2565. {
  2566. dwErr = CopyAndCallCB(pInfo, MSG_RASDIAG_REPORT_TRACE);
  2567. BREAK_ON_DWERR(dwErr);
  2568. }
  2569. if (!TraceCollectTracingLogs(pInfo, fEnabled))
  2570. {
  2571. BufferWriteMessage(
  2572. pInfo->pBuff,
  2573. g_hModule,
  2574. EMSG_RASDIAG_SHOW_TRACE_LOGS_FAIL);
  2575. }
  2576. //
  2577. // Collect modem tracing logs into report
  2578. //
  2579. WriteHtmlSection(
  2580. pInfo->pBuff,
  2581. g_pwszTraceCollectModemLogs,
  2582. MSG_RASDIAG_REPORT_TRACE_MODEM);
  2583. if (pInfo->fDisplay)
  2584. {
  2585. DisplayMessage(g_hModule, MSG_RASDIAG_REPORT_TRACE_MODEM);
  2586. PrintMessage(g_pwszDispNewLine);
  2587. }
  2588. else if (pInfo->pCallback)
  2589. {
  2590. dwErr = CopyAndCallCB(pInfo, MSG_RASDIAG_REPORT_TRACE_MODEM);
  2591. BREAK_ON_DWERR(dwErr);
  2592. }
  2593. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreStart);
  2594. if (!TraceCollectModemLogs(pInfo, fEnabled))
  2595. {
  2596. BufferWriteMessage(
  2597. pInfo->pBuff,
  2598. g_hModule,
  2599. EMSG_RASDIAG_SHOW_MODEMTRACE_LOGS_FAIL);
  2600. }
  2601. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreEnd);
  2602. //
  2603. // Collect CM tracing logs into report
  2604. //
  2605. WriteHtmlSection(
  2606. pInfo->pBuff,
  2607. g_pwszTraceCollectCmLogs,
  2608. MSG_RASDIAG_REPORT_TRACE_CM);
  2609. if (pInfo->fDisplay)
  2610. {
  2611. DisplayMessage(g_hModule, MSG_RASDIAG_REPORT_TRACE_CM);
  2612. PrintMessage(g_pwszDispNewLine);
  2613. }
  2614. else if (pInfo->pCallback)
  2615. {
  2616. dwErr = CopyAndCallCB(pInfo, MSG_RASDIAG_REPORT_TRACE_CM);
  2617. BREAK_ON_DWERR(dwErr);
  2618. }
  2619. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreStart);
  2620. if (!TraceCollectCmLogs(pInfo, fEnabled))
  2621. {
  2622. BufferWriteMessage(
  2623. pInfo->pBuff,
  2624. g_hModule,
  2625. EMSG_RASDIAG_SHOW_CM_LOGS_FAIL);
  2626. }
  2627. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreEnd);
  2628. //
  2629. // Collect IPSec tracing logs into report
  2630. //
  2631. WriteHtmlSection(
  2632. pInfo->pBuff,
  2633. g_pwszTraceCollectIpsecLogs,
  2634. MSG_RASDIAG_REPORT_TRACE_IPSEC);
  2635. if (pInfo->fDisplay)
  2636. {
  2637. DisplayMessage(g_hModule, MSG_RASDIAG_REPORT_TRACE_IPSEC);
  2638. PrintMessage(g_pwszDispNewLine);
  2639. }
  2640. else if (pInfo->pCallback)
  2641. {
  2642. dwErr = CopyAndCallCB(pInfo, MSG_RASDIAG_REPORT_TRACE_IPSEC);
  2643. BREAK_ON_DWERR(dwErr);
  2644. }
  2645. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreStart);
  2646. if (!TraceCollectIpsecLogs(pInfo))
  2647. {
  2648. BufferWriteMessage(
  2649. pInfo->pBuff,
  2650. g_hModule,
  2651. EMSG_RASDIAG_SHOW_IPSEC_LOGS_FAIL);
  2652. }
  2653. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreEnd);
  2654. //
  2655. // Collect RAS Events into report
  2656. //
  2657. WriteHtmlSection(
  2658. pInfo->pBuff,
  2659. g_pwszPrintRasEventLogs,
  2660. MSG_RASDIAG_REPORT_RASEVENT);
  2661. if (pInfo->fDisplay)
  2662. {
  2663. DisplayMessage(g_hModule, MSG_RASDIAG_REPORT_RASEVENT);
  2664. PrintMessage(g_pwszDispNewLine);
  2665. }
  2666. else if (pInfo->pCallback)
  2667. {
  2668. dwErr = CopyAndCallCB(pInfo, MSG_RASDIAG_REPORT_RASEVENT);
  2669. BREAK_ON_DWERR(dwErr);
  2670. }
  2671. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreStart);
  2672. PrintRasEventLogs(pInfo);
  2673. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreEnd);
  2674. //
  2675. // Collect Security Events into report
  2676. //
  2677. WriteHtmlSection(
  2678. pInfo->pBuff,
  2679. g_pwszPrintSecurityEventLogs,
  2680. MSG_RASDIAG_REPORT_SECEVENT);
  2681. if (pInfo->fDisplay)
  2682. {
  2683. DisplayMessage(g_hModule, MSG_RASDIAG_REPORT_SECEVENT);
  2684. PrintMessage(g_pwszDispNewLine);
  2685. }
  2686. else if (pInfo->pCallback)
  2687. {
  2688. dwErr = CopyAndCallCB(pInfo, MSG_RASDIAG_REPORT_SECEVENT);
  2689. BREAK_ON_DWERR(dwErr);
  2690. }
  2691. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreStart);
  2692. PrintSecurityEventLogs(pInfo);
  2693. BufferWriteFileStrW(pInfo->pBuff, g_pwszPreEnd);
  2694. } while (FALSE);
  2695. return dwErr;
  2696. }
  2697. //
  2698. //
  2699. //
  2700. VOID
  2701. TraceShowAll()
  2702. {
  2703. if (!TraceShowTracing())
  2704. {
  2705. DisplayMessage(g_hModule, EMSG_RASDIAG_TRACEALL_RAS_FAIL);
  2706. }
  2707. if (TraceShowModem())
  2708. {
  2709. DisplayMessage(g_hModule, MSG_RASDIAG_SHOW_MODEMTRACE_ENABLED);
  2710. }
  2711. else
  2712. {
  2713. DisplayMessage(g_hModule, EMSG_RASDIAG_SHOW_MODEMTRACE_DISABLED);
  2714. }
  2715. if (TraceShowCm())
  2716. {
  2717. DisplayMessage(g_hModule, MSG_RASDIAG_SHOW_CMTRACE_ENABLED);
  2718. }
  2719. else
  2720. {
  2721. DisplayMessage(g_hModule, EMSG_RASDIAG_SHOW_CMTRACE_DISABLED);
  2722. }
  2723. if (TraceEnableDisableAuditing(TRUE, FALSE))
  2724. {
  2725. DisplayMessage(g_hModule, MSG_RASDIAG_SHOW_AUDITING_ENABLED);
  2726. }
  2727. else
  2728. {
  2729. DisplayMessage(g_hModule, EMSG_RASDIAG_SHOW_AUDITING_DISABLED);
  2730. }
  2731. return;
  2732. }
  2733. //
  2734. // Clear all tracing files. All tracing must be disabled before the files can
  2735. // be 'cleared'. The state of tracing is read before the clear so it can be
  2736. // restored (only in the disabled case).
  2737. //
  2738. DWORD
  2739. DiagClearAll(
  2740. IN BOOL fDisplay)
  2741. {
  2742. BOOL fEnabled;
  2743. DWORD dwErr = ERROR_OPEN_FAILED;
  2744. fEnabled = DiagGetState();
  2745. if (TraceClearTracing(fEnabled))
  2746. {
  2747. dwErr = NO_ERROR;
  2748. if (fDisplay)
  2749. {
  2750. DisplayMessage(g_hModule, MSG_RASDIAG_CLEAR_TRACE_OK);
  2751. }
  2752. }
  2753. else if (fDisplay)
  2754. {
  2755. DisplayMessage(g_hModule, EMSG_RASDIAG_CLEAR_TRACE_FAIL);
  2756. }
  2757. if (TraceClearModem(fEnabled))
  2758. {
  2759. dwErr = NO_ERROR;
  2760. if (fDisplay)
  2761. {
  2762. DisplayMessage(g_hModule, MSG_RASDIAG_CLEAR_MODEMTRACE);
  2763. }
  2764. }
  2765. else if (fDisplay)
  2766. {
  2767. DisplayMessage(g_hModule, EMSG_RASDIAG_CLEAR_MODEMTRACE_FAIL);
  2768. }
  2769. if (TraceClearCm(fEnabled))
  2770. {
  2771. dwErr = NO_ERROR;
  2772. if (fDisplay)
  2773. {
  2774. DisplayMessage(g_hModule, MSG_RASDIAG_CLEAR_CMTRACE);
  2775. }
  2776. }
  2777. else if (fDisplay)
  2778. {
  2779. DisplayMessage(g_hModule, EMSG_RASDIAG_CLEAR_CMTRACE_FAIL);
  2780. }
  2781. if (TraceClearAuditing(fEnabled))
  2782. {
  2783. dwErr = NO_ERROR;
  2784. if (fDisplay)
  2785. {
  2786. DisplayMessage(g_hModule, MSG_RASDIAG_CLEAR_AUDITING);
  2787. }
  2788. }
  2789. else if (fDisplay)
  2790. {
  2791. DisplayMessage(g_hModule, EMSG_RASDIAG_CLEAR_AUDITING_FAIL);
  2792. }
  2793. //
  2794. // .Net bug# 509365 No option to delete Oakley Log via RAS Diagnostics U.I.
  2795. //
  2796. TraceClearIpsecLogs(fEnabled);
  2797. //
  2798. // .Net bug# 522035 RAS Diag: include new WPP tracing logs from RASL2TP and
  2799. // RASPPTP
  2800. //
  2801. ClearWppTracing(fEnabled);
  2802. return dwErr;
  2803. }
  2804. //
  2805. // Callback for DiagGetState to detect if any tracing is turned off
  2806. //
  2807. DWORD
  2808. DiagGetStateCb(
  2809. IN LPCWSTR pszName,
  2810. IN HKEY hKey,
  2811. IN HANDLE hData)
  2812. {
  2813. DWORD dwEnabled = 0;
  2814. TRACING_DATA* pTrace = (TRACING_DATA*)hData;
  2815. //
  2816. // Get the enabling of the current component
  2817. //
  2818. TraceRead(hKey, &dwEnabled);
  2819. //
  2820. // If any of the keys are turned off, report failure
  2821. //
  2822. if (!dwEnabled && pTrace)
  2823. {
  2824. pTrace->fOneOk = FALSE;
  2825. }
  2826. return NO_ERROR;
  2827. }
  2828. //
  2829. // NON-NETSH function to detect whether *only* ras tracing is enabled/disabled.
  2830. // This is only used by people who loadlib on RASMONTR.
  2831. //
  2832. BOOL
  2833. DiagGetState()
  2834. {
  2835. BOOL fRet = FALSE;
  2836. HKEY hkRoot = NULL;
  2837. TRACING_DATA Trace;
  2838. Trace.fOneOk = TRUE;
  2839. if (!TraceOpenRoot(&hkRoot) &&
  2840. !RutlRegEnumKeys(hkRoot, DiagGetStateCb, &Trace)
  2841. )
  2842. {
  2843. fRet = Trace.fOneOk;
  2844. }
  2845. //
  2846. // Clean up
  2847. //
  2848. if (hkRoot)
  2849. {
  2850. RegCloseKey(hkRoot);
  2851. }
  2852. return fRet;
  2853. }
  2854. //
  2855. // enable/disable all tracing.
  2856. //
  2857. DWORD
  2858. DiagSetAll(
  2859. IN BOOL fEnable,
  2860. IN BOOL fDisplay)
  2861. {
  2862. DWORD dwErr = ERROR_OPEN_FAILED;
  2863. if (TraceEnableDisableTracing(fEnable))
  2864. {
  2865. dwErr = NO_ERROR;
  2866. if (fDisplay)
  2867. {
  2868. DisplayMessage(g_hModule, MSG_RASDIAG_TRACEALL_RAS_OK);
  2869. }
  2870. }
  2871. else if (fDisplay)
  2872. {
  2873. DisplayMessage(g_hModule, EMSG_RASDIAG_TRACEALL_RAS_FAIL);
  2874. }
  2875. if (TraceEnableDisableModem(fEnable))
  2876. {
  2877. dwErr = NO_ERROR;
  2878. if (fDisplay)
  2879. {
  2880. DisplayMessage(g_hModule, MSG_RASDIAG_SET_MODEMTRACE_OK);
  2881. }
  2882. }
  2883. else if (fDisplay)
  2884. {
  2885. DisplayMessage(g_hModule, EMSG_RASDIAG_SET_MODEMTRACE_FAIL);
  2886. }
  2887. if (TraceEnableDisableCm(fEnable))
  2888. {
  2889. dwErr = NO_ERROR;
  2890. if (fDisplay)
  2891. {
  2892. DisplayMessage(g_hModule, MSG_RASDIAG_SET_CMTRACE_OK);
  2893. }
  2894. }
  2895. else if (fDisplay)
  2896. {
  2897. DisplayMessage(g_hModule, EMSG_RASDIAG_SET_CMTRACE_FAIL);
  2898. }
  2899. if (TraceEnableDisableAuditing(FALSE, fEnable))
  2900. {
  2901. dwErr = NO_ERROR;
  2902. if (fDisplay)
  2903. {
  2904. DisplayMessage(g_hModule, MSG_RASDIAG_SET_AUDITING_OK);
  2905. }
  2906. }
  2907. else if (fDisplay)
  2908. {
  2909. DisplayMessage(g_hModule, EMSG_RASDIAG_SET_AUDITING_FAIL);
  2910. }
  2911. if (TraceEnableDisableIpsec(fEnable))
  2912. {
  2913. dwErr = NO_ERROR;
  2914. if (fDisplay)
  2915. {
  2916. DisplayMessage(g_hModule, MSG_RASDIAG_SET_IPSEC_OK);
  2917. }
  2918. }
  2919. else if (fDisplay)
  2920. {
  2921. DisplayMessage(g_hModule, EMSG_RASDIAG_SET_IPSEC_FAIL);
  2922. }
  2923. //
  2924. // .Net bug# 522035 RAS Diag: include new WPP tracing logs from RASL2TP and
  2925. // RASPPTP
  2926. //
  2927. TraceEnableDisableAllWpp(fEnable);
  2928. return dwErr;
  2929. }
  2930. //
  2931. // NON-NETSH function to enable/disable *only* ras tracing.
  2932. // This is only used by people who loadlib on RASMONTR.
  2933. //
  2934. DWORD
  2935. DiagSetAllRas(
  2936. IN BOOL fEnable)
  2937. {
  2938. //
  2939. // .Net bug# 522035 RAS Diag: include new WPP tracing logs from RASL2TP and
  2940. // RASPPTP
  2941. //
  2942. if (TraceEnableDisableTracing(fEnable) &&
  2943. TraceEnableDisableAllWpp(fEnable))
  2944. {
  2945. return NO_ERROR;
  2946. }
  2947. else
  2948. {
  2949. return ERROR_OPEN_FAILED;
  2950. }
  2951. }