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.

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