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.

174 lines
4.5 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: audit.c
  3. *
  4. * Copyright (c) 1991, Microsoft Corporation
  5. *
  6. * Implementation of routines that access/manipulate the system audit log
  7. *
  8. * History:
  9. * 12-09-91 Davidc Created.
  10. * 5-6-92 DaveHart Fleshed out.
  11. \***************************************************************************/
  12. #include "msgina.h"
  13. /***************************************************************************\
  14. * GetAuditLogStatus
  15. *
  16. * Purpose : Fills the global data with audit log status information
  17. *
  18. * Returns: TRUE on success, FALSE on failure
  19. *
  20. * History:
  21. * 12-09-91 Davidc Created.
  22. * 5-6-92 DaveHart Fleshed out.
  23. \***************************************************************************/
  24. BOOL
  25. GetAuditLogStatus(
  26. PGLOBALS pGlobals
  27. )
  28. {
  29. EVENTLOG_FULL_INFORMATION EventLogFullInformation;
  30. DWORD dwBytesNeeded;
  31. HANDLE AuditLogHandle;
  32. //
  33. // Assume the log is not full. If we can't get to EventLog, tough.
  34. //
  35. pGlobals->AuditLogFull = FALSE;
  36. AuditLogHandle = OpenEventLog( NULL, TEXT("Security"));
  37. if (AuditLogHandle) {
  38. if (GetEventLogInformation(AuditLogHandle,
  39. EVENTLOG_FULL_INFO,
  40. &EventLogFullInformation,
  41. sizeof(EventLogFullInformation),
  42. &dwBytesNeeded ) ) {
  43. if (EventLogFullInformation.dwFull != FALSE) {
  44. pGlobals->AuditLogFull = TRUE;
  45. }
  46. }
  47. CloseEventLog(AuditLogHandle);
  48. }
  49. //
  50. // There's no way in the current event logger to tell how full the log
  51. // is, always indicate we're NOT near full.
  52. //
  53. pGlobals->AuditLogNearFull = FALSE;
  54. return TRUE;
  55. }
  56. /***************************************************************************\
  57. * DisableAuditing
  58. *
  59. * Purpose : Disable auditing via LSA.
  60. *
  61. * Returns: TRUE on success, FALSE on failure
  62. *
  63. * History:
  64. * 5-6-92 DaveHart Created.
  65. \***************************************************************************/
  66. BOOL
  67. DisableAuditing()
  68. {
  69. NTSTATUS Status, IgnoreStatus;
  70. PPOLICY_AUDIT_EVENTS_INFO AuditInfo;
  71. OBJECT_ATTRIBUTES ObjectAttributes;
  72. SECURITY_QUALITY_OF_SERVICE SecurityQualityOfService;
  73. LSA_HANDLE PolicyHandle;
  74. //
  75. // Set up the Security Quality Of Service for connecting to the
  76. // LSA policy object.
  77. //
  78. SecurityQualityOfService.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
  79. SecurityQualityOfService.ImpersonationLevel = SecurityImpersonation;
  80. SecurityQualityOfService.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  81. SecurityQualityOfService.EffectiveOnly = FALSE;
  82. //
  83. // Set up the object attributes to open the Lsa policy object
  84. //
  85. InitializeObjectAttributes(
  86. &ObjectAttributes,
  87. NULL,
  88. 0L,
  89. NULL,
  90. NULL
  91. );
  92. ObjectAttributes.SecurityQualityOfService = &SecurityQualityOfService;
  93. //
  94. // Open the local LSA policy object
  95. //
  96. Status = LsaOpenPolicy(
  97. NULL,
  98. &ObjectAttributes,
  99. POLICY_VIEW_AUDIT_INFORMATION | POLICY_SET_AUDIT_REQUIREMENTS,
  100. &PolicyHandle
  101. );
  102. if (!NT_SUCCESS(Status)) {
  103. DebugLog((DEB_ERROR, "Failed to open LsaPolicyObject Status = 0x%lx", Status));
  104. return FALSE;
  105. }
  106. Status = LsaQueryInformationPolicy(
  107. PolicyHandle,
  108. PolicyAuditEventsInformation,
  109. (PVOID *)&AuditInfo
  110. );
  111. if (!NT_SUCCESS(Status)) {
  112. IgnoreStatus = LsaClose(PolicyHandle);
  113. ASSERT(NT_SUCCESS(IgnoreStatus));
  114. DebugLog((DEB_ERROR, "Failed to query audit event info Status = 0x%lx", Status));
  115. return FALSE;
  116. }
  117. if (AuditInfo->AuditingMode) {
  118. AuditInfo->AuditingMode = FALSE;
  119. Status = LsaSetInformationPolicy(
  120. PolicyHandle,
  121. PolicyAuditEventsInformation,
  122. AuditInfo
  123. );
  124. } else {
  125. Status = STATUS_SUCCESS;
  126. }
  127. IgnoreStatus = LsaFreeMemory(AuditInfo);
  128. ASSERT(NT_SUCCESS(IgnoreStatus));
  129. IgnoreStatus = LsaClose(PolicyHandle);
  130. ASSERT(NT_SUCCESS(IgnoreStatus));
  131. if (!NT_SUCCESS(Status)) {
  132. DebugLog((DEB_ERROR, "Failed to disable auditing Status = 0x%lx", Status));
  133. return FALSE;
  134. }
  135. return TRUE;
  136. }