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.

720 lines
16 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: ciexit.cpp
  7. //
  8. // Contents: Cert Server Exit dispatch support
  9. //
  10. // History: 20-Jan-97 vich created
  11. //
  12. //---------------------------------------------------------------------------
  13. #include <pch.cpp>
  14. #pragma hdrstop
  15. #include "csdisp.h"
  16. #include "csprop.h"
  17. #define __dwFILE__ __dwFILE_CERTLIB_CIEXIT_CPP__
  18. //+------------------------------------------------------------------------
  19. // ICertServerExit dispatch support
  20. // TCHAR const g_wszRegKeyCIExitClsid[] = wszCLASS_CERTSERVEREXIT TEXT("\\Clsid");
  21. //+------------------------------------
  22. // SetContext method:
  23. static OLECHAR *exit_apszSetContext[] = {
  24. TEXT("SetContext"),
  25. TEXT("Context"),
  26. };
  27. //+------------------------------------
  28. // GetRequestProperty method:
  29. static OLECHAR *exit_apszGetRequestProp[] = {
  30. TEXT("GetRequestProperty"),
  31. TEXT("strPropertyName"),
  32. TEXT("PropertyType"),
  33. };
  34. //+------------------------------------
  35. // GetRequestAttribute method:
  36. static OLECHAR *exit_apszGetRequestAttr[] = {
  37. TEXT("GetRequestAttribute"),
  38. TEXT("strAttributeName"),
  39. };
  40. //+------------------------------------
  41. // GetCertificateProperty method:
  42. static OLECHAR *exit_apszGetCertificateProp[] = {
  43. TEXT("GetCertificateProperty"),
  44. TEXT("strPropertyName"),
  45. TEXT("PropertyType"),
  46. };
  47. //+------------------------------------
  48. // GetCertificateExtension method:
  49. static OLECHAR *exit_apszGetCertificateExt[] = {
  50. TEXT("GetCertificateExtension"),
  51. TEXT("strExtensionName"),
  52. TEXT("Type"),
  53. };
  54. //+------------------------------------
  55. // GetCertificateExtensionFlags method:
  56. static OLECHAR *exit_apszGetCertificateExtFlags[] = {
  57. TEXT("GetCertificateExtensionFlags"),
  58. };
  59. //+------------------------------------
  60. // EnumerateExtensionsSetup method:
  61. static OLECHAR *exit_apszEnumerateExtensionsSetup[] = {
  62. TEXT("EnumerateExtensionsSetup"),
  63. TEXT("Flags"),
  64. };
  65. //+------------------------------------
  66. // EnumerateExtensions method:
  67. static OLECHAR *exit_apszEnumerateExtensions[] = {
  68. TEXT("EnumerateExtensions"),
  69. };
  70. //+------------------------------------
  71. // EnumerateExtensionsClose method:
  72. static OLECHAR *exit_apszEnumerateExtensionsClose[] = {
  73. TEXT("EnumerateExtensionsClose"),
  74. };
  75. //+------------------------------------
  76. // EnumerateAttributesSetup method:
  77. static OLECHAR *exit_apszEnumerateAttributesSetup[] = {
  78. TEXT("EnumerateAttributesSetup"),
  79. TEXT("Flags"),
  80. };
  81. //+------------------------------------
  82. // EnumerateAttributes method:
  83. static OLECHAR *exit_apszEnumerateAttributes[] = {
  84. TEXT("EnumerateAttributes"),
  85. };
  86. //+------------------------------------
  87. // EnumerateAttributesClose method:
  88. static OLECHAR *exit_apszEnumerateAttributesClose[] = {
  89. TEXT("EnumerateAttributesClose"),
  90. };
  91. //+------------------------------------
  92. // Dispatch Table:
  93. DISPATCHTABLE g_adtCIExit[] =
  94. {
  95. #define EXIT_SETCONTEXT 0
  96. DECLARE_DISPATCH_ENTRY(exit_apszSetContext)
  97. #define EXIT_GETREQUESTPROPERTY 1
  98. DECLARE_DISPATCH_ENTRY(exit_apszGetRequestProp)
  99. #define EXIT_GETREQUESTATTRIBUTE 2
  100. DECLARE_DISPATCH_ENTRY(exit_apszGetRequestAttr)
  101. #define EXIT_GETCERTIFICATEPROPERTY 3
  102. DECLARE_DISPATCH_ENTRY(exit_apszGetCertificateProp)
  103. #define EXIT_GETCERTIFICATEEXTENSION 4
  104. DECLARE_DISPATCH_ENTRY(exit_apszGetCertificateExt)
  105. #define EXIT_GETCERTIFICATEEXTENSIONFLAGS 5
  106. DECLARE_DISPATCH_ENTRY(exit_apszGetCertificateExtFlags)
  107. #define EXIT_ENUMERATEEXTENSIONSSETUP 6
  108. DECLARE_DISPATCH_ENTRY(exit_apszEnumerateExtensionsSetup)
  109. #define EXIT_ENUMERATEEXTENSIONS 7
  110. DECLARE_DISPATCH_ENTRY(exit_apszEnumerateExtensions)
  111. #define EXIT_ENUMERATEEXTENSIONSCLOSE 8
  112. DECLARE_DISPATCH_ENTRY(exit_apszEnumerateExtensionsClose)
  113. #define EXIT_ENUMERATEATTRIBUTESSETUP 9
  114. DECLARE_DISPATCH_ENTRY(exit_apszEnumerateAttributesSetup)
  115. #define EXIT_ENUMERATEATTRIBUTES 10
  116. DECLARE_DISPATCH_ENTRY(exit_apszEnumerateAttributes)
  117. #define EXIT_ENUMERATEATTRIBUTESCLOSE 11
  118. DECLARE_DISPATCH_ENTRY(exit_apszEnumerateAttributesClose)
  119. };
  120. #define CEXITDISPATCH (ARRAYSIZE(g_adtCIExit))
  121. HRESULT
  122. CIExit_Init(
  123. IN DWORD Flags,
  124. OUT DISPATCHINTERFACE *pdiCIExit)
  125. {
  126. HRESULT hr;
  127. hr = DispatchSetup(
  128. Flags,
  129. CLSCTX_INPROC_SERVER,
  130. wszCLASS_CERTSERVEREXIT, //g_wszRegKeyCIExitClsid,
  131. &CLSID_CCertServerExit,
  132. &IID_ICertServerExit,
  133. CEXITDISPATCH,
  134. g_adtCIExit,
  135. pdiCIExit);
  136. _JumpIfError(hr, error, "DispatchSetup");
  137. pdiCIExit->pDispatchTable = g_adtCIExit;
  138. error:
  139. return(hr);
  140. }
  141. VOID
  142. CIExit_Release(
  143. IN OUT DISPATCHINTERFACE *pdiCIExit)
  144. {
  145. DispatchRelease(pdiCIExit);
  146. }
  147. HRESULT
  148. CIExit_SetContext(
  149. IN DISPATCHINTERFACE *pdiCIExit,
  150. IN LONG Context)
  151. {
  152. HRESULT hr;
  153. CSASSERT(NULL != pdiCIExit && NULL != pdiCIExit->pDispatchTable);
  154. if (NULL != pdiCIExit->pDispatch)
  155. {
  156. VARIANT avar[1];
  157. avar[0].vt = VT_I4;
  158. avar[0].lVal = Context;
  159. hr = DispatchInvoke(
  160. pdiCIExit,
  161. EXIT_SETCONTEXT,
  162. ARRAYSIZE(avar),
  163. avar,
  164. 0,
  165. NULL);
  166. _JumpIfError(hr, error, "Invoke(SetContext)");
  167. }
  168. else
  169. {
  170. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->SetContext(Context);
  171. _JumpIfError(hr, error, "ICertServerExit::SetContext");
  172. }
  173. error:
  174. return(hr);
  175. }
  176. HRESULT
  177. ciexitGetProperty(
  178. IN DISPATCHINTERFACE *pdiCIExit,
  179. IN DWORD IExitTable,
  180. IN WCHAR const *pwszPropName,
  181. IN LONG PropertyType,
  182. OUT BSTR *pbstrPropValue)
  183. {
  184. HRESULT hr;
  185. BSTR bstrPropName = NULL;
  186. LONG RetType;
  187. VARIANT varResult;
  188. CSASSERT(NULL != pdiCIExit && NULL != pdiCIExit->pDispatchTable);
  189. CSASSERT(
  190. EXIT_GETCERTIFICATEPROPERTY == IExitTable ||
  191. EXIT_GETREQUESTATTRIBUTE == IExitTable ||
  192. EXIT_GETREQUESTPROPERTY == IExitTable);
  193. VariantInit(&varResult);
  194. *pbstrPropValue = NULL;
  195. if (!ConvertWszToBstr(&bstrPropName, pwszPropName, -1))
  196. {
  197. hr = E_OUTOFMEMORY;
  198. goto error;
  199. }
  200. switch (PropertyType)
  201. {
  202. case PROPTYPE_BINARY:
  203. case PROPTYPE_STRING:
  204. RetType = VT_BSTR;
  205. break;
  206. case PROPTYPE_DATE:
  207. RetType = VT_DATE;
  208. break;
  209. case PROPTYPE_LONG:
  210. RetType = VT_I4;
  211. break;
  212. default:
  213. hr = E_INVALIDARG;
  214. _JumpError(hr, error, "PropertyType");
  215. }
  216. if (NULL != pdiCIExit->pDispatch)
  217. {
  218. VARIANT avar[2];
  219. avar[0].vt = VT_BSTR;
  220. avar[0].bstrVal = bstrPropName;
  221. avar[1].vt = VT_I4;
  222. avar[1].lVal = PropertyType;
  223. hr = DispatchInvoke(
  224. pdiCIExit,
  225. IExitTable,
  226. ARRAYSIZE(avar),
  227. avar,
  228. RetType,
  229. pbstrPropValue);
  230. _JumpIfError(
  231. hr,
  232. error,
  233. EXIT_GETCERTIFICATEPROPERTY == IExitTable?
  234. "Invoke(Exit::GetCertificateProperty)" :
  235. EXIT_GETREQUESTPROPERTY == IExitTable?
  236. "Invoke(Exit::GetRequestProperty)" :
  237. "Invoke(Exit::GetRequestAttribute)");
  238. }
  239. else
  240. {
  241. if (EXIT_GETCERTIFICATEPROPERTY == IExitTable)
  242. {
  243. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->GetCertificateProperty(
  244. bstrPropName,
  245. PropertyType,
  246. &varResult);
  247. }
  248. else if (EXIT_GETREQUESTPROPERTY == IExitTable)
  249. {
  250. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->GetRequestProperty(
  251. bstrPropName,
  252. PropertyType,
  253. &varResult);
  254. }
  255. else
  256. {
  257. CSASSERT(EXIT_GETREQUESTATTRIBUTE == IExitTable);
  258. CSASSERT(PROPTYPE_STRING == PropertyType);
  259. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->GetRequestAttribute(
  260. bstrPropName,
  261. &varResult.bstrVal);
  262. if (S_OK == hr)
  263. {
  264. varResult.vt = VT_BSTR;
  265. }
  266. }
  267. _JumpIfError(
  268. hr,
  269. error,
  270. EXIT_GETCERTIFICATEPROPERTY == IExitTable?
  271. "ICertServerExit::GetCertificateProperty" :
  272. EXIT_GETREQUESTPROPERTY == IExitTable?
  273. "ICertServerExit::GetRequestProperty" :
  274. "ICertServerExit::GetRequestAttribute");
  275. hr = DispatchGetReturnValue(&varResult, RetType, pbstrPropValue);
  276. _JumpIfError(hr, error, "DispatchGetReturnValue");
  277. }
  278. error:
  279. VariantClear(&varResult);
  280. if (NULL != bstrPropName)
  281. {
  282. SysFreeString(bstrPropName);
  283. }
  284. return(hr);
  285. }
  286. HRESULT
  287. CIExit_GetRequestProperty(
  288. IN DISPATCHINTERFACE *pdiCIExit,
  289. IN WCHAR const *pwszPropName,
  290. IN LONG PropertyType,
  291. OUT BSTR *pbstrPropValue)
  292. {
  293. return(ciexitGetProperty(
  294. pdiCIExit,
  295. EXIT_GETREQUESTPROPERTY,
  296. pwszPropName,
  297. PropertyType,
  298. pbstrPropValue));
  299. }
  300. HRESULT
  301. CIExit_GetRequestAttribute(
  302. IN DISPATCHINTERFACE *pdiCIExit,
  303. IN WCHAR const *pwszPropName,
  304. OUT BSTR *pbstrPropValue)
  305. {
  306. return(ciexitGetProperty(
  307. pdiCIExit,
  308. EXIT_GETREQUESTATTRIBUTE,
  309. pwszPropName,
  310. PROPTYPE_STRING,
  311. pbstrPropValue));
  312. }
  313. HRESULT
  314. CIExit_GetCertificateProperty(
  315. IN DISPATCHINTERFACE *pdiCIExit,
  316. IN WCHAR const *pwszPropName,
  317. IN LONG PropertyType,
  318. OUT BSTR *pbstrPropValue)
  319. {
  320. return(ciexitGetProperty(
  321. pdiCIExit,
  322. EXIT_GETCERTIFICATEPROPERTY,
  323. pwszPropName,
  324. PropertyType,
  325. pbstrPropValue));
  326. }
  327. HRESULT
  328. CIExit_GetCertificateExtension(
  329. IN DISPATCHINTERFACE *pdiCIExit,
  330. IN WCHAR const *pwszExtensionName,
  331. IN LONG Type,
  332. OUT BSTR *pbstrValue)
  333. {
  334. HRESULT hr;
  335. BSTR bstrExtensionName = NULL;
  336. LONG RetType;
  337. VARIANT varResult;
  338. CSASSERT(NULL != pdiCIExit && NULL != pdiCIExit->pDispatchTable);
  339. VariantInit(&varResult);
  340. *pbstrValue = NULL;
  341. if (!ConvertWszToBstr(&bstrExtensionName, pwszExtensionName, -1))
  342. {
  343. hr = E_OUTOFMEMORY;
  344. goto error;
  345. }
  346. switch (Type)
  347. {
  348. case PROPTYPE_BINARY:
  349. case PROPTYPE_STRING:
  350. RetType = VT_BSTR;
  351. break;
  352. case PROPTYPE_DATE:
  353. RetType = VT_DATE;
  354. break;
  355. case PROPTYPE_LONG:
  356. RetType = VT_I4;
  357. break;
  358. default:
  359. hr = E_INVALIDARG;
  360. _JumpError(hr, error, "PropertyType");
  361. }
  362. if (NULL != pdiCIExit->pDispatch)
  363. {
  364. VARIANT avar[2];
  365. avar[0].vt = VT_BSTR;
  366. avar[0].bstrVal = bstrExtensionName;
  367. avar[1].vt = VT_I4;
  368. avar[1].lVal = Type;
  369. hr = DispatchInvoke(
  370. pdiCIExit,
  371. EXIT_GETCERTIFICATEEXTENSION,
  372. ARRAYSIZE(avar),
  373. avar,
  374. RetType,
  375. pbstrValue);
  376. _JumpIfError(hr, error, "Invoke(Exit::GetCertificateExtension)");
  377. }
  378. else
  379. {
  380. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->GetCertificateExtension(
  381. bstrExtensionName,
  382. Type,
  383. &varResult);
  384. _JumpIfError(hr, error, "ICertServerExit::GetCertificateExtension");
  385. hr = DispatchGetReturnValue(&varResult, RetType, pbstrValue);
  386. _JumpIfError(hr, error, "DispatchGetReturnValue");
  387. }
  388. error:
  389. VariantClear(&varResult);
  390. if (NULL != bstrExtensionName)
  391. {
  392. SysFreeString(bstrExtensionName);
  393. }
  394. return(hr);
  395. }
  396. HRESULT
  397. CIExit_GetCertificateExtensionFlags(
  398. IN DISPATCHINTERFACE *pdiCIExit,
  399. OUT LONG *pExtFlags)
  400. {
  401. HRESULT hr;
  402. CSASSERT(NULL != pdiCIExit && NULL != pdiCIExit->pDispatchTable);
  403. if (NULL != pdiCIExit->pDispatch)
  404. {
  405. hr = DispatchInvoke(
  406. pdiCIExit,
  407. EXIT_GETCERTIFICATEEXTENSIONFLAGS,
  408. 0,
  409. NULL,
  410. VT_I4,
  411. pExtFlags);
  412. _JumpIfError(hr, error, "Invoke(Exit::GetCertificateExtensionFlags)");
  413. }
  414. else
  415. {
  416. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->GetCertificateExtensionFlags(
  417. pExtFlags);
  418. _JumpIfError(hr, error, "ICertServerExit::GetCertificateExtensionFlags");
  419. }
  420. error:
  421. return(hr);
  422. }
  423. HRESULT
  424. CIExit_EnumerateExtensionsSetup(
  425. IN DISPATCHINTERFACE *pdiCIExit,
  426. IN LONG Flags)
  427. {
  428. HRESULT hr;
  429. CSASSERT(NULL != pdiCIExit && NULL != pdiCIExit->pDispatchTable);
  430. if (NULL != pdiCIExit->pDispatch)
  431. {
  432. VARIANT avar[1];
  433. avar[0].vt = VT_I4;
  434. avar[0].lVal = Flags;
  435. hr = DispatchInvoke(
  436. pdiCIExit,
  437. EXIT_ENUMERATEEXTENSIONSSETUP,
  438. ARRAYSIZE(avar),
  439. avar,
  440. 0,
  441. NULL);
  442. _JumpIfError(hr, error, "Invoke(EnumerateExtensionsSetup)");
  443. }
  444. else
  445. {
  446. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->EnumerateExtensionsSetup(
  447. Flags);
  448. _JumpIfError(hr, error, "ICertServerExit::EnumerateExtensionsSetup");
  449. }
  450. error:
  451. return(hr);
  452. }
  453. HRESULT
  454. CIExit_EnumerateExtensions(
  455. IN DISPATCHINTERFACE *pdiCIExit,
  456. OUT BSTR *pstrExtensionName)
  457. {
  458. HRESULT hr;
  459. CSASSERT(NULL != pdiCIExit && NULL != pdiCIExit->pDispatchTable);
  460. if (NULL != pdiCIExit->pDispatch)
  461. {
  462. hr = DispatchInvoke(
  463. pdiCIExit,
  464. EXIT_ENUMERATEEXTENSIONS,
  465. 0,
  466. NULL,
  467. VT_BSTR,
  468. pstrExtensionName);
  469. _JumpIfError(hr, error, "Invoke(EnumerateExtensions)");
  470. }
  471. else
  472. {
  473. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->EnumerateExtensions(
  474. pstrExtensionName);
  475. _JumpIfError(hr, error, "ICertServerExit::EnumerateExtensions");
  476. }
  477. error:
  478. return(hr);
  479. }
  480. HRESULT
  481. CIExit_EnumerateExtensionsClose(
  482. IN DISPATCHINTERFACE *pdiCIExit)
  483. {
  484. HRESULT hr;
  485. CSASSERT(NULL != pdiCIExit && NULL != pdiCIExit->pDispatchTable);
  486. if (NULL != pdiCIExit->pDispatch)
  487. {
  488. hr = DispatchInvoke(
  489. pdiCIExit,
  490. EXIT_ENUMERATEEXTENSIONSCLOSE,
  491. 0,
  492. NULL,
  493. 0,
  494. NULL);
  495. _JumpIfError(hr, error, "Invoke(EnumerateExtensionsClose)");
  496. }
  497. else
  498. {
  499. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->EnumerateExtensionsClose();
  500. _JumpIfError(hr, error, "ICertServerExit::EnumerateExtensionsClose");
  501. }
  502. error:
  503. return(hr);
  504. }
  505. HRESULT
  506. CIExit_EnumerateAttributesSetup(
  507. IN DISPATCHINTERFACE *pdiCIExit,
  508. IN LONG Flags)
  509. {
  510. HRESULT hr;
  511. CSASSERT(NULL != pdiCIExit && NULL != pdiCIExit->pDispatchTable);
  512. if (NULL != pdiCIExit->pDispatch)
  513. {
  514. VARIANT avar[2];
  515. avar[0].vt = VT_I4;
  516. avar[0].lVal = Flags;
  517. hr = DispatchInvoke(
  518. pdiCIExit,
  519. EXIT_ENUMERATEATTRIBUTESSETUP,
  520. ARRAYSIZE(avar),
  521. avar,
  522. 0,
  523. NULL);
  524. _JumpIfError(hr, error, "Invoke(EnumerateAttributesSetup)");
  525. }
  526. else
  527. {
  528. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->EnumerateAttributesSetup(
  529. Flags);
  530. _JumpIfError(hr, error, "ICertServerExit::EnumerateAttributesSetup");
  531. }
  532. error:
  533. return(hr);
  534. }
  535. HRESULT
  536. CIExit_EnumerateAttributes(
  537. IN DISPATCHINTERFACE *pdiCIExit,
  538. OUT BSTR *pstrAttributeName)
  539. {
  540. HRESULT hr;
  541. CSASSERT(NULL != pdiCIExit && NULL != pdiCIExit->pDispatchTable);
  542. if (NULL != pdiCIExit->pDispatch)
  543. {
  544. hr = DispatchInvoke(
  545. pdiCIExit,
  546. EXIT_ENUMERATEATTRIBUTES,
  547. 0,
  548. NULL,
  549. VT_BSTR,
  550. pstrAttributeName);
  551. _JumpIfError(hr, error, "Invoke(EnumerateAttributes)");
  552. }
  553. else
  554. {
  555. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->EnumerateAttributes(
  556. pstrAttributeName);
  557. _JumpIfError(hr, error, "ICertServerExit::EnumerateAttributes");
  558. }
  559. error:
  560. return(hr);
  561. }
  562. HRESULT
  563. CIExit_EnumerateAttributesClose(
  564. IN DISPATCHINTERFACE *pdiCIExit)
  565. {
  566. HRESULT hr;
  567. CSASSERT(NULL != pdiCIExit && NULL != pdiCIExit->pDispatchTable);
  568. if (NULL != pdiCIExit->pDispatch)
  569. {
  570. hr = DispatchInvoke(
  571. pdiCIExit,
  572. EXIT_ENUMERATEATTRIBUTESCLOSE,
  573. 0,
  574. NULL,
  575. 0,
  576. NULL);
  577. _JumpIfError(hr, error, "Invoke(EnumerateAttributesClose)");
  578. }
  579. else
  580. {
  581. hr = ((ICertServerExit *) pdiCIExit->pUnknown)->EnumerateAttributesClose();
  582. _JumpIfError(hr, error, "ICertServerExit::EnumerateAttributesClose");
  583. }
  584. error:
  585. return(hr);
  586. }