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.

446 lines
10 KiB

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