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.

289 lines
7.7 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. smlogsvc.h
  5. Abstract:
  6. Header file for the Performance Logs and Alerts service
  7. --*/
  8. #ifndef _SMLOGSVC_H_
  9. #define _SMLOGSVC_H_
  10. #include <pdh.h>
  11. #include "common.h"
  12. #if !(_IMPLEMENT_WMI)
  13. #define TRACEHANDLE HANDLE
  14. #define EVENT_TRACE_PROPERTIES LPVOID
  15. #endif
  16. #define IDS_UNDER 101
  17. #define IDS_OVER 102
  18. #define IDS_ALERT_MSG_FMT 103
  19. #define IDS_ALERT_TIMESTAMP_FMT 104
  20. #define IDS_CNF_SERIAL_NUMBER_FMT 105
  21. #define IDS_ERR_COUNTER_NOT_VALIDATED 150
  22. // Start or sample delay of NULL_INTERVAL = ULONG_MAX = INFINITE signals to stop immediately.
  23. // The largest single wait time is thus ULONG_MAX -1.
  24. #define NULL_INTERVAL ((DWORD)(INFINITE)) // == ULONG_MAX == 0xFFFFFFFF
  25. #define NULL_INTERVAL_TICS ((LONGLONG)(-1)) // == 0xFFFFFFFF'FFFFFFFF
  26. #define INFINITE_TICS ((LONGLONG)(-1)) // == 0xFFFFFFFF'FFFFFFFF
  27. // Maximum serial number is 999999 for Windows XP
  28. #define MINIMUM_SERIAL_NUMBER ((DWORD)(0x00000000))
  29. #define MAXIMUM_SERIAL_NUMBER ((DWORD)(0x000F423F))
  30. // definitions of dwAutoNameFormat
  31. typedef struct _LOG_COUNTER_INFO {
  32. struct _LOG_COUNTER_INFO *next;
  33. HCOUNTER hCounter;
  34. } LOG_COUNTER_INFO, * PLOG_COUNTER_INFO;
  35. typedef struct _ALERT_COUNTER_INFO {
  36. struct _ALERT_COUNTER_INFO *next;
  37. HCOUNTER hCounter;
  38. PALERT_INFO_BLOCK pAlertInfo;
  39. } ALERT_COUNTER_INFO, * PALERT_COUNTER_INFO;
  40. typedef struct _LOG_QUERY_DATA {
  41. struct _LOG_QUERY_DATA *next;
  42. // These fields are written by the main thread
  43. // and read by the logging thread
  44. HANDLE hThread;
  45. HKEY hKeyQuery;
  46. HANDLE hExitEvent;
  47. HANDLE hReconfigEvent;
  48. LONGLONG llLastConfigured;
  49. // For queries, these fields are written
  50. // and read by the logging thread
  51. SLQ_TIME_INFO stiRegStart;
  52. SLQ_TIME_INFO stiRegStop;
  53. SLQ_TIME_INFO stiCreateNewFile;
  54. SLQ_TIME_INFO stiRepeat;
  55. SLQ_TIME_INFO stiCurrentStart;
  56. SLQ_TIME_INFO stiCurrentStop;
  57. LPWSTR szBaseFileName;
  58. LPWSTR szLogFileFolder;
  59. LPWSTR szSqlLogName;
  60. LPWSTR szLogFileComment;
  61. LPWSTR szCmdFileName;
  62. HANDLE hUserToken;
  63. DWORD dwLogType; // Determines union type below
  64. DWORD dwCurrentState;
  65. DWORD dwLogFileType;
  66. DWORD dwAppendMode;
  67. DWORD dwCmdFileFailure;
  68. DWORD dwAutoNameFormat;
  69. DWORD dwCurrentSerialNumber;
  70. DWORD dwMaxFileSize;
  71. DWORD dwLogFileSizeUnit;
  72. TCHAR szQueryName[MAX_PATH+1];
  73. TCHAR szQueryKeyName[MAX_PATH+1];
  74. BOOL bLoadNewConfig;
  75. union {
  76. struct {
  77. // For trace queries
  78. // these fields are written and read by the logging thread,
  79. // or by the main thread when creating a temporary query
  80. // for comparison.
  81. // Todo: Still true?
  82. TRACEHANDLE LoggerHandle;
  83. LPWSTR mszProviderList;
  84. LPGUID* arrpGuid;
  85. PTCHAR* arrpszProviderName;
  86. HANDLE hNewFileEvent;
  87. EVENT_TRACE_PROPERTIES Properties;
  88. TCHAR szLoggerName[MAX_PATH+1]; // Must follow Properties
  89. TCHAR szLogFileName[MAX_PATH+1]; // Must follow szLoggerName
  90. ULONG ulGuidCount;
  91. DWORD dwBufferSize;
  92. DWORD dwBufferMinCount;
  93. DWORD dwBufferMaxCount;
  94. DWORD dwBufferFlushInterval;
  95. DWORD dwFlags;
  96. };
  97. struct {
  98. // For counter and alert queries
  99. // these fields are written and read by the logging thread,
  100. // or by the main thread when creating a temporary query
  101. // for comparison.
  102. LPWSTR mszCounterList;
  103. PLOG_COUNTER_INFO pFirstCounter;
  104. LPWSTR szNetName;
  105. LPWSTR szPerfLogName;
  106. LPWSTR szUserText;
  107. DWORD dwRealTimeQuery;
  108. DWORD dwAlertActionFlags; // for alert queries
  109. DWORD dwMillisecondSampleInterval;
  110. DWORD dwNetMsgFailureReported;
  111. DWORD dwAlertLogFailureReported;
  112. };
  113. };
  114. } LOG_QUERY_DATA, FAR* PLOG_QUERY_DATA;
  115. // global variables
  116. extern HANDLE hEventLog;
  117. extern HINSTANCE hModule;
  118. extern SERVICE_STATUS_HANDLE hPerfLogStatus;
  119. extern SERVICE_STATUS ssPerfLogStatus;
  120. extern DWORD* arrPdhDataCollectSuccess;
  121. extern INT iPdhDataCollectSuccessCount;
  122. // smlogsvc.c
  123. void SysmonLogServiceControlHandler(
  124. IN DWORD dwControl );
  125. void
  126. SysmonLogServiceStart (
  127. IN DWORD argc,
  128. IN LPTSTR *argv );
  129. int
  130. __cdecl main(int argc, char *argv[]);
  131. // Common functions
  132. BOOL
  133. GetLocalFileTime (
  134. LONGLONG *pFileTime );
  135. long
  136. JulianDateFromSystemTime(
  137. SYSTEMTIME *pST );
  138. DWORD
  139. ReadRegistrySlqTime (
  140. HKEY hKey,
  141. LPCWSTR szQueryName, // For error logging
  142. LPCWSTR szValueName,
  143. PSLQ_TIME_INFO pSlqDefault,
  144. PSLQ_TIME_INFO pSlqValue );
  145. DWORD
  146. ReadRegistryDwordValue (
  147. HKEY hKey,
  148. LPCWSTR szQueryName, // For error logging
  149. LPCWSTR szValueName,
  150. PDWORD pdwDefault,
  151. LPDWORD pdwValue );
  152. DWORD
  153. ReadRegistryStringValue (
  154. HKEY hKey,
  155. LPCWSTR szQueryName, // For error logging
  156. LPCWSTR szValue,
  157. LPCWSTR szDefault,
  158. LPWSTR *pszBuffer,
  159. LPDWORD pdwLength );
  160. DWORD
  161. ReadRegistryIndirectStringValue (
  162. HKEY hKey,
  163. LPCWSTR szQueryName, // For error logging
  164. LPCWSTR szValueName,
  165. LPCWSTR szDefault,
  166. LPWSTR* pszBuffer,
  167. UINT* puiLength );
  168. DWORD
  169. WriteRegistryDwordValue (
  170. HKEY hKey,
  171. LPCWSTR szValueName,
  172. LPDWORD pdwValue,
  173. DWORD dwType); // Also supports REG_BINARY
  174. // *** Optional in C++
  175. DWORD
  176. WriteRegistrySlqTime (
  177. HKEY hKey,
  178. LPCWSTR szValueName,
  179. PSLQ_TIME_INFO pSlqTime );
  180. LONGLONG
  181. ComputeStartWaitTics (
  182. IN PLOG_QUERY_DATA pArg,
  183. IN BOOL bWriteToRegistry );
  184. DWORD
  185. LoadQueryConfig (
  186. IN PLOG_QUERY_DATA pArg );
  187. HRESULT
  188. RegisterCurrentFile(
  189. HKEY hkeyQuery,
  190. LPWSTR strFileName,
  191. DWORD dwSubIndex );
  192. DWORD
  193. BuildCurrentLogFileName (
  194. IN LPCTSTR szQueryName,
  195. IN LPCTSTR szBaseFileName,
  196. IN LPCTSTR szDefaultDir,
  197. IN LPCTSTR szSqlLogName,
  198. IN LPTSTR szOutFileBuffer,
  199. IN LPDWORD lpdwSerialNumber,
  200. IN DWORD dwAutoNameFormat,
  201. IN DWORD dwLogFileType,
  202. IN INT iCnfSerial );
  203. BOOL
  204. FileExists (
  205. IN LPCTSTR szFileName );
  206. void
  207. DeallocateQueryBuffers (
  208. IN PLOG_QUERY_DATA pThisThread );
  209. DWORD
  210. SetStoppedStatus (
  211. IN PLOG_QUERY_DATA pQuery );
  212. // Trace
  213. void
  214. InitTraceProperties (
  215. IN PLOG_QUERY_DATA pQuery,
  216. IN BOOL bUpdateSerial,
  217. IN OUT DWORD* pdwSessionSerial,
  218. IN OUT INT* pCnfSerial );
  219. DWORD
  220. GetTraceQueryStatus (
  221. IN PLOG_QUERY_DATA pQuery,
  222. IN OUT PLOG_QUERY_DATA pReturnQuery);
  223. LPWSTR
  224. FormatEventLogMessage(DWORD dwStatus);
  225. DWORD
  226. DoLogCommandFile (
  227. IN PLOG_QUERY_DATA pArg,
  228. IN LPTSTR szLogFileName,
  229. IN BOOL bStillRunning );
  230. DWORD
  231. GetQueryKeyName (
  232. IN LPCTSTR szQueryName,
  233. OUT LPTSTR szQueryKeyName,
  234. IN DWORD dwQueryKeyNameLen );
  235. // logthred.c
  236. DWORD
  237. LoggingThreadProc (
  238. IN LPVOID lpThreadArg );
  239. #endif //_SMLOGSVC_H_