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.

478 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. adtinit.c
  5. Abstract:
  6. Auditing - Initialization Routines
  7. Author:
  8. Scott Birrell (ScottBi) November 12, 1991
  9. Environment:
  10. Kernel Mode only
  11. Revision History:
  12. --*/
  13. #include "pch.h"
  14. #pragma hdrstop
  15. #ifdef ALLOC_PRAGMA
  16. #pragma alloc_text(PAGE,SepAdtValidateAuditBounds)
  17. #pragma alloc_text(PAGE,SepAdtInitializeBounds)
  18. #pragma alloc_text(INIT,SepAdtInitializeCrashOnFail)
  19. #pragma alloc_text(INIT,SepAdtInitializePrivilegeAuditing)
  20. #pragma alloc_text(INIT,SepAdtInitializeAuditingOptions)
  21. #endif
  22. BOOLEAN
  23. SepAdtValidateAuditBounds(
  24. ULONG Upper,
  25. ULONG Lower
  26. )
  27. /*++
  28. Routine Description:
  29. Examines the audit queue high and low water mark values and performs
  30. a general sanity check on them.
  31. Arguments:
  32. Upper - High water mark.
  33. Lower - Low water mark.
  34. Return Value:
  35. TRUE - values are acceptable.
  36. FALSE - values are unacceptable.
  37. --*/
  38. {
  39. PAGED_CODE();
  40. if ( Lower >= Upper ) {
  41. return( FALSE );
  42. }
  43. if ( Lower < 16 ) {
  44. return( FALSE );
  45. }
  46. if ( (Upper - Lower) < 16 ) {
  47. return( FALSE );
  48. }
  49. return( TRUE );
  50. }
  51. VOID
  52. SepAdtInitializeBounds(
  53. VOID
  54. )
  55. /*++
  56. Routine Description:
  57. Queries the registry for the high and low water mark values for the
  58. audit log. If they are not found or are unacceptable, returns without
  59. modifying the current values, which are statically initialized.
  60. Arguments:
  61. None.
  62. Return Value:
  63. None.
  64. --*/
  65. {
  66. HANDLE KeyHandle;
  67. OBJECT_ATTRIBUTES ObjectAttributes;
  68. UNICODE_STRING KeyName;
  69. UNICODE_STRING ValueName;
  70. NTSTATUS Status;
  71. PSEP_AUDIT_BOUNDS AuditBounds;
  72. PKEY_VALUE_PARTIAL_INFORMATION KeyValueInformation;
  73. ULONG Length;
  74. PAGED_CODE();
  75. //
  76. // Get the high and low water marks out of the registry.
  77. //
  78. RtlInitUnicodeString( &KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa");
  79. InitializeObjectAttributes(
  80. &ObjectAttributes,
  81. &KeyName,
  82. OBJ_CASE_INSENSITIVE,
  83. NULL,
  84. NULL
  85. );
  86. Status = NtOpenKey(
  87. &KeyHandle,
  88. KEY_QUERY_VALUE,
  89. &ObjectAttributes
  90. );
  91. if (!NT_SUCCESS( Status )) {
  92. //
  93. // Didn't work, take the defaults
  94. //
  95. return;
  96. }
  97. RtlInitUnicodeString( &ValueName, L"Bounds");
  98. Length = sizeof( KEY_VALUE_PARTIAL_INFORMATION ) - sizeof( UCHAR ) + sizeof( SEP_AUDIT_BOUNDS );
  99. KeyValueInformation = ExAllocatePool( PagedPool, Length );
  100. if ( KeyValueInformation == NULL ) {
  101. NtClose( KeyHandle );
  102. return;
  103. }
  104. Status = NtQueryValueKey(
  105. KeyHandle,
  106. &ValueName,
  107. KeyValuePartialInformation,
  108. (PVOID)KeyValueInformation,
  109. Length,
  110. &Length
  111. );
  112. NtClose( KeyHandle );
  113. if (!NT_SUCCESS( Status )) {
  114. ExFreePool( KeyValueInformation );
  115. return;
  116. }
  117. AuditBounds = (PSEP_AUDIT_BOUNDS) &KeyValueInformation->Data;
  118. //
  119. // Sanity check what we got back
  120. //
  121. if(!SepAdtValidateAuditBounds( AuditBounds->UpperBound, AuditBounds->LowerBound )) {
  122. //
  123. // The values we got back are not to our liking. Use the defaults.
  124. //
  125. ExFreePool( KeyValueInformation );
  126. return;
  127. }
  128. //
  129. // Take what we got from the registry.
  130. //
  131. SepAdtMaxListLength = AuditBounds->UpperBound;
  132. SepAdtMinListLength = AuditBounds->LowerBound;
  133. ExFreePool( KeyValueInformation );
  134. return;
  135. }
  136. NTSTATUS
  137. SepAdtInitializeCrashOnFail(
  138. VOID
  139. )
  140. /*++
  141. Routine Description:
  142. Reads the registry to see if the user has told us to crash if an audit fails.
  143. Arguments:
  144. None.
  145. Return Value:
  146. STATUS_SUCCESS
  147. --*/
  148. {
  149. HANDLE KeyHandle;
  150. NTSTATUS Status;
  151. NTSTATUS TmpStatus;
  152. OBJECT_ATTRIBUTES Obja;
  153. ULONG ResultLength;
  154. UNICODE_STRING KeyName;
  155. UNICODE_STRING ValueName;
  156. CHAR KeyInfo[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(BOOLEAN)];
  157. PKEY_VALUE_PARTIAL_INFORMATION pKeyInfo;
  158. PAGED_CODE();
  159. SepCrashOnAuditFail = FALSE;
  160. //
  161. // Check the value of the CrashOnAudit flag in the registry.
  162. //
  163. RtlInitUnicodeString( &KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa");
  164. InitializeObjectAttributes( &Obja,
  165. &KeyName,
  166. OBJ_CASE_INSENSITIVE,
  167. NULL,
  168. NULL
  169. );
  170. Status = NtOpenKey(
  171. &KeyHandle,
  172. KEY_QUERY_VALUE | KEY_SET_VALUE,
  173. &Obja
  174. );
  175. if (Status == STATUS_OBJECT_NAME_NOT_FOUND) {
  176. return( STATUS_SUCCESS );
  177. }
  178. RtlInitUnicodeString( &ValueName, CRASH_ON_AUDIT_FAIL_VALUE );
  179. Status = NtQueryValueKey(
  180. KeyHandle,
  181. &ValueName,
  182. KeyValuePartialInformation,
  183. KeyInfo,
  184. sizeof(KeyInfo),
  185. &ResultLength
  186. );
  187. TmpStatus = NtClose(KeyHandle);
  188. ASSERT(NT_SUCCESS(TmpStatus));
  189. //
  190. // If the key isn't there, don't turn on CrashOnFail.
  191. //
  192. if (NT_SUCCESS( Status )) {
  193. pKeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyInfo;
  194. if ((UCHAR) *(pKeyInfo->Data) == LSAP_CRASH_ON_AUDIT_FAIL) {
  195. SepCrashOnAuditFail = TRUE;
  196. }
  197. }
  198. return( STATUS_SUCCESS );
  199. }
  200. BOOLEAN
  201. SepAdtInitializePrivilegeAuditing(
  202. VOID
  203. )
  204. /*++
  205. Routine Description:
  206. Checks to see if there is an entry in the registry telling us to do full privilege auditing
  207. (which currently means audit everything we normall audit, plus backup and restore privileges).
  208. Arguments:
  209. None
  210. Return Value:
  211. BOOLEAN - TRUE if Auditing has been initialized correctly, else FALSE.
  212. --*/
  213. {
  214. HANDLE KeyHandle;
  215. NTSTATUS Status;
  216. NTSTATUS TmpStatus;
  217. OBJECT_ATTRIBUTES Obja;
  218. ULONG ResultLength;
  219. UNICODE_STRING KeyName;
  220. UNICODE_STRING ValueName;
  221. CHAR KeyInfo[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(BOOLEAN)];
  222. PKEY_VALUE_PARTIAL_INFORMATION pKeyInfo;
  223. BOOLEAN Verbose;
  224. PAGED_CODE();
  225. //
  226. // Query the registry to set up the privilege auditing filter.
  227. //
  228. RtlInitUnicodeString( &KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa");
  229. InitializeObjectAttributes( &Obja,
  230. &KeyName,
  231. OBJ_CASE_INSENSITIVE,
  232. NULL,
  233. NULL
  234. );
  235. Status = NtOpenKey(
  236. &KeyHandle,
  237. KEY_QUERY_VALUE | KEY_SET_VALUE,
  238. &Obja
  239. );
  240. if (!NT_SUCCESS( Status )) {
  241. if (Status == STATUS_OBJECT_NAME_NOT_FOUND) {
  242. return ( SepInitializePrivilegeFilter( FALSE ));
  243. } else {
  244. return( FALSE );
  245. }
  246. }
  247. RtlInitUnicodeString( &ValueName, FULL_PRIVILEGE_AUDITING );
  248. Status = NtQueryValueKey(
  249. KeyHandle,
  250. &ValueName,
  251. KeyValuePartialInformation,
  252. KeyInfo,
  253. sizeof(KeyInfo),
  254. &ResultLength
  255. );
  256. TmpStatus = NtClose(KeyHandle);
  257. ASSERT(NT_SUCCESS(TmpStatus));
  258. if (!NT_SUCCESS( Status )) {
  259. Verbose = FALSE;
  260. } else {
  261. pKeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyInfo;
  262. Verbose = (BOOLEAN) *(pKeyInfo->Data);
  263. }
  264. return ( SepInitializePrivilegeFilter( Verbose ));
  265. }
  266. VOID
  267. SepAdtInitializeAuditingOptions(
  268. VOID
  269. )
  270. /*++
  271. Routine Description:
  272. Initialize options that control auditing.
  273. (please refer to note in adtp.h near the def. of SEP_AUDIT_OPTIONS)
  274. Arguments:
  275. None
  276. Return Value:
  277. None
  278. --*/
  279. {
  280. HANDLE KeyHandle;
  281. NTSTATUS Status;
  282. NTSTATUS TmpStatus;
  283. OBJECT_ATTRIBUTES Obja;
  284. ULONG ResultLength;
  285. UNICODE_STRING KeyName;
  286. UNICODE_STRING ValueName;
  287. CHAR KeyInfo[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(BOOLEAN)];
  288. PAGED_CODE();
  289. //
  290. // Query the registry
  291. //
  292. RtlInitUnicodeString( &KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa\\AuditingOptions");
  293. InitializeObjectAttributes( &Obja,
  294. &KeyName,
  295. OBJ_CASE_INSENSITIVE,
  296. NULL,
  297. NULL
  298. );
  299. Status = NtOpenKey(
  300. &KeyHandle,
  301. KEY_QUERY_VALUE,
  302. &Obja
  303. );
  304. if (!NT_SUCCESS( Status )) {
  305. goto Cleanup;
  306. }
  307. RtlInitUnicodeString( &ValueName, L"DoNotAuditCloseObjectEvents" );
  308. Status = NtQueryValueKey(
  309. KeyHandle,
  310. &ValueName,
  311. KeyValuePartialInformation,
  312. KeyInfo,
  313. sizeof(KeyInfo),
  314. &ResultLength
  315. );
  316. TmpStatus = NtClose(KeyHandle);
  317. ASSERT(NT_SUCCESS(TmpStatus));
  318. if (NT_SUCCESS( Status )) {
  319. //
  320. // we check for the presence of this value, its value does not matter
  321. //
  322. SepAuditOptions.DoNotAuditCloseObjectEvents = TRUE;
  323. }
  324. Cleanup:
  325. return;
  326. }