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.

946 lines
28 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: view.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "global.hxx"
  11. #include <dbgdef.h>
  12. extern HINSTANCE HinstDll;
  13. extern HMODULE HmodRichEdit;
  14. #define SPECIAL_NO_COM_FLAG 0x8000
  15. //////////////////////////////////////////////////////////////////////////////////////
  16. //
  17. //////////////////////////////////////////////////////////////////////////////////////
  18. BOOL
  19. WINAPI
  20. CryptUIDlgViewCertificateW(PCCRYPTUI_VIEWCERTIFICATE_STRUCTW pcvp, BOOL *pfPropertiesChanged)
  21. {
  22. int cPages = 3;
  23. UINT cDefaultPages = 0;
  24. BOOL fRetValue = FALSE;
  25. HRESULT hr;
  26. PROPSHEETPAGEW * ppage = NULL;
  27. INT_PTR ret;
  28. WCHAR rgwch[CRYPTUI_MAX_STRING_SIZE];
  29. char rgch[CRYPTUI_MAX_STRING_SIZE];
  30. CERT_VIEW_HELPER viewhelp;
  31. DWORD i;
  32. CRYPTUI_INITDIALOG_STRUCT *pInitDlgStruct;
  33. //
  34. // it doesn't matter what this action is as long as it is a valid action, it is just used for
  35. // freeing the WinVerifyTrust state
  36. //
  37. GUID gAction = WINTRUST_ACTION_GENERIC_CERT_VERIFY;
  38. //
  39. // We use the common controls -- so make sure they have been loaded
  40. //
  41. if (CommonInit() == FALSE)
  42. {
  43. return FALSE;
  44. }
  45. if (pcvp->dwSize != sizeof(CRYPTUI_VIEWCERTIFICATE_STRUCTW)) {
  46. SetLastError(E_INVALIDARG);
  47. return FALSE;
  48. }
  49. memset(&viewhelp, 0, sizeof(CERT_VIEW_HELPER));
  50. viewhelp.pcvp = pcvp;
  51. viewhelp.hwndGeneralPage = NULL;
  52. viewhelp.hwndDetailPage = NULL;
  53. viewhelp.hwndHierarchyPage = NULL;
  54. viewhelp.pfPropertiesChanged = pfPropertiesChanged;
  55. viewhelp.fIgnoreUntrustedRoot = (pcvp->dwFlags & CRYPTUI_ACCEPT_DECLINE_STYLE) ||
  56. (pcvp->dwFlags & CRYPTUI_IGNORE_UNTRUSTED_ROOT);
  57. viewhelp.fWarnUntrustedRoot = (pcvp->dwFlags & CRYPTUI_WARN_UNTRUSTED_ROOT);
  58. viewhelp.fWarnRemoteTrust = (pcvp->dwFlags & CRYPTUI_WARN_REMOTE_TRUST);
  59. //
  60. // set the properties changed flag to FALSE initially, it will be set
  61. // to TRUE if the user edits properties and actually changes them
  62. //
  63. if (viewhelp.pfPropertiesChanged != NULL)
  64. {
  65. *(viewhelp.pfPropertiesChanged) = FALSE;
  66. }
  67. //
  68. // Initialize the CCertifcateBitmap class that is used in the general page
  69. //
  70. viewhelp.pCCertBmp = new (CCertificateBmp);
  71. if (viewhelp.pCCertBmp == NULL)
  72. {
  73. SetLastError(E_OUTOFMEMORY);
  74. return FALSE;
  75. }
  76. //
  77. // this will calculate the initial usages that the cert in question is allowed
  78. //
  79. BuildChain(&viewhelp, NULL);
  80. //
  81. // set the BOOL that turns COM off if the special flag is set
  82. //
  83. viewhelp.fNoCOM = (pcvp->dwFlags & SPECIAL_NO_COM_FLAG);
  84. //
  85. // Build up the list of pages we are going to use in the dialog
  86. //
  87. ppage = (PROPSHEETPAGEW *) malloc((cPages+pcvp->cPropSheetPages) * sizeof(PROPSHEETPAGEW));
  88. if (ppage == NULL) {
  89. SetLastError(E_OUTOFMEMORY);
  90. goto Exit;
  91. }
  92. memset(ppage, 0, cPages * sizeof(PROPSHEETPAGEW));
  93. ppage[0].dwSize = sizeof(ppage[0]);
  94. ppage[0].dwFlags = 0;
  95. ppage[0].hInstance = HinstDll;
  96. ppage[0].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_CERTPROP_GENERAL);
  97. ppage[0].hIcon = 0;
  98. ppage[0].pszTitle = NULL;
  99. ppage[0].pfnDlgProc = ViewPageGeneral;
  100. ppage[0].lParam = (LPARAM) &viewhelp;
  101. ppage[0].pfnCallback = 0;
  102. ppage[0].pcRefParent = NULL;
  103. cPages = 1;
  104. if (!(pcvp->dwFlags & CRYPTUI_HIDE_DETAILPAGE)) {
  105. ppage[cPages].dwSize = sizeof(ppage[0]);
  106. ppage[cPages].dwFlags = 0;
  107. ppage[cPages].hInstance = HinstDll;
  108. ppage[cPages].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_CERTPROP_DETAILS);
  109. ppage[cPages].hIcon = 0;
  110. ppage[cPages].pszTitle = NULL;
  111. ppage[cPages].pfnDlgProc = ViewPageDetails;
  112. ppage[cPages].lParam = (LPARAM) &viewhelp;
  113. ppage[cPages].pfnCallback = 0;
  114. ppage[cPages].pcRefParent = NULL;
  115. cPages += 1;
  116. }
  117. if (!(pcvp->dwFlags & CRYPTUI_HIDE_HIERARCHYPAGE) &&
  118. !(pcvp->dwFlags & CRYPTUI_ACCEPT_DECLINE_STYLE)) {
  119. ppage[cPages].dwSize = sizeof(ppage[0]);
  120. ppage[cPages].dwFlags = 0;
  121. ppage[cPages].hInstance = HinstDll;
  122. ppage[cPages].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_CERTPROP_HIERARCHY);
  123. ppage[cPages].hIcon = 0;
  124. ppage[cPages].pszTitle = NULL;
  125. ppage[cPages].pfnDlgProc = ViewPageHierarchy;
  126. ppage[cPages].lParam = (LPARAM) &viewhelp;
  127. ppage[cPages].pfnCallback = 0;
  128. ppage[cPages].pcRefParent = NULL;
  129. cPages += 1;
  130. }
  131. cDefaultPages = (UINT) cPages;
  132. //
  133. // Copy over the users pages
  134. //
  135. memcpy(&ppage[cPages], pcvp->rgPropSheetPages,
  136. pcvp->cPropSheetPages * sizeof(PROPSHEETPAGEW));
  137. //
  138. // set the lParam for each of the callers property pages to
  139. // be a pointer to a CRYPTUI_INITDIALOG_STRUCT structure
  140. //
  141. for (i=0; i<pcvp->cPropSheetPages; i++)
  142. {
  143. pInitDlgStruct = (CRYPTUI_INITDIALOG_STRUCT *) malloc(sizeof(CRYPTUI_INITDIALOG_STRUCT));
  144. if (pInitDlgStruct == NULL)
  145. {
  146. SetLastError(E_OUTOFMEMORY);
  147. return FALSE;
  148. }
  149. pInitDlgStruct->lParam = pcvp->rgPropSheetPages[i].lParam;
  150. pInitDlgStruct->pCertContext = pcvp->pCertContext;
  151. ppage[cPages].lParam = (LPARAM) pInitDlgStruct;
  152. cPages++;
  153. }
  154. if (FIsWin95) {
  155. PROPSHEETHEADERA hdr;
  156. memset(&hdr, 0, sizeof(hdr));
  157. hdr.dwSize = sizeof(hdr);
  158. hdr.dwFlags = PSH_USECALLBACK | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  159. hdr.hwndParent = (pcvp->hwndParent != NULL) ? pcvp->hwndParent : GetDesktopWindow();
  160. hdr.hInstance = HinstDll;
  161. hdr.hIcon = NULL;
  162. if (pcvp->szTitle != NULL) {
  163. hdr.pszCaption = CertUIMkMBStr(pcvp->szTitle);
  164. }
  165. else {
  166. LoadStringA(HinstDll, IDS_VIEW_TITLE, rgch, sizeof(rgch));
  167. hdr.pszCaption = (LPSTR) rgch;
  168. }
  169. hdr.nPages = cPages;
  170. hdr.nStartPage = (pcvp->nStartPage & 0x8000) ? ((UINT)(pcvp->nStartPage & ~0x8000)) + cDefaultPages : pcvp->nStartPage;
  171. hdr.ppsp = ConvertToPropPageA(ppage, cPages);
  172. if (hdr.ppsp == NULL)
  173. {
  174. if ((pcvp->szTitle != NULL) && (hdr.pszCaption != NULL))
  175. {
  176. free((void *)hdr.pszCaption);
  177. }
  178. goto Exit;
  179. }
  180. hdr.pfnCallback = HidePropSheetCancelButtonCallback;
  181. ret = CryptUIPropertySheetA(&hdr);
  182. if ((pcvp->szTitle != NULL) && (hdr.pszCaption != NULL))
  183. {
  184. free((void *)hdr.pszCaption);
  185. }
  186. FreePropSheetPagesA((PROPSHEETPAGEA *) hdr.ppsp, cPages);
  187. }
  188. else
  189. {
  190. PROPSHEETHEADERW hdr;
  191. memset(&hdr, 0, sizeof(hdr));
  192. hdr.dwSize = sizeof(hdr);
  193. hdr.dwFlags = PSH_USECALLBACK | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  194. hdr.hwndParent = (pcvp->hwndParent != NULL) ? pcvp->hwndParent : GetDesktopWindow();
  195. hdr.hInstance = HinstDll;
  196. hdr.hIcon = NULL;
  197. if (pcvp->szTitle != NULL) {
  198. hdr.pszCaption = pcvp->szTitle;
  199. }
  200. else {
  201. LoadStringW(HinstDll, IDS_VIEW_TITLE, rgwch, ARRAYSIZE(rgwch));
  202. hdr.pszCaption = rgwch;
  203. }
  204. hdr.nPages = cPages;
  205. hdr.nStartPage = (pcvp->nStartPage & 0x8000) ? ((UINT)(pcvp->nStartPage & ~0x8000)) + cDefaultPages : pcvp->nStartPage;
  206. hdr.ppsp = (PROPSHEETPAGEW *) ppage;
  207. hdr.pfnCallback = HidePropSheetCancelButtonCallback;
  208. ret = CryptUIPropertySheetW(&hdr);
  209. }
  210. //
  211. // free the CRYPTUI_INITDIALOG_STRUCT structures
  212. //
  213. for (i=0; i<pcvp->cPropSheetPages; i++)
  214. {
  215. free((void *) ppage[i+cPages-1].lParam);
  216. }
  217. //
  218. // free the WinVerifyTrust state if we need to
  219. //
  220. if (viewhelp.fFreeWTD)
  221. {
  222. viewhelp.sWTD.dwStateAction = WTD_STATEACTION_CLOSE;
  223. WinVerifyTrustEx(NULL, &gAction, &viewhelp.sWTD);
  224. }
  225. //
  226. // free all the usages that were allocated by
  227. //
  228. for (i=0; i<viewhelp.cUsages; i++)
  229. {
  230. free(viewhelp.rgUsages[i]);
  231. }
  232. if (viewhelp.rgUsages != NULL)
  233. {
  234. free(viewhelp.rgUsages);
  235. }
  236. if (viewhelp.pwszErrorString != NULL)
  237. {
  238. free(viewhelp.pwszErrorString);
  239. }
  240. if (viewhelp.fCancelled)
  241. {
  242. SetLastError(ERROR_CANCELLED);
  243. }
  244. fRetValue = (ret >= 1);
  245. Exit:
  246. if (viewhelp.pCCertBmp)
  247. delete(viewhelp.pCCertBmp);
  248. if (ppage)
  249. free(ppage);
  250. if (pcvp->dwFlags & CRYPTUI_ACCEPT_DECLINE_STYLE)
  251. return (viewhelp.fAccept);
  252. else
  253. return fRetValue;
  254. }
  255. //////////////////////////////////////////////////////////////////////////////////////
  256. //
  257. //////////////////////////////////////////////////////////////////////////////////////
  258. BOOL
  259. WINAPI
  260. CryptUIDlgViewCertificateA(PCCRYPTUI_VIEWCERTIFICATE_STRUCTA pcvp, BOOL *pfPropertiesChanged)
  261. {
  262. BOOL fRet;
  263. CRYPTUI_VIEWCERTIFICATE_STRUCTW cvpW;
  264. memcpy(&cvpW, pcvp, sizeof(cvpW));
  265. if (!ConvertToPropPageW(
  266. pcvp->rgPropSheetPages,
  267. pcvp->cPropSheetPages,
  268. &(cvpW.rgPropSheetPages)))
  269. {
  270. return FALSE;
  271. }
  272. cvpW.szTitle = CertUIMkWStr(pcvp->szTitle);
  273. fRet = CryptUIDlgViewCertificateW(&cvpW, pfPropertiesChanged);
  274. if (cvpW.szTitle != NULL)
  275. free((void *)cvpW.szTitle);
  276. FreePropSheetPagesW((LPPROPSHEETPAGEW) cvpW.rgPropSheetPages, cvpW.cPropSheetPages);
  277. return fRet;
  278. }
  279. //////////////////////////////////////////////////////////////////////////////////////
  280. //
  281. //////////////////////////////////////////////////////////////////////////////////////
  282. BOOL
  283. WINAPI
  284. CryptUIDlgViewCTLW(PCCRYPTUI_VIEWCTL_STRUCTW pcvctl)
  285. {
  286. int cPages = 2;
  287. BOOL fRetValue = FALSE;
  288. HRESULT hr;
  289. PROPSHEETPAGEW * ppage = NULL;
  290. INT_PTR ret;
  291. WCHAR rgwch[100];
  292. CTL_VIEW_HELPER viewhelp;
  293. DWORD i;
  294. CRYPTUI_VIEWSIGNATURES_STRUCTW cvs;
  295. PROPSHEETPAGEW * prghExtraPages;
  296. DWORD cExtraPages;
  297. // We use the common controls -- so make sure they have been loaded
  298. if (CommonInit() == FALSE)
  299. {
  300. return FALSE;
  301. }
  302. if (pcvctl->dwSize != sizeof(CRYPTUI_VIEWCTL_STRUCTW)) {
  303. SetLastError(E_INVALIDARG);
  304. return FALSE;
  305. }
  306. //
  307. memset(&viewhelp, 0, sizeof(CTL_VIEW_HELPER));
  308. viewhelp.pcvctl = pcvctl;
  309. viewhelp.hExtraStore = CertOpenStore(
  310. CERT_STORE_PROV_MSG,
  311. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  312. NULL,
  313. NULL,
  314. (const void *) pcvctl->pCTLContext->hCryptMsg);
  315. //
  316. // Build up the list of pages we are going to use in the dialog
  317. //
  318. ppage = (PROPSHEETPAGEW *) malloc((cPages+pcvctl->cPropSheetPages) * sizeof(PROPSHEETPAGEW));
  319. if (ppage == NULL) {
  320. goto Exit;
  321. }
  322. memset(ppage, 0, cPages * sizeof(PROPSHEETPAGEW));
  323. ppage[0].dwSize = sizeof(ppage[0]);
  324. ppage[0].dwFlags = 0;
  325. ppage[0].hInstance = HinstDll;
  326. ppage[0].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_CTL_GENERAL);
  327. ppage[0].hIcon = 0;
  328. ppage[0].pszTitle = NULL;
  329. ppage[0].pfnDlgProc = ViewPageCTLGeneral;
  330. ppage[0].lParam = (LPARAM) &viewhelp;
  331. ppage[0].pfnCallback = 0;
  332. ppage[0].pcRefParent = NULL;
  333. cPages = 1;
  334. //
  335. // if the subject usage is for a catalog file, then display that page instead of CTL page
  336. //
  337. if (fIsCatalogFile(&(pcvctl->pCTLContext->pCtlInfo->SubjectUsage)))
  338. {
  339. ppage[cPages].dwSize = sizeof(ppage[0]);
  340. ppage[cPages].dwFlags = 0;
  341. ppage[cPages].hInstance = HinstDll;
  342. ppage[cPages].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_CATALOGFILE);
  343. ppage[cPages].hIcon = 0;
  344. ppage[cPages].pszTitle = NULL;
  345. ppage[cPages].pfnDlgProc = ViewPageCatalogEntries;
  346. ppage[cPages].lParam = (LPARAM) &viewhelp;
  347. ppage[cPages].pfnCallback = 0;
  348. ppage[cPages].pcRefParent = NULL;
  349. cPages += 1;
  350. }
  351. else
  352. {
  353. if (!(pcvctl->dwFlags & CRYPTUI_HIDE_TRUSTLIST_PAGE))
  354. {
  355. ppage[cPages].dwSize = sizeof(ppage[0]);
  356. ppage[cPages].dwFlags = 0;
  357. ppage[cPages].hInstance = HinstDll;
  358. ppage[cPages].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_CTL_TRUSTLIST);
  359. ppage[cPages].hIcon = 0;
  360. ppage[cPages].pszTitle = NULL;
  361. ppage[cPages].pfnDlgProc = ViewPageCTLTrustList;
  362. ppage[cPages].lParam = (LPARAM) &viewhelp;
  363. ppage[cPages].pfnCallback = 0;
  364. ppage[cPages].pcRefParent = NULL;
  365. cPages += 1;
  366. }
  367. }
  368. //
  369. // Copy over the users pages
  370. //
  371. memcpy(&ppage[cPages], pcvctl->rgPropSheetPages,
  372. pcvctl->cPropSheetPages * sizeof(PROPSHEETPAGEW));
  373. cPages += pcvctl->cPropSheetPages;
  374. if (FIsWin95)
  375. {
  376. PROPSHEETHEADERA hdr;
  377. memset(&hdr, 0, sizeof(hdr));
  378. hdr.dwSize = sizeof(hdr);
  379. hdr.dwFlags = PSH_USECALLBACK | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  380. hdr.hwndParent = (pcvctl->hwndParent != NULL) ? pcvctl->hwndParent : GetDesktopWindow();
  381. hdr.hInstance = HinstDll;
  382. hdr.hIcon = NULL;
  383. if (pcvctl->szTitle != NULL)
  384. {
  385. hdr.pszCaption = CertUIMkMBStr(pcvctl->szTitle);
  386. }
  387. else if (fIsCatalogFile(&(pcvctl->pCTLContext->pCtlInfo->SubjectUsage)))
  388. {
  389. LoadStringA(HinstDll, IDS_CATALOG_TITLE, (LPSTR) rgwch, ARRAYSIZE(rgwch));
  390. hdr.pszCaption = (LPSTR) rgwch;
  391. }
  392. else
  393. {
  394. LoadStringA(HinstDll, IDS_CTLVIEW_TITLE, (LPSTR) rgwch, ARRAYSIZE(rgwch));
  395. hdr.pszCaption = (LPSTR) rgwch;
  396. }
  397. hdr.nPages = cPages;
  398. hdr.nStartPage = 0;
  399. hdr.ppsp = ConvertToPropPageA(ppage, cPages);
  400. if (hdr.ppsp == NULL)
  401. {
  402. if ((pcvctl->szTitle != NULL) && (hdr.pszCaption != NULL))
  403. {
  404. free((void *)hdr.pszCaption);
  405. }
  406. goto Exit;
  407. }
  408. hdr.pfnCallback = HidePropSheetCancelButtonCallback;
  409. ret = CryptUIPropertySheetA(&hdr);
  410. if ((pcvctl->szTitle != NULL) && (hdr.pszCaption != NULL))
  411. {
  412. free((void *)hdr.pszCaption);
  413. }
  414. FreePropSheetPagesA((PROPSHEETPAGEA *) hdr.ppsp, cPages);
  415. }
  416. else {
  417. PROPSHEETHEADERW hdr;
  418. memset(&hdr, 0, sizeof(hdr));
  419. hdr.dwSize = sizeof(hdr);
  420. hdr.dwFlags = PSH_USECALLBACK | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  421. hdr.hwndParent = (pcvctl->hwndParent != NULL) ? pcvctl->hwndParent : GetDesktopWindow();
  422. hdr.hInstance = HinstDll;
  423. hdr.hIcon = NULL;
  424. if (pcvctl->szTitle != NULL)
  425. {
  426. hdr.pszCaption = pcvctl->szTitle;
  427. }
  428. else if (fIsCatalogFile(&(pcvctl->pCTLContext->pCtlInfo->SubjectUsage)))
  429. {
  430. LoadStringW(HinstDll, IDS_CATALOG_TITLE, rgwch, ARRAYSIZE(rgwch));
  431. hdr.pszCaption = rgwch;
  432. }
  433. else
  434. {
  435. LoadStringW(HinstDll, IDS_CTLVIEW_TITLE, rgwch, ARRAYSIZE(rgwch));
  436. hdr.pszCaption = rgwch;
  437. }
  438. hdr.nPages = cPages;
  439. hdr.nStartPage = 0;
  440. hdr.ppsp = (PROPSHEETPAGEW *) ppage;
  441. hdr.pfnCallback = HidePropSheetCancelButtonCallback;
  442. ret = CryptUIPropertySheetW(&hdr);
  443. }
  444. CertCloseStore(viewhelp.hExtraStore, 0);
  445. if (viewhelp.fCancelled)
  446. {
  447. SetLastError(ERROR_CANCELLED);
  448. }
  449. fRetValue = (ret >= 1);
  450. Exit:
  451. if (ppage)
  452. free(ppage);
  453. return fRetValue;
  454. }
  455. //////////////////////////////////////////////////////////////////////////////////////
  456. //
  457. //////////////////////////////////////////////////////////////////////////////////////
  458. BOOL
  459. WINAPI
  460. CryptUIDlgViewCTLA(PCCRYPTUI_VIEWCTL_STRUCTA pcvctl)
  461. {
  462. BOOL fRet;
  463. CRYPTUI_VIEWCTL_STRUCTW cvctlW;
  464. memcpy(&cvctlW, pcvctl, sizeof(cvctlW));
  465. if (!ConvertToPropPageW(
  466. pcvctl->rgPropSheetPages,
  467. pcvctl->cPropSheetPages,
  468. &(cvctlW.rgPropSheetPages)))
  469. {
  470. return FALSE;
  471. }
  472. cvctlW.szTitle = CertUIMkWStr(pcvctl->szTitle);
  473. fRet = CryptUIDlgViewCTLW(&cvctlW);
  474. if (cvctlW.szTitle != NULL)
  475. free((void *)cvctlW.szTitle);
  476. FreePropSheetPagesW((LPPROPSHEETPAGEW) cvctlW.rgPropSheetPages, cvctlW.cPropSheetPages);
  477. return fRet;
  478. }
  479. //////////////////////////////////////////////////////////////////////////////////////
  480. //
  481. //////////////////////////////////////////////////////////////////////////////////////
  482. BOOL
  483. WINAPI
  484. CryptUIDlgViewCRLW(PCCRYPTUI_VIEWCRL_STRUCTW pcvcrl)
  485. {
  486. int cPages = 2;
  487. BOOL fRetValue = FALSE;
  488. HRESULT hr;
  489. PROPSHEETPAGEW * ppage = NULL;
  490. INT_PTR ret;
  491. WCHAR rgwch[CRYPTUI_MAX_STRING_SIZE];
  492. CRL_VIEW_HELPER viewhelp;
  493. DWORD i;
  494. // We use the common controls -- so make sure they have been loaded
  495. if (CommonInit() == FALSE)
  496. {
  497. return FALSE;
  498. }
  499. if (pcvcrl->dwSize != sizeof(CRYPTUI_VIEWCRL_STRUCTW)) {
  500. SetLastError(E_INVALIDARG);
  501. return FALSE;
  502. }
  503. //
  504. memset(&viewhelp, 0, sizeof(CRL_VIEW_HELPER));
  505. viewhelp.pcvcrl = pcvcrl;
  506. //
  507. // Build up the list of pages we are going to use in the dialog
  508. //
  509. ppage = (PROPSHEETPAGEW *) malloc((cPages+pcvcrl->cPropSheetPages) * sizeof(PROPSHEETPAGEW));
  510. if (ppage == NULL) {
  511. goto Exit;
  512. }
  513. memset(ppage, 0, cPages * sizeof(PROPSHEETPAGEW));
  514. ppage[0].dwSize = sizeof(ppage[0]);
  515. ppage[0].dwFlags = 0;
  516. ppage[0].hInstance = HinstDll;
  517. ppage[0].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_CRL_GENERAL);
  518. ppage[0].hIcon = 0;
  519. ppage[0].pszTitle = NULL;
  520. ppage[0].pfnDlgProc = ViewPageCRLGeneral;
  521. ppage[0].lParam = (LPARAM) &viewhelp;
  522. ppage[0].pfnCallback = 0;
  523. ppage[0].pcRefParent = NULL;
  524. cPages = 1;
  525. if (!(pcvcrl->dwFlags & CRYPTUI_HIDE_REVOCATIONLIST_PAGE)) {
  526. ppage[cPages].dwSize = sizeof(ppage[0]);
  527. ppage[cPages].dwFlags = 0;
  528. ppage[cPages].hInstance = HinstDll;
  529. ppage[cPages].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_CRL_REVOCATIONLIST);
  530. ppage[cPages].hIcon = 0;
  531. ppage[cPages].pszTitle = NULL;
  532. ppage[cPages].pfnDlgProc = ViewPageCRLRevocationList;
  533. ppage[cPages].lParam = (LPARAM) &viewhelp;
  534. ppage[cPages].pfnCallback = 0;
  535. ppage[cPages].pcRefParent = NULL;
  536. cPages += 1;
  537. }
  538. //
  539. // Copy over the users pages
  540. //
  541. memcpy(&ppage[cPages], pcvcrl->rgPropSheetPages,
  542. pcvcrl->cPropSheetPages * sizeof(PROPSHEETPAGEW));
  543. cPages += pcvcrl->cPropSheetPages;
  544. if (FIsWin95) {
  545. PROPSHEETHEADERA hdr;
  546. memset(&hdr, 0, sizeof(hdr));
  547. hdr.dwSize = sizeof(hdr);
  548. hdr.dwFlags = PSH_USECALLBACK | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  549. hdr.hwndParent = (pcvcrl->hwndParent != NULL) ? pcvcrl->hwndParent : GetDesktopWindow();
  550. hdr.hInstance = HinstDll;
  551. hdr.hIcon = NULL;
  552. if (pcvcrl->szTitle != NULL) {
  553. hdr.pszCaption = CertUIMkMBStr(pcvcrl->szTitle);
  554. }
  555. else {
  556. LoadStringA(HinstDll, IDS_CRLVIEW_TITLE, (LPSTR) rgwch, ARRAYSIZE(rgwch));
  557. hdr.pszCaption = (LPSTR) rgwch;
  558. }
  559. hdr.nPages = cPages;
  560. hdr.nStartPage = 0;
  561. hdr.ppsp = ConvertToPropPageA(ppage, cPages);
  562. if (hdr.ppsp == NULL)
  563. {
  564. if ((pcvcrl->szTitle != NULL) && (hdr.pszCaption != NULL))
  565. {
  566. free((void *)hdr.pszCaption);
  567. }
  568. goto Exit;
  569. }
  570. hdr.pfnCallback = HidePropSheetCancelButtonCallback;
  571. ret = CryptUIPropertySheetA(&hdr);
  572. if ((pcvcrl->szTitle != NULL) && (hdr.pszCaption != NULL))
  573. {
  574. free((void *)hdr.pszCaption);
  575. }
  576. FreePropSheetPagesA((PROPSHEETPAGEA *) hdr.ppsp, cPages);
  577. }
  578. else {
  579. PROPSHEETHEADERW hdr;
  580. memset(&hdr, 0, sizeof(hdr));
  581. hdr.dwSize = sizeof(hdr);
  582. hdr.dwFlags = PSH_USECALLBACK | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  583. hdr.hwndParent = (pcvcrl->hwndParent != NULL) ? pcvcrl->hwndParent : GetDesktopWindow();
  584. hdr.hInstance = HinstDll;
  585. hdr.hIcon = NULL;
  586. if (pcvcrl->szTitle != NULL) {
  587. hdr.pszCaption = pcvcrl->szTitle;
  588. }
  589. else {
  590. LoadStringW(HinstDll, IDS_CRLVIEW_TITLE, rgwch, ARRAYSIZE(rgwch));
  591. hdr.pszCaption = rgwch;
  592. }
  593. hdr.nPages = cPages;
  594. hdr.nStartPage = 0;
  595. hdr.ppsp = (PROPSHEETPAGEW *) ppage;
  596. hdr.pfnCallback = HidePropSheetCancelButtonCallback;
  597. ret = CryptUIPropertySheetW(&hdr);
  598. }
  599. if (viewhelp.fCancelled)
  600. {
  601. SetLastError(ERROR_CANCELLED);
  602. }
  603. fRetValue = (ret >= 1);
  604. Exit:
  605. if (ppage)
  606. free(ppage);
  607. return fRetValue;
  608. }
  609. //////////////////////////////////////////////////////////////////////////////////////
  610. //
  611. //////////////////////////////////////////////////////////////////////////////////////
  612. BOOL
  613. WINAPI
  614. CryptUIDlgViewCRLA(PCCRYPTUI_VIEWCRL_STRUCTA pcvcrl)
  615. {
  616. BOOL fRet;
  617. CRYPTUI_VIEWCRL_STRUCTW cvcrlW;
  618. memcpy(&cvcrlW, pcvcrl, sizeof(cvcrlW));
  619. if (!ConvertToPropPageW(
  620. pcvcrl->rgPropSheetPages,
  621. pcvcrl->cPropSheetPages,
  622. &(cvcrlW.rgPropSheetPages)))
  623. {
  624. return FALSE;
  625. }
  626. cvcrlW.szTitle = CertUIMkWStr(pcvcrl->szTitle);
  627. fRet = CryptUIDlgViewCRLW(&cvcrlW);
  628. if (cvcrlW.szTitle != NULL)
  629. free((void *)cvcrlW.szTitle);
  630. FreePropSheetPagesW((LPPROPSHEETPAGEW) cvcrlW.rgPropSheetPages, cvcrlW.cPropSheetPages);
  631. return fRet;
  632. }
  633. //////////////////////////////////////////////////////////////////////////////////////
  634. //
  635. //////////////////////////////////////////////////////////////////////////////////////
  636. BOOL
  637. WINAPI
  638. CryptUIDlgViewSignerInfoW(PCCRYPTUI_VIEWSIGNERINFO_STRUCTW pcvsi)
  639. {
  640. int cPages = 2;
  641. BOOL fRetValue = FALSE;
  642. HRESULT hr;
  643. PROPSHEETPAGEW * ppage = NULL;
  644. INT_PTR ret;
  645. WCHAR rgwch[CRYPTUI_MAX_STRING_SIZE];
  646. SIGNER_VIEW_HELPER viewhelp;
  647. DWORD i;
  648. // We use the common controls -- so make sure they have been loaded
  649. if (CommonInit() == FALSE)
  650. {
  651. return FALSE;
  652. }
  653. if (pcvsi->dwSize != sizeof(CRYPTUI_VIEWSIGNERINFO_STRUCTW)) {
  654. SetLastError(E_INVALIDARG);
  655. return FALSE;
  656. }
  657. //
  658. memset(&viewhelp, 0, sizeof(SIGNER_VIEW_HELPER));
  659. viewhelp.pcvsi = pcvsi;
  660. if (pcvsi->dwFlags & CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_SIGNERINFO_PRIVATE)
  661. {
  662. viewhelp.pPrivate = (PCERT_VIEWSIGNERINFO_PRIVATE) pcvsi->dwReserved;
  663. }
  664. else if (pcvsi->dwFlags & CRYPTUI_VIEWSIGNERINFO_RESERVED_FIELD_IS_ERROR_CODE)
  665. {
  666. viewhelp.dwInheritedError = (DWORD) pcvsi->dwReserved;
  667. }
  668. viewhelp.fPrivateAllocated = FALSE;
  669. viewhelp.hExtraStore = CertOpenStore(
  670. CERT_STORE_PROV_MSG,
  671. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  672. NULL,
  673. NULL,
  674. (const void *) pcvsi->hMsg);
  675. //
  676. // Build up the list of pages we are going to use in the dialog
  677. //
  678. ppage = (PROPSHEETPAGEW *) malloc((cPages+pcvsi->cPropSheetPages) * sizeof(PROPSHEETPAGEW));
  679. if (ppage == NULL) {
  680. goto Exit;
  681. }
  682. memset(ppage, 0, cPages * sizeof(PROPSHEETPAGEW));
  683. ppage[0].dwSize = sizeof(ppage[0]);
  684. ppage[0].dwFlags = 0;
  685. ppage[0].hInstance = HinstDll;
  686. ppage[0].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_SIGNER_GENERAL_DIALOG);
  687. ppage[0].hIcon = 0;
  688. ppage[0].pszTitle = NULL;
  689. ppage[0].pfnDlgProc = ViewPageSignerGeneral;
  690. ppage[0].lParam = (LPARAM) &viewhelp;
  691. ppage[0].pfnCallback = 0;
  692. ppage[0].pcRefParent = NULL;
  693. cPages = 1;
  694. if (!(pcvsi->dwFlags & CRYPTUI_HIDE_TRUSTLIST_PAGE)) {
  695. ppage[cPages].dwSize = sizeof(ppage[0]);
  696. ppage[cPages].dwFlags = 0;
  697. ppage[cPages].hInstance = HinstDll;
  698. ppage[cPages].pszTemplate = (LPWSTR) MAKEINTRESOURCE(IDD_SIGNER_ADVANCED_DIALOG);
  699. ppage[cPages].hIcon = 0;
  700. ppage[cPages].pszTitle = NULL;
  701. ppage[cPages].pfnDlgProc = ViewPageSignerAdvanced;
  702. ppage[cPages].lParam = (LPARAM) &viewhelp;
  703. ppage[cPages].pfnCallback = 0;
  704. ppage[cPages].pcRefParent = NULL;
  705. cPages += 1;
  706. }
  707. //
  708. // Copy over the users pages
  709. //
  710. memcpy(&ppage[cPages], pcvsi->rgPropSheetPages,
  711. pcvsi->cPropSheetPages * sizeof(PROPSHEETPAGEW));
  712. cPages += pcvsi->cPropSheetPages;
  713. if (FIsWin95) {
  714. PROPSHEETHEADERA hdr;
  715. memset(&hdr, 0, sizeof(hdr));
  716. hdr.dwSize = sizeof(hdr);
  717. hdr.dwFlags = PSH_USECALLBACK | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  718. hdr.hwndParent = (pcvsi->hwndParent != NULL) ? pcvsi->hwndParent : GetDesktopWindow();
  719. hdr.hInstance = HinstDll;
  720. hdr.hIcon = NULL;
  721. if (pcvsi->szTitle != NULL) {
  722. hdr.pszCaption = CertUIMkMBStr(pcvsi->szTitle);
  723. }
  724. else {
  725. LoadStringA(HinstDll, IDS_SIGNERVIEW_TITLE, (LPSTR) rgwch, ARRAYSIZE(rgwch));
  726. hdr.pszCaption = (LPSTR) rgwch;
  727. }
  728. hdr.nPages = cPages;
  729. hdr.nStartPage = 0;
  730. hdr.ppsp = ConvertToPropPageA(ppage, cPages);
  731. if (hdr.ppsp == NULL)
  732. {
  733. if ((pcvsi->szTitle != NULL) && (hdr.pszCaption != NULL))
  734. {
  735. free((void *)hdr.pszCaption);
  736. }
  737. goto Exit;
  738. }
  739. hdr.pfnCallback = HidePropSheetCancelButtonCallback;
  740. ret = CryptUIPropertySheetA(&hdr);
  741. if ((pcvsi->szTitle != NULL) && (hdr.pszCaption != NULL))
  742. {
  743. free((void *)hdr.pszCaption);
  744. }
  745. FreePropSheetPagesA((PROPSHEETPAGEA *) hdr.ppsp, cPages);
  746. }
  747. else {
  748. PROPSHEETHEADERW hdr;
  749. memset(&hdr, 0, sizeof(hdr));
  750. hdr.dwSize = sizeof(hdr);
  751. hdr.dwFlags = PSH_USECALLBACK | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  752. hdr.hwndParent = (pcvsi->hwndParent != NULL) ? pcvsi->hwndParent : GetDesktopWindow();
  753. hdr.hInstance = HinstDll;
  754. hdr.hIcon = NULL;
  755. if (pcvsi->szTitle != NULL) {
  756. hdr.pszCaption = pcvsi->szTitle;
  757. }
  758. else {
  759. LoadStringW(HinstDll, IDS_SIGNERVIEW_TITLE, rgwch, ARRAYSIZE(rgwch));
  760. hdr.pszCaption = rgwch;
  761. }
  762. hdr.nPages = cPages;
  763. hdr.nStartPage = 0;
  764. hdr.ppsp = (PROPSHEETPAGEW *) ppage;
  765. hdr.pfnCallback = HidePropSheetCancelButtonCallback;
  766. ret = CryptUIPropertySheetW(&hdr);
  767. }
  768. CertCloseStore(viewhelp.hExtraStore, 0);
  769. if (viewhelp.fCancelled)
  770. {
  771. SetLastError(ERROR_CANCELLED);
  772. }
  773. fRetValue = (ret >= 1);
  774. Exit:
  775. if (ppage)
  776. free(ppage);
  777. return fRetValue;
  778. }
  779. //////////////////////////////////////////////////////////////////////////////////////
  780. //
  781. //////////////////////////////////////////////////////////////////////////////////////
  782. BOOL
  783. WINAPI
  784. CryptUIDlgViewSignerInfoA(PCCRYPTUI_VIEWSIGNERINFO_STRUCTA pcvsi)
  785. {
  786. BOOL fRet;
  787. CRYPTUI_VIEWSIGNERINFO_STRUCTW cvsiW;
  788. memcpy(&cvsiW, pcvsi, sizeof(cvsiW));
  789. if (!ConvertToPropPageW(
  790. pcvsi->rgPropSheetPages,
  791. pcvsi->cPropSheetPages,
  792. &(cvsiW.rgPropSheetPages)))
  793. {
  794. return FALSE;
  795. }
  796. cvsiW.szTitle = CertUIMkWStr(pcvsi->szTitle);
  797. fRet = CryptUIDlgViewSignerInfoW(&cvsiW);
  798. if (cvsiW.szTitle)
  799. free((void *)cvsiW.szTitle);
  800. FreePropSheetPagesW((LPPROPSHEETPAGEW) cvsiW.rgPropSheetPages, cvsiW.cPropSheetPages);
  801. return fRet;
  802. }