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.

218 lines
6.2 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999 - 2000
  5. //
  6. // File: audit.h
  7. //
  8. // Contents: Cert Server audit classes
  9. //
  10. //---------------------------------------------------------------------------
  11. #ifndef __AUDIT_H__
  12. #define __AUDIT_H__
  13. #include <ntsecapi.h>
  14. #include <authzi.h>
  15. #define AUDIT_FILTER_STARTSTOP 0x00000001
  16. #define AUDIT_FILTER_BACKUPRESTORE 0x00000002
  17. #define AUDIT_FILTER_CERTIFICATE 0x00000004
  18. #define AUDIT_FILTER_CERTREVOCATION 0x00000008
  19. #define AUDIT_FILTER_CASECURITY 0x00000010
  20. #define AUDIT_FILTER_KEYAARCHIVAL 0x00000020
  21. #define AUDIT_FILTER_CACONFIG 0x00000040
  22. #define CA_ACCESS_ALLREADROLES \
  23. CA_ACCESS_ADMIN | \
  24. CA_ACCESS_OFFICER | \
  25. CA_ACCESS_AUDITOR | \
  26. CA_ACCESS_OPERATOR| \
  27. CA_ACCESS_READ
  28. namespace CertSrv
  29. {
  30. static const LPCWSTR cAuditString_UnknownDataType = L"?";
  31. // define event
  32. class CAuditEvent
  33. {
  34. public:
  35. static const DWORD m_gcAuditSuccessOrFailure = 0;
  36. static const DWORD m_gcNoAuditSuccess = 1;
  37. static const DWORD m_gcNoAuditFailure = 2;
  38. CAuditEvent(ULONG ulEventID = 0L, DWORD dwFilter = 0);
  39. ~CAuditEvent();
  40. void SetEventID(ULONG ulEventID);
  41. HRESULT AddData(DWORD dwValue);
  42. HRESULT AddData(PBYTE pData, DWORD dwDataLen);
  43. HRESULT AddData(bool fData);
  44. HRESULT AddData(LPCWSTR pcwszData);
  45. HRESULT AddData(LPCWSTR *ppcwszData);
  46. HRESULT AddData(FILETIME time);
  47. HRESULT AddData(const VARIANT *pvar, bool fDoublePercentInString);
  48. void DeleteLastData()
  49. { delete m_pEventDataList[--m_cEventData]; }
  50. HRESULT Report(bool fSuccess = true);
  51. HRESULT SaveFilter(LPCWSTR pcwszSanitizedName);
  52. HRESULT LoadFilter(LPCWSTR pcwszSanitizedName);
  53. DWORD GetFilter() {return m_dwFilter;}
  54. HRESULT AccessCheck(
  55. ACCESS_MASK Mask,
  56. DWORD dwAuditFlags,
  57. handle_t hRpc = NULL,
  58. HANDLE *phToken = NULL);
  59. HRESULT CachedGenerateAudit();
  60. void FreeCachedHandles();
  61. HRESULT GetMyRoles(DWORD *pdwRoles);
  62. bool IsEventEnabled();
  63. HRESULT Impersonate();
  64. HRESULT RevertToSelf();
  65. HANDLE GetClientToken();
  66. // role separation
  67. void EventRoleSeparationEnable(bool fEnable)
  68. {m_fRoleSeparationEnabled = fEnable;};
  69. static void RoleSeparationEnable(bool fEnable)
  70. {m_gfRoleSeparationEnabled = fEnable;};
  71. static bool RoleSeparationIsEnabled() {return m_gfRoleSeparationEnabled;}
  72. static HRESULT RoleSeparationFlagSave(LPCWSTR pcwszSanitizedName);
  73. static HRESULT RoleSeparationFlagLoad(LPCWSTR pcwszSanitizedName);
  74. static void CleanupAuditEventTypeHandles();
  75. struct AUDIT_CATEGORIES
  76. {
  77. ULONG ulAuditID;
  78. DWORD dwFilter;
  79. DWORD dwParamCount;
  80. bool fRoleSeparationEnabled;
  81. AUTHZ_AUDIT_EVENT_TYPE_HANDLE hAuditEventType;
  82. };
  83. private:
  84. bool IsEventValid();
  85. bool IsEventRoleSeparationEnabled();
  86. CAuditEvent(const CAuditEvent&);
  87. const CAuditEvent& operator=(const CAuditEvent&);
  88. struct EventData
  89. {
  90. EventData() : m_fDoublePercentsInStrings(false)
  91. {
  92. PropVariantInit(&m_vtData);
  93. };
  94. ~EventData()
  95. {
  96. PropVariantClear(&m_vtData);
  97. };
  98. HRESULT ConvertToStringI2I4(
  99. LONG lVal,
  100. LPWSTR *ppwszOut);
  101. HRESULT ConvertToStringUI2UI4(
  102. ULONG ulVal,
  103. LPWSTR *ppwszOut);
  104. HRESULT ConvertToStringWSZ(
  105. LPCWSTR pcwszVal,
  106. LPWSTR *ppwszOut);
  107. HRESULT ConvertToStringBOOL(
  108. BOOL fVal,
  109. LPWSTR *ppwszOut);
  110. HRESULT ConvertToStringArrayUI1(
  111. LPSAFEARRAY psa,
  112. LPWSTR *ppwszOut);
  113. HRESULT ConvertToStringArrayBSTR(
  114. LPSAFEARRAY psa,
  115. LPWSTR *ppwszOut);
  116. HRESULT DoublePercentsInString(
  117. LPCWSTR pcwszIn,
  118. LPWSTR *ppwszOut);
  119. HRESULT ConvertToString(LPWSTR *pwszData);
  120. PROPVARIANT m_vtData;
  121. bool m_fDoublePercentsInStrings; // Insertion strings containing %number get
  122. // displayed incorrectly in the event log.
  123. // If this value is set, we double % chars.
  124. };// struct EventData
  125. PROPVARIANT *CreateNewEventData();
  126. EventData *CreateNewEventData1();
  127. HRESULT BuildAuditParamArray(PAUDIT_PARAM& rpParamArray);
  128. void FreeAuditParamArray(PAUDIT_PARAM pParamArray);
  129. HRESULT GetPrivilegeRoles(PDWORD pdwRoles);
  130. HRESULT GetUserPrivilegeRoles(
  131. LSA_HANDLE lsah,
  132. PSID_AND_ATTRIBUTES pSA,
  133. PDWORD pdwRoles);
  134. HRESULT BuildPrivilegeSecurityDescriptor(
  135. DWORD dwRoles);
  136. DWORD GetBitCount(DWORD dwBits)
  137. {
  138. DWORD dwCount = 0;
  139. for(DWORD dwSize = 0; dwSize<sizeof(DWORD); dwSize++, dwBits>>=1)
  140. {
  141. dwCount += dwBits&1;
  142. }
  143. return dwCount;
  144. }
  145. HRESULT DoublePercentsInString(
  146. LPCWSTR pcwszIn,
  147. LPCWSTR *ppcwszOut);
  148. ULONG m_ulEventID;
  149. enum {m_EventDataMaxSize=10};
  150. EventData* m_pEventDataList[m_EventDataMaxSize];
  151. DWORD m_cEventData;
  152. DWORD m_cRequiredEventData; // expected number of audit parameters
  153. DWORD m_dwFilter;
  154. bool m_fRoleSeparationEnabled;
  155. // free these
  156. IServerSecurity *m_pISS;
  157. HANDLE m_hClientToken;
  158. PSECURITY_DESCRIPTOR m_pCASD;
  159. AUTHZ_CLIENT_CONTEXT_HANDLE m_ClientContext;
  160. AUTHZ_ACCESS_CHECK_RESULTS_HANDLE m_AuthzHandle;
  161. PSECURITY_DESCRIPTOR m_pSDPrivileges;
  162. PACL m_pDaclPrivileges;
  163. // no free
  164. handle_t m_hRpc;
  165. DWORD m_Error;
  166. DWORD m_SaclEval;
  167. ACCESS_MASK m_MaskAllowed;
  168. AUTHZ_ACCESS_REQUEST m_Request;
  169. AUTHZ_ACCESS_REPLY m_Reply;
  170. DWORD m_crtGUID;
  171. AUTHZ_AUDIT_EVENT_TYPE_HANDLE m_hAuditEventType;
  172. PSID m_pUserSid;
  173. static AUDIT_CATEGORIES *m_gAuditCategories;
  174. static DWORD m_gdwAuditCategoriesSize;
  175. static bool m_gfRoleSeparationEnabled;
  176. static const DWORD AuditorRoleBit;
  177. static const DWORD OperatorRoleBit;
  178. static const DWORD CAAdminRoleBit;
  179. static const DWORD OfficerRoleBit;
  180. static const DWORD dwMaskRoles;
  181. }; // class CAuditEvent
  182. } // namespace CertSrv
  183. #endif //__AUDIT_H__