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.

220 lines
5.2 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. protected:
  77. HRESULT IsCAAllowedFullControl(
  78. PSECURITY_DESCRIPTOR pSDRead,
  79. PSID pSid,
  80. bool& fAllowed);
  81. HRESULT AllowCAFullControl(
  82. PSECURITY_DESCRIPTOR pSDRead,
  83. PSID pSid,
  84. PSECURITY_DESCRIPTOR& pSDWrite);
  85. HRESULT GetCAFlagsFromDS(
  86. PDWORD pdwFlags);
  87. };
  88. class CertSvrMachine
  89. {
  90. friend CComponentDataImpl;
  91. public:
  92. // IPersistStream interface members
  93. STDMETHOD(Load)(IStream *pStm);
  94. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  95. STDMETHOD(GetSizeMax)(int *pcbSize);
  96. #if DBG
  97. bool m_bInitializedCD;
  98. bool m_bLoadedCD;
  99. bool m_bDestroyedCD;
  100. #endif
  101. public:
  102. CString m_strMachineNamePersist; // Machine name to persist into .msc file
  103. CString m_strMachineName; // Effective machine name
  104. DWORD m_dwServiceStatus; //
  105. HKEY m_hCachedConfigBaseKey; // base registry key
  106. BOOL m_bAttemptedBaseKeyOpen;
  107. BOOL m_fIsWhistlerMachine;
  108. BOOL m_fIsWhistlerMachineKnown;
  109. protected:
  110. CArray<CertSvrCA*, CertSvrCA*> m_CAList;
  111. public:
  112. CertSvrMachine();
  113. ~CertSvrMachine();
  114. ULONG AddRef() { return(InterlockedIncrement(&m_cRef)); }
  115. ULONG Release()
  116. {
  117. ULONG cRef = InterlockedDecrement(&m_cRef);
  118. if (0 == cRef)
  119. {
  120. delete this;
  121. }
  122. return cRef;
  123. }
  124. private:
  125. DWORD RetrieveCertSvrCAs(DWORD dwFlags);
  126. LONG m_cRef;
  127. BOOL m_fLocalIsKnown, m_fIsLocal;
  128. void Init();
  129. public:
  130. HRESULT GetAdmin(ICertAdmin** ppAdmin);
  131. HRESULT GetAdmin2(ICertAdmin2** ppAdmin, bool fIgnoreServiceDown = false);
  132. // Fills local cache with CAs for current machine
  133. DWORD PrepareData(HWND hwndParent);
  134. // enum CAs on current machine
  135. LPCWSTR GetCaCommonNameAtPos(DWORD iPos);
  136. CertSvrCA* GetCaAtPos(DWORD iPos);
  137. HRESULT GetRootConfigEntry(
  138. LPWSTR szConfigEntry,
  139. VARIANT *pvarOut);
  140. DWORD GetCaCount()
  141. { return m_CAList.GetSize(); }
  142. BOOL FIsWhistlerMachine();
  143. // control CA on current machine
  144. DWORD CertSvrStartStopService(HWND hwndParent, BOOL fStartSvc);
  145. DWORD RefreshServiceStatus();
  146. DWORD GetCertSvrServiceStatus()
  147. { return m_dwServiceStatus; };
  148. BOOL IsCertSvrServiceRunning()
  149. { return (m_dwServiceStatus == SERVICE_RUNNING); };
  150. BOOL IsLocalMachine()
  151. {
  152. if (!m_fLocalIsKnown)
  153. {
  154. m_fLocalIsKnown = TRUE;
  155. m_fIsLocal = FIsCurrentMachine(m_strMachineName);
  156. }
  157. return m_fIsLocal;
  158. };
  159. };
  160. #endif // _CERTWRAP_H_