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.

307 lines
5.9 KiB

  1. #include <pch.cpp>
  2. #pragma hdrstop
  3. #include "csdisp.h"
  4. #include "csprop.h"
  5. #define __dwFILE__ __dwFILE_CERTLIB_EXITDISP_CPP__
  6. //+------------------------------------------------------------------------
  7. // ICertExit dispatch support
  8. //+------------------------------------
  9. // Initialize method:
  10. OLECHAR *exit_apszInitialize[] = {
  11. TEXT("Initialize"),
  12. TEXT("strConfig"),
  13. };
  14. //+------------------------------------
  15. // Notify method:
  16. OLECHAR *exit_apszNotify[] = {
  17. TEXT("Notify"),
  18. TEXT("ExitEvent"),
  19. TEXT("Context"),
  20. };
  21. //+------------------------------------
  22. // GetDescription method:
  23. OLECHAR *exit_apszGetDescription[] = {
  24. TEXT("GetDescription"),
  25. };
  26. //+------------------------------------
  27. // GetManageModule method:
  28. OLECHAR *exit_apszGetManageModule[] = {
  29. TEXT("GetManageModule"),
  30. };
  31. //+------------------------------------
  32. // Dispatch Table:
  33. DISPATCHTABLE g_adtExit[] =
  34. {
  35. DECLARE_DISPATCH_ENTRY(exit_apszInitialize)
  36. DECLARE_DISPATCH_ENTRY(exit_apszNotify)
  37. DECLARE_DISPATCH_ENTRY(exit_apszGetDescription)
  38. DECLARE_DISPATCH_ENTRY(exit_apszGetManageModule)
  39. };
  40. DWORD CEXITDISPATCH (ARRAYSIZE(g_adtExit));
  41. DWORD s_acExitDispatch[] = {
  42. CEXITDISPATCH_V2,
  43. CEXITDISPATCH_V1,
  44. };
  45. IID const *s_apExitiid[] = {
  46. &IID_ICertExit2,
  47. &IID_ICertExit,
  48. };
  49. HRESULT
  50. Exit_Init(
  51. IN DWORD Flags,
  52. IN LPCWSTR pcwszProgID,
  53. IN CLSID const *pclsid,
  54. OUT DISPATCHINTERFACE *pdi)
  55. {
  56. HRESULT hr;
  57. hr = DispatchSetup2(
  58. Flags,
  59. CLSCTX_INPROC_SERVER,
  60. pcwszProgID, // g_wszRegKeyCIPolicyClsid,
  61. pclsid,
  62. ARRAYSIZE(s_acExitDispatch),
  63. s_apExitiid,
  64. s_acExitDispatch,
  65. g_adtExit,
  66. pdi);
  67. _JumpIfError(hr, error, "DispatchSetup");
  68. pdi->pDispatchTable = g_adtExit;
  69. error:
  70. return(hr);
  71. }
  72. VOID
  73. Exit_Release(
  74. IN OUT DISPATCHINTERFACE *pdiManage)
  75. {
  76. DispatchRelease(pdiManage);
  77. }
  78. HRESULT
  79. ExitVerifyVersion(
  80. IN DISPATCHINTERFACE *pdiExit,
  81. IN DWORD RequiredVersion)
  82. {
  83. HRESULT hr;
  84. CSASSERT(NULL != pdiExit && NULL != pdiExit->pDispatchTable);
  85. switch (pdiExit->m_dwVersion)
  86. {
  87. case 1:
  88. CSASSERT(
  89. NULL == pdiExit->pDispatch ||
  90. CEXITDISPATCH_V1 == pdiExit->m_cDispatchTable);
  91. break;
  92. case 2:
  93. CSASSERT(
  94. NULL == pdiExit->pDispatch ||
  95. CEXITDISPATCH_V2 == pdiExit->m_cDispatchTable);
  96. break;
  97. default:
  98. hr = HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
  99. _JumpError(hr, error, "m_dwVersion");
  100. }
  101. if (pdiExit->m_dwVersion < RequiredVersion)
  102. {
  103. hr = E_NOTIMPL;
  104. _JumpError(hr, error, "old interface");
  105. }
  106. hr = S_OK;
  107. error:
  108. return(hr);
  109. }
  110. HRESULT
  111. Exit_Initialize(
  112. IN DISPATCHINTERFACE *pdiExit,
  113. IN WCHAR const *pwszConfig,
  114. OUT LONG *pEventMask)
  115. {
  116. HRESULT hr;
  117. BSTR strConfig = NULL;
  118. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  119. {
  120. hr = E_OUTOFMEMORY;
  121. goto error;
  122. }
  123. hr = S_OK;
  124. __try
  125. {
  126. if (NULL != pdiExit->pDispatch)
  127. {
  128. VARIANT avar[1];
  129. CSASSERT(NULL != pdiExit->pDispatchTable);
  130. avar[0].vt = VT_BSTR;
  131. avar[0].bstrVal = strConfig;
  132. hr = DispatchInvoke(
  133. pdiExit,
  134. EXIT_INITIALIZE,
  135. ARRAYSIZE(avar),
  136. avar,
  137. VT_I4,
  138. pEventMask);
  139. _LeaveIfError(hr, "Invoke(Initialize)");
  140. }
  141. else
  142. {
  143. hr = ((ICertExit *) pdiExit->pUnknown)->Initialize(
  144. strConfig,
  145. pEventMask);
  146. _LeaveIfError(hr, "ICertExit::Initialize");
  147. }
  148. }
  149. __finally
  150. {
  151. if (NULL != strConfig)
  152. {
  153. SysFreeString(strConfig);
  154. }
  155. }
  156. error:
  157. return(hr);
  158. }
  159. HRESULT
  160. Exit_Notify(
  161. IN DISPATCHINTERFACE *pdiExit,
  162. IN LONG ExitEvent,
  163. IN LONG Context)
  164. {
  165. HRESULT hr;
  166. if (NULL != pdiExit->pDispatch)
  167. {
  168. VARIANT avar[2];
  169. CSASSERT(NULL != pdiExit->pDispatchTable);
  170. avar[0].vt = VT_I4;
  171. avar[0].lVal = ExitEvent;
  172. avar[1].vt = VT_I4;
  173. avar[1].lVal = Context;
  174. hr = DispatchInvoke(
  175. pdiExit,
  176. EXIT_NOTIFY,
  177. ARRAYSIZE(avar),
  178. avar,
  179. 0,
  180. NULL);
  181. _JumpIfError(hr, error, "Invoke(Notify)");
  182. }
  183. else
  184. {
  185. hr = ((ICertExit *) pdiExit->pUnknown)->Notify(ExitEvent, Context);
  186. _JumpIfError(hr, error, "ICertExit::Notify");
  187. }
  188. error:
  189. return(hr);
  190. }
  191. HRESULT
  192. Exit_GetDescription(
  193. IN DISPATCHINTERFACE *pdiExit,
  194. OUT BSTR *pstrDescription)
  195. {
  196. HRESULT hr;
  197. if (NULL != pdiExit->pDispatch)
  198. {
  199. CSASSERT(NULL != pdiExit->pDispatchTable);
  200. hr = DispatchInvoke(
  201. pdiExit,
  202. EXIT_GETDESCRIPTION,
  203. 0,
  204. NULL,
  205. VT_BSTR,
  206. pstrDescription);
  207. _JumpIfError(hr, error, "Invoke(GetDescription)");
  208. }
  209. else
  210. {
  211. hr = ((ICertExit *) pdiExit->pUnknown)->GetDescription(pstrDescription);
  212. _JumpIfError(hr, error, "ICertExit::GetDescription");
  213. }
  214. error:
  215. return(hr);
  216. }
  217. HRESULT
  218. Exit2_GetManageModule(
  219. IN DISPATCHINTERFACE *pdiExit,
  220. OUT DISPATCHINTERFACE *pdiManageModule)
  221. {
  222. HRESULT hr;
  223. ICertManageModule *pManageModule = NULL;
  224. hr = ExitVerifyVersion(pdiExit, 2);
  225. _JumpIfError(hr, error, "ExitVerifyVersion");
  226. if (NULL != pdiExit->pDispatch)
  227. {
  228. CSASSERT(NULL != pdiExit->pDispatchTable);
  229. hr = DispatchInvoke(
  230. pdiExit,
  231. EXIT2_GETMANAGEMODULE,
  232. 0,
  233. NULL,
  234. VT_DISPATCH,
  235. &pManageModule);
  236. _JumpIfError(hr, error, "Invoke(GetManageModule)");
  237. }
  238. else
  239. {
  240. hr = ((ICertExit2 *) pdiExit->pUnknown)->GetManageModule(
  241. &pManageModule);
  242. _JumpIfError(hr, error, "ICertExit::GetManageModule");
  243. }
  244. hr = ManageModule_Init2(
  245. NULL != pdiExit->pDispatch,
  246. pManageModule,
  247. pdiManageModule);
  248. _JumpIfError(hr, error, "ManageModule_Init2");
  249. error:
  250. return(hr);
  251. }