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.

585 lines
17 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. adtp.h
  5. Abstract:
  6. Local Security Authority - Audit Log Management - Private Defines,
  7. data and function prototypes.
  8. Functions, data and defines in this module are internal to the
  9. Auditing Subcomponent of the LSA Subsystem.
  10. Author:
  11. Scott Birrell (ScottBi) November 20, 1991
  12. Environment:
  13. Revision History:
  14. --*/
  15. #ifndef _LSAP_ADTP_
  16. #define _LSAP_ADTP_
  17. #include "ausrvp.h"
  18. //
  19. // Names of the registry keys where security event log information
  20. // is rooted and the object names are listed under an event source
  21. // module.
  22. //
  23. #define LSAP_ADT_AUDIT_MODULES_KEY_NAME L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\EventLog\\Security"
  24. #define LSAP_ADT_OBJECT_NAMES_KEY_NAME L"ObjectNames"
  25. //
  26. // Macros for setting fields in an SE_AUDIT_PARAMETERS array.
  27. //
  28. // These must be kept in sync with similar macros in se\sepaudit.c.
  29. //
  30. #define LsapSetParmTypeSid( AuditParameters, Index, Sid ) \
  31. { \
  32. if( Sid ) { \
  33. \
  34. (AuditParameters).Parameters[(Index)].Type = SeAdtParmTypeSid; \
  35. (AuditParameters).Parameters[(Index)].Length = RtlLengthSid( (Sid) ); \
  36. (AuditParameters).Parameters[(Index)].Address = (Sid); \
  37. \
  38. } else { \
  39. \
  40. (AuditParameters).Parameters[(Index)].Type = SeAdtParmTypeNone; \
  41. (AuditParameters).Parameters[(Index)].Length = 0; \
  42. (AuditParameters).Parameters[(Index)].Address = NULL; \
  43. \
  44. } \
  45. }
  46. #define LsapSetParmTypeAccessMask( AuditParameters, Index, AccessMask, ObjectTypeIndex ) \
  47. { \
  48. (AuditParameters).Parameters[(Index)].Type = SeAdtParmTypeAccessMask; \
  49. (AuditParameters).Parameters[(Index)].Length = sizeof( ACCESS_MASK ); \
  50. (AuditParameters).Parameters[(Index)].Data[0] = (AccessMask); \
  51. (AuditParameters).Parameters[(Index)].Data[1] = (ObjectTypeIndex); \
  52. }
  53. #define LsapSetParmTypeString( AuditParameters, Index, String ) \
  54. { \
  55. (AuditParameters).Parameters[(Index)].Type = SeAdtParmTypeString; \
  56. (AuditParameters).Parameters[(Index)].Length = \
  57. sizeof(UNICODE_STRING)+(String)->Length; \
  58. (AuditParameters).Parameters[(Index)].Address = (String); \
  59. }
  60. #define LsapSetParmTypeUlong( AuditParameters, Index, Ulong ) \
  61. { \
  62. (AuditParameters).Parameters[(Index)].Type = SeAdtParmTypeUlong; \
  63. (AuditParameters).Parameters[(Index)].Length = sizeof( (Ulong) ); \
  64. (AuditParameters).Parameters[(Index)].Data[0] = (ULONG)(Ulong); \
  65. }
  66. #define LsapSetParmTypeHexUlong( AuditParameters, Index, Ulong ) \
  67. { \
  68. (AuditParameters).Parameters[(Index)].Type = SeAdtParmTypeHexUlong; \
  69. (AuditParameters).Parameters[(Index)].Length = sizeof( (Ulong) ); \
  70. (AuditParameters).Parameters[(Index)].Data[0] = (ULONG)(Ulong); \
  71. }
  72. #define LsapSetParmTypeGuid( AuditParameters, Index, pGuid ) \
  73. { \
  74. (AuditParameters).Parameters[(Index)].Type = SeAdtParmTypeGuid; \
  75. (AuditParameters).Parameters[(Index)].Length = sizeof( GUID ); \
  76. (AuditParameters).Parameters[(Index)].Address = pGuid; \
  77. }
  78. #define LsapSetParmTypeNoLogon( AuditParameters, Index ) \
  79. { \
  80. (AuditParameters).Parameters[(Index)].Type = SeAdtParmTypeNoLogonId; \
  81. }
  82. #define LsapSetParmTypeLogonId( AuditParameters, Index, LogonId ) \
  83. { \
  84. PLUID TmpLuid; \
  85. \
  86. (AuditParameters).Parameters[(Index)].Type = SeAdtParmTypeLogonId; \
  87. (AuditParameters).Parameters[(Index)].Length = sizeof( (LogonId) ); \
  88. TmpLuid = (PLUID)(&(AuditParameters).Parameters[(Index)].Data[0]); \
  89. *TmpLuid = (LogonId); \
  90. }
  91. #define LsapSetParmTypePrivileges( AuditParameters, Index, Privileges ) \
  92. { \
  93. (AuditParameters).Parameters[(Index)].Type = SeAdtParmTypePrivs; \
  94. (AuditParameters).Parameters[(Index)].Length = LsapPrivilegeSetSize( (Privileges) ); \
  95. (AuditParameters).Parameters[(Index)].Address = (Privileges); \
  96. }
  97. #define IsInRange(item,min_val,max_val) \
  98. (((item) >= min_val) && ((item) <= max_val))
  99. //
  100. // see msaudite.mc for def. of valid category-id
  101. //
  102. #define IsValidCategoryId(c) \
  103. (IsInRange((c), SE_ADT_MIN_CATEGORY_ID, SE_ADT_MAX_CATEGORY_ID))
  104. //
  105. // see msaudite.mc for def. of valid audit-id
  106. //
  107. #define IsValidAuditId(a) \
  108. (IsInRange((a), SE_ADT_MIN_AUDIT_ID, SE_ADT_MAX_AUDIT_ID))
  109. //
  110. // check for reasonable value of parameter count. we must have atleast
  111. // 2 parameters in the audit-params array. Thus the min limit is 3.
  112. // The max limit is determined by the value in ntlsa.h
  113. //
  114. #define IsValidParameterCount(p) \
  115. (IsInRange((p), 2, SE_MAX_AUDIT_PARAMETERS))
  116. ///////////////////////////////////////////////////////////////////////////
  117. // //
  118. // Private data for Audit Log Management //
  119. // //
  120. ///////////////////////////////////////////////////////////////////////////
  121. #define LSAP_ADT_LOG_FULL_SHUTDOWN_TIMEOUT (ULONG) 0x0000012cL
  122. extern RTL_CRITICAL_SECTION LsapAdtQueueLock;
  123. extern RTL_CRITICAL_SECTION LsapAdtLogFullLock;
  124. extern BOOLEAN LsapAuditSuccessfulLogons;
  125. extern BOOLEAN LsapAuditFailedLogons;
  126. //
  127. // Options for LsapAdtWriteLog
  128. //
  129. #define LSAP_ADT_LOG_QUEUE_PREPEND ((ULONG) 0x00000001L)
  130. //
  131. // Structure describing a queued audit record
  132. //
  133. typedef struct _LSAP_ADT_QUEUED_RECORD {
  134. LIST_ENTRY Link;
  135. SE_ADT_PARAMETER_ARRAY Buffer;
  136. } LSAP_ADT_QUEUED_RECORD, *PLSAP_ADT_QUEUED_RECORD;
  137. //
  138. // Audit Log Queue Header. The queue is maintained in chronological
  139. // (FIFO) order. New records are appended to the back of the queue.
  140. //
  141. typedef struct _LSAP_ADT_LOG_QUEUE_HEAD {
  142. PLSAP_ADT_QUEUED_RECORD FirstQueuedRecord;
  143. PLSAP_ADT_QUEUED_RECORD LastQueuedRecord;
  144. } LSAP_ADT_LOG_QUEUE_HEAD, *PLSAP_ADT_LOG_QUEUE_HEAD;
  145. //
  146. // Lsa Global flag to indicate if we are auditing logon events.
  147. //
  148. extern BOOLEAN LsapAdtLogonEvents;
  149. //
  150. // String that will be passed in for SubsystemName for audits generated
  151. // by LSA (eg, logon, logoff, restart, etc).
  152. //
  153. extern UNICODE_STRING LsapSubsystemName;
  154. //
  155. // max number of replacement string params that we support in
  156. // eventlog audit record.
  157. //
  158. #define SE_MAX_AUDIT_PARAM_STRINGS 32
  159. ///////////////////////////////////////////////////////////////////////////////
  160. // /
  161. // The following structures and data are used by LSA to contain /
  162. // drive letter-device name mapping information. LSA obtains this /
  163. // information once during initialization and saves it for use /
  164. // by auditing code. /
  165. // /
  166. ///////////////////////////////////////////////////////////////////////////////
  167. ///////////////////////////////////////////////////////////////////////////////
  168. // /
  169. // The DRIVE_MAPPING structure contains the drive letter (without /
  170. // the colon) and a unicode string containing the name of the /
  171. // corresponding device. The buffer in the unicode string is /
  172. // allocated from the LSA heap and is never freed. /
  173. // /
  174. ///////////////////////////////////////////////////////////////////////////////
  175. typedef struct _DRIVE_MAPPING {
  176. WCHAR DriveLetter;
  177. UNICODE_STRING DeviceName;
  178. } DRIVE_MAPPING, PDRIVE_MAPPING;
  179. ////////////////////////////////////////////////////////////////////////////////
  180. // /
  181. // We assume a maximum of 26 drive letters. Though no auditing /
  182. // will occur due to references to files on floppy (drives A and /
  183. // B), perform their name lookup anyway. This will then just /
  184. // work if somehow we start auditing files on floppies. /
  185. // /
  186. ////////////////////////////////////////////////////////////////////////////////
  187. #define MAX_DRIVE_MAPPING 26
  188. extern DRIVE_MAPPING DriveMappingArray[];
  189. //
  190. // Special privilege values which are not normally audited,
  191. // but generate audits when assigned to a user. See
  192. // LsapAdtAuditSpecialPrivileges.
  193. //
  194. extern LUID ChangeNotifyPrivilege;
  195. extern LUID AuditPrivilege;
  196. extern LUID CreateTokenPrivilege;
  197. extern LUID AssignPrimaryTokenPrivilege;
  198. extern LUID BackupPrivilege;
  199. extern LUID RestorePrivilege;
  200. extern LUID DebugPrivilege;
  201. //
  202. // Global variable to indicate whether or not we're
  203. // supposed to crash when an audit fails.
  204. //
  205. extern BOOLEAN LsapCrashOnAuditFail;
  206. extern BOOLEAN LsapAllowAdminLogonsOnly;
  207. ////////////////////////////////////////////////////////////////////////////////
  208. // /
  209. // /
  210. ////////////////////////////////////////////////////////////////////////////////
  211. NTSTATUS
  212. LsapAdtWriteLog(
  213. IN OPTIONAL PSE_ADT_PARAMETER_ARRAY AuditRecord,
  214. IN ULONG Options
  215. );
  216. NTSTATUS
  217. LsapAdtDemarshallAuditInfo(
  218. IN PSE_ADT_PARAMETER_ARRAY AuditParameters
  219. );
  220. VOID
  221. LsapAdtNormalizeAuditInfo(
  222. IN PSE_ADT_PARAMETER_ARRAY AuditParameters
  223. );
  224. NTSTATUS
  225. LsapAdtOpenLog(
  226. OUT PHANDLE AuditLogHandle
  227. );
  228. VOID
  229. LsapAdtAuditLogon(
  230. IN USHORT EventCategory,
  231. IN ULONG EventID,
  232. IN USHORT EventType,
  233. IN PUNICODE_STRING AccountName,
  234. IN PUNICODE_STRING AuthenticatingAuthority,
  235. IN PUNICODE_STRING Source,
  236. IN PUNICODE_STRING PackageName,
  237. IN SECURITY_LOGON_TYPE LogonType,
  238. IN PSID UserSid,
  239. IN LUID AuthenticationId,
  240. IN PUNICODE_STRING WorkstationName,
  241. IN NTSTATUS LogonStatus,
  242. IN NTSTATUS SubStatus,
  243. IN LPGUID LogonGuid OPTIONAL
  244. );
  245. VOID
  246. LsapAuditLogonHelper(
  247. IN NTSTATUS LogonStatus,
  248. IN NTSTATUS LogonSubStatus,
  249. IN PUNICODE_STRING AccountName,
  250. IN PUNICODE_STRING AuthenticatingAuthority,
  251. IN PUNICODE_STRING WorkstationName,
  252. IN PSID UserSid, OPTIONAL
  253. IN SECURITY_LOGON_TYPE LogonType,
  254. IN PTOKEN_SOURCE TokenSource,
  255. IN PLUID LogonId,
  256. IN LPGUID LogonGuid OPTIONAL
  257. );
  258. #define LSAP_ADT_LOG_QUEUE_DISCARD ((ULONG) 0x00000001L)
  259. #define LSAP_ADT_LOG_QUEUE_WRITEOUT ((ULONG) 0x00000002L)
  260. VOID
  261. LsapAdtSystemRestart(
  262. PLSARM_POLICY_AUDIT_EVENTS_INFO AuditEventsInfo
  263. );
  264. VOID
  265. LsapAdtAuditLogonProcessRegistration(
  266. IN PLSAP_AU_REGISTER_CONNECT_INFO_EX ConnectInfo
  267. );
  268. NTSTATUS
  269. LsapAdtInitializeLogQueue(
  270. VOID
  271. );
  272. NTSTATUS
  273. LsapAdtQueueRecord(
  274. IN PSE_ADT_PARAMETER_ARRAY AuditRecord,
  275. IN ULONG Options
  276. );
  277. #define LsapAdtAcquireLogFullLock() RtlEnterCriticalSection(&LsapAdtLogFullLock)
  278. #define LsapAdtReleaseLogFullLock() RtlLeaveCriticalSection(&LsapAdtLogFullLock)
  279. NTSTATUS
  280. LsapAdtObjsInitialize(
  281. );
  282. NTSTATUS
  283. LsapAdtBuildDashString(
  284. OUT PUNICODE_STRING ResultantString,
  285. OUT PBOOLEAN FreeWhenDone
  286. );
  287. NTSTATUS
  288. LsapAdtBuildUlongString(
  289. IN ULONG Value,
  290. OUT PUNICODE_STRING ResultantString,
  291. OUT PBOOLEAN FreeWhenDone
  292. );
  293. NTSTATUS
  294. LsapAdtBuildHexUlongString(
  295. IN ULONG Value,
  296. OUT PUNICODE_STRING ResultantString,
  297. OUT PBOOLEAN FreeWhenDone
  298. );
  299. NTSTATUS
  300. LsapAdtBuildPtrString(
  301. IN PVOID Value,
  302. OUT PUNICODE_STRING ResultantString,
  303. OUT PBOOLEAN FreeWhenDone
  304. );
  305. NTSTATUS
  306. LsapAdtBuildLuidString(
  307. IN PLUID Value,
  308. OUT PUNICODE_STRING ResultantString,
  309. OUT PBOOLEAN FreeWhenDone
  310. );
  311. NTSTATUS
  312. LsapAdtBuildSidString(
  313. IN PSID Value,
  314. OUT PUNICODE_STRING ResultantString,
  315. OUT PBOOLEAN FreeWhenDone
  316. );
  317. NTSTATUS
  318. LsapAdtBuildObjectTypeStrings(
  319. IN PUNICODE_STRING SourceModule,
  320. IN PUNICODE_STRING ObjectTypeName,
  321. IN PSE_ADT_OBJECT_TYPE ObjectTypeList,
  322. IN ULONG ObjectTypeCount,
  323. OUT PUNICODE_STRING ResultantString,
  324. OUT PBOOLEAN FreeWhenDone,
  325. OUT PUNICODE_STRING NewObjectTypeName
  326. );
  327. NTSTATUS
  328. LsapAdtBuildAccessesString(
  329. IN PUNICODE_STRING SourceModule,
  330. IN PUNICODE_STRING ObjectTypeName,
  331. IN ACCESS_MASK Accesses,
  332. IN BOOLEAN Indent,
  333. OUT PUNICODE_STRING ResultantString,
  334. OUT PBOOLEAN FreeWhenDone
  335. );
  336. NTSTATUS
  337. LsapAdtBuildFilePathString(
  338. IN PUNICODE_STRING Value,
  339. OUT PUNICODE_STRING ResultantString,
  340. OUT PBOOLEAN FreeWhenDone
  341. );
  342. NTSTATUS
  343. LsapAdtBuildLogonIdStrings(
  344. IN PLUID LogonId,
  345. OUT PUNICODE_STRING ResultantString1,
  346. OUT PBOOLEAN FreeWhenDone1,
  347. OUT PUNICODE_STRING ResultantString2,
  348. OUT PBOOLEAN FreeWhenDone2,
  349. OUT PUNICODE_STRING ResultantString3,
  350. OUT PBOOLEAN FreeWhenDone3
  351. );
  352. NTSTATUS
  353. LsapBuildPrivilegeAuditString(
  354. IN PPRIVILEGE_SET PrivilegeSet,
  355. OUT PUNICODE_STRING ResultantString,
  356. OUT PBOOLEAN FreeWhenDone
  357. );
  358. NTSTATUS
  359. LsapAdtBuildTimeString(
  360. IN PLARGE_INTEGER Value,
  361. OUT PUNICODE_STRING ResultantString,
  362. OUT PBOOLEAN FreeWhenDone
  363. );
  364. NTSTATUS
  365. LsapAdtBuildDateString(
  366. IN PLARGE_INTEGER Value,
  367. OUT PUNICODE_STRING ResultantString,
  368. OUT PBOOLEAN FreeWhenDone
  369. );
  370. NTSTATUS
  371. LsapAdtBuildGuidString(
  372. IN LPGUID pGuid,
  373. OUT PUNICODE_STRING ResultantString,
  374. OUT PBOOLEAN FreeWhenDone
  375. );
  376. NTSTATUS
  377. LsapAdtMarshallAuditRecord(
  378. IN PSE_ADT_PARAMETER_ARRAY AuditParameters,
  379. OUT PSE_ADT_PARAMETER_ARRAY *MarshalledAuditParameters
  380. );
  381. NTSTATUS
  382. LsapAdtInitializeDriveLetters(
  383. VOID
  384. );
  385. BOOLEAN
  386. LsapAdtLookupDriveLetter(
  387. IN PUNICODE_STRING FileName,
  388. OUT PUSHORT DeviceNameLength,
  389. OUT PWCHAR DriveLetter
  390. );
  391. VOID
  392. LsapAdtSubstituteDriveLetter(
  393. IN PUNICODE_STRING FileName
  394. );
  395. VOID
  396. LsapAdtUserRightAssigned(
  397. IN USHORT EventCategory,
  398. IN ULONG EventID,
  399. IN USHORT EventType,
  400. IN PSID UserSid,
  401. IN LUID CallerAuthenticationId,
  402. IN PSID ClientSid,
  403. IN PPRIVILEGE_SET Privileges
  404. );
  405. VOID
  406. LsapAdtTrustedDomain(
  407. IN USHORT EventCategory,
  408. IN ULONG EventID,
  409. IN USHORT EventType,
  410. IN PSID ClientSid,
  411. IN LUID CallerAuthenticationId,
  412. IN PSID TargetSid,
  413. IN PUNICODE_STRING DomainName
  414. );
  415. VOID
  416. LsapAdtAuditLogoff(
  417. PLSAP_LOGON_SESSION Session
  418. );
  419. VOID
  420. LsapAdtPolicyChange(
  421. IN USHORT EventCategory,
  422. IN ULONG EventID,
  423. IN USHORT EventType,
  424. IN PSID ClientSid,
  425. IN LUID CallerAuthenticationId,
  426. IN PLSARM_POLICY_AUDIT_EVENTS_INFO LsapAdtEventsInformation
  427. );
  428. VOID
  429. LsapAdtAuditSpecialPrivileges(
  430. PPRIVILEGE_SET Privileges,
  431. LUID LogonId,
  432. PSID UserSid
  433. );
  434. VOID
  435. LsapAuditFailed(
  436. IN NTSTATUS AuditStatus
  437. );
  438. VOID
  439. LsapAdtInitParametersArray(
  440. IN SE_ADT_PARAMETER_ARRAY* AuditParameters,
  441. IN ULONG AuditCategoryId,
  442. IN ULONG AuditId,
  443. IN USHORT AuditEventType,
  444. IN USHORT ParameterCount,
  445. ...);
  446. NTSTATUS
  447. LsapAdtInitGenericAudits( VOID );
  448. #endif // _LSAP_ADTP_