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.

300 lines
9.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-2002.
  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. bool IsSelected () const;
  50. void SetSelected (bool bIsSelected);
  51. LPRESULTDATA m_resultDataID;
  52. virtual void Refresh ();
  53. virtual HRESULT Commit ();
  54. CString GetServiceName () const;
  55. void SetServiceName (CString &szManagedService);
  56. LPCWSTR GetObjectName ();
  57. const CertificateManagerObjectType m_objecttype;
  58. UINT IncrementOpenPageCount ();
  59. UINT DecrementOpenPageCount ();
  60. bool HasOpenPropertyPages () const;
  61. private:
  62. bool m_bIsSelected;
  63. CString m_objectName;
  64. UINT m_nOpenPageCount;
  65. };
  66. typedef enum {
  67. NO_SPECIAL_TYPE = 0,
  68. MY_STORE,
  69. CA_STORE,
  70. ROOT_STORE,
  71. TRUST_STORE,
  72. USERDS_STORE,
  73. ACRS_STORE,
  74. EFS_STORE,
  75. REQUEST_STORE,
  76. SAFER_TRUSTED_PUBLISHER_STORE,
  77. SAFER_DISALLOWED_STORE
  78. } SPECIAL_STORE_TYPE;
  79. SPECIAL_STORE_TYPE GetSpecialStoreType(PCWSTR pwszStoreName);
  80. SPECIAL_STORE_TYPE StoreNameToType (const CString& szStoreName);
  81. class CCTL; // forward declaration
  82. class CCertStore : public CCertMgrCookie
  83. {
  84. friend CCTL;
  85. public:
  86. virtual bool IsNullEFSPolicy()
  87. {
  88. return false;
  89. }
  90. void IncrementCertCount ();
  91. void Unlock ();
  92. void Lock ();
  93. void InvalidateCertCount();
  94. BOOL AddEncodedCTL (DWORD dwMsgAndCertEncodingType,
  95. const BYTE* pbCtlEncoded,
  96. DWORD cbCtlEncoded,
  97. DWORD dwAddDisposition,
  98. PCCTL_CONTEXT* ppCtlContext);
  99. virtual void Close (bool bForceClose = false);
  100. void SetDirty();
  101. HRESULT AddStoreToCollection(CCertStore& siblingStore,
  102. DWORD dwUpdateFlags = 0,
  103. DWORD dwPriority = 0);
  104. HRESULT AddStoreToCollection(HCERTSTORE hSiblingStore,
  105. DWORD dwUpdateFlags = 0,
  106. DWORD dwPriority = 0);
  107. int GetCTLCount ();
  108. inline DWORD GetLocation () { return m_dwLocation;}
  109. HRESULT Resync ();
  110. inline bool IsOpen()
  111. {
  112. // If m_hCertStore is 0, then this store hasn't been used for anything
  113. if ( !m_hCertStore )
  114. return false;
  115. else
  116. return true;
  117. }
  118. PCCRL_CONTEXT GetCRL (
  119. PCCERT_CONTEXT pIssuerContext,
  120. PCCRL_CONTEXT pPrevCrlContext,
  121. DWORD* pdwFlags);
  122. bool AddCTLContext (PCCTL_CONTEXT pCtlContext);
  123. bool AddCRLContext (PCCRL_CONTEXT pCrlContext);
  124. PCCERT_CONTEXT FindCertificate (
  125. DWORD dwFindFlags,
  126. DWORD dwFindType,
  127. const void *pvFindPara,
  128. PCCERT_CONTEXT pPrevCertContext);
  129. PCCRL_CONTEXT EnumCRLs (PCCRL_CONTEXT pPrevCrlContext);
  130. PCCTL_CONTEXT EnumCTLs (PCCTL_CONTEXT pPrevCtlContext);
  131. virtual PCCERT_CONTEXT EnumCertificates (PCCERT_CONTEXT pPrevCertContext);
  132. CCertificate* GetSubjectCertificate (PCERT_INFO pCertId);
  133. BOOL operator==(CCertStore&);
  134. int GetCertCount ();
  135. virtual HRESULT AddCertificateContext (
  136. PCCERT_CONTEXT pContext,
  137. LPCONSOLE pConsole,
  138. bool bDeletePrivateKey,
  139. PCCERT_CONTEXT* ppNewCertContext = 0,
  140. bool* pbCertWasReplaced = false);
  141. inline virtual void AddRef()
  142. {
  143. ASSERT (CERTMGR_LOG_STORE_GPE == m_objecttype ||
  144. CERTMGR_LOG_STORE_RSOP == m_objecttype ||
  145. CERTMGR_LOG_STORE == m_objecttype ||
  146. CERTMGR_PHYS_STORE == m_objecttype);
  147. CCertMgrCookie::AddRef ();
  148. }
  149. inline virtual void Release ()
  150. {
  151. ASSERT (CERTMGR_LOG_STORE_GPE == m_objecttype ||
  152. CERTMGR_LOG_STORE_RSOP == m_objecttype ||
  153. CERTMGR_LOG_STORE == m_objecttype ||
  154. CERTMGR_PHYS_STORE == m_objecttype);
  155. CCertMgrCookie::Release ();
  156. }
  157. CString GetStoreName () const;
  158. LPCWSTR GetLocalizedName();
  159. bool ContainsCTLs ();
  160. bool ContainsCRLs ();
  161. bool ContainsCertificates ();
  162. virtual HRESULT Commit ();
  163. virtual bool IsReadOnly ();
  164. inline const SPECIAL_STORE_TYPE GetStoreType () const
  165. {
  166. ASSERT (CERTMGR_LOG_STORE_GPE == m_objecttype ||
  167. CERTMGR_LOG_STORE_RSOP == m_objecttype ||
  168. CERTMGR_LOG_STORE == m_objecttype ||
  169. CERTMGR_PHYS_STORE == m_objecttype);
  170. return m_storeType;
  171. }
  172. CCertStore (CertificateManagerObjectType objecttype,
  173. LPCSTR pszStoreProv,
  174. DWORD dwFlags,
  175. LPCWSTR lpcszMachineName,
  176. LPCWSTR objectName,
  177. const CString & pcszLogStoreName,
  178. const CString & pcszPhysStoreName,
  179. const SPECIAL_STORE_TYPE storeType,
  180. const DWORD dwLocation,
  181. IConsole* pConsole,
  182. bool fIsComputerType = false);
  183. virtual ~CCertStore ();
  184. virtual HCERTSTORE GetStoreHandle (BOOL bSilent = FALSE, HRESULT* phr = 0);
  185. virtual bool CanContain (CertificateManagerObjectType /*nodeType*/)
  186. {
  187. return false;
  188. }
  189. virtual bool IsMachineStore()
  190. {
  191. return false;
  192. }
  193. virtual bool IsComputerType ()
  194. {
  195. return m_fIsComputerType;
  196. }
  197. virtual void SetAdding ()
  198. {
  199. }
  200. virtual void SetDeleting ()
  201. {
  202. }
  203. protected:
  204. virtual void FinalCommit();
  205. HRESULT RetrieveBLOBFromFile (LPCWSTR pwszFileName, DWORD *pcb, BYTE **ppb);
  206. bool m_fCertCountValid;
  207. bool m_bUnableToOpenMsgDisplayed;
  208. LPCSTR m_storeProvider;
  209. DWORD m_dwFlags;
  210. CString m_pcszStoreName;
  211. bool m_bReadOnly;
  212. HCERTSTORE m_hCertStore;
  213. IConsole* m_pConsole;
  214. bool m_bDirty;
  215. bool m_fIsComputerType;
  216. private:
  217. int m_nCertCount;
  218. bool m_fReadOnlyFlagChecked;
  219. const DWORD m_dwLocation;
  220. CString m_localizedName;
  221. const SPECIAL_STORE_TYPE m_storeType;
  222. int m_nLockCnt; // test
  223. };
  224. class CContainerCookie : public CCertMgrCookie
  225. {
  226. public:
  227. virtual HRESULT Commit ();
  228. inline const SPECIAL_STORE_TYPE GetStoreType () const
  229. {
  230. ASSERT (CERTMGR_CRL_CONTAINER == m_objecttype ||
  231. CERTMGR_CTL_CONTAINER == m_objecttype ||
  232. CERTMGR_CERT_CONTAINER == m_objecttype);
  233. return m_rCertStore.GetStoreType ();
  234. }
  235. CContainerCookie (CCertStore& rStore,
  236. CertificateManagerObjectType objecttype,
  237. LPCWSTR lpcszMachineName,
  238. LPCWSTR objectName);
  239. virtual ~CContainerCookie ();
  240. CCertStore& GetCertStore () const;
  241. private:
  242. CCertStore& m_rCertStore;
  243. };
  244. class CUsageCookie : public CCertMgrCookie
  245. {
  246. public:
  247. int GetCertCount () const;
  248. void SetCertCount (int nCertCount);
  249. CUsageCookie (
  250. CertificateManagerObjectType objecttype,
  251. LPCWSTR lpcszMachineName,
  252. LPCWSTR objectName);
  253. void AddOID (LPCSTR pszOID);
  254. virtual ~CUsageCookie ();
  255. LPSTR GetFirstOID ();
  256. LPSTR GetNextOID ();
  257. int GetOIDCount () const;
  258. private:
  259. int m_nCertCount;
  260. CTypedPtrList<CPtrList, LPSTR> m_OIDList;
  261. POSITION m_OIDListPos;
  262. };
  263. #endif // ~__COOKIE_H_INCLUDED__