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.

200 lines
5.9 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. HRESULT AddData(ULARGE_INTEGER *puliValue);
  49. void DeleteLastData()
  50. { delete m_pEventDataList[--m_cEventData]; }
  51. HRESULT Report(bool fSuccess = true);
  52. HRESULT SaveFilter(LPCWSTR pcwszSanitizedName);
  53. HRESULT LoadFilter(LPCWSTR pcwszSanitizedName);
  54. DWORD GetFilter() {return m_dwFilter;}
  55. HRESULT AccessCheck(
  56. ACCESS_MASK Mask,
  57. DWORD dwAuditFlags,
  58. handle_t hRpc = NULL,
  59. HANDLE *phToken = NULL);
  60. HRESULT CachedGenerateAudit();
  61. void FreeCachedHandles();
  62. HRESULT GetMyRoles(DWORD *pdwRoles);
  63. bool IsEventEnabled();
  64. HRESULT Impersonate();
  65. HRESULT RevertToSelf();
  66. HANDLE GetClientToken();
  67. // role separation
  68. void EventRoleSeparationEnable(bool fEnable)
  69. {m_fRoleSeparationEnabled = fEnable;};
  70. static void RoleSeparationEnable(bool fEnable)
  71. {m_gfRoleSeparationEnabled = fEnable;};
  72. static bool RoleSeparationIsEnabled() {return m_gfRoleSeparationEnabled;}
  73. static HRESULT RoleSeparationFlagSave(LPCWSTR pcwszSanitizedName);
  74. static HRESULT RoleSeparationFlagLoad(LPCWSTR pcwszSanitizedName);
  75. static void CleanupAuditEventTypeHandles();
  76. struct AUDIT_CATEGORIES
  77. {
  78. ULONG ulAuditID;
  79. DWORD dwFilter;
  80. DWORD dwParamCount;
  81. bool fRoleSeparationEnabled;
  82. AUTHZ_AUDIT_EVENT_TYPE_HANDLE hAuditEventType;
  83. };
  84. private:
  85. bool IsEventValid();
  86. bool IsEventRoleSeparationEnabled();
  87. CAuditEvent(const CAuditEvent&);
  88. const CAuditEvent& operator=(const CAuditEvent&);
  89. struct EventData
  90. {
  91. EventData() : m_fDoublePercentsInStrings(false)
  92. {
  93. PropVariantInit(&m_vtData);
  94. };
  95. ~EventData()
  96. {
  97. PropVariantClear(&m_vtData);
  98. };
  99. HRESULT ConvertToString(LPWSTR *pwszData);
  100. PROPVARIANT m_vtData;
  101. bool m_fDoublePercentsInStrings; // Insertion strings containing %number get
  102. // displayed incorrectly in the event log.
  103. // If this value is set, we double % chars.
  104. };// struct EventData
  105. PROPVARIANT *CreateNewEventData();
  106. EventData *CreateNewEventData1();
  107. HRESULT BuildAuditParamArray(PAUDIT_PARAM& rpParamArray);
  108. void FreeAuditParamArray(PAUDIT_PARAM pParamArray);
  109. HRESULT GetPrivilegeRoles(PDWORD pdwRoles);
  110. HRESULT GetUserPrivilegeRoles(
  111. LSA_HANDLE lsah,
  112. PSID_AND_ATTRIBUTES pSA,
  113. PDWORD pdwRoles);
  114. HRESULT BuildPrivilegeSecurityDescriptor(
  115. DWORD dwRoles);
  116. DWORD GetBitCount(DWORD dwBits)
  117. {
  118. DWORD dwCount = 0;
  119. for(DWORD dwSize = 0; dwSize<sizeof(DWORD); dwSize++, dwBits>>=1)
  120. {
  121. dwCount += dwBits&1;
  122. }
  123. return dwCount;
  124. }
  125. HRESULT DoublePercentsInString(
  126. LPCWSTR pcwszIn,
  127. LPCWSTR *ppcwszOut);
  128. HRESULT EnforceEncryption(bool fRequestInterface);
  129. HRESULT EnforceLocalVsRemote(ACCESS_MASK Mask);
  130. ULONG m_ulEventID;
  131. enum {m_EventDataMaxSize=10};
  132. EventData* m_pEventDataList[m_EventDataMaxSize];
  133. DWORD m_cEventData;
  134. DWORD m_cRequiredEventData; // expected number of audit parameters
  135. DWORD m_dwFilter;
  136. bool m_fRoleSeparationEnabled;
  137. // free these
  138. IServerSecurity *m_pISS;
  139. HANDLE m_hClientToken;
  140. PSECURITY_DESCRIPTOR m_pCASD;
  141. AUTHZ_CLIENT_CONTEXT_HANDLE m_ClientContext;
  142. AUTHZ_ACCESS_CHECK_RESULTS_HANDLE m_AuthzHandle;
  143. PSECURITY_DESCRIPTOR m_pSDPrivileges;
  144. PACL m_pDaclPrivileges;
  145. // no free
  146. handle_t m_hRpc;
  147. DWORD m_Error;
  148. DWORD m_SaclEval;
  149. ACCESS_MASK m_MaskAllowed;
  150. AUTHZ_ACCESS_REQUEST m_Request;
  151. AUTHZ_ACCESS_REPLY m_Reply;
  152. DWORD m_crtGUID;
  153. AUTHZ_AUDIT_EVENT_TYPE_HANDLE m_hAuditEventType;
  154. PSID m_pUserSid;
  155. static AUDIT_CATEGORIES *m_gAuditCategories;
  156. static DWORD m_gdwAuditCategoriesSize;
  157. static bool m_gfRoleSeparationEnabled;
  158. static const DWORD AuditorRoleBit;
  159. static const DWORD OperatorRoleBit;
  160. static const DWORD CAAdminRoleBit;
  161. static const DWORD OfficerRoleBit;
  162. static const DWORD dwMaskRoles;
  163. }; // class CAuditEvent
  164. } // namespace CertSrv
  165. #endif //__AUDIT_H__