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.

287 lines
5.9 KiB

  1. //
  2. //
  3. //***************************************************************************
  4. //
  5. // judyp May 1999
  6. //
  7. //***************************************************************************
  8. #include "stdafx.h"
  9. #pragma warning (disable : 4786)
  10. #pragma warning (disable : 4275)
  11. #include <iostream>
  12. #include <strstream>
  13. #include <fstream>
  14. #include <string>
  15. #include <sstream>
  16. #include <map>
  17. #include <ctime>
  18. #include <list>
  19. using namespace std;
  20. #include <tchar.h>
  21. #include <windows.h>
  22. #ifdef NONNT5
  23. typedef unsigned long ULONG_PTR;
  24. #endif
  25. #include <wmistr.h>
  26. #include <guiddef.h>
  27. #include <initguid.h>
  28. #include <evntrace.h>
  29. #include <WTYPES.H>
  30. #include "t_string.h"
  31. #include "StructureWrappers.h"
  32. #include "StructureWapperHelpers.h"
  33. #include "ConstantMap.h"
  34. #include "TCOData.h"
  35. #include "Persistor.h"
  36. #include "Logger.h"
  37. #include "Validator.h"
  38. #include "Utilities.h"
  39. #include "CollectionControl.h"
  40. // Enable all Guids
  41. int EnableTraceAPI
  42. (
  43. IN LPTSTR lptstrAction, // For logging only.
  44. IN LPCTSTR lpctstrDataFile, // For logging only.
  45. IN LPCTSTR lpctstrTCODetailFile, // If valid we will log to it, can be NULL.
  46. IN bool bLogExpected, // If true we log expected vs actual result.
  47. IN OUT TCOData *pstructTCOData, // TCO test data.
  48. OUT int *pAPIReturn // EnableTrace API call return
  49. )
  50. {
  51. *pAPIReturn = -1;
  52. ULONG ulResult =
  53. EnableTraceAPI
  54. (
  55. lptstrAction,
  56. lpctstrDataFile,
  57. lpctstrTCODetailFile,
  58. bLogExpected,
  59. -1,
  60. pstructTCOData,
  61. pAPIReturn
  62. );
  63. for (int i = 0; i < pstructTCOData->m_nGuids; i++)
  64. {
  65. ulResult =
  66. EnableTraceAPI
  67. (
  68. lptstrAction,
  69. lpctstrDataFile,
  70. NULL, // Write detail only for the first Guid enabled!
  71. bLogExpected,
  72. i,
  73. pstructTCOData,
  74. pAPIReturn
  75. );
  76. }
  77. return ulResult;
  78. }
  79. int EnableTraceAPI
  80. (
  81. IN LPTSTR lptstrAction, // For logging only.
  82. IN LPCTSTR lpctstrDataFile, // For logging only.
  83. IN LPCTSTR lpctstrTCODetailFile, // If valid we will log to it, can be NULL.
  84. IN bool bLogExpected, // If true we log expected vs actual result.
  85. IN int nGuidIndex, // Index or if -1 use Guid from WNode.
  86. IN OUT TCOData *pstructTCOData, // TCO test data.
  87. OUT int *pAPIReturn // EnableTrace API call return
  88. )
  89. {
  90. LPTSTR lpstrReturnedError = NULL;
  91. CLogger *pDetailLogger = NULL;
  92. int nResult = 0;
  93. // We only log if the test of "interest" is EnableTrace.
  94. if (pstructTCOData->m_ulAPITest == TCOData::EnableTraceTest)
  95. {
  96. nResult =
  97. OpenLogFiles
  98. (
  99. lpctstrTCODetailFile,
  100. pDetailLogger,
  101. &lpstrReturnedError
  102. );
  103. }
  104. if (FAILED(nResult))
  105. {
  106. delete pDetailLogger;
  107. // Open log files sets error string lpstrReturnedError.
  108. LogSummaryBeforeCall
  109. (
  110. pstructTCOData,
  111. lpctstrDataFile,
  112. lptstrAction,
  113. _T("EnableTrace"),
  114. bLogExpected
  115. );
  116. LogSummaryAfterCall
  117. (
  118. pstructTCOData,
  119. lpctstrDataFile,
  120. lptstrAction,
  121. nResult,
  122. lpstrReturnedError,
  123. bLogExpected
  124. );
  125. free(lpstrReturnedError);
  126. lpstrReturnedError = NULL;
  127. return nResult;
  128. }
  129. // This is our log file.
  130. if (pDetailLogger)
  131. {
  132. pDetailLogger->LogTCHAR(_T("\n-------------------------------------------------------\n"));
  133. pDetailLogger->LogTCHAR(_T("EnableTraceAPI TCO test "));
  134. pDetailLogger->Flush();
  135. }
  136. if (pDetailLogger)
  137. {
  138. pDetailLogger->LogTCHAR(pstructTCOData->m_lptstrShortDesc);
  139. int n = pDetailLogger->LogTCHAR(_T(" started at time "));
  140. time_t Time;
  141. time(&Time);
  142. pDetailLogger->LogTime(Time);
  143. pDetailLogger->LogTCHAR(_T(".\n"));
  144. pDetailLogger->Flush();
  145. }
  146. BOOL bAdmin = IsAdmin();
  147. if (pDetailLogger)
  148. {
  149. // Log argument values before calling StopTrace.
  150. LogDetailBeforeCall
  151. (
  152. pDetailLogger,
  153. pstructTCOData,
  154. bAdmin
  155. );
  156. }
  157. LogSummaryBeforeCall
  158. (
  159. pstructTCOData,
  160. lpctstrDataFile,
  161. lptstrAction,
  162. _T("EnableTrace"),
  163. bLogExpected
  164. );
  165. GUID Guid = nGuidIndex == -1 ?
  166. pstructTCOData->m_pProps->Wnode.Guid:
  167. pstructTCOData->m_lpguidArray[nGuidIndex];
  168. *pAPIReturn =
  169. EnableTrace
  170. (
  171. pstructTCOData->m_ulEnable ? TRUE : FALSE,
  172. pstructTCOData->m_ulEnableFlag,
  173. pstructTCOData->m_ulEnableLevel,
  174. &Guid,
  175. *pstructTCOData->m_pTraceHandle
  176. );
  177. ULONG ulResult = pstructTCOData->m_ulExpectedResult == *pAPIReturn ? ERROR_SUCCESS : -1;
  178. if (ulResult != ERROR_SUCCESS && *pAPIReturn == ERROR_SUCCESS)
  179. {
  180. ulResult = *pAPIReturn;
  181. }
  182. else if (*pAPIReturn != ERROR_SUCCESS)
  183. {
  184. lpstrReturnedError = DecodeStatus(*pAPIReturn);
  185. }
  186. else if (pstructTCOData->m_ulAPITest == TCOData::EnableTraceTest &&
  187. pstructTCOData->m_lptstrValidator &&
  188. _tcslen(pstructTCOData->m_lptstrValidator) > 0)
  189. {
  190. CValidator Validator;
  191. bool bValid =
  192. Validator.Validate
  193. (
  194. pstructTCOData->m_pTraceHandle,
  195. pstructTCOData->m_lptstrInstanceName,
  196. pstructTCOData->m_pProps,
  197. pstructTCOData->m_lptstrValidator
  198. );
  199. if (!bValid)
  200. {
  201. ulResult = -1;
  202. lpstrReturnedError = NewTCHAR(_T("Validation routine failed."));
  203. }
  204. }
  205. t_string tsBanner;
  206. LPTSTR lptstrGuid = NULL;
  207. if (pstructTCOData->m_pProps != 0 &&
  208. Guid.Data1 != 0 &&
  209. Guid.Data2 != 0 &&
  210. Guid.Data3 != 0)
  211. {
  212. lptstrGuid = LPTSTRFromGuid(Guid);
  213. tsBanner = _T("EnableTrace for Guid:");
  214. tsBanner += lptstrGuid;
  215. free (lptstrGuid);
  216. lptstrGuid = NULL;
  217. }
  218. if (pDetailLogger)
  219. {
  220. LogDetailAfterCall
  221. ( pDetailLogger,
  222. pstructTCOData,
  223. &pstructTCOData->m_pProps,
  224. *pAPIReturn,
  225. lpstrReturnedError,
  226. true,
  227. bAdmin,
  228. tsBanner.length() > 0 ? tsBanner.c_str() : NULL,
  229. false
  230. );
  231. }
  232. tsBanner.erase();
  233. LogSummaryAfterCall
  234. (
  235. pstructTCOData,
  236. lpctstrDataFile,
  237. lptstrAction,
  238. *pAPIReturn,
  239. lpstrReturnedError,
  240. bLogExpected
  241. );
  242. free(lpstrReturnedError);
  243. lpstrReturnedError = NULL;
  244. return ulResult;
  245. }