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.

510 lines
14 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /*****************************************************************/
  5. /*
  6. * logmisc.hxx
  7. *
  8. * This file contains some misc. class definitions used in EVENT_LOG
  9. * which include the pattern classes for filter/search and the log
  10. * entry classes encapsulating common information about the log entries.
  11. *
  12. * EVENT_PATTERN_BASE LOG_ENTRY_BASE
  13. * / \ / \
  14. * / \ / \
  15. * EVENT_FILTER_PATTERN EVENT_FIND_PATTERN RAW_LOG_ENTRY FORMATTED_LOG_ENTRY
  16. *
  17. *
  18. * History:
  19. * Yi-HsinS 10/15/91 Created
  20. * Yi-HsinS 3/5/92 Added Set methods to log entry classes
  21. * Yi-HsinS 4/3/92 Change Subtype to Category
  22. *
  23. */
  24. #ifndef _LOGMISC_HXX_
  25. #define _LOGMISC_HXX_
  26. #include "base.hxx"
  27. // Forward declaration of EVENT_LOG in eventlog.hxx
  28. // This file has to be included before eventlog.hxx
  29. DLL_CLASS EVENT_LOG;
  30. /*
  31. * Direction of reading the event log : forward or backward
  32. */
  33. enum EVLOG_DIRECTION { EVLOG_FWD, EVLOG_BACK };
  34. #define NUM_MATCH_ALL ((ULONG) -1)
  35. /*************************************************************************
  36. NAME: LOG_ENTRY_BASE
  37. SYNOPSIS: This class encapsulates all the common information
  38. contained in both a RAW_LOG_ENTRY and a FORMATTED_LOG_ENTRY.
  39. INTERFACE: LOG_ENTRY_BASE() - Constructor
  40. ~LOG_ENTRY_BASE() - Destructor
  41. Set() - Set all members in the class. Used mainly
  42. when the object is constructed with the
  43. dummy constructor.
  44. The QueryXXX methods:
  45. QueryRecordNum()- Returns the record number of the log entry
  46. QueryTime() - Returns the time in ULONG
  47. QueryType() - Returns the type of the event
  48. QueryCategory() - Returns the category string of the event
  49. QueryEventID() - Returns the event ID
  50. QueryDisplayEventID() - Returns the event ID to be displayed
  51. i. e. strip the top 16 bits off...
  52. QueryEventLog() - Returns the associated event log that
  53. created this entry.
  54. QuerySource() - Returns the source which recorded the event.
  55. QueryUser() - Returns the name of the user on whose behalf
  56. the application which recorded the event is
  57. running.
  58. QueryComputer() - Returns the computer on which the event
  59. is recorded.
  60. PARENT: BASE
  61. USES: NLS_STR, EVENT_LOG
  62. CAVEATS:
  63. NOTES:
  64. HISTORY:
  65. Yi-HsinS 10/15/91 Created
  66. **************************************************************************/
  67. DLL_CLASS LOG_ENTRY_BASE : public BASE
  68. {
  69. protected:
  70. /*
  71. * The following are the common information between a
  72. * RAW_LOG_ENTRY and a FORMATTED_LOG_ENTRY.
  73. */
  74. ULONG _ulRecordNum;
  75. ULONG _ulTime;
  76. USHORT _usType;
  77. NLS_STR _nlsCategory;
  78. ULONG _ulEventID;
  79. /*
  80. * The pointer to the eventlog object is kept here so that in
  81. * case the log entry description is needed when filtering or finding
  82. * the log, we can get the description via this pointer.
  83. */
  84. EVENT_LOG *_pEventLog;
  85. public:
  86. LOG_ENTRY_BASE( VOID ) {};
  87. LOG_ENTRY_BASE( ULONG ulRecordNum,
  88. ULONG ulTime,
  89. USHORT usType,
  90. const TCHAR *pszCategory,
  91. ULONG ulEventID,
  92. EVENT_LOG *pEventLog );
  93. ~LOG_ENTRY_BASE();
  94. APIERR Set( ULONG ulRecordNum,
  95. ULONG ulTime,
  96. USHORT usType,
  97. const TCHAR *pszCategory,
  98. ULONG ulEventID,
  99. EVENT_LOG *pEventLog );
  100. ULONG QueryRecordNum( VOID ) const
  101. { return _ulRecordNum; }
  102. ULONG QueryTime( VOID ) const
  103. { return _ulTime; }
  104. USHORT QueryType( VOID ) const
  105. { return _usType; }
  106. NLS_STR *QueryCategory( VOID )
  107. { return &_nlsCategory; }
  108. ULONG QueryEventID( VOID ) const
  109. { return _ulEventID; }
  110. ULONG QueryDisplayEventID( VOID ) const
  111. { return _ulEventID & 0x0000FFFF; }
  112. EVENT_LOG *QueryEventLog( VOID ) const
  113. { return _pEventLog; }
  114. virtual NLS_STR *QuerySource( VOID ) = 0;
  115. virtual NLS_STR *QueryUser( VOID ) = 0;
  116. virtual NLS_STR *QueryComputer( VOID ) = 0;
  117. };
  118. /*************************************************************************
  119. NAME: RAW_LOG_ENTRY
  120. SYNOPSIS: This class encapsulates all the common information
  121. contained in a LANMAN audit log entry, LANMAN error
  122. log entry, or a NT event log entry. Each entry contains
  123. pointers into the actual buffer. So, there is no
  124. guarantee that after another read ( Next() or SeekLogEntry() ),
  125. the pointers will still be valid.
  126. INTERFACE: RAW_LOG_ENTRY() - Constructor
  127. Set() - Set all members in the class.
  128. The QueryXXX methods:
  129. QuerySource() - Returns the source which recorded the event.
  130. QueryUser() - Returns the name of the user on whose behalf
  131. the application which recorded the event is
  132. running.
  133. QueryComputer() - Returns the computer on which the event
  134. is recorded.
  135. PARENT: LOG_ENTRY_BASE
  136. USES: ALIAS_STR, NLS_STR
  137. CAVEATS:
  138. NOTES:
  139. HISTORY:
  140. Yi-HsinS 10/15/91 Created
  141. **************************************************************************/
  142. DLL_CLASS RAW_LOG_ENTRY : public LOG_ENTRY_BASE
  143. {
  144. private:
  145. ALIAS_STR _nlsSource;
  146. ALIAS_STR _nlsComputer;
  147. /*
  148. * This cannot be a ALIAS_STR because the buffer for NT_EVENT_LOG
  149. * contains a SID and not a user name.
  150. */
  151. NLS_STR _nlsUser;
  152. public:
  153. RAW_LOG_ENTRY( VOID );
  154. RAW_LOG_ENTRY( ULONG ulRecordNum,
  155. ULONG ulTime,
  156. USHORT usType,
  157. const TCHAR *pszCategory,
  158. ULONG ulEventID,
  159. const TCHAR *pszSource,
  160. const TCHAR *pszUser,
  161. const TCHAR *pszComputer,
  162. EVENT_LOG *pEventLog );
  163. APIERR Set( ULONG ulRecordNum,
  164. ULONG ulTime,
  165. USHORT usType,
  166. const TCHAR *pszCategory,
  167. ULONG ulEventID,
  168. const TCHAR *pszSource,
  169. const TCHAR *pszUser,
  170. const TCHAR *pszComputer,
  171. EVENT_LOG *pEventLog );
  172. virtual NLS_STR *QuerySource( VOID ) ;
  173. virtual NLS_STR *QueryUser( VOID ) ;
  174. virtual NLS_STR *QueryComputer( VOID ) ;
  175. };
  176. /*************************************************************************
  177. NAME: FORMATTED_LOG_ENTRY
  178. SYNOPSIS: This class encapsulates all the common information
  179. contained in a LANMAN audit log entry, LANMAN error
  180. log entry, or a NT event log entry. In contrast to
  181. the RAW_LOG_ENTRY, all information in the original
  182. buffer are copied so the log entry will still be
  183. valid after the next read.
  184. INTERFACE: FORMATTED_LOG_ENTRY() - Constructor
  185. Set() - Set all members in the class. Used
  186. mainly when the object is constructed
  187. with the dummy constructor.
  188. The QueryXXX methods:
  189. QuerySource() - Returns the source which recorded the event.
  190. QueryUser() - Returns the name of the user on whose behalf
  191. the application which recorded the event is
  192. running.
  193. QueryComputer() - Returns the computer name which the event
  194. is recorded
  195. QueryTypeString() - Returns the string assoc. with the type
  196. QueryDescription() - Returns the description of the event.
  197. SetDesciption() - Set the description of the event.
  198. PARENT: LOG_ENTRY_BASE
  199. USES: NLS_STR
  200. CAVEATS:
  201. NOTES: This class only contains the common information
  202. of the LM audit log entry, LM error log entry and the NT
  203. event log entry for use in the Event Viewer. It does not
  204. contain all the information available in a log entry.
  205. HISTORY:
  206. Yi-HsinS 10/15/91 Created
  207. **************************************************************************/
  208. DLL_CLASS FORMATTED_LOG_ENTRY : public LOG_ENTRY_BASE
  209. {
  210. private:
  211. NLS_STR _nlsType;
  212. NLS_STR _nlsSource;
  213. NLS_STR _nlsUser;
  214. NLS_STR _nlsComputer;
  215. NLS_STR _nlsDescription;
  216. public:
  217. FORMATTED_LOG_ENTRY( VOID ) {};
  218. FORMATTED_LOG_ENTRY( ULONG ulRecordNum,
  219. ULONG ulTime,
  220. USHORT usType,
  221. const TCHAR *pszType,
  222. const TCHAR *pszCategory,
  223. ULONG ulEventID,
  224. const TCHAR *pszSource,
  225. const TCHAR *pszUser,
  226. const TCHAR *pszComputer,
  227. const TCHAR *pszDescription,
  228. EVENT_LOG *pEventLog );
  229. APIERR Set( ULONG ulRecordNum,
  230. ULONG ulTime,
  231. USHORT usType,
  232. const TCHAR *pszType,
  233. const TCHAR *pszCategory,
  234. ULONG ulEventID,
  235. const TCHAR *pszSource,
  236. const TCHAR *pszUser,
  237. const TCHAR *pszComputer,
  238. const TCHAR *pszDescription,
  239. EVENT_LOG *pEventLog );
  240. /*
  241. * The following returns a pointer to the the _nlsSource, _nlsUser...
  242. * so that we don't need to instantiate another NLS_STR to hold the
  243. * information.
  244. */
  245. virtual NLS_STR *QuerySource( VOID ) ;
  246. virtual NLS_STR *QueryUser( VOID ) ;
  247. virtual NLS_STR *QueryComputer( VOID ) ;
  248. NLS_STR *QueryTypeString( VOID )
  249. { return &_nlsType; }
  250. NLS_STR *QueryDescription( VOID )
  251. { return &_nlsDescription; }
  252. APIERR SetDescription( const TCHAR *pszDescription )
  253. { return _nlsDescription.CopyFrom( pszDescription ); }
  254. };
  255. /*************************************************************************
  256. NAME: EVENT_PATTERN_BASE
  257. SYNOPSIS: Contains common parts of the EVENT_FIND_PATTERN and the
  258. EVENT_FILTER_PATTERN
  259. INTERFACE: EVENT_PATTERN_BASE() - Constructor
  260. QueryType() - Query the type stored in the pattern
  261. QueryCategory() - Query the category stored in the pattern
  262. QuerySource() - Query the source stored in the pattern
  263. QueryUser() - Query the user stored in the pattern
  264. QueryComputer() - Query the computer stored in the pattern
  265. QueryEventID() - Query the event ID stored in the pattern
  266. CheckForMatch() - Check if a LOG_ENTRY_BASE matches the pattern
  267. or not
  268. PARENT: BASE
  269. USES: NLS_STR
  270. CAVEATS:
  271. NOTES: String fields with empty string "" matches all strings
  272. and numerical fields with NUM_MATCH_ALL matches any number.
  273. HISTORY:
  274. Yi-HsinS 10/15/91 Created
  275. **************************************************************************/
  276. DLL_CLASS EVENT_PATTERN_BASE: public BASE
  277. {
  278. private:
  279. USHORT _usType;
  280. NLS_STR _nlsCategory;
  281. NLS_STR _nlsSource;
  282. NLS_STR _nlsUser;
  283. NLS_STR _nlsComputer;
  284. ULONG _ulEventID;
  285. public:
  286. EVENT_PATTERN_BASE( USHORT usType,
  287. const TCHAR *pszCategory,
  288. const TCHAR *pszSource,
  289. const TCHAR *pszUser,
  290. const TCHAR *pszComputer,
  291. ULONG ulEventID );
  292. USHORT QueryType( VOID ) const
  293. { return _usType; }
  294. NLS_STR *QueryCategory( VOID )
  295. { return &_nlsCategory; }
  296. NLS_STR *QuerySource( VOID )
  297. { return &_nlsSource; }
  298. NLS_STR *QueryUser( VOID )
  299. { return &_nlsUser; }
  300. NLS_STR *QueryComputer( VOID )
  301. { return &_nlsComputer; }
  302. ULONG QueryEventID( VOID ) const
  303. { return _ulEventID; }
  304. APIERR CheckForMatch( BOOL *pfMatch, LOG_ENTRY_BASE *pLogEntry ) const;
  305. };
  306. /*************************************************************************
  307. NAME: EVENT_FILTER_PATTERN
  308. SYNOPSIS: The pattern used in filtering
  309. INTERFACE: EVENT_FILTER_PATTERN() - Constructor
  310. QueryFromTime() - Query the from time stored in the pattern
  311. QueryThroughTime() - Query the through time stored in
  312. the pattern
  313. CheckForMatch() - Check if a RAW_LOG_ENTRY matches the
  314. pattern or not
  315. PARENT: EVENT_PATTERN_BASE
  316. USES:
  317. CAVEATS:
  318. NOTES:
  319. HISTORY:
  320. Yi-HsinS 10/15/91 Created
  321. **************************************************************************/
  322. DLL_CLASS EVENT_FILTER_PATTERN : public EVENT_PATTERN_BASE
  323. {
  324. private:
  325. ULONG _ulFromTime;
  326. ULONG _ulThroughTime;
  327. public:
  328. EVENT_FILTER_PATTERN( USHORT usType,
  329. const TCHAR *pszCategory,
  330. const TCHAR *pszSource,
  331. const TCHAR *pszUser,
  332. const TCHAR *pszComputer,
  333. ULONG ulEventID,
  334. ULONG ulFromTime,
  335. ULONG ulThroughTime );
  336. ULONG QueryFromTime( VOID ) const
  337. { return _ulFromTime; }
  338. ULONG QueryThroughTime( VOID ) const
  339. { return _ulThroughTime; }
  340. APIERR CheckForMatch( BOOL *pfMatch, RAW_LOG_ENTRY *pRawLogEntry ) const;
  341. };
  342. /*************************************************************************
  343. NAME: EVENT_FIND_PATTERN
  344. SYNOPSIS: The pattern used in finding a particular log entry
  345. INTERFACE: EVENT_FIND_PATTERN() - Constructor
  346. QueryDescription()- Query the description
  347. QueryDirection() - Query the direction of search the log
  348. CheckForMatch() - Check if a RAW_LOG_ENTRY or
  349. FORMATTED_LOG_ENTRY matches the pattern
  350. or not
  351. PARENT: EVENT_PATTERN_BASE
  352. USES: NLS_STR
  353. CAVEATS:
  354. NOTES:
  355. HISTORY:
  356. Yi-HsinS 10/15/91 Created
  357. **************************************************************************/
  358. DLL_CLASS EVENT_FIND_PATTERN: public EVENT_PATTERN_BASE
  359. {
  360. private:
  361. NLS_STR _nlsDescription;
  362. /*
  363. * The direction of doing the search - EVLOG_FWD or EVLOG_BACK
  364. */
  365. EVLOG_DIRECTION _evdir;
  366. public:
  367. EVENT_FIND_PATTERN( USHORT usType,
  368. const TCHAR *pszCategory,
  369. const TCHAR *pszSource,
  370. const TCHAR *pszUser,
  371. const TCHAR *pszComputer,
  372. ULONG ulEventID,
  373. const TCHAR *pszDescription,
  374. EVLOG_DIRECTION evdir );
  375. NLS_STR *QueryDescription( VOID )
  376. { return &_nlsDescription; }
  377. EVLOG_DIRECTION QueryDirection( VOID ) const
  378. { return _evdir; }
  379. APIERR CheckForMatch( BOOL *pfMatch,
  380. RAW_LOG_ENTRY *pRawLogEntry ) const;
  381. APIERR CheckForMatch( BOOL *pfMatch,
  382. FORMATTED_LOG_ENTRY *pFmtLogEntry ) const;
  383. };
  384. #endif