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.

511 lines
16 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. elfdef.h
  5. Abstract:
  6. This file contains defines for the eventlog service.
  7. Author:
  8. Rajen Shah (rajens) 1-Jul-1991
  9. Revision History:
  10. --*/
  11. #ifndef _EVENTDEF_
  12. #define _EVENTDEF_
  13. //
  14. // Logfile object specific access type
  15. //
  16. #define ELF_LOGFILE_READ 0x0001
  17. #define ELF_LOGFILE_WRITE 0x0002
  18. #define ELF_LOGFILE_CLEAR 0x0004
  19. #define ELF_LOGFILE_START 0x0008
  20. #define ELF_LOGFILE_STOP 0x000C
  21. #define ELF_LOGFILE_CONFIGURE 0x0010
  22. #define ELF_LOGFILE_BACKUP 0x0020 // Set iff a backup operator
  23. // opens the security log -
  24. // this overrides all other
  25. // flags.
  26. #define ELF_LOGFILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
  27. ELF_LOGFILE_READ | \
  28. ELF_LOGFILE_WRITE | \
  29. ELF_LOGFILE_CLEAR | \
  30. ELF_LOGFILE_START | \
  31. ELF_LOGFILE_STOP | \
  32. ELF_LOGFILE_CONFIGURE)
  33. //
  34. // Three types of logfiles are defined from a security perspective:
  35. //
  36. // ELF_LOGFILE_SECURITY - Only Admins/LocalSystem can RW these files
  37. // ELF_LOGFILE_SYSTEM - Only Admins/LocalSystem can W these files
  38. // ELF_LOGFILE_APPLICATION - World can R/W these files
  39. //
  40. // System and Security will be SECURE, Application will be NON_SECURE
  41. //
  42. #define ELF_LOGFILE_SECURITY 0x0000
  43. #define ELF_LOGFILE_SYSTEM 0x0001
  44. #define ELF_LOGFILE_APPLICATION 0x0002
  45. //
  46. // Macro to convert a given file size into one that is "acceptable" for
  47. // eventlogging. It basically truncates it to a 64K boundary making sure
  48. // that it is as least 64K
  49. //
  50. #define ELFFILESIZE(x) ((x & 0xFFFF0000) ? (x & 0xFFFF0000) : 65536)
  51. //
  52. // The largest possible buffer we would need to hold an admin alert
  53. // information. This primarily depends on the number and length of the
  54. // replacement strings that would be passed with the message ID.
  55. //
  56. #define ELF_ADMIN_ALERT_BUFFER_SIZE 256
  57. //
  58. // Timeout defines.
  59. //
  60. #define INFINITE_WAIT_TIME -1 // Wait time for events
  61. #define ELF_GLOBAL_RESOURCE_WAIT 2000 // 2-second timeout for global resource
  62. //
  63. // Signature placed before each event record in a file. Is used to
  64. // validate where we are in a file.
  65. //
  66. #define ELF_RECORD_SIGNATURE 0x654c6652 // ASCII for eLfR
  67. //
  68. // Size by which to grow a log file until it reaches the max size
  69. //
  70. #define ELF_DEFAULT_LOG_SIZE 65536
  71. //
  72. // Bits for whether to take the global resource exclusively or shared.
  73. //
  74. #define ELF_GLOBAL_SHARED 0x0001
  75. #define ELF_GLOBAL_EXCLUSIVE 0x0002
  76. //
  77. // Flag bits to keep track of what resources have been allocated at INIT time
  78. //
  79. #define ELF_INIT_LOGHANDLE_CRIT_SEC 0x0001
  80. #define ELF_INIT_GLOBAL_RESOURCE 0x0002
  81. #define ELF_STARTED_LPC_THREAD 0x0004
  82. #define ELF_STARTED_REGISTRY_MONITOR 0x0008
  83. #define ELF_STARTED_RPC_SERVER 0x0010
  84. #define ELF_INIT_LOGFILE_CRIT_SEC 0x0020
  85. #define ELF_INIT_LOGMODULE_CRIT_SEC 0x0040
  86. #define ELF_INIT_WELL_KNOWN_SIDS 0x0080
  87. #define ELF_INIT_QUEUED_EVENT_CRIT_SEC 0x0100
  88. #define ELF_INIT_QUEUED_MESSAGE_CRIT_SEC 0x0200
  89. #define ELF_INIT_CLUS_CRIT_SEC 0x0400
  90. //
  91. // Enumeration and macro to keep track of the "log full" popup per log
  92. //
  93. #define IS_WORKSTATION() (USER_SHARED_DATA->NtProductType == NtProductWinNt)
  94. typedef enum
  95. {
  96. LOGPOPUP_NEVER_SHOW = 0, // Never show it for this log (e.g., Security)
  97. LOGPOPUP_CLEARED, // Show it when this log fills up
  98. LOGPOPUP_ALREADY_SHOWN // Don't show it again until this log is cleared
  99. }
  100. LOGPOPUP, *PLOGPOPUP;
  101. //
  102. // Structure containing information on each log file
  103. //
  104. // ActualMaxFileSize and ConfigMaxFileSize are stored in BYTEs.
  105. // ActualMaxFileSize is the actual size of the file on the disk.
  106. // ConfigMaxFileSize is the configured size of the file, which may not
  107. // be the same as the actual size of the file.
  108. //
  109. // CurrentRecordNumber is the next absolute record number to write
  110. //
  111. // OldestRecordNumber is the next one to get overwritten
  112. //
  113. // Retention time is stored as the number of seconds.
  114. //
  115. // BaseAddress points to the physical beginning of the file.
  116. //
  117. // ViewSize is ALWAYS the size of the file in bytes.
  118. //
  119. // For the Flag bits, see the ELF_LOGFILE_HEADER_xxxx bits defined below.
  120. //
  121. typedef struct _LOGFILE {
  122. LIST_ENTRY FileList;
  123. LIST_ENTRY Notifiees; // List of ChangeNotify recipients
  124. PUNICODE_STRING LogFileName; // Full path name of log file
  125. PUNICODE_STRING LogModuleName; // Name of default module for this log
  126. ULONG RefCount; // Number of modules using this file
  127. ULONG Flags; // Autowrap, dirty, etc. - See bits below
  128. ULONG ConfigMaxFileSize; // Max it can be
  129. ULONG ActualMaxFileSize; // How big it is now
  130. ULONG NextClearMaxFileSize; // Can't be shrunk on the fly
  131. ULONG CurrentRecordNumber;// The next one to be created
  132. ULONG OldestRecordNumber; // The next one to overwrite
  133. ULONG SessionStartRecordNumber; //the first record number logged in this session
  134. ULONG Retention; // Max. Retention time
  135. ULONG NextClearRetention; // they shrank the file when they set this
  136. HANDLE FileHandle; // Handle to open file
  137. HANDLE SectionHandle; // Memory mapped section handle
  138. PVOID BaseAddress; // Map view base address
  139. ULONG ViewSize; // Mapped view size
  140. ULONG BeginRecord; // Offset of first log record
  141. ULONG EndRecord; // Offset of byte after last log record
  142. ULONG ulLastPulseTime; // Time this log was last notified of a change
  143. LOGPOPUP logpLogPopup; // "Log full" policy for this log
  144. PSECURITY_DESCRIPTOR Sd; // User security object for this log
  145. RTL_RESOURCE Resource;
  146. BOOL bFullAlertDone;
  147. DWORD AutoBackupLogFiles;
  148. } LOGFILE, *PLOGFILE;
  149. //
  150. // Structure containing information on each module that is registered to
  151. // log events.
  152. //
  153. typedef struct _LOGMODULE {
  154. LIST_ENTRY ModuleList;
  155. PWSTR ModuleName; // Name of module
  156. ATOM ModuleAtom; // Atom identifying this module
  157. PLOGFILE LogFile; // Log file for this module
  158. } LOGMODULE, *PLOGMODULE;
  159. //
  160. // Command codes put in the request packets.
  161. //
  162. #define ELF_COMMAND_READ 1
  163. #define ELF_COMMAND_WRITE 2
  164. #define ELF_COMMAND_CLEAR 3
  165. #define ELF_COMMAND_BACKUP 4
  166. #define ELF_COMMAND_WRITE_QUEUED 5
  167. //
  168. // Structures that contain the operation-specific information.
  169. //
  170. typedef struct _WRITE_PKT {
  171. DWORD Datasize; // Size of data in the buffer
  172. PVOID Buffer; // Contains filled event log record
  173. } WRITE_PKT, *PWRITE_PKT;
  174. //
  175. // The following flag bits are used in the READ_PKT Flag field.
  176. //
  177. #define ELF_IREAD_UNICODE 0x0001
  178. #define ELF_IREAD_ANSI 0x0002
  179. #define ELF_LAST_READ_FORWARD 0x0004
  180. typedef struct _READ_PKT {
  181. ULONG Flags; // UNICODE or ANSI
  182. ULONG BufferSize; // Bytes to read
  183. PVOID Buffer; // User's buffer
  184. ULONG ReadFlags; // Sequential? Forwards? Random-access? Backwards?
  185. ULONG RecordNumber; // Where to start the READ
  186. ULONG MinimumBytesNeeded; // For return info if buffer too small
  187. ULONG LastSeekPos; // Last seek position in terms of bytes
  188. ULONG LastSeekRecord; // Last seek position in terms of records
  189. ULONG BytesRead; // Bytes read - for return to caller
  190. ULONG RecordsRead;
  191. } READ_PKT, *PREAD_PKT;
  192. typedef struct _CLEAR_PKT {
  193. PUNICODE_STRING BackupFileName; // File to back up current log file (or NULL)
  194. } CLEAR_PKT, *PCLEAR_PKT;
  195. typedef struct _BACKUP_PKT {
  196. PUNICODE_STRING BackupFileName; // File to back up current log file (or NULL)
  197. } BACKUP_PKT, *PBACKUP_PKT;
  198. //
  199. // Flags used in the ELF_REQUEST_RECORD
  200. //
  201. #define ELF_FORCE_OVERWRITE 0x01 // Ignore retention period for this write
  202. //
  203. // Structure for the packet that contains all the information needed
  204. // to perform the request.
  205. //
  206. typedef struct _ELF_REQUEST_RECORD {
  207. USHORT Flags;
  208. NTSTATUS Status; // To return status of operation
  209. PLOGFILE LogFile; // File on which to operate
  210. PLOGMODULE Module; // Information on module
  211. USHORT Command; // Operation to be performed
  212. union {
  213. PWRITE_PKT WritePkt;
  214. PREAD_PKT ReadPkt;
  215. PCLEAR_PKT ClearPkt;
  216. PBACKUP_PKT BackupPkt;
  217. } Pkt;
  218. } ELF_REQUEST_RECORD, *PELF_REQUEST_RECORD;
  219. typedef
  220. #ifdef _WIN64
  221. __declspec(align(8))
  222. #endif
  223. struct _ELF_ALERT_RECORD {
  224. DWORD TimeOut;
  225. DWORD MessageId;
  226. DWORD NumberOfStrings;
  227. // array of UNICODE_STRINGs NumberOfStringsLong
  228. // each string
  229. } ELF_ALERT_RECORD, * PELF_ALERT_RECORD;
  230. typedef struct _ELF_MESSAGE_RECORD {
  231. DWORD MessageId;
  232. DWORD NumberOfStrings;
  233. // UNICODE null terminated strings
  234. } ELF_MESSAGE_RECORD, * PELF_MESSAGE_RECORD;
  235. //
  236. // Record for the linked list of deferred events (these are raised by the
  237. // eventlog service itself for writing once the current operation is complete
  238. //
  239. typedef struct _ELF_QUEUED_EVENT {
  240. LIST_ENTRY Next;
  241. enum _ELF_QUEUED_EVENT_TYPE {
  242. Event,
  243. Alert,
  244. Message
  245. } Type;
  246. union _ELF_QUEUED_EVENT_DATA {
  247. ELF_REQUEST_RECORD Request;
  248. ELF_ALERT_RECORD Alert;
  249. ELF_MESSAGE_RECORD Message;
  250. } Event;
  251. } ELF_QUEUED_EVENT, *PELF_QUEUED_EVENT;
  252. //
  253. // Structure containing information on callers of ElfChangeNotify
  254. //
  255. typedef struct _NOTIFIEE {
  256. LIST_ENTRY Next;
  257. IELF_HANDLE Handle;
  258. HANDLE Event;
  259. } NOTIFIEE, *PNOTIFIEE;
  260. //
  261. // Structure that describes the header that is at the beginning of the
  262. // log files.
  263. //
  264. // To see if there are any records in the file, one must subtract the
  265. // EndOffset from the StartOffset (allowing for the file having wrapped
  266. // around) and check for a difference of greater than 1.
  267. //
  268. // The header size is stored at the beginning and end so that it looks
  269. // just like any other event log record (the lengths do at any rate).
  270. //
  271. typedef struct _ELF_LOGFILE_HEADER {
  272. ULONG HeaderSize; // Size of this header
  273. ULONG Signature; // Signature field
  274. ULONG MajorVersion;
  275. ULONG MinorVersion;
  276. ULONG StartOffset; // Where the first record is located
  277. ULONG EndOffset; // The end of the last record + 1
  278. ULONG CurrentRecordNumber; // The next record to create
  279. ULONG OldestRecordNumber; // The next record to overwrite
  280. ULONG MaxSize; // Max. size when file was created
  281. ULONG Flags; // DIRTY, etc.
  282. ULONG Retention; // Last Retention period.
  283. ULONG EndHeaderSize; // Size of this header
  284. } ELF_LOGFILE_HEADER, *PELF_LOGFILE_HEADER;
  285. #define FILEHEADERBUFSIZE sizeof(ELF_LOGFILE_HEADER)
  286. #define ELF_LOG_FILE_SIGNATURE 0x654c664c // ASCII for eLfL
  287. //
  288. // The following flag bits are used in ELF_LOGFILE_HEADER and in the
  289. // LOGFILE structures' Flag fields.
  290. //
  291. #define ELF_LOGFILE_HEADER_DIRTY 0x0001 // File has been written to
  292. #define ELF_LOGFILE_HEADER_WRAP 0x0002 // The file has wrapped
  293. #define ELF_LOGFILE_LOGFULL_WRITTEN 0x0004 // Written logfull record
  294. #define ELF_LOGFILE_ARCHIVE_SET 0x0008 // Archive bit flag
  295. //
  296. // Structure that defines the record that identifies the end of the
  297. // circular log file.
  298. // This record is used to identify where the last record in the circular
  299. // buffer is located.
  300. //
  301. // NOTE: It is *essential* that this record is of a size that a "normal"
  302. // event log record can never have. There is code that relies on
  303. // this fact to detect an "EOF" record.
  304. //
  305. // Care must be taken to not disturb the first part of this record. It
  306. // is used to identify an EOF record. ELFEOFUNIQUEPART must be the
  307. // number of bytes that are constant.
  308. //
  309. typedef struct _ELF_EOF_RECORD {
  310. ULONG RecordSizeBeginning;
  311. ULONG One;
  312. ULONG Two;
  313. ULONG Three;
  314. ULONG Four;
  315. ULONG BeginRecord;
  316. ULONG EndRecord;
  317. ULONG CurrentRecordNumber;
  318. ULONG OldestRecordNumber;
  319. ULONG RecordSizeEnd;
  320. } ELF_EOF_RECORD, *PELF_EOF_RECORD;
  321. #define ELFEOFRECORDSIZE sizeof (ELF_EOF_RECORD)
  322. //
  323. // The following constant is how much of the EOF record is constant, and can
  324. // be used to identify an EOF record
  325. //
  326. #define ELFEOFUNIQUEPART 5 * sizeof(ULONG)
  327. //
  328. // This is used to fill the end of a log record so that the fixed portion
  329. // of a log record doesn't split the end of the file. It must be less than
  330. // the minimum size of any valid record
  331. //
  332. #define ELF_SKIP_DWORD sizeof(ELF_EOF_RECORD) - 1
  333. //
  334. // Time for the sender of a start or stop request to the Eventlog
  335. // service to wait (in milliseconds) before checking on the
  336. // Eventlog service again to see if it is done
  337. //
  338. #define ELF_WAIT_HINT_TIME 20000 // 20 seconds
  339. //
  340. // Flags used by ElfpCloseLogFile
  341. //
  342. #define ELF_LOG_CLOSE_NORMAL 0x0000
  343. #define ELF_LOG_CLOSE_FORCE 0x0001
  344. #define ELF_LOG_CLOSE_BACKUP 0x0002
  345. //
  346. // Structure used to store information read from the registry
  347. //
  348. typedef struct _LOG_FILE_INFO {
  349. PUNICODE_STRING LogFileName;
  350. ULONG MaxFileSize;
  351. ULONG Retention;
  352. ULONG GuestAccessRestriction;
  353. LOGPOPUP logpLogPopup;
  354. DWORD dwAutoBackup;
  355. } LOG_FILE_INFO, *PLOG_FILE_INFO;
  356. //
  357. // DEBUG stuff.
  358. //
  359. //
  360. // This signature is placed in the context handle for debug purposes only,
  361. // to track down a bug in freeing the structures.
  362. //
  363. #define ELF_CONTEXTHANDLE_SIGN 0x654c6648 // ASCII for eLfH
  364. //
  365. // The different file open (or create) options are based on the type of file.
  366. // The types, and their meanings are:
  367. //
  368. // ElfNormalLog Normal log file, opened for cached io
  369. // ElfSecurityLog Audit logs, opened for write-thru
  370. // ElfBackupLog Not an active log file, opened read only, cached
  371. //
  372. typedef enum _ELF_LOG_TYPE {
  373. ElfNormalLog,
  374. ElfSecurityLog,
  375. ElfBackupLog
  376. } ELF_LOG_TYPE, *PELF_LOG_TYPE;
  377. //
  378. // Eventlog States (used as return codes)
  379. //
  380. #define UPDATE_ONLY 0 // no change in state - just send current status.
  381. #define STARTING 1 // the messenger is initializing.
  382. #define RUNNING 2 // initialization completed normally - now running
  383. #define STOPPING 3 // uninstall pending
  384. #define STOPPED 4 // uninstalled
  385. #define PAUSED 5 // Paused
  386. #define PAUSING 6 // In the process of pausing
  387. #define CONTINUING 7 // In the process of continuing
  388. //
  389. // Forced Shutdown PendingCodes
  390. //
  391. #define PENDING TRUE
  392. #define IMMEDIATE FALSE
  393. //
  394. // defines for reliability logging
  395. //
  396. #define DEFAULT_INTERVAL 0
  397. #define SHUTDOWN_UNPLANNED 0x80000000
  398. #define SHUTDOWN_REASON_MASK 0xFFFF
  399. typedef enum _TIMESTAMPEVENT{
  400. EVENT_Boot=0,
  401. EVENT_NormalShutdown,
  402. EVENT_AbNormalShutdown
  403. } TIMESTAMPEVENT, *PTIMESTAMPEVENT;
  404. //SS:Clustering specific extensions
  405. typedef struct _PROPLOGFILEINFO{
  406. PLOGFILE pLogFile;
  407. PVOID pStartPosition;
  408. PVOID pEndPosition;
  409. ULONG ulTotalEventSize;
  410. ULONG ulNumRecords;
  411. }PROPLOGFILEINFO, *PPROPLOGFILEINFO;
  412. //structure for propagation is preallocated.
  413. #define MAXSIZE_OF_EVENTSTOPROP (1 * 1024)
  414. #endif // ifndef _EVENTDEF_