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.

282 lines
7.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-2001.
  5. //
  6. // File: cookie.h
  7. //
  8. // Contents:
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef __COOKIE_H_INCLUDED__
  12. #define __COOKIE_H_INCLUDED__
  13. extern HINSTANCE g_hInstanceSave; // Instance handle of the DLL (initialized during CCertMgrComponent::Initialize)
  14. #include "nodetype.h"
  15. #pragma warning(push,3)
  16. #include <efsstruc.h>
  17. #pragma warning(pop)
  18. // Name of Encrypting File System store
  19. #define ACRS_SYSTEM_STORE_NAME L"ACRS"
  20. #define EFS_SYSTEM_STORE_NAME L"EFS"
  21. #define TRUST_SYSTEM_STORE_NAME L"Trust"
  22. #define ROOT_SYSTEM_STORE_NAME L"Root"
  23. #define MY_SYSTEM_STORE_NAME L"MY"
  24. #define CA_SYSTEM_STORE_NAME L"CA"
  25. #define USERDS_SYSTEM_STORE_NAME L"UserDS"
  26. #define REQUEST_SYSTEM_STORE_NAME L"REQUEST"
  27. #define SAFER_TRUSTED_PUBLISHER_STORE_NAME L"TrustedPublisher"
  28. #define SAFER_DISALLOWED_STORE_NAME L"Disallowed"
  29. /////////////////////////////////////////////////////////////////////////////
  30. // cookie
  31. //REVIEW -- using pointers to ID's is necessary because some compilers don't like
  32. //references as template arguments.
  33. class CCertificate; // forward declaration
  34. class CCertMgrCookie : public CCookie,
  35. public CStoresMachineName,
  36. public CBaseCookieBlock
  37. {
  38. public:
  39. CCertMgrCookie (CertificateManagerObjectType objecttype,
  40. LPCWSTR lpcszMachineName = 0,
  41. LPCWSTR objectName = 0);
  42. virtual ~CCertMgrCookie ();
  43. // returns <0, 0 or >0
  44. virtual HRESULT CompareSimilarCookies( CCookie* pOtherCookie, int* pnResult );
  45. // CBaseCookieBlock
  46. virtual CCookie* QueryBaseCookie(int i);
  47. virtual int QueryNumCookies();
  48. public:
  49. LPRESULTDATA m_resultDataID;
  50. virtual void Refresh ();
  51. virtual HRESULT Commit ();
  52. CString GetServiceName () const;
  53. void SetServiceName (CString &szManagedService);
  54. LPCWSTR GetObjectName ();
  55. const CertificateManagerObjectType m_objecttype;
  56. UINT IncrementOpenPageCount ();
  57. UINT DecrementOpenPageCount ();
  58. bool HasOpenPropertyPages () const;
  59. private:
  60. CString m_objectName;
  61. UINT m_nOpenPageCount;
  62. };
  63. typedef enum {
  64. NO_SPECIAL_TYPE = 0,
  65. MY_STORE,
  66. CA_STORE,
  67. ROOT_STORE,
  68. TRUST_STORE,
  69. USERDS_STORE,
  70. ACRS_STORE,
  71. EFS_STORE,
  72. REQUEST_STORE,
  73. SAFER_TRUSTED_PUBLISHER_STORE,
  74. SAFER_DISALLOWED_STORE
  75. } SPECIAL_STORE_TYPE;
  76. SPECIAL_STORE_TYPE GetSpecialStoreType(LPWSTR pwszStoreName);
  77. SPECIAL_STORE_TYPE StoreNameToType (const CString& szStoreName);
  78. class CCTL; // forward declaration
  79. class CCertStore : public CCertMgrCookie
  80. {
  81. friend CCTL;
  82. public:
  83. virtual bool IsNullEFSPolicy()
  84. {
  85. return false;
  86. }
  87. void IncrementCertCount ();
  88. void Unlock ();
  89. void Lock ();
  90. void InvalidateCertCount();
  91. BOOL AddEncodedCTL (DWORD dwMsgAndCertEncodingType,
  92. const BYTE* pbCtlEncoded,
  93. DWORD cbCtlEncoded,
  94. DWORD dwAddDisposition,
  95. PCCTL_CONTEXT* ppCtlContext);
  96. virtual void Close (bool bForceClose = false);
  97. void SetDirty();
  98. HRESULT AddStoreToCollection(CCertStore& siblingStore,
  99. DWORD dwUpdateFlags = 0,
  100. DWORD dwPriority = 0);
  101. HRESULT AddStoreToCollection(HCERTSTORE hSiblingStore,
  102. DWORD dwUpdateFlags = 0,
  103. DWORD dwPriority = 0);
  104. int GetCTLCount ();
  105. inline DWORD GetLocation () { return m_dwLocation;}
  106. HRESULT Resync ();
  107. inline bool IsOpen()
  108. {
  109. // If m_hCertStore is 0, then this store hasn't been used for anything
  110. if ( !m_hCertStore )
  111. return false;
  112. else
  113. return true;
  114. }
  115. PCCRL_CONTEXT GetCRL (
  116. PCCERT_CONTEXT pIssuerContext,
  117. PCCRL_CONTEXT pPrevCrlContext,
  118. DWORD* pdwFlags);
  119. bool AddCTLContext (PCCTL_CONTEXT pCtlContext);
  120. bool AddCRLContext (PCCRL_CONTEXT pCrlContext);
  121. PCCERT_CONTEXT FindCertificate (
  122. DWORD dwFindFlags,
  123. DWORD dwFindType,
  124. const void *pvFindPara,
  125. PCCERT_CONTEXT pPrevCertContext);
  126. PCCRL_CONTEXT EnumCRLs (PCCRL_CONTEXT pPrevCrlContext);
  127. PCCTL_CONTEXT EnumCTLs (PCCTL_CONTEXT pPrevCtlContext);
  128. virtual PCCERT_CONTEXT EnumCertificates (PCCERT_CONTEXT pPrevCertContext);
  129. CCertificate* GetSubjectCertificate (PCERT_INFO pCertId);
  130. BOOL operator==(CCertStore&);
  131. int GetCertCount ();
  132. virtual HRESULT AddCertificateContext (
  133. PCCERT_CONTEXT pContext,
  134. LPCONSOLE pConsole,
  135. bool bDeletePrivateKey,
  136. PCCERT_CONTEXT* ppNewCertContext = 0);
  137. inline virtual void AddRef()
  138. {
  139. ASSERT (CERTMGR_LOG_STORE_GPE == m_objecttype ||
  140. CERTMGR_LOG_STORE_RSOP == m_objecttype ||
  141. CERTMGR_LOG_STORE == m_objecttype ||
  142. CERTMGR_PHYS_STORE == m_objecttype);
  143. CCertMgrCookie::AddRef ();
  144. }
  145. inline virtual void Release ()
  146. {
  147. ASSERT (CERTMGR_LOG_STORE_GPE == m_objecttype ||
  148. CERTMGR_LOG_STORE_RSOP == m_objecttype ||
  149. CERTMGR_LOG_STORE == m_objecttype ||
  150. CERTMGR_PHYS_STORE == m_objecttype);
  151. CCertMgrCookie::Release ();
  152. }
  153. CString GetStoreName () const;
  154. LPCWSTR GetLocalizedName();
  155. bool ContainsCTLs ();
  156. bool ContainsCRLs ();
  157. bool ContainsCertificates ();
  158. virtual HRESULT Commit ();
  159. virtual bool IsReadOnly ();
  160. inline const SPECIAL_STORE_TYPE GetStoreType () const
  161. {
  162. ASSERT (CERTMGR_LOG_STORE_GPE == m_objecttype ||
  163. CERTMGR_LOG_STORE_RSOP == m_objecttype ||
  164. CERTMGR_LOG_STORE == m_objecttype ||
  165. CERTMGR_PHYS_STORE == m_objecttype);
  166. return m_storeType;
  167. }
  168. CCertStore (CertificateManagerObjectType objecttype,
  169. LPCSTR pszStoreProv,
  170. DWORD dwFlags,
  171. LPCWSTR lpcszMachineName,
  172. LPCWSTR objectName,
  173. const CString & pcszLogStoreName,
  174. const CString & pcszPhysStoreName,
  175. const SPECIAL_STORE_TYPE storeType,
  176. const DWORD dwLocation,
  177. IConsole* pConsole);
  178. virtual ~CCertStore ();
  179. virtual HCERTSTORE GetStoreHandle (BOOL bSilent = FALSE, HRESULT* phr = 0);
  180. virtual bool CanContain (CertificateManagerObjectType /*nodeType*/)
  181. {
  182. return false;
  183. }
  184. virtual bool IsMachineStore()
  185. {
  186. return false;
  187. }
  188. protected:
  189. virtual void FinalCommit();
  190. HRESULT RetrieveBLOBFromFile (LPCWSTR pwszFileName, DWORD *pcb, BYTE **ppb);
  191. bool m_fCertCountValid;
  192. bool m_bUnableToOpenMsgDisplayed;
  193. LPCSTR m_storeProvider;
  194. DWORD m_dwFlags;
  195. CString m_pcszStoreName;
  196. bool m_bReadOnly;
  197. HCERTSTORE m_hCertStore;
  198. IConsole* m_pConsole;
  199. bool m_bDirty;
  200. private:
  201. int m_nCertCount;
  202. bool m_fReadOnlyFlagChecked;
  203. const DWORD m_dwLocation;
  204. CString m_localizedName;
  205. const SPECIAL_STORE_TYPE m_storeType;
  206. int m_nLockCnt; // test
  207. };
  208. class CContainerCookie : public CCertMgrCookie
  209. {
  210. public:
  211. virtual HRESULT Commit ();
  212. inline const SPECIAL_STORE_TYPE GetStoreType () const
  213. {
  214. ASSERT (CERTMGR_CRL_CONTAINER == m_objecttype ||
  215. CERTMGR_CTL_CONTAINER == m_objecttype ||
  216. CERTMGR_CERT_CONTAINER == m_objecttype);
  217. return m_rCertStore.GetStoreType ();
  218. }
  219. CContainerCookie (CCertStore& rStore,
  220. CertificateManagerObjectType objecttype,
  221. LPCWSTR lpcszMachineName,
  222. LPCWSTR objectName);
  223. virtual ~CContainerCookie ();
  224. CCertStore& GetCertStore () const;
  225. private:
  226. CCertStore& m_rCertStore;
  227. };
  228. class CUsageCookie : public CCertMgrCookie
  229. {
  230. public:
  231. int GetCertCount () const;
  232. void SetCertCount (int nCertCount);
  233. CUsageCookie (
  234. CertificateManagerObjectType objecttype,
  235. LPCWSTR lpcszMachineName,
  236. LPCWSTR objectName);
  237. void AddOID (LPCSTR pszOID);
  238. virtual ~CUsageCookie ();
  239. LPSTR GetFirstOID ();
  240. LPSTR GetNextOID ();
  241. int GetOIDCount () const;
  242. private:
  243. int m_nCertCount;
  244. CTypedPtrList<CPtrList, LPSTR> m_OIDList;
  245. POSITION m_OIDListPos;
  246. };
  247. #endif // ~__COOKIE_H_INCLUDED__