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.

527 lines
17 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_BACKUP 0x0020 // Set iff a backup operator
  20. // opens the security log -
  21. // this overrides all other
  22. // flags.
  23. #define ELF_LOGFILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
  24. ELF_LOGFILE_READ | \
  25. ELF_LOGFILE_WRITE | \
  26. ELF_LOGFILE_CLEAR)
  27. //
  28. // Three types of logfiles are defined from a security perspective:
  29. //
  30. // ELF_LOGFILE_SECURITY - Only Admins/LocalSystem can RW these files
  31. // ELF_LOGFILE_SYSTEM - Only Admins/LocalSystem can W these files
  32. // ELF_LOGFILE_APPLICATION - interactive can R/W these files
  33. // ELF_LOGFILE_CUSTOM - normally same as application, but can be SDDL string
  34. //
  35. // System and Security will be SECURE, Application will be NON_SECURE
  36. //
  37. #define ELF_LOGFILE_SECURITY 0x0000
  38. #define ELF_LOGFILE_SYSTEM 0x0001
  39. #define ELF_LOGFILE_APPLICATION 0x0002
  40. #define ELF_LOGFILE_CUSTOM 0x0003
  41. //
  42. // Macro to convert a given file size into one that is "acceptable" for
  43. // eventlogging. It basically truncates it to a 64K boundary making sure
  44. // that it is as least 64K
  45. //
  46. #define ELFFILESIZE(x) ((x & 0xFFFF0000) ? (x & 0xFFFF0000) : 65536)
  47. //
  48. // The largest possible buffer we would need to hold an admin alert
  49. // information. This primarily depends on the number and length of the
  50. // replacement strings that would be passed with the message ID.
  51. //
  52. #define ELF_ADMIN_ALERT_BUFFER_SIZE 256
  53. //
  54. // Timeout defines.
  55. //
  56. #define INFINITE_WAIT_TIME -1 // Wait time for events
  57. #define ELF_GLOBAL_RESOURCE_WAIT 2000 // 2-second timeout for global resource
  58. //
  59. // Signature placed before each event record in a file. Is used to
  60. // validate where we are in a file.
  61. //
  62. #define ELF_RECORD_SIGNATURE 0x654c6652 // ASCII for eLfR
  63. //
  64. // Size by which to grow a log file until it reaches the max size
  65. //
  66. #define ELF_DEFAULT_LOG_SIZE 65536
  67. //
  68. // Bits for whether to take the global resource exclusively or shared.
  69. //
  70. #define ELF_GLOBAL_SHARED 0x0001
  71. #define ELF_GLOBAL_EXCLUSIVE 0x0002
  72. //
  73. // Flag bits to keep track of what resources have been allocated at INIT time
  74. //
  75. #define ELF_INIT_LOGHANDLE_CRIT_SEC 0x0001
  76. #define ELF_INIT_GLOBAL_RESOURCE 0x0002
  77. #define ELF_STARTED_LPC_THREAD 0x0004
  78. #define ELF_STARTED_REGISTRY_MONITOR 0x0008
  79. #define ELF_STARTED_RPC_SERVER 0x0010
  80. #define ELF_INIT_LOGFILE_CRIT_SEC 0x0020
  81. #define ELF_INIT_LOGMODULE_CRIT_SEC 0x0040
  82. #define ELF_INIT_WELL_KNOWN_SIDS 0x0080
  83. #define ELF_INIT_QUEUED_EVENT_CRIT_SEC 0x0100
  84. #define ELF_INIT_QUEUED_MESSAGE_CRIT_SEC 0x0200
  85. #define ELF_INIT_CLUS_CRIT_SEC 0x0400
  86. //
  87. // Enumeration and macro to keep track of the "log full" popup per log
  88. //
  89. #define IS_WORKSTATION() (USER_SHARED_DATA->NtProductType == NtProductWinNt)
  90. typedef enum
  91. {
  92. LOGPOPUP_NEVER_SHOW = 0, // Never show it for this log (e.g., Security)
  93. LOGPOPUP_CLEARED, // Show it when this log fills up
  94. LOGPOPUP_ALREADY_SHOWN // Don't show it again until this log is cleared
  95. }
  96. LOGPOPUP, *PLOGPOPUP;
  97. //
  98. // Structure containing information on each log file
  99. //
  100. // ActualMaxFileSize and ConfigMaxFileSize are stored in BYTEs.
  101. // ActualMaxFileSize is the actual size of the file on the disk.
  102. // ConfigMaxFileSize is the configured size of the file, which may not
  103. // be the same as the actual size of the file.
  104. //
  105. // CurrentRecordNumber is the next absolute record number to write
  106. //
  107. // OldestRecordNumber is the next one to get overwritten
  108. //
  109. // Retention time is stored as the number of seconds.
  110. //
  111. // BaseAddress points to the physical beginning of the file.
  112. //
  113. // ViewSize is ALWAYS the size of the file in bytes.
  114. //
  115. // For the Flag bits, see the ELF_LOGFILE_HEADER_xxxx bits defined below.
  116. //
  117. typedef struct _LOGFILE {
  118. LIST_ENTRY FileList;
  119. LIST_ENTRY Notifiees; // List of ChangeNotify recipients
  120. PUNICODE_STRING LogFileName; // Full path name of log file
  121. PUNICODE_STRING LogModuleName; // Name of default module for this log
  122. ULONG RefCount; // Number of modules using this file
  123. ULONG Flags; // Autowrap, dirty, etc. - See bits below
  124. ULONG ConfigMaxFileSize; // Max it can be
  125. ULONG ActualMaxFileSize; // How big it is now
  126. ULONG NextClearMaxFileSize; // Can't be shrunk on the fly
  127. ULONG CurrentRecordNumber;// The next one to be created
  128. ULONG OldestRecordNumber; // The next one to overwrite
  129. ULONG SessionStartRecordNumber; //the first record number logged in this session
  130. ULONG Retention; // Max. Retention time
  131. ULONG NextClearRetention; // they shrank the file when they set this
  132. HANDLE FileHandle; // Handle to open file
  133. HANDLE SectionHandle; // Memory mapped section handle
  134. PVOID BaseAddress; // Map view base address
  135. ULONG ViewSize; // Mapped view size
  136. ULONG BeginRecord; // Offset of first log record
  137. ULONG EndRecord; // Offset of byte after last log record
  138. ULONG ulLastPulseTime; // Time this log was last notified of a change
  139. LOGPOPUP logpLogPopup; // "Log full" policy for this log
  140. PSECURITY_DESCRIPTOR Sd; // User security object for this log
  141. RTL_RESOURCE Resource;
  142. BOOL bHosedByClear;
  143. NTSTATUS LastStatus;
  144. BOOL bFullAlertDone;
  145. DWORD AutoBackupLogFiles;
  146. LPWSTR pwsCurrCustomSD;
  147. BOOL bFailedExpansion;
  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. IELF_HANDLE ContextHandle;
  192. } READ_PKT, *PREAD_PKT;
  193. typedef struct _CLEAR_PKT {
  194. PUNICODE_STRING BackupFileName; // File to back up current log file (or NULL)
  195. } CLEAR_PKT, *PCLEAR_PKT;
  196. typedef struct _BACKUP_PKT {
  197. PUNICODE_STRING BackupFileName; // File to back up current log file (or NULL)
  198. } BACKUP_PKT, *PBACKUP_PKT;
  199. //
  200. // Flags used in the ELF_REQUEST_RECORD
  201. //
  202. #define ELF_FORCE_OVERWRITE 0x01 // Ignore retention period for this write
  203. //
  204. // Structure for the packet that contains all the information needed
  205. // to perform the request.
  206. //
  207. typedef struct _ELF_REQUEST_RECORD {
  208. USHORT Flags;
  209. NTSTATUS Status; // To return status of operation
  210. PLOGFILE LogFile; // File on which to operate
  211. PLOGMODULE Module; // Information on module
  212. USHORT Command; // Operation to be performed
  213. union {
  214. PWRITE_PKT WritePkt;
  215. PREAD_PKT ReadPkt;
  216. PCLEAR_PKT ClearPkt;
  217. PBACKUP_PKT BackupPkt;
  218. } Pkt;
  219. } ELF_REQUEST_RECORD, *PELF_REQUEST_RECORD;
  220. typedef
  221. #ifdef _WIN64
  222. __declspec(align(8))
  223. #endif
  224. struct _ELF_ALERT_RECORD {
  225. DWORD TimeOut;
  226. DWORD MessageId;
  227. DWORD NumberOfStrings;
  228. // array of UNICODE_STRINGs NumberOfStringsLong
  229. // each string
  230. } ELF_ALERT_RECORD, * PELF_ALERT_RECORD;
  231. typedef struct _ELF_MESSAGE_RECORD {
  232. DWORD MessageId;
  233. DWORD NumberOfStrings;
  234. // UNICODE null terminated strings
  235. } ELF_MESSAGE_RECORD, * PELF_MESSAGE_RECORD;
  236. //
  237. // Record for the linked list of deferred events (these are raised by the
  238. // eventlog service itself for writing once the current operation is complete
  239. //
  240. typedef struct _ELF_QUEUED_EVENT {
  241. LIST_ENTRY Next;
  242. enum _ELF_QUEUED_EVENT_TYPE {
  243. Event,
  244. Alert,
  245. Message
  246. } Type;
  247. union _ELF_QUEUED_EVENT_DATA {
  248. ELF_REQUEST_RECORD Request;
  249. ELF_ALERT_RECORD Alert;
  250. ELF_MESSAGE_RECORD Message;
  251. } Event;
  252. } ELF_QUEUED_EVENT, *PELF_QUEUED_EVENT;
  253. //
  254. // Structure containing information on callers of ElfChangeNotify
  255. //
  256. typedef struct _NOTIFIEE {
  257. LIST_ENTRY Next;
  258. IELF_HANDLE Handle;
  259. HANDLE Event;
  260. } NOTIFIEE, *PNOTIFIEE;
  261. //
  262. // Structure that describes the header that is at the beginning of the
  263. // log files.
  264. //
  265. // To see if there are any records in the file, one must subtract the
  266. // EndOffset from the StartOffset (allowing for the file having wrapped
  267. // around) and check for a difference of greater than 1.
  268. //
  269. // The header size is stored at the beginning and end so that it looks
  270. // just like any other event log record (the lengths do at any rate).
  271. //
  272. typedef struct _ELF_LOGFILE_HEADER {
  273. ULONG HeaderSize; // Size of this header
  274. ULONG Signature; // Signature field
  275. ULONG MajorVersion;
  276. ULONG MinorVersion;
  277. ULONG StartOffset; // Where the first record is located
  278. ULONG EndOffset; // The end of the last record + 1
  279. ULONG CurrentRecordNumber; // The next record to create
  280. ULONG OldestRecordNumber; // The next record to overwrite
  281. ULONG MaxSize; // Max. size when file was created
  282. ULONG Flags; // DIRTY, etc.
  283. ULONG Retention; // Last Retention period.
  284. ULONG EndHeaderSize; // Size of this header
  285. } ELF_LOGFILE_HEADER, *PELF_LOGFILE_HEADER;
  286. #define FILEHEADERBUFSIZE sizeof(ELF_LOGFILE_HEADER)
  287. #define ELF_LOG_FILE_SIGNATURE 0x654c664c // ASCII for eLfL
  288. //
  289. // The following flag bits are used in ELF_LOGFILE_HEADER and in the
  290. // LOGFILE structures' Flag fields.
  291. //
  292. #define ELF_LOGFILE_HEADER_DIRTY 0x0001 // File has been written to
  293. #define ELF_LOGFILE_HEADER_WRAP 0x0002 // The file has wrapped
  294. #define ELF_LOGFILE_LOGFULL_WRITTEN 0x0004 // Written logfull record
  295. #define ELF_LOGFILE_ARCHIVE_SET 0x0008 // Archive bit flag
  296. //
  297. // Structure that defines the record that identifies the end of the
  298. // circular log file.
  299. // This record is used to identify where the last record in the circular
  300. // buffer is located.
  301. //
  302. // NOTE: It is *essential* that this record is of a size that a "normal"
  303. // event log record can never have. There is code that relies on
  304. // this fact to detect an "EOF" record.
  305. //
  306. // Care must be taken to not disturb the first part of this record. It
  307. // is used to identify an EOF record. ELFEOFUNIQUEPART must be the
  308. // number of bytes that are constant.
  309. //
  310. typedef struct _ELF_EOF_RECORD {
  311. ULONG RecordSizeBeginning;
  312. ULONG One;
  313. ULONG Two;
  314. ULONG Three;
  315. ULONG Four;
  316. ULONG BeginRecord;
  317. ULONG EndRecord;
  318. ULONG CurrentRecordNumber;
  319. ULONG OldestRecordNumber;
  320. ULONG RecordSizeEnd;
  321. } ELF_EOF_RECORD, *PELF_EOF_RECORD;
  322. #define ELFEOFRECORDSIZE sizeof (ELF_EOF_RECORD)
  323. //
  324. // The following constant is how much of the EOF record is constant, and can
  325. // be used to identify an EOF record
  326. //
  327. #define ELFEOFUNIQUEPART 5 * sizeof(ULONG)
  328. //
  329. // This is used to fill the end of a log record so that the fixed portion
  330. // of a log record doesn't split the end of the file. It must be less than
  331. // the minimum size of any valid record
  332. //
  333. #define ELF_SKIP_DWORD sizeof(ELF_EOF_RECORD) - 1
  334. //
  335. // Time for the sender of a start or stop request to the Eventlog
  336. // service to wait (in milliseconds) before checking on the
  337. // Eventlog service again to see if it is done
  338. //
  339. #define ELF_WAIT_HINT_TIME 20000 // 20 seconds
  340. //
  341. // Flags used by ElfpCloseLogFile
  342. //
  343. #define ELF_LOG_CLOSE_NORMAL 0x0000
  344. #define ELF_LOG_CLOSE_FORCE 0x0001
  345. #define ELF_LOG_CLOSE_BACKUP 0x0002
  346. //
  347. // Structure used to store information read from the registry
  348. //
  349. typedef struct _LOG_FILE_INFO {
  350. PUNICODE_STRING LogFileName;
  351. ULONG MaxFileSize;
  352. ULONG Retention;
  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. //
  405. // SS: Clustering specific extensions
  406. //
  407. typedef struct _PROPLOGFILEINFO {
  408. PLOGFILE pLogFile;
  409. PVOID pStartPosition;
  410. PVOID pEndPosition;
  411. ULONG ulTotalEventSize;
  412. ULONG ulNumRecords;
  413. } PROPLOGFILEINFO, *PPROPLOGFILEINFO;
  414. typedef struct _PROPINFO
  415. {
  416. UNICODE_STRING LogFileName; // Log file name used to find the log file ptr
  417. DWORD dwCurrentRecordNum; // Currently propagated record
  418. } PROPINFO, *PPROPINFO;
  419. typedef struct _BATCH_QUEUE_ELEMENT {
  420. LPWSTR lpszLogicalLogFile; // Name of the logical file - security/application/system
  421. DWORD dwRecordLength; // Event record length
  422. PVOID pEventBuffer; // Event buffer
  423. PROPINFO PropagatedInfo; // Propagated info
  424. } BATCH_QUEUE_ELEMENT, *PBATCH_QUEUE_ELEMENT;
  425. //
  426. // Structure for propagation is preallocated.
  427. //
  428. #define MAXSIZE_OF_EVENTSTOPROP (1 * 1024)
  429. #define BATCHING_SUPPORT_TIMER_DUE_TIME ( 20 * 1000 ) // 20 sec
  430. #endif // ifndef _EVENTDEF_