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.

1420 lines
28 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: admin.cpp
  8. //
  9. // Contents: ICertAdmin IDispatch helper functions
  10. //
  11. //--------------------------------------------------------------------------
  12. #include <pch.cpp>
  13. #pragma hdrstop
  14. #include <stdlib.h>
  15. #include "csdisp.h"
  16. //+------------------------------------------------------------------------
  17. // ICertAdmin dispatch support
  18. //TCHAR szRegKeyAdminClsid[] = wszCLASS_CERTADMIN TEXT("\\Clsid");
  19. //+------------------------------------
  20. // IsValidCertificate method:
  21. static OLECHAR *_apszIsValidCertificate[] = {
  22. TEXT("IsValidCertificate"),
  23. TEXT("strConfig"),
  24. TEXT("strSerialNumber"),
  25. };
  26. //+------------------------------------
  27. // GetRevocationReason method:
  28. static OLECHAR *_apszGetRevocationReason[] = {
  29. TEXT("GetRevocationReason"),
  30. };
  31. //+------------------------------------
  32. // RevokeCertificate method:
  33. static OLECHAR *_apszRevokeCertificate[] = {
  34. TEXT("RevokeCertificate"),
  35. TEXT("strConfig"),
  36. TEXT("strSerialNumber"),
  37. TEXT("Reason"),
  38. TEXT("Date"),
  39. };
  40. //+------------------------------------
  41. // SetRequestAttributes method:
  42. static OLECHAR *_apszSetRequestAttributes[] = {
  43. TEXT("SetRequestAttributes"),
  44. TEXT("strConfig"),
  45. TEXT("RequestId"),
  46. TEXT("strAttributes"),
  47. };
  48. //+------------------------------------
  49. // SetCertificateExtension method:
  50. static OLECHAR *_apszSetCertificateExtension[] = {
  51. TEXT("SetCertificateExtension"),
  52. TEXT("strConfig"),
  53. TEXT("RequestId"),
  54. TEXT("strExtensionName"),
  55. TEXT("Type"),
  56. TEXT("Flags"),
  57. TEXT("pvarValue"),
  58. };
  59. //+------------------------------------
  60. // DenyRequest method:
  61. static OLECHAR *_apszDenyRequest[] = {
  62. TEXT("DenyRequest"),
  63. TEXT("strConfig"),
  64. TEXT("RequestId"),
  65. };
  66. //+------------------------------------
  67. // ResubmitRequest method:
  68. static OLECHAR *_apszResubmitRequest[] = {
  69. TEXT("ResubmitRequest"),
  70. TEXT("strConfig"),
  71. TEXT("RequestId"),
  72. };
  73. //+------------------------------------
  74. // PublishCRL method:
  75. static OLECHAR *_apszPublishCRL[] = {
  76. TEXT("PublishCRL"),
  77. TEXT("strConfig"),
  78. TEXT("Date"),
  79. };
  80. //+------------------------------------
  81. // GetCRL method:
  82. static OLECHAR *_apszGetCRL[] = {
  83. TEXT("GetCRL"),
  84. TEXT("strConfig"),
  85. TEXT("Flags"),
  86. };
  87. //+------------------------------------
  88. // ImportCertificate method:
  89. static OLECHAR *_apszImportCertificate[] = {
  90. TEXT("ImportCertificate"),
  91. TEXT("strConfig"),
  92. TEXT("strCertificate"),
  93. TEXT("Flags"),
  94. };
  95. //+------------------------------------
  96. // PublishCRLs method:
  97. static OLECHAR *_apszPublishCRLs[] = {
  98. TEXT("PublishCRLs"),
  99. TEXT("strConfig"),
  100. TEXT("Date"),
  101. TEXT("CRLFlags"),
  102. };
  103. //+------------------------------------
  104. // GetCAProperty method:
  105. static OLECHAR *_apszGetCAProperty[] = {
  106. TEXT("GetCAProperty"),
  107. TEXT("strConfig"),
  108. TEXT("PropId"),
  109. TEXT("PropIndex"),
  110. TEXT("PropType"),
  111. TEXT("Flags"),
  112. };
  113. //+------------------------------------
  114. // SetCAProperty method:
  115. static OLECHAR *_apszSetCAProperty[] = {
  116. TEXT("SetCAProperty"),
  117. TEXT("strConfig"),
  118. TEXT("PropId"),
  119. TEXT("PropIndex"),
  120. TEXT("PropType"),
  121. TEXT("pvarPropertyValue"),
  122. };
  123. //+------------------------------------
  124. // GetCAPropertyFlags method:
  125. static OLECHAR *_apszGetCAPropertyFlags[] = {
  126. TEXT("GetCAPropertyFlags"),
  127. TEXT("strConfig"),
  128. TEXT("PropId"),
  129. };
  130. //+------------------------------------
  131. // GetCAPropertyDisplayName method:
  132. static OLECHAR *_apszGetCAPropertyDisplayName[] = {
  133. TEXT("GetCAPropertyDisplayName"),
  134. TEXT("strConfig"),
  135. TEXT("PropId"),
  136. };
  137. //+------------------------------------
  138. // GetArchivedKey method:
  139. static OLECHAR *_apszGetArchivedKey[] = {
  140. TEXT("GetArchivedKey"),
  141. TEXT("strConfig"),
  142. TEXT("RequestId"),
  143. TEXT("Flags"),
  144. };
  145. //+------------------------------------
  146. // GetConfigEntry method:
  147. static OLECHAR *_apszGetConfigEntry[] = {
  148. TEXT("GetConfigEntry"),
  149. TEXT("strConfig"),
  150. TEXT("strNodePath"),
  151. TEXT("strEntryName"),
  152. };
  153. //+------------------------------------
  154. // SetConfigEntry method:
  155. static OLECHAR *_apszSetConfigEntry[] = {
  156. TEXT("SetConfigEntry"),
  157. TEXT("strConfig"),
  158. TEXT("strNodePath"),
  159. TEXT("strEntryName"),
  160. TEXT("pvarEntry"),
  161. };
  162. //+------------------------------------
  163. // ImportKey method:
  164. static OLECHAR *_apszImportKey[] = {
  165. TEXT("ImportKey"),
  166. TEXT("strConfig"),
  167. TEXT("RequestId"),
  168. TEXT("strCertHash"),
  169. TEXT("Flags"),
  170. TEXT("strKey"),
  171. };
  172. //+------------------------------------
  173. // GetMyRoles method:
  174. static OLECHAR *_apszGetMyRoles[] = {
  175. TEXT("GetMyRoles"),
  176. TEXT("strConfig"),
  177. };
  178. //+------------------------------------
  179. // DeleteRow method:
  180. static OLECHAR *_apszDeleteRow[] = {
  181. TEXT("DeleteRow"),
  182. TEXT("strConfig"),
  183. TEXT("Flags"),
  184. TEXT("Date"),
  185. TEXT("Table"),
  186. TEXT("RowId"),
  187. };
  188. //+------------------------------------
  189. // Dispatch Table:
  190. DISPATCHTABLE s_adtAdmin[] =
  191. {
  192. #define ADMIN_ISVALIDCERTIFICATE 0
  193. DECLARE_DISPATCH_ENTRY(_apszIsValidCertificate)
  194. #define ADMIN_GETREVOCATIONREASON 1
  195. DECLARE_DISPATCH_ENTRY(_apszGetRevocationReason)
  196. #define ADMIN_REVOKECERTIFICATE 2
  197. DECLARE_DISPATCH_ENTRY(_apszRevokeCertificate)
  198. #define ADMIN_SETREQUESTATTRIBUTES 3
  199. DECLARE_DISPATCH_ENTRY(_apszSetRequestAttributes)
  200. #define ADMIN_SETCERTIFICATEEXTENSION 4
  201. DECLARE_DISPATCH_ENTRY(_apszSetCertificateExtension)
  202. #define ADMIN_DENYREQUEST 5
  203. DECLARE_DISPATCH_ENTRY(_apszDenyRequest)
  204. #define ADMIN_RESUBMITREQUEST 6
  205. DECLARE_DISPATCH_ENTRY(_apszResubmitRequest)
  206. #define ADMIN_PUBLISHCRL 7
  207. DECLARE_DISPATCH_ENTRY(_apszPublishCRL)
  208. #define ADMIN_GETCRL 8
  209. DECLARE_DISPATCH_ENTRY(_apszGetCRL)
  210. #define ADMIN_IMPORTCERTIFICATE 9
  211. DECLARE_DISPATCH_ENTRY(_apszImportCertificate)
  212. #define ADMIN2_PUBLISHCRLS 10
  213. DECLARE_DISPATCH_ENTRY(_apszPublishCRLs)
  214. #define ADMIN2_GETCAPROPERTY 11
  215. DECLARE_DISPATCH_ENTRY(_apszGetCAProperty)
  216. #define ADMIN2_SETCAPROPERTY 12
  217. DECLARE_DISPATCH_ENTRY(_apszSetCAProperty)
  218. #define ADMIN2_GETCAPROPERTYFLAGS 13
  219. DECLARE_DISPATCH_ENTRY(_apszGetCAPropertyFlags)
  220. #define ADMIN2_GETCAPROPERTYDISPLAYNAME 14
  221. DECLARE_DISPATCH_ENTRY(_apszGetCAPropertyDisplayName)
  222. #define ADMIN2_GETARCHIVEDKEY 15
  223. DECLARE_DISPATCH_ENTRY(_apszGetArchivedKey)
  224. #define ADMIN2_GETCONFIGENTRY 16
  225. DECLARE_DISPATCH_ENTRY(_apszGetConfigEntry)
  226. #define ADMIN2_SETCONFIGENTRY 17
  227. DECLARE_DISPATCH_ENTRY(_apszSetConfigEntry)
  228. #define ADMIN2_IMPORTKEY 18
  229. DECLARE_DISPATCH_ENTRY(_apszImportKey)
  230. #define ADMIN2_GETMYROLES 19
  231. DECLARE_DISPATCH_ENTRY(_apszGetMyRoles)
  232. #define ADMIN2_DELETEROW 20
  233. DECLARE_DISPATCH_ENTRY(_apszDeleteRow)
  234. };
  235. #define CADMINDISPATCH (ARRAYSIZE(s_adtAdmin))
  236. #define CADMINDISPATCH_V1 ADMIN2_PUBLISHCRLS
  237. #define CADMINDISPATCH_V2 CADMINDISPATCH
  238. DWORD s_acAdminDispatch[] = {
  239. CADMINDISPATCH_V2,
  240. CADMINDISPATCH_V1,
  241. };
  242. IID const *s_apAdminiid[] = {
  243. &IID_ICertAdmin2,
  244. &IID_ICertAdmin,
  245. };
  246. HRESULT
  247. Admin_Init(
  248. IN DWORD Flags,
  249. OUT DISPATCHINTERFACE *pdiAdmin)
  250. {
  251. HRESULT hr;
  252. hr = DispatchSetup2(
  253. Flags,
  254. CLSCTX_INPROC_SERVER,
  255. wszCLASS_CERTADMIN,
  256. &CLSID_CCertAdmin,
  257. ARRAYSIZE(s_acAdminDispatch), // cver
  258. s_apAdminiid,
  259. s_acAdminDispatch,
  260. s_adtAdmin,
  261. pdiAdmin);
  262. _JumpIfError(hr, error, "DispatchSetup2(ICertAdmin)");
  263. error:
  264. return(hr);
  265. }
  266. VOID
  267. Admin_Release(
  268. IN OUT DISPATCHINTERFACE *pdiAdmin)
  269. {
  270. DispatchRelease(pdiAdmin);
  271. }
  272. HRESULT
  273. AdminVerifyVersion(
  274. IN DISPATCHINTERFACE *pdiAdmin,
  275. IN DWORD RequiredVersion)
  276. {
  277. HRESULT hr;
  278. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  279. switch (pdiAdmin->m_dwVersion)
  280. {
  281. case 1:
  282. CSASSERT(
  283. NULL == pdiAdmin->pDispatch ||
  284. CADMINDISPATCH_V1 == pdiAdmin->m_cDispatchTable);
  285. break;
  286. case 2:
  287. CSASSERT(
  288. NULL == pdiAdmin->pDispatch ||
  289. CADMINDISPATCH_V2 == pdiAdmin->m_cDispatchTable);
  290. break;
  291. default:
  292. hr = HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
  293. _JumpError(hr, error, "m_dwVersion");
  294. }
  295. if (pdiAdmin->m_dwVersion < RequiredVersion)
  296. {
  297. hr = E_NOTIMPL;
  298. _JumpError(hr, error, "old interface");
  299. }
  300. hr = S_OK;
  301. error:
  302. return(hr);
  303. }
  304. HRESULT
  305. Admin_IsValidCertificate(
  306. IN DISPATCHINTERFACE *pdiAdmin,
  307. IN WCHAR const *pwszConfig,
  308. IN WCHAR const *pwszSerialNumber,
  309. OUT LONG *pDisposition)
  310. {
  311. HRESULT hr;
  312. BSTR strConfig = NULL;
  313. BSTR strSerialNumber = NULL;
  314. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  315. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  316. {
  317. hr = E_OUTOFMEMORY;
  318. _JumpError(hr, error, "ConvertWszToBstr");
  319. }
  320. if (!ConvertWszToBstr(&strSerialNumber, pwszSerialNumber, -1))
  321. {
  322. hr = E_OUTOFMEMORY;
  323. _JumpError(hr, error, "ConvertWszToBstr");
  324. }
  325. if (NULL != pdiAdmin->pDispatch)
  326. {
  327. VARIANT avar[2];
  328. avar[0].vt = VT_BSTR;
  329. avar[0].bstrVal = strConfig;
  330. avar[1].vt = VT_BSTR;
  331. avar[1].bstrVal = strSerialNumber;
  332. hr = DispatchInvoke(
  333. pdiAdmin,
  334. ADMIN_ISVALIDCERTIFICATE,
  335. ARRAYSIZE(avar),
  336. avar,
  337. VT_I4,
  338. pDisposition);
  339. _JumpIfError(hr, error, "Invoke(IsValidCertificate)");
  340. }
  341. else
  342. {
  343. hr = ((ICertAdmin *) pdiAdmin->pUnknown)->IsValidCertificate(
  344. strConfig,
  345. strSerialNumber,
  346. pDisposition);
  347. _JumpIfError(hr, error, "ICertAdmin::IsValidCertificate");
  348. }
  349. error:
  350. if (NULL != strConfig)
  351. {
  352. SysFreeString(strConfig);
  353. }
  354. if (NULL != strSerialNumber)
  355. {
  356. SysFreeString(strSerialNumber);
  357. }
  358. return(hr);
  359. }
  360. HRESULT
  361. Admin_GetRevocationReason(
  362. IN DISPATCHINTERFACE *pdiAdmin,
  363. OUT LONG *pReason)
  364. {
  365. HRESULT hr;
  366. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  367. if (NULL != pdiAdmin->pDispatch)
  368. {
  369. hr = DispatchInvoke(
  370. pdiAdmin,
  371. ADMIN_GETREVOCATIONREASON,
  372. 0,
  373. NULL,
  374. VT_I4,
  375. pReason);
  376. _JumpIfError(hr, error, "Invoke(GetRevocationReason)");
  377. }
  378. else
  379. {
  380. hr = ((ICertAdmin *) pdiAdmin->pUnknown)->GetRevocationReason(pReason);
  381. _JumpIfError(hr, error, "ICertAdmin::GetRevocationReason");
  382. }
  383. error:
  384. return(hr);
  385. }
  386. HRESULT
  387. Admin_RevokeCertificate(
  388. IN DISPATCHINTERFACE *pdiAdmin,
  389. IN WCHAR const *pwszConfig,
  390. IN WCHAR const *pwszSerialNumber,
  391. IN LONG Reason,
  392. IN DATE Date)
  393. {
  394. HRESULT hr;
  395. BSTR strConfig = NULL;
  396. BSTR strSerialNumber = NULL;
  397. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  398. hr = E_OUTOFMEMORY;
  399. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  400. {
  401. _JumpError(hr, error, "ConvertWszToBstr");
  402. }
  403. if (!ConvertWszToBstr(&strSerialNumber, pwszSerialNumber, -1))
  404. {
  405. _JumpError(hr, error, "ConvertWszToBstr");
  406. }
  407. if (NULL != pdiAdmin->pDispatch)
  408. {
  409. VARIANT avar[4];
  410. avar[0].vt = VT_BSTR;
  411. avar[0].bstrVal = strConfig;
  412. avar[1].vt = VT_BSTR;
  413. avar[1].bstrVal = strSerialNumber;
  414. avar[2].vt = VT_I4;
  415. avar[2].lVal = Reason;
  416. avar[3].vt = VT_DATE;
  417. avar[3].date = Date;
  418. hr = DispatchInvoke(
  419. pdiAdmin,
  420. ADMIN_REVOKECERTIFICATE,
  421. ARRAYSIZE(avar),
  422. avar,
  423. 0,
  424. NULL);
  425. _JumpIfError(hr, error, "Invoke(RevokeCertificate)");
  426. }
  427. else
  428. {
  429. hr = ((ICertAdmin *) pdiAdmin->pUnknown)->RevokeCertificate(
  430. strConfig,
  431. strSerialNumber,
  432. Reason,
  433. Date);
  434. _JumpIfError(hr, error, "ICertAdmin::RevokeCertificate");
  435. }
  436. error:
  437. if (NULL != strConfig)
  438. {
  439. SysFreeString(strConfig);
  440. }
  441. if (NULL != strSerialNumber)
  442. {
  443. SysFreeString(strSerialNumber);
  444. }
  445. return(hr);
  446. }
  447. HRESULT
  448. Admin_SetRequestAttributes(
  449. IN DISPATCHINTERFACE *pdiAdmin,
  450. IN WCHAR const *pwszConfig,
  451. IN LONG RequestId,
  452. IN WCHAR const *pwszAttributes)
  453. {
  454. HRESULT hr;
  455. BSTR strConfig = NULL;
  456. BSTR strAttributes = NULL;
  457. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  458. hr = E_OUTOFMEMORY;
  459. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  460. {
  461. _JumpError(hr, error, "ConvertWszToBstr");
  462. }
  463. if (!ConvertWszToBstr(&strAttributes, pwszAttributes, -1))
  464. {
  465. _JumpError(hr, error, "ConvertWszToBstr");
  466. }
  467. if (NULL != pdiAdmin->pDispatch)
  468. {
  469. VARIANT avar[3];
  470. avar[0].vt = VT_BSTR;
  471. avar[0].bstrVal = strConfig;
  472. avar[1].vt = VT_I4;
  473. avar[1].lVal = RequestId;
  474. avar[2].vt = VT_BSTR;
  475. avar[2].bstrVal = strAttributes;
  476. hr = DispatchInvoke(
  477. pdiAdmin,
  478. ADMIN_SETREQUESTATTRIBUTES,
  479. ARRAYSIZE(avar),
  480. avar,
  481. 0,
  482. NULL);
  483. _JumpIfError(hr, error, "Invoke(SetRequestAttributes)");
  484. }
  485. else
  486. {
  487. hr = ((ICertAdmin *) pdiAdmin->pUnknown)->SetRequestAttributes(
  488. strConfig,
  489. RequestId,
  490. strAttributes);
  491. _JumpIfError(hr, error, "ICertAdmin::SetRequestAttributes");
  492. }
  493. error:
  494. if (NULL != strConfig)
  495. {
  496. SysFreeString(strConfig);
  497. }
  498. if (NULL != strAttributes)
  499. {
  500. SysFreeString(strAttributes);
  501. }
  502. return(hr);
  503. }
  504. HRESULT
  505. Admin_SetCertificateExtension(
  506. IN DISPATCHINTERFACE *pdiAdmin,
  507. IN WCHAR const *pwszConfig,
  508. IN LONG RequestId,
  509. IN WCHAR const *pwszExtensionName,
  510. IN LONG Type,
  511. IN LONG Flags,
  512. IN VARIANT const *pvarValue)
  513. {
  514. HRESULT hr;
  515. BSTR strConfig = NULL;
  516. BSTR strExtensionName = NULL;
  517. hr = E_OUTOFMEMORY;
  518. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  519. {
  520. _JumpError(hr, error, "ConvertWszToBstr");
  521. }
  522. if (!ConvertWszToBstr(&strExtensionName, pwszExtensionName, -1))
  523. {
  524. _JumpError(hr, error, "ConvertWszToBstr");
  525. }
  526. if (NULL != pdiAdmin->pDispatch)
  527. {
  528. VARIANT avar[6];
  529. avar[0].vt = VT_BSTR;
  530. avar[0].bstrVal = strConfig;
  531. avar[1].vt = VT_I4;
  532. avar[1].lVal = RequestId;
  533. avar[2].vt = VT_BSTR;
  534. avar[2].bstrVal = strExtensionName;
  535. avar[3].vt = VT_I4;
  536. avar[3].lVal = Type;
  537. avar[4].vt = VT_I4;
  538. avar[4].lVal = Flags;
  539. avar[5].vt = VT_VARIANT | VT_BYREF;
  540. avar[5].pvarVal = (VARIANT *) pvarValue;
  541. hr = DispatchInvoke(
  542. pdiAdmin,
  543. ADMIN_SETCERTIFICATEEXTENSION,
  544. ARRAYSIZE(avar),
  545. avar,
  546. 0,
  547. NULL);
  548. _JumpIfError(hr, error, "Invoke(SetCertificateExtension)");
  549. }
  550. else
  551. {
  552. hr = ((ICertAdmin *) pdiAdmin->pUnknown)->SetCertificateExtension(
  553. strConfig,
  554. RequestId,
  555. strExtensionName,
  556. Type,
  557. Flags,
  558. pvarValue);
  559. _JumpIfError(hr, error, "ICertAdmin::SetCertificateExtension");
  560. }
  561. error:
  562. if (NULL != strConfig)
  563. {
  564. SysFreeString(strConfig);
  565. }
  566. if (NULL != strExtensionName)
  567. {
  568. SysFreeString(strExtensionName);
  569. }
  570. return(hr);
  571. }
  572. HRESULT
  573. Admin_DenyRequest(
  574. IN DISPATCHINTERFACE *pdiAdmin,
  575. IN WCHAR const *pwszConfig,
  576. IN LONG RequestId)
  577. {
  578. HRESULT hr;
  579. BSTR strConfig = NULL;
  580. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  581. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  582. {
  583. hr = E_OUTOFMEMORY;
  584. _JumpError(hr, error, "ConvertWszToBstr");
  585. }
  586. if (NULL != pdiAdmin->pDispatch)
  587. {
  588. VARIANT avar[2];
  589. avar[0].vt = VT_BSTR;
  590. avar[0].bstrVal = strConfig;
  591. avar[1].vt = VT_I4;
  592. avar[1].lVal = RequestId;
  593. hr = DispatchInvoke(
  594. pdiAdmin,
  595. ADMIN_DENYREQUEST,
  596. ARRAYSIZE(avar),
  597. avar,
  598. 0,
  599. NULL);
  600. _JumpIfError(hr, error, "Invoke(DenyRequest)");
  601. }
  602. else
  603. {
  604. hr = ((ICertAdmin *) pdiAdmin->pUnknown)->DenyRequest(
  605. strConfig,
  606. RequestId);
  607. _JumpIfError(hr, error, "ICertAdmin::DenyRequest");
  608. }
  609. error:
  610. if (NULL != strConfig)
  611. {
  612. SysFreeString(strConfig);
  613. }
  614. return(hr);
  615. }
  616. HRESULT
  617. Admin_ResubmitRequest(
  618. IN DISPATCHINTERFACE *pdiAdmin,
  619. IN WCHAR const *pwszConfig,
  620. IN LONG RequestId,
  621. OUT LONG *pDisposition)
  622. {
  623. HRESULT hr;
  624. BSTR strConfig = NULL;
  625. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  626. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  627. {
  628. hr = E_OUTOFMEMORY;
  629. _JumpError(hr, error, "ConvertWszToBstr");
  630. }
  631. if (NULL != pdiAdmin->pDispatch)
  632. {
  633. VARIANT avar[2];
  634. avar[0].vt = VT_BSTR;
  635. avar[0].bstrVal = strConfig;
  636. avar[1].vt = VT_I4;
  637. avar[1].lVal = RequestId;
  638. hr = DispatchInvoke(
  639. pdiAdmin,
  640. ADMIN_RESUBMITREQUEST,
  641. ARRAYSIZE(avar),
  642. avar,
  643. VT_I4,
  644. pDisposition);
  645. _JumpIfError(hr, error, "Invoke(ResubmitRequest)");
  646. }
  647. else
  648. {
  649. hr = ((ICertAdmin *) pdiAdmin->pUnknown)->ResubmitRequest(
  650. strConfig,
  651. RequestId,
  652. pDisposition);
  653. _JumpIfError(hr, error, "ICertAdmin::ResubmitRequest");
  654. }
  655. error:
  656. if (NULL != strConfig)
  657. {
  658. SysFreeString(strConfig);
  659. }
  660. return(hr);
  661. }
  662. HRESULT
  663. Admin_PublishCRL(
  664. IN DISPATCHINTERFACE *pdiAdmin,
  665. IN WCHAR const *pwszConfig,
  666. IN DATE Date)
  667. {
  668. HRESULT hr;
  669. BSTR strConfig = NULL;
  670. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  671. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  672. {
  673. hr = E_OUTOFMEMORY;
  674. _JumpError(hr, error, "ConvertWszToBstr");
  675. }
  676. if (NULL != pdiAdmin->pDispatch)
  677. {
  678. VARIANT avar[2];
  679. avar[0].vt = VT_BSTR;
  680. avar[0].bstrVal = strConfig;
  681. avar[1].vt = VT_DATE;
  682. avar[1].date = Date;
  683. hr = DispatchInvoke(
  684. pdiAdmin,
  685. ADMIN_PUBLISHCRL,
  686. ARRAYSIZE(avar),
  687. avar,
  688. 0,
  689. NULL);
  690. _JumpIfError(hr, error, "Invoke(PublishCRL)");
  691. }
  692. else
  693. {
  694. hr = ((ICertAdmin *) pdiAdmin->pUnknown)->PublishCRL(
  695. strConfig,
  696. Date);
  697. _JumpIfError(hr, error, "ICertAdmin::PublishCRL");
  698. }
  699. error:
  700. if (NULL != strConfig)
  701. {
  702. SysFreeString(strConfig);
  703. }
  704. return(hr);
  705. }
  706. HRESULT
  707. Admin2_PublishCRLs(
  708. IN DISPATCHINTERFACE *pdiAdmin,
  709. IN WCHAR const *pwszConfig,
  710. IN DATE Date,
  711. IN LONG CRLFlags) // CA_CRL_*
  712. {
  713. HRESULT hr;
  714. BSTR strConfig = NULL;
  715. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  716. hr = AdminVerifyVersion(pdiAdmin, 2);
  717. _JumpIfError(hr, error, "AdminVerifyVersion");
  718. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  719. {
  720. hr = E_OUTOFMEMORY;
  721. _JumpError(hr, error, "ConvertWszToBstr");
  722. }
  723. if (NULL != pdiAdmin->pDispatch)
  724. {
  725. VARIANT avar[3];
  726. avar[0].vt = VT_BSTR;
  727. avar[0].bstrVal = strConfig;
  728. avar[1].vt = VT_DATE;
  729. avar[1].date = Date;
  730. avar[2].vt = VT_I4;
  731. avar[2].date = CRLFlags;
  732. hr = DispatchInvoke(
  733. pdiAdmin,
  734. ADMIN2_PUBLISHCRLS,
  735. ARRAYSIZE(avar),
  736. avar,
  737. 0,
  738. NULL);
  739. _JumpIfError(hr, error, "Invoke(PublishCRLs)");
  740. }
  741. else
  742. {
  743. hr = ((ICertAdmin2 *) pdiAdmin->pUnknown)->PublishCRLs(
  744. strConfig,
  745. Date,
  746. CRLFlags);
  747. _JumpIfError(hr, error, "ICertAdmin2::PublishCRLs");
  748. }
  749. error:
  750. if (NULL != strConfig)
  751. {
  752. SysFreeString(strConfig);
  753. }
  754. return(hr);
  755. }
  756. HRESULT
  757. Admin_GetCRL(
  758. IN DISPATCHINTERFACE *pdiAdmin,
  759. IN WCHAR const *pwszConfig,
  760. IN LONG Flags,
  761. OUT BSTR *pstrCRL)
  762. {
  763. HRESULT hr;
  764. BSTR strConfig = NULL;
  765. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  766. hr = AdminVerifyVersion(pdiAdmin, 2);
  767. _JumpIfError(hr, error, "AdminVerifyVersion");
  768. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  769. {
  770. hr = E_OUTOFMEMORY;
  771. _JumpError(hr, error, "ConvertWszToBstr");
  772. }
  773. if (NULL != pdiAdmin->pDispatch)
  774. {
  775. VARIANT avar[2];
  776. avar[0].vt = VT_BSTR;
  777. avar[0].bstrVal = strConfig;
  778. avar[1].vt = VT_I4;
  779. avar[1].lVal = Flags;
  780. hr = DispatchInvoke(
  781. pdiAdmin,
  782. ADMIN_GETCRL,
  783. ARRAYSIZE(avar),
  784. avar,
  785. VT_BSTR,
  786. pstrCRL);
  787. _JumpIfError(hr, error, "Invoke(GetCRL)");
  788. }
  789. else
  790. {
  791. hr = ((ICertAdmin *) pdiAdmin->pUnknown)->GetCRL(
  792. strConfig,
  793. Flags,
  794. pstrCRL);
  795. _JumpIfError(hr, error, "ICertAdmin::GetCRL");
  796. }
  797. error:
  798. if (NULL != strConfig)
  799. {
  800. SysFreeString(strConfig);
  801. }
  802. return(hr);
  803. }
  804. HRESULT
  805. Admin_ImportCertificate(
  806. IN DISPATCHINTERFACE *pdiAdmin,
  807. IN WCHAR const *pwszConfig,
  808. IN WCHAR const *pwszCertificate,
  809. IN DWORD cbCertificate,
  810. IN LONG dwFlags,
  811. OUT LONG *pRequestId)
  812. {
  813. HRESULT hr;
  814. BSTR strConfig = NULL;
  815. BSTR strCertificate = NULL;
  816. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  817. hr = E_OUTOFMEMORY;
  818. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  819. {
  820. _JumpError(hr, error, "ConvertWszToBstr");
  821. }
  822. strCertificate = SysAllocStringByteLen(
  823. (CHAR const *) pwszCertificate,
  824. cbCertificate);
  825. if (NULL == strCertificate)
  826. {
  827. _JumpError(hr, error, "SysAllocStringByteLen");
  828. }
  829. if (NULL != pdiAdmin->pDispatch)
  830. {
  831. VARIANT avar[3];
  832. avar[0].vt = VT_BSTR;
  833. avar[0].bstrVal = strConfig;
  834. avar[1].vt = VT_BSTR;
  835. avar[1].bstrVal = strCertificate;
  836. avar[2].vt = VT_I4;
  837. avar[2].lVal = dwFlags;
  838. hr = DispatchInvoke(
  839. pdiAdmin,
  840. ADMIN_IMPORTCERTIFICATE,
  841. ARRAYSIZE(avar),
  842. avar,
  843. VT_I4,
  844. pRequestId);
  845. _JumpIfError(hr, error, "Invoke(ImportCertificate)");
  846. }
  847. else
  848. {
  849. hr = ((ICertAdmin *) pdiAdmin->pUnknown)->ImportCertificate(
  850. strConfig,
  851. strCertificate,
  852. dwFlags,
  853. pRequestId);
  854. _JumpIfError3(
  855. hr,
  856. error,
  857. "ICertAdmin::ImportCertificate",
  858. NTE_BAD_SIGNATURE,
  859. HRESULT_FROM_WIN32(ERROR_OBJECT_ALREADY_EXISTS));
  860. }
  861. error:
  862. if (NULL != strConfig)
  863. {
  864. SysFreeString(strConfig);
  865. }
  866. if (NULL != strCertificate)
  867. {
  868. SysFreeString(strCertificate);
  869. }
  870. return(hr);
  871. }
  872. HRESULT
  873. AdminRevokeCertificate(
  874. IN DWORD Flags,
  875. OPTIONAL IN WCHAR const *pwszConfig,
  876. IN WCHAR const *pwszSerialNumber,
  877. IN LONG Reason,
  878. IN DATE Date)
  879. {
  880. HRESULT hr;
  881. LONG count;
  882. DISPATCHINTERFACE diAdmin;
  883. BSTR strConfig = NULL;
  884. if (NULL == pwszConfig)
  885. {
  886. hr = ConfigGetConfig(Flags, CC_LOCALACTIVECONFIG, &strConfig);
  887. _JumpIfError(hr, error, "ConfigGetConfig");
  888. pwszConfig = strConfig;
  889. }
  890. hr = Admin_Init(Flags, &diAdmin);
  891. _JumpIfError(hr, error, "Admin_Init");
  892. hr = Admin_RevokeCertificate(
  893. &diAdmin,
  894. pwszConfig,
  895. pwszSerialNumber,
  896. Reason,
  897. Date);
  898. _JumpIfError(hr, error, "Admin_RevokeCertificate");
  899. error:
  900. Admin_Release(&diAdmin);
  901. if (NULL != strConfig)
  902. {
  903. SysFreeString(strConfig);
  904. }
  905. return(hr);
  906. }
  907. #define CCERTADMIN
  908. #include "prop2.cpp"
  909. #if 0
  910. HRESULT
  911. Admin2_SetCAProperty(
  912. IN WCHAR const *pwszConfig,
  913. IN LONG PropId, // CR_PROP_*
  914. IN LONG PropIndex,
  915. IN LONG PropType, // PROPTYPE_*
  916. IN VARIANT *pvarPropertyValue)
  917. {
  918. }
  919. #endif
  920. HRESULT
  921. Admin2_GetArchivedKey(
  922. IN DISPATCHINTERFACE *pdiAdmin,
  923. IN WCHAR const *pwszConfig,
  924. IN LONG RequestId,
  925. IN LONG Flags, // CR_OUT_*
  926. OUT BSTR *pstrArchivedKey)
  927. {
  928. HRESULT hr;
  929. BSTR strConfig = NULL;
  930. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  931. hr = AdminVerifyVersion(pdiAdmin, 2);
  932. _JumpIfError(hr, error, "AdminVerifyVersion");
  933. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  934. {
  935. hr = E_OUTOFMEMORY;
  936. _JumpError(hr, error, "ConvertWszToBstr");
  937. }
  938. if (NULL != pdiAdmin->pDispatch)
  939. {
  940. VARIANT avar[3];
  941. avar[0].vt = VT_BSTR;
  942. avar[0].bstrVal = strConfig;
  943. avar[1].vt = VT_I4;
  944. avar[1].lVal = RequestId;
  945. avar[2].vt = VT_I4;
  946. avar[2].lVal = Flags;
  947. hr = DispatchInvoke(
  948. pdiAdmin,
  949. ADMIN2_GETARCHIVEDKEY,
  950. ARRAYSIZE(avar),
  951. avar,
  952. VT_BSTR,
  953. pstrArchivedKey);
  954. _JumpIfError(hr, error, "Invoke(GetArchivedKey)");
  955. }
  956. else
  957. {
  958. hr = ((ICertAdmin2 *) pdiAdmin->pUnknown)->GetArchivedKey(
  959. strConfig,
  960. RequestId,
  961. Flags,
  962. pstrArchivedKey);
  963. _JumpIfError(hr, error, "ICertAdmin::GetArchivedKey");
  964. }
  965. error:
  966. if (NULL != strConfig)
  967. {
  968. SysFreeString(strConfig);
  969. }
  970. return(hr);
  971. }
  972. #if 0
  973. HRESULT
  974. Admin2_GetConfigEntry(
  975. IN DISPATCHINTERFACE *pdiAdmin,
  976. IN WCHAR const *pwszConfig,
  977. IN WCHAR const *pwszNodePath,
  978. IN WCHAR const *pwszEntryName,
  979. OUT VARIANT *pvarEntry)
  980. {
  981. }
  982. #endif
  983. #if 0
  984. HRESULT
  985. Admin2_SetConfigEntry(
  986. IN DISPATCHINTERFACE *pdiAdmin,
  987. IN WCHAR const *pwszConfig,
  988. IN WCHAR const *pwszNodePath,
  989. IN WCHAR const *pwszEntryName,
  990. IN VARIANT const *pvarEntry)
  991. {
  992. }
  993. #endif
  994. HRESULT
  995. Admin2_ImportKey(
  996. IN DISPATCHINTERFACE *pdiAdmin,
  997. IN WCHAR const *pwszConfig,
  998. IN LONG RequestId,
  999. IN WCHAR const *pwszCertHash,
  1000. IN LONG Flags,
  1001. IN WCHAR const *pwszKey,
  1002. IN DWORD cbKey)
  1003. {
  1004. HRESULT hr;
  1005. BSTR strConfig = NULL;
  1006. BSTR strCertHash = NULL;
  1007. BSTR strKey = NULL;
  1008. if (NULL == pwszKey || NULL == pwszConfig)
  1009. {
  1010. hr = E_INVALIDARG;
  1011. _JumpError(hr, error, "NULL parm");
  1012. }
  1013. hr = E_OUTOFMEMORY;
  1014. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  1015. {
  1016. _JumpError(hr, error, "ConvertWszToBstr");
  1017. }
  1018. if (NULL != pwszCertHash)
  1019. {
  1020. if (!ConvertWszToBstr(&strCertHash, pwszCertHash, -1))
  1021. {
  1022. _JumpError(hr, error, "ConvertWszToBstr");
  1023. }
  1024. }
  1025. strKey = SysAllocStringByteLen((CHAR const *) pwszKey, cbKey);
  1026. if (NULL == strKey)
  1027. {
  1028. _JumpError(hr, error, "SysAllocStringByteLen");
  1029. }
  1030. if (NULL != pdiAdmin->pDispatch)
  1031. {
  1032. VARIANT avar[5];
  1033. avar[0].vt = VT_BSTR;
  1034. avar[0].bstrVal = strConfig;
  1035. avar[1].vt = VT_I4;
  1036. avar[1].lVal = RequestId;
  1037. avar[2].vt = VT_BSTR;
  1038. avar[2].bstrVal = strCertHash;
  1039. avar[3].vt = VT_I4;
  1040. avar[3].lVal = Flags;
  1041. avar[4].vt = VT_BSTR;
  1042. avar[4].bstrVal = strKey;
  1043. hr = DispatchInvoke(
  1044. pdiAdmin,
  1045. ADMIN2_IMPORTKEY,
  1046. ARRAYSIZE(avar),
  1047. avar,
  1048. 0,
  1049. NULL);
  1050. _JumpIfError(hr, error, "Invoke(ImportKey)");
  1051. }
  1052. else
  1053. {
  1054. hr = ((ICertAdmin2 *) pdiAdmin->pUnknown)->ImportKey(
  1055. strConfig,
  1056. RequestId,
  1057. strCertHash,
  1058. Flags,
  1059. strKey);
  1060. _JumpIfError2(
  1061. hr,
  1062. error,
  1063. "ICertAdmin::ImportKey",
  1064. HRESULT_FROM_WIN32(ERROR_OBJECT_ALREADY_EXISTS));
  1065. }
  1066. error:
  1067. if (NULL != strConfig)
  1068. {
  1069. SysFreeString(strConfig);
  1070. }
  1071. if (NULL != strCertHash)
  1072. {
  1073. SysFreeString(strCertHash);
  1074. }
  1075. if (NULL != strKey)
  1076. {
  1077. SysFreeString(strKey);
  1078. }
  1079. return(hr);
  1080. }
  1081. HRESULT
  1082. Admin2_GetMyRoles(
  1083. IN DISPATCHINTERFACE *pdiAdmin,
  1084. IN WCHAR const *pwszConfig,
  1085. OUT LONG *pRoles) // CA_ACCESS_*
  1086. {
  1087. HRESULT hr;
  1088. BSTR strConfig = NULL;
  1089. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  1090. hr = AdminVerifyVersion(pdiAdmin, 2);
  1091. _JumpIfError(hr, error, "AdminVerifyVersion");
  1092. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  1093. {
  1094. hr = E_OUTOFMEMORY;
  1095. _JumpError(hr, error, "ConvertWszToBstr");
  1096. }
  1097. if (NULL != pdiAdmin->pDispatch)
  1098. {
  1099. VARIANT avar[1];
  1100. avar[0].vt = VT_BSTR;
  1101. avar[0].bstrVal = strConfig;
  1102. hr = DispatchInvoke(
  1103. pdiAdmin,
  1104. ADMIN2_GETMYROLES,
  1105. ARRAYSIZE(avar),
  1106. avar,
  1107. VT_I4,
  1108. pRoles);
  1109. _JumpIfError(hr, error, "Invoke(GetMyRoles)");
  1110. }
  1111. else
  1112. {
  1113. hr = ((ICertAdmin2 *) pdiAdmin->pUnknown)->GetMyRoles(
  1114. strConfig,
  1115. pRoles);
  1116. _JumpIfError(hr, error, "ICertAdmin::GetMyRoles");
  1117. }
  1118. error:
  1119. if (NULL != strConfig)
  1120. {
  1121. SysFreeString(strConfig);
  1122. }
  1123. return(hr);
  1124. }
  1125. HRESULT
  1126. Admin2_DeleteRow(
  1127. IN DISPATCHINTERFACE *pdiAdmin,
  1128. IN WCHAR const *pwszConfig,
  1129. IN LONG Flags, // CDR_*
  1130. IN DATE Date,
  1131. IN LONG Table, // CVRC_TABLE_*
  1132. IN LONG RowId,
  1133. OUT LONG *pcDeleted)
  1134. {
  1135. HRESULT hr;
  1136. BSTR strConfig = NULL;
  1137. CSASSERT(NULL != pdiAdmin && NULL != pdiAdmin->pDispatchTable);
  1138. hr = AdminVerifyVersion(pdiAdmin, 2);
  1139. _JumpIfError(hr, error, "AdminVerifyVersion");
  1140. if (!ConvertWszToBstr(&strConfig, pwszConfig, -1))
  1141. {
  1142. hr = E_OUTOFMEMORY;
  1143. _JumpError(hr, error, "ConvertWszToBstr");
  1144. }
  1145. if (NULL != pdiAdmin->pDispatch)
  1146. {
  1147. VARIANT avar[5];
  1148. avar[0].vt = VT_BSTR;
  1149. avar[0].bstrVal = strConfig;
  1150. avar[1].vt = VT_I4;
  1151. avar[1].lVal = Flags;
  1152. avar[2].vt = VT_DATE;
  1153. avar[2].date = Date;
  1154. avar[3].vt = VT_I4;
  1155. avar[3].lVal = Table;
  1156. avar[4].vt = VT_I4;
  1157. avar[4].lVal = RowId;
  1158. hr = DispatchInvoke(
  1159. pdiAdmin,
  1160. ADMIN2_DELETEROW,
  1161. ARRAYSIZE(avar),
  1162. avar,
  1163. VT_I4,
  1164. pcDeleted);
  1165. _JumpIfError(hr, error, "Invoke(DeleteRow)");
  1166. }
  1167. else
  1168. {
  1169. hr = ((ICertAdmin2 *) pdiAdmin->pUnknown)->DeleteRow(
  1170. strConfig,
  1171. Flags,
  1172. Date,
  1173. Table,
  1174. RowId,
  1175. pcDeleted);
  1176. _JumpIfError(hr, error, "ICertAdmin::DeleteRow");
  1177. }
  1178. error:
  1179. if (NULL != strConfig)
  1180. {
  1181. SysFreeString(strConfig);
  1182. }
  1183. return(hr);
  1184. }