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.

368 lines
6.9 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. 06-February-2002 kumarp security review
  13. --*/
  14. #include "pch.h"
  15. #pragma hdrstop
  16. #ifdef ALLOC_PRAGMA
  17. #pragma alloc_text(PAGE,SepAdtValidateAuditBounds)
  18. #pragma alloc_text(PAGE,SepAdtInitializeBounds)
  19. #pragma alloc_text(INIT,SepAdtInitializeCrashOnFail)
  20. #pragma alloc_text(INIT,SepAdtInitializePrivilegeAuditing)
  21. #pragma alloc_text(INIT,SepAdtInitializeAuditingOptions)
  22. #endif
  23. BOOLEAN
  24. SepAdtValidateAuditBounds(
  25. ULONG Upper,
  26. ULONG Lower
  27. )
  28. /*++
  29. Routine Description:
  30. Examines the audit queue high and low water mark values and performs
  31. a general sanity check on them.
  32. Arguments:
  33. Upper - High water mark.
  34. Lower - Low water mark.
  35. Return Value:
  36. TRUE - values are acceptable.
  37. FALSE - values are unacceptable.
  38. --*/
  39. {
  40. PAGED_CODE();
  41. if ( Lower >= Upper ) {
  42. return( FALSE );
  43. }
  44. if ( Lower < 16 ) {
  45. return( FALSE );
  46. }
  47. if ( (Upper - Lower) < 16 ) {
  48. return( FALSE );
  49. }
  50. return( TRUE );
  51. }
  52. VOID
  53. SepAdtInitializeBounds(
  54. VOID
  55. )
  56. /*++
  57. Routine Description:
  58. Queries the registry for the high and low water mark values for the
  59. audit log. If they are not found or are unacceptable, returns without
  60. modifying the current values, which are statically initialized.
  61. Arguments:
  62. None.
  63. Return Value:
  64. None.
  65. --*/
  66. {
  67. NTSTATUS Status;
  68. PSEP_AUDIT_BOUNDS AuditBounds;
  69. UCHAR Buffer[8];
  70. PAGED_CODE();
  71. Status = SepRegQueryHelper(
  72. L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa",
  73. L"Bounds",
  74. REG_BINARY,
  75. 8, // 8 bytes
  76. Buffer,
  77. NULL
  78. );
  79. if (!NT_SUCCESS( Status )) {
  80. //
  81. // Didn't work, take the defaults
  82. //
  83. return;
  84. }
  85. AuditBounds = (PSEP_AUDIT_BOUNDS) Buffer;
  86. //
  87. // Sanity check what we got back
  88. //
  89. if(SepAdtValidateAuditBounds( AuditBounds->UpperBound,
  90. AuditBounds->LowerBound ))
  91. {
  92. //
  93. // Take what we got from the registry.
  94. //
  95. SepAdtMaxListLength = AuditBounds->UpperBound;
  96. SepAdtMinListLength = AuditBounds->LowerBound;
  97. }
  98. }
  99. NTSTATUS
  100. SepAdtInitializeCrashOnFail(
  101. VOID
  102. )
  103. /*++
  104. Routine Description:
  105. Reads the registry to see if the user has told us to crash if an audit fails.
  106. Arguments:
  107. None.
  108. Return Value:
  109. STATUS_SUCCESS
  110. --*/
  111. {
  112. NTSTATUS Status;
  113. ULONG CrashOnAuditFail = 0;
  114. PAGED_CODE();
  115. SepCrashOnAuditFail = FALSE;
  116. //
  117. // Check the value of the CrashOnAudit flag in the registry.
  118. //
  119. Status = SepRegQueryDwordValue(
  120. L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa",
  121. CRASH_ON_AUDIT_FAIL_VALUE,
  122. &CrashOnAuditFail
  123. );
  124. //
  125. // If the key isn't there, don't turn on CrashOnFail.
  126. //
  127. if (Status == STATUS_OBJECT_NAME_NOT_FOUND) {
  128. return( STATUS_SUCCESS );
  129. }
  130. if (NT_SUCCESS( Status )) {
  131. if ( CrashOnAuditFail == LSAP_CRASH_ON_AUDIT_FAIL) {
  132. SepCrashOnAuditFail = TRUE;
  133. }
  134. }
  135. return( STATUS_SUCCESS );
  136. }
  137. BOOLEAN
  138. SepAdtInitializePrivilegeAuditing(
  139. VOID
  140. )
  141. /*++
  142. Routine Description:
  143. Checks to see if there is an entry in the registry telling us to do full privilege auditing
  144. (which currently means audit everything we normall audit, plus backup and restore privileges).
  145. Arguments:
  146. None
  147. Return Value:
  148. BOOLEAN - TRUE if Auditing has been initialized correctly, else FALSE.
  149. --*/
  150. {
  151. HANDLE KeyHandle;
  152. NTSTATUS Status;
  153. NTSTATUS TmpStatus;
  154. OBJECT_ATTRIBUTES Obja;
  155. ULONG ResultLength;
  156. UNICODE_STRING KeyName;
  157. UNICODE_STRING ValueName;
  158. CHAR KeyInfo[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(BOOLEAN)];
  159. PKEY_VALUE_PARTIAL_INFORMATION pKeyInfo;
  160. BOOLEAN Verbose;
  161. PAGED_CODE();
  162. //
  163. // Query the registry to set up the privilege auditing filter.
  164. //
  165. RtlInitUnicodeString( &KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa");
  166. InitializeObjectAttributes( &Obja,
  167. &KeyName,
  168. OBJ_CASE_INSENSITIVE,
  169. NULL,
  170. NULL
  171. );
  172. Status = NtOpenKey(
  173. &KeyHandle,
  174. KEY_QUERY_VALUE | KEY_SET_VALUE,
  175. &Obja
  176. );
  177. if (!NT_SUCCESS( Status )) {
  178. if (Status == STATUS_OBJECT_NAME_NOT_FOUND) {
  179. return ( SepInitializePrivilegeFilter( FALSE ));
  180. } else {
  181. return( FALSE );
  182. }
  183. }
  184. //
  185. // ISSUE-2002/02/06-kumarp : should we convert FULL_PRIVILEGE_AUDITING
  186. // to type REG_DWORD ?
  187. //
  188. RtlInitUnicodeString( &ValueName, FULL_PRIVILEGE_AUDITING );
  189. Status = NtQueryValueKey(
  190. KeyHandle,
  191. &ValueName,
  192. KeyValuePartialInformation,
  193. KeyInfo,
  194. sizeof(KeyInfo),
  195. &ResultLength
  196. );
  197. TmpStatus = NtClose(KeyHandle);
  198. ASSERT(NT_SUCCESS(TmpStatus));
  199. if (!NT_SUCCESS( Status )) {
  200. Verbose = FALSE;
  201. } else {
  202. pKeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyInfo;
  203. Verbose = (BOOLEAN) *(pKeyInfo->Data);
  204. }
  205. return ( SepInitializePrivilegeFilter( Verbose ));
  206. }
  207. VOID
  208. SepAdtInitializeAuditingOptions(
  209. VOID
  210. )
  211. /*++
  212. Routine Description:
  213. Initialize options that control auditing.
  214. (please refer to note in adtp.h near the def. of SEP_AUDIT_OPTIONS)
  215. Arguments:
  216. None
  217. Return Value:
  218. None
  219. --*/
  220. {
  221. NTSTATUS Status;
  222. ULONG OptionValue = 0;
  223. PAGED_CODE();
  224. //
  225. // initialize the default value
  226. //
  227. SepAuditOptions.DoNotAuditCloseObjectEvents = FALSE;
  228. //
  229. // if the value is present and set to 1, set the global
  230. // auditing option accordingly
  231. //
  232. Status = SepRegQueryDwordValue(
  233. L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Lsa\\AuditingOptions",
  234. L"DoNotAuditCloseObjectEvents",
  235. &OptionValue
  236. );
  237. if (NT_SUCCESS(Status) && OptionValue)
  238. {
  239. SepAuditOptions.DoNotAuditCloseObjectEvents = TRUE;
  240. }
  241. return;
  242. }