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.

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