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.

225 lines
5.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: certwrap.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _CERTWRAP_H_
  11. #define _CERTWRAP_H_
  12. #include <iads.h>
  13. #include <adshlp.h>
  14. // fwd
  15. class CertSvrMachine;
  16. class CertSvrCA
  17. {
  18. protected:
  19. HCERTSTORE m_hCACertStore; // our cert store
  20. BOOL m_fCertStoreOpenAttempted;
  21. HRESULT m_hrCACertStoreOpen;
  22. HCERTSTORE m_hRootCertStore; // root store on machine
  23. BOOL m_fRootStoreOpenAttempted;
  24. HRESULT m_hrRootCertStoreOpen;
  25. HCERTSTORE m_hKRACertStore; // KRA store on machine
  26. BOOL m_fKRAStoreOpenAttempted;
  27. HRESULT m_hrKRACertStoreOpen;
  28. BOOL m_fIsUsingDS;
  29. BOOL m_fIsUsingDSKnown;
  30. ENUM_CATYPES m_enumCAType;
  31. BOOL m_fCATypeKnown;
  32. BOOL m_fAdvancedServer;
  33. BOOL m_fAdvancedServerKnown;
  34. DWORD m_dwRoles;
  35. BOOL m_fRolesKnown;
  36. public:
  37. CertSvrMachine* m_pParentMachine;
  38. CString m_strServer;
  39. CString m_strCommonName;
  40. CString m_strSanitizedName;
  41. CString m_strConfig;
  42. CString m_strComment;
  43. CString m_strCAObjectDN;
  44. BSTR m_bstrConfig; // oft used as BSTR
  45. public:
  46. CertSvrCA(CertSvrMachine* pParent);
  47. ~CertSvrCA();
  48. public:
  49. DWORD GetMyRoles();
  50. BOOL AccessAllowed(DWORD dwAccess);
  51. HRESULT GetConfigEntry(
  52. LPWSTR szConfigSubKey,
  53. LPWSTR szConfigEntry,
  54. VARIANT *pvarOut);
  55. HRESULT SetConfigEntry(
  56. LPWSTR szConfigSubKey,
  57. LPWSTR szConfigEntry,
  58. VARIANT *pvarIn);
  59. DWORD DeleteConfigEntry(
  60. LPWSTR szConfigSubKey,
  61. LPWSTR szConfigEntry);
  62. ENUM_CATYPES GetCAType();
  63. BOOL FIsUsingDS();
  64. BOOL FIsIncompleteInstallation();
  65. BOOL FIsRequestOutstanding();
  66. BOOL FIsAdvancedServer();
  67. BOOL FDoesSecurityNeedUpgrade();
  68. BOOL FDoesServerAllowForeignCerts();
  69. DWORD GetCACertStore(HCERTSTORE* phCertStore); // class frees
  70. DWORD GetRootCertStore(HCERTSTORE* phCertStore); // class frees
  71. DWORD GetKRACertStore(HCERTSTORE* phCertStore); // class frees
  72. DWORD GetCurrentCRL(PCCRL_CONTEXT* ppCRLCtxt, BOOL fBaseCRL); // use CertFreeCRLContext()
  73. DWORD GetCRLByKeyIndex(PCCRL_CONTEXT* ppCRLCtxt, BOOL fBaseCRL, int iKeyIndex); // use CertFreeCRLContext()
  74. DWORD GetCACertByKeyIndex(PCCERT_CONTEXT*ppCertCtxt, int iKeyIndex); // use CertFreeCertificateContext()
  75. HRESULT FixEnrollmentObject();
  76. HRESULT CleanSetupStatusBits(DWORD dwBitsToClean);
  77. protected:
  78. HRESULT IsCAAllowedFullControl(
  79. PSECURITY_DESCRIPTOR pSDRead,
  80. PSID pSid,
  81. bool& fAllowed);
  82. HRESULT AllowCAFullControl(
  83. PSECURITY_DESCRIPTOR pSDRead,
  84. PSID pSid,
  85. PSECURITY_DESCRIPTOR& pSDWrite);
  86. HRESULT GetCAFlagsFromDS(
  87. PDWORD pdwFlags);
  88. HRESULT _GetSetupStatus(DWORD &rdwStatus);
  89. HRESULT _SetSetupStatus(DWORD dwStatus);
  90. };
  91. class CertSvrMachine
  92. {
  93. friend CComponentDataImpl;
  94. public:
  95. // IPersistStream interface members
  96. STDMETHOD(Load)(IStream *pStm);
  97. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  98. STDMETHOD(GetSizeMax)(int *pcbSize);
  99. #if DBG
  100. bool m_bInitializedCD;
  101. bool m_bLoadedCD;
  102. bool m_bDestroyedCD;
  103. #endif
  104. public:
  105. CString m_strMachineNamePersist; // Machine name to persist into .msc file
  106. CString m_strMachineName; // Effective machine name
  107. DWORD m_dwServiceStatus; //
  108. HKEY m_hCachedConfigBaseKey; // base registry key
  109. BOOL m_bAttemptedBaseKeyOpen;
  110. BOOL m_fIsWhistlerMachine;
  111. BOOL m_fIsWhistlerMachineKnown;
  112. protected:
  113. CArray<CertSvrCA*, CertSvrCA*> m_CAList;
  114. public:
  115. CertSvrMachine();
  116. ~CertSvrMachine();
  117. ULONG AddRef() { return(InterlockedIncrement(&m_cRef)); }
  118. ULONG Release()
  119. {
  120. ULONG cRef = InterlockedDecrement(&m_cRef);
  121. if (0 == cRef)
  122. {
  123. delete this;
  124. }
  125. return cRef;
  126. }
  127. private:
  128. DWORD RetrieveCertSvrCAs(DWORD dwFlags);
  129. LONG m_cRef;
  130. BOOL m_fLocalIsKnown, m_fIsLocal;
  131. void Init();
  132. public:
  133. HRESULT GetAdmin(ICertAdmin** ppAdmin);
  134. HRESULT GetAdmin2(ICertAdmin2** ppAdmin, bool fIgnoreServiceDown = false);
  135. // Fills local cache with CAs for current machine
  136. DWORD PrepareData(HWND hwndParent);
  137. // enum CAs on current machine
  138. LPCWSTR GetCaCommonNameAtPos(DWORD iPos);
  139. CertSvrCA* GetCaAtPos(DWORD iPos);
  140. HRESULT GetRootConfigEntry(
  141. LPWSTR szConfigEntry,
  142. VARIANT *pvarOut);
  143. DWORD GetCaCount()
  144. { return m_CAList.GetSize(); }
  145. BOOL FIsWhistlerMachine();
  146. // control CA on current machine
  147. DWORD CertSvrStartStopService(HWND hwndParent, BOOL fStartSvc);
  148. DWORD RefreshServiceStatus();
  149. DWORD GetCertSvrServiceStatus()
  150. { return m_dwServiceStatus; };
  151. BOOL IsCertSvrServiceRunning()
  152. { return (m_dwServiceStatus == SERVICE_RUNNING); };
  153. BOOL IsLocalMachine()
  154. {
  155. if (!m_fLocalIsKnown)
  156. {
  157. m_fLocalIsKnown = TRUE;
  158. m_fIsLocal = FIsCurrentMachine(m_strMachineName);
  159. }
  160. return m_fIsLocal;
  161. };
  162. };
  163. #endif // _CERTWRAP_H_