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.

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