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.

386 lines
7.0 KiB

  1. #include <pch.cpp>
  2. #pragma hdrstop
  3. #include "csdisp.h"
  4. #include "csprop.h"
  5. #define __dwFILE__ __dwFILE_CERTLIB_POLDISP_CPP__
  6. //+------------------------------------------------------------------------
  7. // ICertPolicy dispatch support
  8. //+------------------------------------
  9. // VerifyRequest method:
  10. OLECHAR *_apszVerifyRequest[] = {
  11. TEXT("VerifyRequest"),
  12. TEXT("strConfig"),
  13. TEXT("Context"),
  14. TEXT("bNewRequest"),
  15. TEXT("Flags")
  16. };
  17. //+------------------------------------
  18. // GetDescription method:
  19. OLECHAR *_apszGetDescription[] = {
  20. TEXT("GetDescription"),
  21. };
  22. //+------------------------------------
  23. // Initialize method:
  24. OLECHAR *_apszInitialize[] = {
  25. TEXT("Initialize"),
  26. TEXT("strConfig"),
  27. };
  28. //+------------------------------------
  29. // ShutDown method:
  30. OLECHAR *_apszShutDown[] = {
  31. TEXT("ShutDown"),
  32. };
  33. //+------------------------------------
  34. // GetManageModule method:
  35. OLECHAR *_apszGetManageModule[] = {
  36. TEXT("GetManageModule"),
  37. };
  38. //+------------------------------------
  39. // Dispatch Table:
  40. DISPATCHTABLE g_adtPolicy[] =
  41. {
  42. DECLARE_DISPATCH_ENTRY(_apszVerifyRequest)
  43. DECLARE_DISPATCH_ENTRY(_apszGetDescription)
  44. DECLARE_DISPATCH_ENTRY(_apszInitialize)
  45. DECLARE_DISPATCH_ENTRY(_apszShutDown)
  46. DECLARE_DISPATCH_ENTRY(_apszGetManageModule)
  47. };
  48. DWORD CPOLICYDISPATCH = (ARRAYSIZE(g_adtPolicy));
  49. DWORD s_acPolicyDispatch[2] = {
  50. CPOLICYDISPATCH_V2,
  51. CPOLICYDISPATCH_V1,
  52. };
  53. IID const *s_apPolicyiid[2] = {
  54. &IID_ICertPolicy2,
  55. &IID_ICertPolicy,
  56. };
  57. HRESULT
  58. PolicyVerifyVersion(
  59. IN DISPATCHINTERFACE *pdiPolicy,
  60. IN DWORD RequiredVersion)
  61. {
  62. HRESULT hr;
  63. CSASSERT(NULL != pdiPolicy && NULL != pdiPolicy->pDispatchTable);
  64. switch (pdiPolicy->m_dwVersion)
  65. {
  66. case 1:
  67. CSASSERT(
  68. NULL == pdiPolicy->pDispatch ||
  69. CPOLICYDISPATCH_V1 == pdiPolicy->m_cDispatchTable);
  70. break;
  71. case 2:
  72. CSASSERT(
  73. NULL == pdiPolicy->pDispatch ||
  74. CPOLICYDISPATCH_V2 == pdiPolicy->m_cDispatchTable);
  75. break;
  76. default:
  77. hr = HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
  78. _JumpError(hr, error, "m_dwVersion");
  79. }
  80. if (pdiPolicy->m_dwVersion < RequiredVersion)
  81. {
  82. hr = E_NOTIMPL;
  83. _JumpError(hr, error, "old interface");
  84. }
  85. hr = S_OK;
  86. error:
  87. return(hr);
  88. }
  89. HRESULT
  90. Policy_Init(
  91. IN DWORD Flags,
  92. IN LPCWSTR pcwszProgID,
  93. IN CLSID const *pclsid,
  94. OUT DISPATCHINTERFACE *pdi)
  95. {
  96. HRESULT hr;
  97. hr = DispatchSetup2(
  98. Flags,
  99. CLSCTX_INPROC_SERVER,
  100. pcwszProgID, // g_wszRegKeyCIPolicyClsid,
  101. pclsid,
  102. ARRAYSIZE(s_acPolicyDispatch),
  103. s_apPolicyiid,
  104. s_acPolicyDispatch,
  105. g_adtPolicy,
  106. pdi);
  107. _JumpIfError(hr, error, "DispatchSetup");
  108. pdi->pDispatchTable = g_adtPolicy;
  109. error:
  110. return(hr);
  111. }
  112. VOID
  113. Policy_Release(
  114. IN OUT DISPATCHINTERFACE *pdiManage)
  115. {
  116. DispatchRelease(pdiManage);
  117. }
  118. HRESULT
  119. Policy_Initialize(
  120. IN DISPATCHINTERFACE *pdiPolicy,
  121. IN WCHAR const *pwszConfig)
  122. {
  123. HRESULT hr;
  124. BSTR strConfig = NULL;
  125. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  126. {
  127. hr = E_OUTOFMEMORY;
  128. goto error;
  129. }
  130. __try
  131. {
  132. if (NULL != pdiPolicy->pDispatch)
  133. {
  134. VARIANT avar[1];
  135. CSASSERT(NULL != pdiPolicy->pDispatchTable);
  136. avar[0].vt = VT_BSTR;
  137. avar[0].bstrVal = strConfig;
  138. hr = DispatchInvoke(
  139. pdiPolicy,
  140. POLICY_INITIALIZE,
  141. ARRAYSIZE(avar),
  142. avar,
  143. 0,
  144. NULL);
  145. _LeaveIfError(hr, "Invoke(Initialize)");
  146. }
  147. else
  148. {
  149. hr = ((ICertPolicy *) pdiPolicy->pUnknown)->Initialize(strConfig);
  150. _LeaveIfError(hr, "ICertPolicy::Initialize");
  151. }
  152. }
  153. _finally
  154. {
  155. if (NULL != strConfig)
  156. {
  157. SysFreeString(strConfig);
  158. }
  159. }
  160. error:
  161. return(hr);
  162. }
  163. HRESULT
  164. Policy_ShutDown(
  165. IN DISPATCHINTERFACE *pdiPolicy)
  166. {
  167. HRESULT hr;
  168. if (NULL != pdiPolicy->pDispatch)
  169. {
  170. CSASSERT(NULL != pdiPolicy->pDispatchTable);
  171. hr = DispatchInvoke(
  172. pdiPolicy,
  173. POLICY_SHUTDOWN,
  174. 0,
  175. NULL,
  176. 0,
  177. NULL);
  178. _JumpIfError(hr, error, "Invoke(ShutDown)");
  179. }
  180. else
  181. {
  182. hr = ((ICertPolicy *) pdiPolicy->pUnknown)->ShutDown();
  183. _JumpIfError(hr, error, "ICertPolicy::ShutDown");
  184. }
  185. error:
  186. return(hr);
  187. }
  188. HRESULT
  189. Policy_VerifyRequest(
  190. IN DISPATCHINTERFACE *pdiPolicy,
  191. IN WCHAR const *pwszConfig,
  192. IN LONG Context,
  193. IN LONG bNewRequest,
  194. IN LONG Flags,
  195. OUT LONG *pResult)
  196. {
  197. HRESULT hr;
  198. BSTR strConfig = NULL;
  199. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  200. {
  201. hr = E_OUTOFMEMORY;
  202. goto error;
  203. }
  204. __try
  205. {
  206. if (NULL != pdiPolicy->pDispatch)
  207. {
  208. VARIANT avar[4];
  209. CSASSERT(NULL != pdiPolicy->pDispatchTable);
  210. avar[0].vt = VT_BSTR;
  211. avar[0].bstrVal = strConfig;
  212. avar[1].vt = VT_I4;
  213. avar[1].lVal = Context;
  214. avar[2].vt = VT_I4;
  215. avar[2].lVal = bNewRequest;
  216. avar[3].vt = VT_I4;
  217. avar[3].lVal = Flags;
  218. hr = DispatchInvoke(
  219. pdiPolicy,
  220. POLICY_VERIFYREQUEST,
  221. ARRAYSIZE(avar),
  222. avar,
  223. VT_I4,
  224. pResult);
  225. _PrintIfError(hr, "Invoke(VerifyRequest)");
  226. // Emulate the way C++ Policy Modules overload *pRequest with
  227. // a FAILED HRESULT:
  228. if (FAILED(hr))
  229. {
  230. *pResult = hr;
  231. hr = S_OK;
  232. }
  233. _LeaveIfError(hr, "Invoke(VerifyRequest)");
  234. }
  235. else
  236. {
  237. hr = ((ICertPolicy *) pdiPolicy->pUnknown)->VerifyRequest(
  238. strConfig,
  239. Context,
  240. bNewRequest,
  241. Flags,
  242. pResult);
  243. _LeaveIfError(hr, "ICertPolicy::VerifyRequest");
  244. }
  245. }
  246. _finally
  247. {
  248. if (NULL != strConfig)
  249. {
  250. SysFreeString(strConfig);
  251. }
  252. }
  253. error:
  254. return(hr);
  255. }
  256. HRESULT
  257. Policy_GetDescription(
  258. IN DISPATCHINTERFACE *pdiPolicy,
  259. OUT BSTR *pstrDescription)
  260. {
  261. HRESULT hr;
  262. if (NULL != pdiPolicy->pDispatch)
  263. {
  264. CSASSERT(NULL != pdiPolicy->pDispatchTable);
  265. hr = DispatchInvoke(
  266. pdiPolicy,
  267. POLICY_GETDESCRIPTION,
  268. 0,
  269. NULL,
  270. VT_BSTR,
  271. pstrDescription);
  272. _JumpIfError(hr, error, "Invoke(GetDescription)");
  273. }
  274. else
  275. {
  276. hr = ((ICertPolicy *) pdiPolicy->pUnknown)->GetDescription(
  277. pstrDescription);
  278. _JumpIfError(hr, error, "ICertPolicy::GetDescription");
  279. }
  280. error:
  281. return(hr);
  282. }
  283. HRESULT
  284. Policy2_GetManageModule(
  285. IN DISPATCHINTERFACE *pdiPolicy,
  286. OUT DISPATCHINTERFACE *pdiManageModule)
  287. {
  288. HRESULT hr;
  289. ICertManageModule *pManageModule = NULL;
  290. hr = PolicyVerifyVersion(pdiPolicy, 2);
  291. _JumpIfError(hr, error, "PolicyVerifyVersion");
  292. if (NULL != pdiPolicy->pDispatch)
  293. {
  294. CSASSERT(NULL != pdiPolicy->pDispatchTable);
  295. hr = DispatchInvoke(
  296. pdiPolicy,
  297. POLICY2_GETMANAGEMODULE,
  298. 0,
  299. NULL,
  300. VT_DISPATCH,
  301. &pManageModule);
  302. _JumpIfError(hr, error, "Invoke(GetManageModule)");
  303. }
  304. else
  305. {
  306. hr = ((ICertPolicy2 *) pdiPolicy->pUnknown)->GetManageModule(
  307. &pManageModule);
  308. _JumpIfError(hr, error, "ICertPolicy::GetManageModule");
  309. }
  310. hr = ManageModule_Init2(
  311. NULL != pdiPolicy->pDispatch,
  312. pManageModule,
  313. pdiManageModule);
  314. _JumpIfError(hr, error, "ManageModule_Init2");
  315. error:
  316. return(hr);
  317. }