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.

399 lines
9.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: ciexit.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // ciexit.cpp: Implementation of CCertServerExit
  11. #include "pch.cpp"
  12. #pragma hdrstop
  13. #include "csprop.h"
  14. #include "csdisp.h"
  15. #include "ciinit.h"
  16. #include <assert.h>
  17. #include "ciexit.h"
  18. extern SERVERCALLBACKS ServerCallBacks;
  19. /////////////////////////////////////////////////////////////////////////////
  20. //
  21. CCertServerExit::~CCertServerExit()
  22. {
  23. EnumerateExtensionsClose();
  24. EnumerateAttributesClose();
  25. }
  26. STDMETHODIMP
  27. CCertServerExit::SetContext(
  28. IN LONG Context)
  29. {
  30. HRESULT hr;
  31. VARIANT var;
  32. VariantInit(&var);
  33. assert(NULL != ServerCallBacks.pfnGetProperty);
  34. if (NULL == ServerCallBacks.pfnGetProperty)
  35. {
  36. hr = E_UNEXPECTED;
  37. _JumpError(hr, error, "pfnGetProperty NULL");
  38. }
  39. if (0 != Context)
  40. {
  41. // PROPCALLER_SERVER indicates this call is only for Context validation
  42. // -- returns a zero RequestId. This keeps CRL publication exit module
  43. // notification from failing.
  44. hr = (*ServerCallBacks.pfnGetProperty)(
  45. Context,
  46. PROPTYPE_LONG |
  47. PROPCALLER_SERVER |
  48. PROPTABLE_REQUEST,
  49. wszPROPREQUESTREQUESTID,
  50. &var);
  51. _JumpIfError(hr, error, "GetProperty");
  52. }
  53. m_Context = Context;
  54. hr = S_OK;
  55. error:
  56. VariantClear(&var);
  57. return(_SetErrorInfo(hr, L"CCertServerExit::SetContext", NULL));
  58. }
  59. STDMETHODIMP
  60. CCertServerExit::GetRequestProperty(
  61. IN BSTR const strPropertyName,
  62. IN LONG PropertyType,
  63. OUT VARIANT __RPC_FAR *pvarPropertyValue)
  64. {
  65. HRESULT hr;
  66. assert(NULL != ServerCallBacks.pfnGetProperty);
  67. if (NULL == ServerCallBacks.pfnGetProperty)
  68. {
  69. hr = E_UNEXPECTED;
  70. _JumpError(hr, error, "pfnGetProperty NULL");
  71. }
  72. hr = (*ServerCallBacks.pfnGetProperty)(
  73. m_Context,
  74. (PropertyType & PROPTYPE_MASK) |
  75. PROPCALLER_EXIT | PROPTABLE_REQUEST,
  76. strPropertyName,
  77. pvarPropertyValue);
  78. error:
  79. return(_SetErrorInfo(hr, L"CCertServerExit::GetRequestProperty", strPropertyName));
  80. }
  81. STDMETHODIMP
  82. CCertServerExit::GetRequestAttribute(
  83. IN BSTR const strAttributeName,
  84. OUT BSTR __RPC_FAR *pstrAttributeValue)
  85. {
  86. HRESULT hr;
  87. VARIANT var;
  88. var.vt = VT_BYREF | VT_BSTR;
  89. var.pbstrVal = pstrAttributeValue;
  90. if (NULL == pstrAttributeValue)
  91. {
  92. hr = E_POINTER;
  93. _JumpError(hr, error, "pstrAttributeValue NULL");
  94. }
  95. assert(NULL != ServerCallBacks.pfnGetProperty);
  96. if (NULL == ServerCallBacks.pfnGetProperty)
  97. {
  98. hr = E_UNEXPECTED;
  99. _JumpError(hr, error, "pfnGetProperty NULL");
  100. }
  101. hr = (*ServerCallBacks.pfnGetProperty)(
  102. m_Context,
  103. PROPTYPE_STRING |
  104. PROPCALLER_EXIT |
  105. PROPTABLE_ATTRIBUTE,
  106. strAttributeName,
  107. &var);
  108. if (VT_BSTR == var.vt)
  109. {
  110. *pstrAttributeValue = var.bstrVal;
  111. var.vt = VT_EMPTY;
  112. }
  113. else
  114. if ((VT_BYREF | VT_BSTR) == var.vt)
  115. {
  116. *pstrAttributeValue = *var.pbstrVal;
  117. var.vt = VT_EMPTY;
  118. }
  119. error:
  120. VariantClear(&var);
  121. return(_SetErrorInfo(hr, L"CCertServerExit::GetRequestAttribute", strAttributeName));
  122. }
  123. STDMETHODIMP
  124. CCertServerExit::GetCertificateProperty(
  125. IN BSTR const strPropertyName,
  126. IN LONG PropertyType,
  127. OUT VARIANT __RPC_FAR *pvarPropertyValue)
  128. {
  129. HRESULT hr;
  130. assert(NULL != ServerCallBacks.pfnGetProperty);
  131. if (NULL == ServerCallBacks.pfnGetProperty)
  132. {
  133. hr = E_UNEXPECTED;
  134. _JumpError(hr, error, "pfnGetProperty NULL");
  135. }
  136. hr = (*ServerCallBacks.pfnGetProperty)(
  137. m_Context,
  138. (PropertyType & PROPTYPE_MASK) |
  139. PROPCALLER_EXIT | PROPTABLE_CERTIFICATE,
  140. strPropertyName,
  141. pvarPropertyValue);
  142. error:
  143. return(_SetErrorInfo(hr, L"CCertServerExit::GetCertificateProperty", strPropertyName));
  144. }
  145. STDMETHODIMP
  146. CCertServerExit::GetCertificateExtension(
  147. IN BSTR const strExtensionName,
  148. IN LONG Type,
  149. OUT VARIANT __RPC_FAR *pvarValue)
  150. {
  151. HRESULT hr;
  152. m_fExtensionValid = FALSE;
  153. assert(NULL != ServerCallBacks.pfnGetExtension);
  154. if (NULL == ServerCallBacks.pfnGetExtension)
  155. {
  156. hr = E_UNEXPECTED;
  157. _JumpError(hr, error, "pfnGetExtension NULL");
  158. }
  159. hr = (*ServerCallBacks.pfnGetExtension)(
  160. m_Context,
  161. (Type & PROPTYPE_MASK) | PROPCALLER_EXIT,
  162. strExtensionName,
  163. (DWORD *) &m_ExtFlags,
  164. pvarValue);
  165. if (S_OK == hr)
  166. {
  167. m_fExtensionValid = TRUE;
  168. }
  169. error:
  170. return(_SetErrorInfo(hr, L"CCertServerExit::GetCertificateExtension", strExtensionName));
  171. }
  172. STDMETHODIMP
  173. CCertServerExit::GetCertificateExtensionFlags(
  174. OUT LONG __RPC_FAR *pExtFlags)
  175. {
  176. HRESULT hr = E_INVALIDARG;
  177. if (NULL == pExtFlags)
  178. {
  179. hr = E_POINTER;
  180. _JumpError(hr, error, "pExtFlags NULL");
  181. }
  182. *pExtFlags = 0;
  183. if (m_fExtensionValid)
  184. {
  185. *pExtFlags = m_ExtFlags;
  186. hr = S_OK;
  187. }
  188. error:
  189. return(_SetErrorInfo(hr, L"CCertServerExit::GetCertificateExtensionFlags", NULL));
  190. }
  191. STDMETHODIMP
  192. CCertServerExit::EnumerateExtensionsSetup(
  193. IN LONG Flags)
  194. {
  195. HRESULT hr;
  196. assert(NULL != ServerCallBacks.pfnEnumSetup);
  197. if (NULL == ServerCallBacks.pfnEnumSetup)
  198. {
  199. hr = E_UNEXPECTED;
  200. _JumpError(hr, error, "pfnEnumSetup NULL");
  201. }
  202. hr = (*ServerCallBacks.pfnEnumSetup)(
  203. m_Context,
  204. (Flags & CIE_OBJECTID) |
  205. CIE_TABLE_EXTENSIONS |
  206. CIE_CALLER_EXIT,
  207. &m_ciEnumExtensions);
  208. error:
  209. return(_SetErrorInfo(hr, L"CCertServerExit::EnumerateExtensionsSetup", NULL));
  210. }
  211. STDMETHODIMP
  212. CCertServerExit::EnumerateExtensions(
  213. OUT BSTR *pstrExtensionName)
  214. {
  215. HRESULT hr;
  216. assert(NULL != ServerCallBacks.pfnEnumNext);
  217. if (NULL == ServerCallBacks.pfnEnumNext)
  218. {
  219. hr = E_UNEXPECTED;
  220. _JumpError(hr, error, "pfnEnumNext NULL");
  221. }
  222. hr = (*ServerCallBacks.pfnEnumNext)(
  223. &m_ciEnumExtensions,
  224. pstrExtensionName);
  225. error:
  226. return(_SetErrorInfo(hr, L"CCertServerExit::EnumerateExtensions", NULL));
  227. }
  228. STDMETHODIMP
  229. CCertServerExit::EnumerateExtensionsClose(VOID)
  230. {
  231. HRESULT hr;
  232. assert(NULL != ServerCallBacks.pfnEnumClose);
  233. if (NULL == ServerCallBacks.pfnEnumClose)
  234. {
  235. hr = E_UNEXPECTED;
  236. _JumpError(hr, error, "pfnEnumClose NULL");
  237. }
  238. hr = (*ServerCallBacks.pfnEnumClose)(&m_ciEnumExtensions);
  239. error:
  240. return(_SetErrorInfo(hr, L"CCertServerExit::EnumerateExtensionsClose", NULL));
  241. }
  242. STDMETHODIMP
  243. CCertServerExit::EnumerateAttributesSetup(
  244. IN LONG Flags)
  245. {
  246. HRESULT hr;
  247. assert(NULL != ServerCallBacks.pfnEnumSetup);
  248. if (NULL == ServerCallBacks.pfnEnumSetup)
  249. {
  250. hr = E_UNEXPECTED;
  251. _JumpError(hr, error, "pfnEnumSetup NULL");
  252. }
  253. hr = (*ServerCallBacks.pfnEnumSetup)(
  254. m_Context,
  255. (Flags & CIE_OBJECTID) |
  256. CIE_TABLE_ATTRIBUTES |
  257. CIE_CALLER_EXIT,
  258. &m_ciEnumAttributes);
  259. error:
  260. return(_SetErrorInfo(hr, L"CCertServerExit::EnumerateAttributesSetup", NULL));
  261. }
  262. STDMETHODIMP
  263. CCertServerExit::EnumerateAttributes(
  264. OUT BSTR *pstrAttributeName)
  265. {
  266. HRESULT hr;
  267. assert(NULL != ServerCallBacks.pfnEnumNext);
  268. if (NULL == ServerCallBacks.pfnEnumNext)
  269. {
  270. hr = E_UNEXPECTED;
  271. _JumpError(hr, error, "pfnEnumNext NULL");
  272. }
  273. hr = (*ServerCallBacks.pfnEnumNext)(
  274. &m_ciEnumAttributes,
  275. pstrAttributeName);
  276. error:
  277. return(_SetErrorInfo(hr, L"CCertServerExit::EnumerateAttributes", NULL));
  278. }
  279. STDMETHODIMP
  280. CCertServerExit::EnumerateAttributesClose(VOID)
  281. {
  282. HRESULT hr;
  283. assert(NULL != ServerCallBacks.pfnEnumClose);
  284. if (NULL == ServerCallBacks.pfnEnumClose)
  285. {
  286. hr = E_UNEXPECTED;
  287. _JumpError(hr, error, "pfnEnumClose NULL");
  288. }
  289. hr = (*ServerCallBacks.pfnEnumClose)(&m_ciEnumAttributes);
  290. error:
  291. return(_SetErrorInfo(hr, L"CCertServerExit::EnumerateAttributesClose", NULL));
  292. }
  293. HRESULT
  294. CCertServerExit::_SetErrorInfo(
  295. IN HRESULT hrError,
  296. IN WCHAR const *pwszDescription,
  297. OPTIONAL IN WCHAR const *pwszPropName)
  298. {
  299. CSASSERT(FAILED(hrError) || S_OK == hrError || S_FALSE == hrError);
  300. CSASSERT(NULL != pwszDescription);
  301. if (NULL == pwszDescription)
  302. {
  303. _JumpError(E_POINTER, error, "NULL parm");
  304. }
  305. if (FAILED(hrError))
  306. {
  307. HRESULT hr;
  308. WCHAR const *pwszLog = pwszDescription;
  309. WCHAR *pwszAlloc = NULL;
  310. if (NULL != pwszPropName)
  311. {
  312. pwszAlloc = (WCHAR *) LocalAlloc(
  313. LMEM_FIXED,
  314. (wcslen(pwszDescription) +
  315. wcslen(pwszPropName) +
  316. 2 +
  317. 1) * sizeof(WCHAR));
  318. if (NULL != pwszAlloc)
  319. {
  320. wcscpy(pwszAlloc, pwszDescription);
  321. wcscat(pwszAlloc, wszLPAREN);
  322. wcscat(pwszAlloc, pwszPropName);
  323. wcscat(pwszAlloc, wszRPAREN);
  324. pwszLog = pwszAlloc;
  325. }
  326. }
  327. hr = DispatchSetErrorInfo(
  328. hrError,
  329. pwszLog,
  330. wszCLASS_CERTSERVEREXIT,
  331. &IID_ICertServerExit);
  332. CSASSERT(hr == hrError);
  333. if (NULL != pwszAlloc)
  334. {
  335. LocalFree(pwszAlloc);
  336. }
  337. }
  338. error:
  339. return(hrError);
  340. }