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.

289 lines
7.8 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: exit.h
  7. //
  8. // Contents: CCertExit definition
  9. //
  10. //---------------------------------------------------------------------------
  11. #include <certca.h>
  12. //#include <mapi.h>
  13. //#include <mapix.h>
  14. #include "resource.h" // main symbols
  15. #include "certxds.h"
  16. #include <winldap.h>
  17. #include <cdosys.h>
  18. //#include <cdosysstr.h>
  19. #include "rwlock.h"
  20. using namespace CDO;
  21. HRESULT RegGetValue(
  22. HKEY hkey,
  23. LPCWSTR pcwszValName,
  24. VARIANT* pvarValue);
  25. HRESULT RegSetValue(
  26. HKEY hkey,
  27. LPCWSTR pcwszValName,
  28. VARIANT* pvarValue);
  29. class CEmailNotify;
  30. typedef HRESULT (__stdcall ICertServerExit::* GetCertOrRequestProp)(
  31. const BSTR strPropertyName,
  32. LONG PropertyType,
  33. VARIANT *pvarPropertyValue);
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CNotifyInfo stores info about each type of notification, including
  36. // title and message body formatting and recipient/sender/CC
  37. class CNotifyInfo
  38. {
  39. public:
  40. CNotifyInfo();
  41. ~CNotifyInfo();
  42. HRESULT LoadInfoFromRegistry(
  43. HKEY hkeySMTP,
  44. LPCWSTR pcwszSubkey);
  45. HRESULT BuildMessageTitle(ICertServerExit* pServer, BSTR& rbstrOut);
  46. HRESULT BuildMessageBody (ICertServerExit* pServer, BSTR& rbstrOut);
  47. friend class CEmailNotify;
  48. protected:
  49. class FormattedMessageInfo
  50. {
  51. public:
  52. FormattedMessageInfo()
  53. {
  54. m_nArgs = 0;
  55. VariantInit(&m_varFormat);
  56. VariantInit(&m_varArgs);
  57. m_pfArgFromRequestTable = NULL;
  58. m_pArgType = NULL;
  59. m_fInitialized = false;
  60. InitializeCriticalSection(&m_critsectObjInit);
  61. }
  62. ~FormattedMessageInfo()
  63. {
  64. VariantClear(&m_varFormat);
  65. VariantClear(&m_varArgs);
  66. LOCAL_FREE(m_pfArgFromRequestTable);
  67. LOCAL_FREE(m_pArgType);
  68. DeleteCriticalSection(&m_critsectObjInit);
  69. }
  70. HRESULT InitializeArgInfo(ICertServerExit* pServer);
  71. HRESULT BuildArgList(
  72. ICertServerExit* pServer,
  73. LPWSTR*& rppwszArgs);
  74. void FreeArgList(
  75. LPWSTR*& ppwszArgs);
  76. HRESULT BuildFormattedString(
  77. ICertServerExit* pServer,
  78. BSTR& bstrOut);
  79. HRESULT ConvertToString(
  80. VARIANT* pvarValue,
  81. LONG lType,
  82. LPCWSTR pcwszPropertyName,
  83. LPWSTR* ppwszValue);
  84. private:
  85. HRESULT _FormatStringFromArgs(
  86. IN LPWSTR *ppwszArgs,
  87. OPTIONAL OUT WCHAR *pwszOut,
  88. IN OUT DWORD *pcwcOut);
  89. public:
  90. // "static" info about the message format, initialized once
  91. LONG m_nArgs;
  92. VARIANT m_varFormat;
  93. VARIANT m_varArgs;
  94. bool* m_pfArgFromRequestTable; // array of m_nArgs to cache if argument
  95. // is request or certificate property
  96. LONG* m_pArgType; // array of m_nArgs to cache argument type
  97. bool m_fInitialized;
  98. CRITICAL_SECTION m_critsectObjInit;
  99. static LONG m_gPropTypes[4];
  100. static LPCWSTR m_gwszArchivedKeyPresent;
  101. };
  102. HRESULT _ConvertBSTRArrayToBSTR(VARIANT& varIn, VARIANT& varOut);
  103. FormattedMessageInfo m_BodyFormat;
  104. FormattedMessageInfo m_TitleFormat;
  105. VARIANT m_varFrom;
  106. VARIANT m_varTo;
  107. VARIANT m_varCC;
  108. };
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CEmailNotify contains all email notification functionality. It is called
  111. // by the main exit class
  112. class CEmailNotify
  113. {
  114. public:
  115. CEmailNotify();
  116. ~CEmailNotify();
  117. HRESULT Init(
  118. IN HKEY hExitKey,
  119. IN WCHAR const *pwszDescription);
  120. HRESULT Notify(
  121. IN DWORD lExitEvent,
  122. IN LONG lContext,
  123. IN WCHAR const *pwszDescription);
  124. protected:
  125. HRESULT _CreateSMTPRegSettings(HKEY hExitKey);
  126. HRESULT _LoadEventInfoFromRegistry();
  127. HRESULT _LoadTemplateRestrictionsFromRegistry();
  128. HRESULT _LoadSMTPFieldsFromRegistry(Fields* pFields);
  129. HRESULT _LoadSMTPFieldsFromLSASecret(Fields* pFields);
  130. HRESULT _GetCAMailAddress(
  131. ICertServerExit* pServer,
  132. BSTR& bstrAddress);
  133. HRESULT _SetField(
  134. Fields* pFields,
  135. LPCWSTR pcwszFieldSchemaName,
  136. VARIANT *pvarFieldValue);
  137. HRESULT _GetEmailFromCertSubject(
  138. const VARIANT *pVarCert,
  139. LPWSTR *ppwszEmail);
  140. bool _IsRestrictedTemplate(BSTR strTemplate);
  141. inline bool _TemplateRestrictionsEnabled(DWORD dwEvent);
  142. inline DWORD _MapEventToOrd(LONG lEvent);
  143. inline bool _IsEventEnabled(DWORD dwEvent);
  144. HRESULT _InitCDO();
  145. enum { m_gcEvents = 7 };
  146. CNotifyInfo m_NotifyInfoArray[m_gcEvents];
  147. HKEY m_hkeySMTP;
  148. DWORD m_dwEventFilter;
  149. BSTR m_bstrCAMailAddress;
  150. IConfiguration *m_pICDOConfig;
  151. CReadWriteLock m_rwlockCDOConfig;
  152. bool m_fReloadCDOConfig;
  153. VARIANT m_varTemplateRestrictions;
  154. static LPCWSTR m_pcwszEventRegKeys[m_gcEvents];
  155. };
  156. // begin_sdksample
  157. HRESULT
  158. GetServerCallbackInterface(
  159. OUT ICertServerExit** ppServer,
  160. IN LONG Context);
  161. HRESULT
  162. exitGetProperty(
  163. IN ICertServerExit *pServer,
  164. IN BOOL fRequest,
  165. IN WCHAR const *pwszPropertyName,
  166. IN DWORD PropType,
  167. OUT VARIANT *pvarOut);
  168. /////////////////////////////////////////////////////////////////////////////
  169. // certexit
  170. class CCertExit:
  171. public CComDualImpl<ICertExit2, &IID_ICertExit2, &LIBID_CERTEXITLib>,
  172. public ISupportErrorInfo,
  173. public CComObjectRoot,
  174. public CComCoClass<CCertExit, &CLSID_CCertExit>
  175. {
  176. public:
  177. CCertExit()
  178. {
  179. m_strDescription = NULL;
  180. m_strCAName = NULL;
  181. m_pwszRegStorageLoc = NULL;
  182. m_hExitKey = NULL;
  183. m_dwExitPublishFlags = 0;
  184. m_cCACert = 0;
  185. }
  186. ~CCertExit();
  187. BEGIN_COM_MAP(CCertExit)
  188. COM_INTERFACE_ENTRY(IDispatch)
  189. COM_INTERFACE_ENTRY(ICertExit)
  190. COM_INTERFACE_ENTRY(ICertExit2)
  191. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  192. END_COM_MAP()
  193. DECLARE_NOT_AGGREGATABLE(CCertExit)
  194. DECLARE_REGISTRY(
  195. CCertExit,
  196. wszCLASS_CERTEXIT TEXT(".1"),
  197. wszCLASS_CERTEXIT,
  198. IDS_CERTEXIT_DESC,
  199. THREADFLAGS_BOTH)
  200. // ISupportsErrorInfo
  201. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  202. // ICertExit
  203. public:
  204. STDMETHOD(Initialize)(
  205. /* [in] */ BSTR const strConfig,
  206. /* [retval][out] */ LONG __RPC_FAR *pEventMask);
  207. STDMETHOD(Notify)(
  208. /* [in] */ LONG ExitEvent,
  209. /* [in] */ LONG Context);
  210. STDMETHOD(GetDescription)(
  211. /* [retval][out] */ BSTR *pstrDescription);
  212. // ICertExit2
  213. public:
  214. STDMETHOD(GetManageModule)(
  215. /* [out, retval] */ ICertManageModule **ppManageModule);
  216. private:
  217. HRESULT _NotifyNewCert(IN LONG Context);
  218. HRESULT _NotifyCRLIssued(IN LONG Context);
  219. HRESULT _WriteCertToFile(
  220. IN ICertServerExit *pServer,
  221. IN BYTE const *pbCert,
  222. IN DWORD cbCert);
  223. HRESULT _ExpandEnvironmentVariables(
  224. IN WCHAR const *pwszIn,
  225. OUT WCHAR *pwszOut,
  226. IN DWORD cwcOut);
  227. // Member variables & private methods here:
  228. BSTR m_strDescription;
  229. BSTR m_strCAName;
  230. LPWSTR m_pwszRegStorageLoc;
  231. HKEY m_hExitKey;
  232. DWORD m_dwExitPublishFlags;
  233. DWORD m_cCACert;
  234. // end_sdksample
  235. CEmailNotify m_EmailNotifyObj; // email notification support
  236. // begin_sdksample
  237. };
  238. // end_sdksample