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.

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