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.

1564 lines
42 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: genpage.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // genpage.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "certca.h"
  14. #include "tfcprop.h"
  15. #include "genpage.h"
  16. // sddl.h requires this value to be at least
  17. // 0x0500. Bump it up if necessary. NOTE: This
  18. // 'bump' comes after all other H files that may
  19. // be sensitive to this value.
  20. #if(_WIN32_WINNT < 0x500)
  21. #undef _WIN32_WINNT
  22. #define _WIN32_WINNT 0x0500
  23. #endif
  24. #include <sddl.h>
  25. #include "helparr.h"
  26. #define DURATION_INDEX_YEARS 0
  27. #define DURATION_INDEX_MONTHS 1
  28. #define DURATION_INDEX_WEEKS 2
  29. #define DURATION_INDEX_DAYS 3
  30. void myDisplayError(HWND hwnd, HRESULT hr, UINT id)
  31. {
  32. CString cstrTitle, cstrFullText;
  33. cstrTitle.LoadString(IDS_SNAPIN_NAME);
  34. if (hr != S_OK)
  35. {
  36. WCHAR const *pwszError = myGetErrorMessageText(hr, TRUE);
  37. cstrFullText = pwszError;
  38. // Free the buffer
  39. if (NULL != pwszError)
  40. {
  41. LocalFree(const_cast<WCHAR *>(pwszError));
  42. }
  43. }
  44. if (id != -1)
  45. {
  46. CString cstrMsg;
  47. cstrMsg.LoadString(id);
  48. cstrFullText += cstrMsg;
  49. }
  50. ::MessageBoxW(hwnd, cstrFullText, cstrTitle, MB_OK | MB_ICONERROR);
  51. }
  52. /////////////////////////////////////////////////////////////////////
  53. /////////////////////////////////////////////////////////////////////
  54. // replacement for DoDataExchange
  55. BOOL CAutoDeletePropPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  56. {
  57. if (fSuckFromDlg)
  58. {
  59. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  60. }
  61. else
  62. {
  63. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  64. }
  65. return TRUE;
  66. }
  67. // replacement for BEGIN_MESSAGE_MAP
  68. BOOL CAutoDeletePropPage::OnCommand(WPARAM wParam, LPARAM lParam)
  69. {
  70. /*
  71. switch(LOWORD(wParam))
  72. {
  73. default:
  74. return FALSE;
  75. break;
  76. }
  77. */
  78. return TRUE;
  79. }
  80. /////////////////////////////////////////////////////////////////////
  81. // Constructor
  82. CAutoDeletePropPage::CAutoDeletePropPage(UINT uIDD) : PropertyPage(uIDD)
  83. {
  84. m_prgzHelpIDs = NULL;
  85. m_autodeleteStuff.cWizPages = 1; // Number of pages in wizard
  86. m_autodeleteStuff.pfnOriginalPropSheetPageProc = m_psp.pfnCallback;
  87. m_psp.dwFlags |= PSP_USECALLBACK;
  88. m_psp.pfnCallback = S_PropSheetPageProc;
  89. m_psp.lParam = reinterpret_cast<LPARAM>(this);
  90. }
  91. CAutoDeletePropPage::~CAutoDeletePropPage()
  92. {
  93. }
  94. /////////////////////////////////////////////////////////////////////
  95. void CAutoDeletePropPage::SetCaption(LPCTSTR pszCaption)
  96. {
  97. m_strCaption = pszCaption; // Copy the caption
  98. m_psp.pszTitle = m_strCaption; // Set the title
  99. m_psp.dwFlags |= PSP_USETITLE;
  100. }
  101. /////////////////////////////////////////////////////////////////////
  102. void CAutoDeletePropPage::SetCaption(UINT uStringID)
  103. {
  104. VERIFY(m_strCaption.LoadString(uStringID));
  105. SetCaption(m_strCaption);
  106. }
  107. /////////////////////////////////////////////////////////////////////
  108. void CAutoDeletePropPage::SetHelp(LPCTSTR szHelpFile, const DWORD rgzHelpIDs[])
  109. {
  110. //szHelpFile == NULL; // TRUE => No help file supplied (meaning no help)
  111. //rgzHelpIDs == NULL; // TRUE => No help at all
  112. m_strHelpFile = szHelpFile;
  113. m_prgzHelpIDs = rgzHelpIDs;
  114. }
  115. /////////////////////////////////////////////////////////////////////
  116. void CAutoDeletePropPage::EnableDlgItem(INT nIdDlgItem, BOOL fEnable)
  117. {
  118. ASSERT(IsWindow(::GetDlgItem(m_hWnd, nIdDlgItem)));
  119. ::EnableWindow(::GetDlgItem(m_hWnd, nIdDlgItem), fEnable);
  120. }
  121. /////////////////////////////////////////////////////////////////////
  122. BOOL CAutoDeletePropPage::OnSetActive()
  123. {
  124. HWND hwndParent = ::GetParent(m_hWnd);
  125. ASSERT(IsWindow(hwndParent));
  126. ::PropSheet_SetWizButtons(hwndParent, PSWIZB_FINISH);
  127. return PropertyPage::OnSetActive();
  128. }
  129. /////////////////////////////////////////////////////////////////////
  130. void CAutoDeletePropPage::OnContextHelp(HWND hwnd)
  131. {
  132. if (m_prgzHelpIDs == NULL || m_strHelpFile.IsEmpty())
  133. return;
  134. ASSERT(IsWindow(hwnd));
  135. ::WinHelp(hwnd, m_strHelpFile, HELP_CONTEXTMENU, (ULONG_PTR)(LPVOID)m_prgzHelpIDs);
  136. return;
  137. }
  138. /////////////////////////////////////////////////////////////////////
  139. void CAutoDeletePropPage::OnHelp(LPHELPINFO pHelpInfo)
  140. {
  141. if (m_prgzHelpIDs == NULL || m_strHelpFile.IsEmpty())
  142. return;
  143. if (pHelpInfo != NULL && pHelpInfo->iContextType == HELPINFO_WINDOW)
  144. {
  145. // Display context help for a control
  146. ::WinHelp((HWND)pHelpInfo->hItemHandle, m_strHelpFile,
  147. HELP_WM_HELP, (ULONG_PTR)(LPVOID)m_prgzHelpIDs);
  148. }
  149. return;
  150. }
  151. /////////////////////////////////////////////////////////////////////
  152. // S_PropSheetPageProc()
  153. //
  154. // Static member function used to delete the CAutoDeletePropPage object
  155. // when wizard terminates
  156. //
  157. UINT CALLBACK CAutoDeletePropPage::S_PropSheetPageProc(
  158. HWND hwnd,
  159. UINT uMsg,
  160. LPPROPSHEETPAGE ppsp)
  161. {
  162. ASSERT(ppsp != NULL);
  163. CAutoDeletePropPage *pThis;
  164. pThis = reinterpret_cast<CAutoDeletePropPage*>(ppsp->lParam);
  165. ASSERT(pThis != NULL);
  166. BOOL fDefaultRet;
  167. switch (uMsg)
  168. {
  169. case PSPCB_RELEASE:
  170. fDefaultRet = FALSE;
  171. if (--(pThis->m_autodeleteStuff.cWizPages) <= 0)
  172. {
  173. // Remember callback on stack since "this" will be deleted
  174. LPFNPSPCALLBACK pfnOrig = pThis->m_autodeleteStuff.pfnOriginalPropSheetPageProc;
  175. delete pThis;
  176. if (pfnOrig)
  177. return (pfnOrig)(hwnd, uMsg, ppsp);
  178. else
  179. return fDefaultRet;
  180. }
  181. break;
  182. case PSPCB_CREATE:
  183. fDefaultRet = TRUE;
  184. // do not increase refcount, PSPCB_CREATE may or may not be called
  185. // depending on whether the page was created. PSPCB_RELEASE can be
  186. // depended upon to be called exactly once per page however.
  187. break;
  188. } // switch
  189. if (pThis->m_autodeleteStuff.pfnOriginalPropSheetPageProc)
  190. return (pThis->m_autodeleteStuff.pfnOriginalPropSheetPageProc)(hwnd, uMsg, ppsp);
  191. else
  192. return fDefaultRet;
  193. } // CAutoDeletePropPage::S_PropSheetPageProc()
  194. /////////////////////////////////////////////////////////////////////////////
  195. // CGeneralPage property page
  196. CGeneralPage::CGeneralPage(UINT uIDD) : CAutoDeletePropPage(uIDD)
  197. {
  198. m_hConsoleHandle = NULL;
  199. m_bUpdate = FALSE;
  200. SetHelp(CAPESNPN_HELPFILENAME , g_aHelpIDs_IDD_CERTIFICATE_TEMPLATE_PROPERTIES_GENERAL_PAGE);
  201. }
  202. CGeneralPage::~CGeneralPage()
  203. {
  204. }
  205. // replacement for DoDataExchange
  206. BOOL CGeneralPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  207. {
  208. if (fSuckFromDlg)
  209. {
  210. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  211. }
  212. else
  213. {
  214. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  215. }
  216. return TRUE;
  217. }
  218. // replacement for BEGIN_MESSAGE_MAP
  219. BOOL CGeneralPage::OnCommand(WPARAM wParam, LPARAM lParam)
  220. {
  221. /*
  222. switch(LOWORD(wParam))
  223. {
  224. default:
  225. return FALSE;
  226. break;
  227. }
  228. */
  229. return TRUE;
  230. }
  231. /////////////////////////////////////////////////////////////////////////////
  232. // CGeneralPage message handlers
  233. void CGeneralPage::OnDestroy()
  234. {
  235. // Note - This needs to be called only once.
  236. // If called more than once, it will gracefully return an error.
  237. if (m_hConsoleHandle)
  238. MMCFreeNotifyHandle(m_hConsoleHandle);
  239. m_hConsoleHandle = NULL;
  240. CAutoDeletePropPage::OnDestroy();
  241. }
  242. void CGeneralPage::OnEditChange()
  243. {
  244. if (!m_bUpdate)
  245. {
  246. // Page is dirty, mark it.
  247. SetModified();
  248. m_bUpdate = TRUE;
  249. }
  250. }
  251. BOOL CGeneralPage::OnApply()
  252. {
  253. if (m_bUpdate == TRUE)
  254. {
  255. /*
  256. USES_CONVERSION;
  257. // Simple string cookie, could be anything!
  258. LPWSTR lpString =
  259. reinterpret_cast<LPWSTR>(
  260. ::GlobalAlloc(GMEM_SHARE,
  261. (sizeof(wchar_t) *
  262. (m_szName.GetLength() + 1))
  263. ));
  264. wcscpy(lpString, T2COLE(m_szName));
  265. // Send a property change notify to the console
  266. MMCPropertyChangeNotify(m_hConsoleHandle, reinterpret_cast<LONG_PTR>(lpString));
  267. m_bUpdate = FALSE;
  268. */
  269. }
  270. return CAutoDeletePropPage::OnApply();
  271. }
  272. //////////////////////////////
  273. // hand-hewn pages
  274. ////
  275. // 1
  276. /////////////////////////////////////////////////////////////////////////////
  277. // CPolicySettingsGeneralPage property page
  278. CPolicySettingsGeneralPage::CPolicySettingsGeneralPage(CString szCAName, HCAINFO hCAInfo, UINT uIDD)
  279. : CAutoDeletePropPage(uIDD), m_hCAInfo(hCAInfo), m_szCAName(szCAName)
  280. {
  281. m_hConsoleHandle = NULL;
  282. m_bUpdate = FALSE;
  283. SetHelp(CAPESNPN_HELPFILENAME , g_aHelpIDs_IDD_POLICYSETTINGS_PROPPAGE1);
  284. }
  285. CPolicySettingsGeneralPage::~CPolicySettingsGeneralPage()
  286. {
  287. }
  288. // replacement for DoDataExchange
  289. BOOL CPolicySettingsGeneralPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  290. {
  291. if (fSuckFromDlg)
  292. {
  293. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  294. }
  295. else
  296. {
  297. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  298. }
  299. return TRUE;
  300. }
  301. // replacement for BEGIN_MESSAGE_MAP
  302. BOOL CPolicySettingsGeneralPage::OnCommand(WPARAM wParam, LPARAM lParam)
  303. {
  304. /*
  305. switch(LOWORD(wParam))
  306. {
  307. default:
  308. return FALSE;
  309. break;
  310. }
  311. */
  312. return TRUE;
  313. }
  314. BOOL CPolicySettingsGeneralPage::OnNotify(UINT idCtrl, NMHDR* pnmh)
  315. {
  316. switch(idCtrl)
  317. {
  318. case IDC_DURATION_EDIT:
  319. if (EN_CHANGE == pnmh->code)
  320. {
  321. OnEditChange();
  322. break;
  323. }
  324. case IDC_DURATION_UNIT_COMBO:
  325. if (CBN_SELCHANGE == pnmh->code)
  326. {
  327. OnEditChange();
  328. break;
  329. }
  330. default:
  331. return FALSE;
  332. }
  333. return TRUE;
  334. }
  335. /////////////////////////////////////////////////////////////////////////////
  336. // CPolicySettingsGeneralPage message handlers
  337. BOOL CPolicySettingsGeneralPage::OnInitDialog()
  338. {
  339. // does parent init and UpdateData call
  340. CAutoDeletePropPage::OnInitDialog();
  341. DWORD dwExpiration;
  342. DWORD dwExpirationUnits;
  343. WCHAR szNumberString[256];
  344. int iEntry;
  345. m_cboxDurationUnits.ResetContent();
  346. CString cstr;
  347. cstr.LoadString(IDS_PERIOD_YEARS);
  348. iEntry = m_cboxDurationUnits.AddString(cstr);
  349. if (iEntry >= 0)
  350. m_cboxDurationUnits.SetItemData(iEntry, DURATION_INDEX_YEARS);
  351. cstr.LoadString(IDS_PERIOD_MONTHS);
  352. iEntry = m_cboxDurationUnits.AddString(cstr);
  353. if (iEntry >= 0)
  354. m_cboxDurationUnits.SetItemData(iEntry, DURATION_INDEX_MONTHS);
  355. cstr.LoadString(IDS_PERIOD_WEEKS);
  356. iEntry = m_cboxDurationUnits.AddString(cstr);
  357. if (iEntry >= 0)
  358. m_cboxDurationUnits.SetItemData(iEntry, DURATION_INDEX_WEEKS);
  359. cstr.LoadString(IDS_PERIOD_DAYS);
  360. iEntry = m_cboxDurationUnits.AddString(cstr);
  361. if (iEntry >= 0)
  362. m_cboxDurationUnits.SetItemData(iEntry, DURATION_INDEX_DAYS);
  363. //
  364. // use m_hCAInfo find out the initial durations times
  365. //
  366. CAGetCAExpiration(m_hCAInfo, &dwExpiration, &dwExpirationUnits);
  367. wsprintf(szNumberString, L"%u", dwExpiration);
  368. SetWindowText(GetDlgItem(m_hWnd, IDC_DURATION_EDIT), szNumberString);
  369. StringFromDurationUnit(dwExpirationUnits, &cstr, TRUE);
  370. m_cboxDurationUnits.SelectString(
  371. -1,
  372. cstr);
  373. UpdateData(FALSE);
  374. return TRUE;
  375. }
  376. void CPolicySettingsGeneralPage::OnDestroy()
  377. {
  378. // Note - This needs to be called only once.
  379. // If called more than once, it will gracefully return an error.
  380. if (m_hConsoleHandle)
  381. MMCFreeNotifyHandle(m_hConsoleHandle);
  382. m_hConsoleHandle = NULL;
  383. CAutoDeletePropPage::OnDestroy();
  384. }
  385. void CPolicySettingsGeneralPage::OnEditChange()
  386. {
  387. if (!m_bUpdate)
  388. {
  389. // Page is dirty, mark it.
  390. SetModified();
  391. m_bUpdate = TRUE;
  392. }
  393. }
  394. BOOL CPolicySettingsGeneralPage::OnApply()
  395. {
  396. HRESULT hr;
  397. CString szNumberString;
  398. LPSTR psz;
  399. DWORD dwExpiration;
  400. if (m_bUpdate == TRUE)
  401. {
  402. if (FALSE == szNumberString.FromWindow(GetDlgItem(m_hWnd, IDC_DURATION_EDIT)))
  403. return FALSE;
  404. psz = MyMkMBStr((LPCTSTR)szNumberString);
  405. if(psz == NULL)
  406. {
  407. return FALSE;
  408. }
  409. dwExpiration = atoi(psz);
  410. delete(psz);
  411. UINT iSel = m_cboxDurationUnits.GetCurSel();
  412. switch (m_cboxDurationUnits.GetItemData(iSel))
  413. {
  414. case DURATION_INDEX_DAYS:
  415. hr = CASetCAExpiration(m_hCAInfo, dwExpiration, CA_UNITS_DAYS);
  416. break;
  417. case DURATION_INDEX_WEEKS:
  418. hr = CASetCAExpiration(m_hCAInfo, dwExpiration, CA_UNITS_WEEKS);
  419. break;
  420. case DURATION_INDEX_MONTHS:
  421. hr = CASetCAExpiration(m_hCAInfo, dwExpiration, CA_UNITS_MONTHS);
  422. break;
  423. case DURATION_INDEX_YEARS:
  424. hr = CASetCAExpiration(m_hCAInfo, dwExpiration, CA_UNITS_YEARS);
  425. break;
  426. }
  427. hr = CAUpdateCA(m_hCAInfo);
  428. if (FAILED(hr))
  429. {
  430. MyErrorBox(m_hWnd, IDS_FAILED_CA_UPDATE ,IDS_SNAPIN_NAME, hr);
  431. return FALSE;
  432. }
  433. m_bUpdate = FALSE;
  434. }
  435. return CAutoDeletePropPage::OnApply();
  436. }
  437. /////////////////////////////////////////////////////////////////////////////
  438. // CGlobalCertTemplateCSPPage property page
  439. CGlobalCertTemplateCSPPage::CGlobalCertTemplateCSPPage(IGPEInformation * pGPTInformation, UINT uIDD)
  440. : CAutoDeletePropPage(uIDD), m_pGPTInformation(pGPTInformation)
  441. {
  442. m_hConsoleHandle = NULL;
  443. m_bUpdate = FALSE;
  444. }
  445. CGlobalCertTemplateCSPPage::~CGlobalCertTemplateCSPPage()
  446. {
  447. }
  448. // replacement for DoDataExchange
  449. BOOL CGlobalCertTemplateCSPPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  450. {
  451. if (fSuckFromDlg)
  452. {
  453. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  454. }
  455. else
  456. {
  457. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  458. }
  459. return TRUE;
  460. }
  461. // replacement for BEGIN_MESSAGE_MAP
  462. BOOL CGlobalCertTemplateCSPPage::OnCommand(WPARAM wParam, LPARAM lParam)
  463. {
  464. switch(LOWORD(wParam))
  465. {
  466. case IDC_ADDCSPS_BUTTON:
  467. if (HIWORD(wParam) == BN_CLICKED)
  468. {
  469. OnAddButton();
  470. break;
  471. }
  472. case IDC_REMOVECSPS_BUTTON:
  473. if (HIWORD(wParam) == BN_CLICKED)
  474. {
  475. OnRemoveButton();
  476. break;
  477. }
  478. default:
  479. return FALSE;
  480. break;
  481. }
  482. return TRUE;
  483. }
  484. BOOL CGlobalCertTemplateCSPPage::OnNotify(UINT idCtrl, NMHDR* pnmh)
  485. {
  486. switch(idCtrl)
  487. {
  488. case IDC_CSP_LIST:
  489. if (LVN_ITEMCHANGED == pnmh->code)
  490. {
  491. OnSelChange(pnmh);
  492. break;
  493. }
  494. default:
  495. return FALSE;
  496. }
  497. return TRUE;
  498. }
  499. /////////////////////////////////////////////////////////////////////////////
  500. // CGlobalCertTemplateCSPPage message handlers
  501. BOOL CGlobalCertTemplateCSPPage::OnInitDialog()
  502. {
  503. // does parent init and UpdateData call
  504. CAutoDeletePropPage::OnInitDialog();
  505. m_hwndCSPList = GetDlgItem(m_hWnd, IDC_CSP_LIST);
  506. HRESULT hr = S_OK;
  507. DWORD dwIndex = 0;
  508. DWORD dwFlags = 0;
  509. DWORD dwCharCount = 0;
  510. LPWSTR pwszProvName = NULL;
  511. LVCOLUMN lvcol;
  512. lvcol.mask = LVCF_FMT | LVCF_WIDTH;
  513. lvcol.fmt = LVCFMT_LEFT;
  514. lvcol.cx = 200;
  515. ListView_InsertColumn(m_hwndCSPList, 0, &lvcol);
  516. EnableWindow(GetDlgItem(m_hWnd, IDC_REMOVECSPS_BUTTON), FALSE);
  517. //
  518. // add the current default list
  519. //
  520. /* while (S_OK == (hr = CAEnumGPTGlobalProviders(m_pGPTInformation, dwIndex, &dwFlags, NULL, &dwCharCount)))
  521. {
  522. if (NULL == (pwszProvName = (LPWSTR) new(WCHAR[dwCharCount+1])))
  523. {
  524. break;
  525. }
  526. if (S_OK != (hr = CAEnumGPTGlobalProviders(m_pGPTInformation, dwIndex, &dwFlags, pwszProvName, &dwCharCount)))
  527. {
  528. delete[](pwszProvName);
  529. break;
  530. }
  531. ListView_NewItem(m_hwndCSPList, dwIndex, pwszProvName);
  532. //
  533. // setup for next pass
  534. //
  535. dwCharCount = 0;
  536. delete[](pwszProvName);
  537. pwszProvName = NULL;
  538. dwIndex++;
  539. } */
  540. ListView_SetColumnWidth(m_hwndCSPList, 0, LVSCW_AUTOSIZE);
  541. if (hr != S_OK)
  542. myDisplayError(m_hWnd, hr, -1);
  543. UpdateData(FALSE);
  544. return TRUE;
  545. }
  546. void CGlobalCertTemplateCSPPage::OnDestroy()
  547. {
  548. // Note - This needs to be called only once.
  549. // If called more than once, it will gracefully return an error.
  550. if (m_hConsoleHandle)
  551. MMCFreeNotifyHandle(m_hConsoleHandle);
  552. m_hConsoleHandle = NULL;
  553. CAutoDeletePropPage::OnDestroy();
  554. }
  555. BOOL CGlobalCertTemplateCSPPage::OnApply()
  556. {
  557. DWORD dwFlags = 0;
  558. DWORD dwCharCount = 0;
  559. LPWSTR pwszProvName = NULL;
  560. int i;
  561. CString szProvName;
  562. if (m_bUpdate == TRUE)
  563. {
  564. //
  565. // since there is really no good way to know which csps in the
  566. // list box aren't already in the global list, just delete all
  567. // csps in the global list and re-add all the ones in the list box
  568. //
  569. /* while (S_OK == CAEnumGPTGlobalProviders(m_pGPTInformation, 0, &dwFlags, NULL, &dwCharCount))
  570. {
  571. if (NULL == (pwszProvName = (LPWSTR) new(WCHAR[dwCharCount+1])))
  572. {
  573. break;
  574. }
  575. if (S_OK != CAEnumGPTGlobalProviders(m_pGPTInformation, 0, &dwFlags, pwszProvName, &dwCharCount))
  576. {
  577. delete[](pwszProvName);
  578. break;
  579. }
  580. CARemoveGPTGlobalProvider(m_pGPTInformation, pwszProvName);
  581. //
  582. // setup for next pass
  583. //
  584. dwCharCount = 0;
  585. delete[](pwszProvName);
  586. pwszProvName = NULL;
  587. } */
  588. int iListCount = ListView_GetItemCount(m_hwndCSPList);
  589. for (i=0; i<iListCount; i++)
  590. {
  591. ListView_GetItemText(m_hwndCSPList, i, 0, szProvName.GetBuffer(MAX_PATH), MAX_PATH*sizeof(WCHAR));
  592. // CAAddGPTGlobalProvider(m_pGPTInformation, 0, (LPWSTR) (LPCWSTR) szProvName);
  593. }
  594. GUID guidExtension = REGISTRY_EXTENSION_GUID;
  595. GUID guidSnapin = CLSID_CAPolicyExtensionSnapIn;
  596. m_pGPTInformation->PolicyChanged(TRUE, TRUE, &guidExtension, &guidSnapin);
  597. m_bUpdate = FALSE;
  598. }
  599. return CAutoDeletePropPage::OnApply();
  600. }
  601. BOOL CGlobalCertTemplateCSPPage::CSPDoesntExist(LPWSTR pwszCSPName)
  602. {
  603. LV_FINDINFO findInfo;
  604. findInfo.flags = LVFI_STRING;
  605. findInfo.psz = pwszCSPName;
  606. return ( ListView_FindItem(m_hwndCSPList, -1, &findInfo) == -1 );
  607. }
  608. void CGlobalCertTemplateCSPPage::OnAddButton()
  609. {
  610. DWORD dwProvIndex;
  611. //
  612. // enumerate all the CSPs on the machine, and if they are not
  613. // already in the list, then add them.
  614. //
  615. for (dwProvIndex = 0; TRUE; dwProvIndex++)
  616. {
  617. BOOL fResult;
  618. LPWSTR pwszProvName;
  619. DWORD cbProvName;
  620. HCRYPTPROV hProv;
  621. DWORD dwProvType;
  622. cbProvName = 0;
  623. dwProvType = 0;
  624. if (!CryptEnumProvidersW(
  625. dwProvIndex,
  626. NULL, // pdwReserved
  627. 0, // dwFlags
  628. &dwProvType,
  629. NULL, // pwszProvName,
  630. &cbProvName
  631. ) || 0 == cbProvName)
  632. {
  633. if (ERROR_NO_MORE_ITEMS != GetLastError())
  634. {
  635. // error
  636. }
  637. break;
  638. }
  639. if (NULL == (pwszProvName = (LPWSTR) new(WCHAR[cbProvName + 1])))
  640. {
  641. break;
  642. }
  643. if (!CryptEnumProvidersW(
  644. dwProvIndex,
  645. NULL, // pdwReserved
  646. 0, // dwFlags
  647. &dwProvType,
  648. pwszProvName,
  649. &cbProvName
  650. )) {
  651. delete[](pwszProvName);
  652. break;
  653. }
  654. if (CSPDoesntExist(pwszProvName))
  655. {
  656. ListView_NewItem(m_hwndCSPList, ListView_GetItemCount(m_hwndCSPList), pwszProvName);
  657. m_bUpdate = TRUE;
  658. SetModified();
  659. }
  660. delete[](pwszProvName);
  661. }
  662. ListView_SetColumnWidth(m_hwndCSPList, 0, LVSCW_AUTOSIZE);
  663. }
  664. void CGlobalCertTemplateCSPPage::OnRemoveButton()
  665. {
  666. int i;
  667. for (i=ListView_GetItemCount(m_hwndCSPList)-1; i>=0; i--)
  668. {
  669. if (ListView_GetItemState(m_hwndCSPList, i, LVIS_SELECTED) == LVIS_SELECTED)
  670. {
  671. ListView_DeleteItem(m_hwndCSPList, i);
  672. m_bUpdate = TRUE;
  673. SetModified();
  674. }
  675. }
  676. EnableWindow(GetDlgItem(m_hWnd, IDC_REMOVECSPS_BUTTON), FALSE);
  677. }
  678. void CGlobalCertTemplateCSPPage::OnSelChange(NMHDR * pNotifyStruct)
  679. {
  680. BOOL fEmpty = (ListView_GetSelectedCount(m_hwndCSPList) == 0);
  681. EnableWindow(GetDlgItem(m_hWnd, IDC_REMOVECSPS_BUTTON), !fEmpty);
  682. }
  683. ///////////////////////////////////////////
  684. // CCertTemplateGeneralPage
  685. /////////////////////////////////////////////////////////////////////////////
  686. // CCertTemplateGeneralPage property page
  687. CCertTemplateGeneralPage::CCertTemplateGeneralPage(HCERTTYPE hCertType, UINT uIDD)
  688. : CAutoDeletePropPage(uIDD), m_hCertType(hCertType)
  689. {
  690. m_hConsoleHandle = NULL;
  691. m_bUpdate = FALSE;
  692. SetHelp(CAPESNPN_HELPFILENAME , g_aHelpIDs_IDD_CERTIFICATE_TEMPLATE_PROPERTIES_GENERAL_PAGE);
  693. }
  694. CCertTemplateGeneralPage::~CCertTemplateGeneralPage()
  695. {
  696. }
  697. // replacement for DoDataExchange
  698. BOOL CCertTemplateGeneralPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  699. {
  700. if (fSuckFromDlg)
  701. {
  702. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  703. }
  704. else
  705. {
  706. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  707. }
  708. return TRUE;
  709. }
  710. // replacement for BEGIN_MESSAGE_MAP
  711. BOOL CCertTemplateGeneralPage::OnCommand(WPARAM wParam, LPARAM lParam)
  712. {
  713. /*
  714. switch(LOWORD(wParam))
  715. {
  716. default:
  717. return FALSE;
  718. break;
  719. }
  720. */
  721. return TRUE;
  722. }
  723. /////////////////////////////////////////////////////////////////////////////
  724. // CCertTemplateGeneralPage message handlers
  725. void CCertTemplateGeneralPage::OnDestroy()
  726. {
  727. // Note - This needs to be called only once.
  728. // If called more than once, it will gracefully return an error.
  729. if (m_hConsoleHandle)
  730. MMCFreeNotifyHandle(m_hConsoleHandle);
  731. m_hConsoleHandle = NULL;
  732. CAutoDeletePropPage::OnDestroy();
  733. }
  734. void CCertTemplateGeneralPage::SetItemTextWrapper(UINT nID, int *piItem, BOOL fDoInsert, BOOL *pfFirstUsageItem)
  735. {
  736. CString szOtherInfoName;
  737. if (fDoInsert)
  738. {
  739. szOtherInfoName.LoadString(nID);
  740. if (!(*pfFirstUsageItem))
  741. {
  742. ListView_NewItem(m_hwndOtherInfoList, *piItem, L"");
  743. }
  744. else
  745. {
  746. *pfFirstUsageItem = FALSE;
  747. }
  748. ListView_SetItemText(m_hwndOtherInfoList, *piItem, 1, (LPWSTR)(LPCWSTR)szOtherInfoName);
  749. (*piItem)++;
  750. }
  751. }
  752. BOOL CCertTemplateGeneralPage::OnInitDialog()
  753. {
  754. // does parent init and UpdateData call
  755. CAutoDeletePropPage::OnInitDialog();
  756. m_hwndPurposesList = GetDlgItem(m_hWnd, IDC_PURPOSE_LIST);
  757. m_hwndOtherInfoList = GetDlgItem(m_hWnd, IDC_OTHER_INFO_LIST);
  758. int i=0;
  759. CString **aszUsages = NULL;
  760. DWORD cNumUsages;
  761. WCHAR **pszNameArray = NULL;
  762. CString szOtherInfoName;
  763. CRYPT_BIT_BLOB *pBitBlob;
  764. BOOL fPublicKeyUsageCritical;
  765. BOOL bKeyUsageFirstItem = TRUE;
  766. BOOL fCA;
  767. BOOL fPathLenConstraint;
  768. DWORD dwPathLenConstraint;
  769. WCHAR szNumberString[256];
  770. CString szAll;
  771. BOOL fEKUCritical;
  772. DWORD dwFlags;
  773. HRESULT hr;
  774. //
  775. // get the name of the certificate template and set it in the dialog
  776. //
  777. if((S_OK == CAGetCertTypeProperty(m_hCertType, CERTTYPE_PROP_FRIENDLY_NAME, &pszNameArray)) &&
  778. (pszNameArray != NULL))
  779. {
  780. SendMessage(GetDlgItem(m_hWnd, IDC_CERTIFICATE_TEMPLATE_NAME), EM_SETSEL, 0, -1);
  781. SendMessage(GetDlgItem(m_hWnd, IDC_CERTIFICATE_TEMPLATE_NAME), EM_REPLACESEL, FALSE, (LPARAM)(LPCWSTR)pszNameArray[0]);
  782. CAFreeCertTypeProperty(m_hCertType, pszNameArray);
  783. }
  784. //
  785. // get the list of purposes for this certificate template and
  786. // add all of them to the list in the dialog
  787. //
  788. ListView_NewColumn(m_hwndPurposesList, 0, 200);
  789. if(!MyGetEnhancedKeyUsages(m_hCertType, NULL, &cNumUsages, &fEKUCritical, FALSE))
  790. {
  791. return FALSE;
  792. }
  793. if (cNumUsages == 0)
  794. {
  795. szAll.LoadString(IDS_ALL);
  796. ListView_NewItem(m_hwndPurposesList, i, szAll);
  797. }
  798. else
  799. {
  800. aszUsages = new CString*[cNumUsages];
  801. if(!aszUsages)
  802. return FALSE;
  803. if(!MyGetEnhancedKeyUsages(m_hCertType, aszUsages, &cNumUsages, &fEKUCritical, FALSE))
  804. {
  805. delete[] aszUsages;
  806. return FALSE;
  807. }
  808. for (i=0; i<(LONG)cNumUsages; i++)
  809. {
  810. ListView_NewItem(m_hwndPurposesList, i, *(aszUsages[i]));
  811. delete(aszUsages[i]);
  812. }
  813. delete[] aszUsages;
  814. }
  815. ListView_SetColumnWidth(m_hwndPurposesList, 0, LVSCW_AUTOSIZE);
  816. //
  817. // add the other certificate type info
  818. //
  819. ListView_NewColumn(m_hwndOtherInfoList, 0, 200);
  820. ListView_NewColumn(m_hwndOtherInfoList, 1, 200);
  821. //
  822. // add include email address flag to other certificate type info
  823. //
  824. szOtherInfoName.LoadString(IDS_INCLUDE_EMAIL_ADDRESS);
  825. i = 0;
  826. ListView_NewItem(m_hwndOtherInfoList, i, szOtherInfoName);
  827. hr = CAGetCertTypeFlags(m_hCertType, &dwFlags);
  828. if (FAILED(hr))
  829. {
  830. return FALSE;
  831. }
  832. if (dwFlags & CT_FLAG_ADD_EMAIL)
  833. szOtherInfoName.LoadString(IDS_YES);
  834. else
  835. szOtherInfoName.LoadString(IDS_NO);
  836. ListView_SetItemText(m_hwndOtherInfoList, i++, 1, (LPWSTR)(LPCWSTR)szOtherInfoName);
  837. //
  838. // add key usages to other certificate type info
  839. //
  840. if (MyGetKeyUsages(m_hCertType, &pBitBlob, &fPublicKeyUsageCritical))
  841. {
  842. szOtherInfoName.LoadString(IDS_PUBLIC_KEY_USAGE_LIST);
  843. ListView_NewItem(m_hwndOtherInfoList, i, szOtherInfoName);
  844. if (pBitBlob->cbData >= 1)
  845. {
  846. SetItemTextWrapper(
  847. IDS_DIGITAL_SIGNATURE_KEY_USAGE,
  848. &i,
  849. pBitBlob->pbData[0] & CERT_DIGITAL_SIGNATURE_KEY_USAGE,
  850. &bKeyUsageFirstItem);
  851. SetItemTextWrapper(
  852. IDS_NON_REPUDIATION_KEY_USAGE,
  853. &i,
  854. pBitBlob->pbData[0] & CERT_NON_REPUDIATION_KEY_USAGE,
  855. &bKeyUsageFirstItem);
  856. SetItemTextWrapper(
  857. IDS_KEY_ENCIPHERMENT_KEY_USAGE,
  858. &i,
  859. pBitBlob->pbData[0] & CERT_KEY_ENCIPHERMENT_KEY_USAGE,
  860. &bKeyUsageFirstItem);
  861. SetItemTextWrapper(
  862. IDS_DATA_ENCIPHERMENT_KEY_USAGE,
  863. &i,
  864. pBitBlob->pbData[0] & CERT_DATA_ENCIPHERMENT_KEY_USAGE,
  865. &bKeyUsageFirstItem);
  866. SetItemTextWrapper(
  867. IDS_KEY_AGREEMENT_KEY_USAGE,
  868. &i,
  869. pBitBlob->pbData[0] & CERT_KEY_AGREEMENT_KEY_USAGE,
  870. &bKeyUsageFirstItem);
  871. SetItemTextWrapper(
  872. IDS_KEY_CERT_SIGN_KEY_USAGE,
  873. &i,
  874. pBitBlob->pbData[0] & CERT_KEY_CERT_SIGN_KEY_USAGE,
  875. &bKeyUsageFirstItem);
  876. SetItemTextWrapper(
  877. IDS_OFFLINE_CRL_SIGN_KEY_USAGE,
  878. &i,
  879. pBitBlob->pbData[0] & CERT_OFFLINE_CRL_SIGN_KEY_USAGE,
  880. &bKeyUsageFirstItem);
  881. SetItemTextWrapper(
  882. IDS_ENCIPHER_ONLY_KEY_USAGE,
  883. &i,
  884. pBitBlob->pbData[0] & CERT_ENCIPHER_ONLY_KEY_USAGE,
  885. &bKeyUsageFirstItem);
  886. }
  887. if (pBitBlob->cbData >= 2)
  888. {
  889. SetItemTextWrapper(
  890. IDS_DECIPHER_ONLY_KEY_USAGE,
  891. &i,
  892. pBitBlob->pbData[1] & CERT_DECIPHER_ONLY_KEY_USAGE,
  893. &bKeyUsageFirstItem);
  894. }
  895. szOtherInfoName.LoadString(IDS_PUBLIC_KEY_USAGE_CRITICAL);
  896. ListView_NewItem(m_hwndOtherInfoList, i, szOtherInfoName);
  897. if (fPublicKeyUsageCritical)
  898. szOtherInfoName.LoadString(IDS_YES);
  899. else
  900. szOtherInfoName.LoadString(IDS_NO);
  901. ListView_SetItemText(m_hwndOtherInfoList, i++, 1, (LPWSTR)(LPCWSTR)szOtherInfoName);
  902. delete[]((BYTE *)pBitBlob);
  903. }
  904. //
  905. // maybe we should add a display of whether this is a ca cert or not
  906. //
  907. /*
  908. if (MyGetBasicConstraintInfo(m_hCertType, &fCA, &fPathLenConstraint, &dwPathLenConstraint))
  909. {
  910. }
  911. */
  912. ListView_SetColumnWidth(m_hwndOtherInfoList, 0, LVSCW_AUTOSIZE);
  913. ListView_SetColumnWidth(m_hwndOtherInfoList, 1, LVSCW_AUTOSIZE);
  914. return TRUE;
  915. }
  916. BOOL CCertTemplateGeneralPage::OnApply()
  917. {
  918. DWORD dwRet;
  919. if (m_bUpdate == TRUE)
  920. {
  921. m_bUpdate = FALSE;
  922. }
  923. return CAutoDeletePropPage::OnApply();
  924. }
  925. /////////////////////////////////////////////////////////////////////////////
  926. // CCertTemplateSelectDialog property page
  927. CCertTemplateSelectDialog::CCertTemplateSelectDialog(HWND hParent) :
  928. m_hCAInfo(NULL)
  929. {
  930. SetHelp(CAPESNPN_HELPFILENAME , g_aHelpIDs_IDD_SELECT_CERTIFICATE_TEMPLATE);
  931. }
  932. CCertTemplateSelectDialog::~CCertTemplateSelectDialog()
  933. {
  934. }
  935. // replacement for DoDataExchange
  936. BOOL CCertTemplateSelectDialog::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  937. {
  938. if (fSuckFromDlg)
  939. {
  940. // m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  941. }
  942. else
  943. {
  944. // m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  945. }
  946. return TRUE;
  947. }
  948. // replacement for BEGIN_MESSAGE_MAP
  949. BOOL CCertTemplateSelectDialog::OnCommand(WPARAM wParam, LPARAM lParam)
  950. {
  951. /*
  952. switch(LOWORD(wParam))
  953. {
  954. default:
  955. return FALSE;
  956. break;
  957. }
  958. */
  959. return TRUE;
  960. }
  961. BOOL CCertTemplateSelectDialog::OnNotify(UINT idCtrl, NMHDR* pnmh)
  962. {
  963. switch(idCtrl)
  964. {
  965. case IDC_CERTIFICATE_TYPE_LIST:
  966. if (LVN_ITEMCHANGED == pnmh->code)
  967. {
  968. OnSelChange(pnmh);
  969. break;
  970. }
  971. else if (NM_DBLCLK == pnmh->code)
  972. {
  973. SendMessage(m_hDlg, WM_COMMAND, IDOK, NULL);
  974. break;
  975. }
  976. default:
  977. return FALSE;
  978. }
  979. return TRUE;
  980. }
  981. BOOL CertTypeAlreadyExists(WCHAR *szCertTypeName, WCHAR **aszCertTypesCurrentlySupported)
  982. {
  983. int i = 0;
  984. //
  985. // if there are no cert types then obvisously this one doesn't already exist
  986. //
  987. if (aszCertTypesCurrentlySupported == NULL)
  988. {
  989. return FALSE;
  990. }
  991. while (aszCertTypesCurrentlySupported[i] != NULL)
  992. {
  993. if (wcscmp(szCertTypeName, aszCertTypesCurrentlySupported[i]) == 0)
  994. {
  995. return TRUE;
  996. }
  997. i++;
  998. }
  999. return FALSE;
  1000. }
  1001. /////////////////////////////////////////////////////////////////////
  1002. void CCertTemplateSelectDialog::SetHelp(LPCTSTR szHelpFile, const DWORD rgzHelpIDs[])
  1003. {
  1004. //szHelpFile == NULL; // TRUE => No help file supplied (meaning no help)
  1005. //rgzHelpIDs == NULL; // TRUE => No help at all
  1006. m_strHelpFile = szHelpFile;
  1007. m_prgzHelpIDs = rgzHelpIDs;
  1008. }
  1009. /////////////////////////////////////////////////////////////////////
  1010. void CCertTemplateSelectDialog::OnContextHelp(HWND hwnd)
  1011. {
  1012. if (m_prgzHelpIDs == NULL || m_strHelpFile.IsEmpty())
  1013. return;
  1014. ASSERT(IsWindow(hwnd));
  1015. ::WinHelp(hwnd, m_strHelpFile, HELP_CONTEXTMENU, (ULONG_PTR)(LPVOID)m_prgzHelpIDs);
  1016. return;
  1017. }
  1018. /////////////////////////////////////////////////////////////////////
  1019. void CCertTemplateSelectDialog::OnHelp(LPHELPINFO pHelpInfo)
  1020. {
  1021. if (m_prgzHelpIDs == NULL || m_strHelpFile.IsEmpty())
  1022. return;
  1023. if (pHelpInfo != NULL && pHelpInfo->iContextType == HELPINFO_WINDOW)
  1024. {
  1025. // Display context help for a control
  1026. ::WinHelp((HWND)pHelpInfo->hItemHandle, m_strHelpFile,
  1027. HELP_WM_HELP, (ULONG_PTR)(LPVOID)m_prgzHelpIDs);
  1028. }
  1029. return;
  1030. }
  1031. int CALLBACK CertTemplCompareFunc(
  1032. LPARAM lParam1,
  1033. LPARAM lParam2,
  1034. LPARAM lParamSort)
  1035. {
  1036. BOOL fSortAscending = (BOOL)lParamSort;
  1037. HCERTTYPE hCertTypeLeft = (HCERTTYPE)lParam1;
  1038. HCERTTYPE hCertTypeRight = (HCERTTYPE)lParam2;
  1039. WCHAR ** ppwszFriendlyNameLeft = NULL;
  1040. WCHAR ** ppwszFriendlyNameRight = NULL;
  1041. int nRet;
  1042. CAGetCertTypeProperty(
  1043. hCertTypeLeft,
  1044. CERTTYPE_PROP_FRIENDLY_NAME,
  1045. &ppwszFriendlyNameLeft);
  1046. CAGetCertTypeProperty(
  1047. hCertTypeRight,
  1048. CERTTYPE_PROP_FRIENDLY_NAME,
  1049. &ppwszFriendlyNameRight);
  1050. if(!ppwszFriendlyNameLeft ||
  1051. !ppwszFriendlyNameLeft[0] ||
  1052. !ppwszFriendlyNameRight ||
  1053. !ppwszFriendlyNameRight[0])
  1054. return 0; // couldn't figure it out
  1055. nRet = wcscmp(ppwszFriendlyNameLeft[0], ppwszFriendlyNameRight[0]);
  1056. CAFreeCertTypeProperty(
  1057. hCertTypeLeft,
  1058. ppwszFriendlyNameLeft);
  1059. CAFreeCertTypeProperty(
  1060. hCertTypeRight,
  1061. ppwszFriendlyNameRight);
  1062. return nRet;
  1063. }
  1064. /////////////////////////////////////////////////////////////////////////////
  1065. // CCertTemplateSelectDialog message handlers
  1066. BOOL CCertTemplateSelectDialog::OnInitDialog(HWND hDlg)
  1067. {
  1068. // does parent init and UpdateData call
  1069. m_hwndCertTypeList = GetDlgItem(hDlg, IDC_CERTIFICATE_TYPE_LIST);
  1070. CString szColumnHeading;
  1071. HRESULT hr;
  1072. HCERTTYPE hCertTypeNext;
  1073. HCERTTYPE hCertTypePrev;
  1074. WCHAR ** aszCertTypeName;
  1075. WCHAR ** aszCertTypeCN;
  1076. int i = 0;
  1077. CString szUsageString;
  1078. DWORD dwVersion;
  1079. m_hDlg = hDlg;
  1080. ::SetWindowLong(m_hDlg, GWL_EXSTYLE, ::GetWindowLong(m_hDlg, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
  1081. hr = RetrieveCATemplateList(
  1082. m_hCAInfo,
  1083. m_TemplateList);
  1084. if(S_OK != hr)
  1085. {
  1086. myDisplayError(hDlg, hr, IDS_CERTTYPE_INFO_FAIL);
  1087. return TRUE;
  1088. }
  1089. HIMAGELIST hImgList = ImageList_LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_16x16), 16, 1, RGB(255, 0, 255));
  1090. ListView_SetImageList(m_hwndCertTypeList, hImgList, LVSIL_SMALL);
  1091. szColumnHeading.LoadString(IDS_COLUMN_NAME);
  1092. ListView_NewColumn(m_hwndCertTypeList, 0, 200, szColumnHeading);
  1093. szColumnHeading.LoadString(IDS_COLUMN_INTENDED_PURPOSE);
  1094. ListView_NewColumn(m_hwndCertTypeList, 1, 200, szColumnHeading);
  1095. hr = CAEnumCertTypes(CT_ENUM_USER_TYPES |
  1096. CT_ENUM_MACHINE_TYPES |
  1097. CT_FLAG_NO_CACHE_LOOKUP,
  1098. &hCertTypeNext
  1099. );
  1100. // display error in getting 1st element
  1101. if (hr != S_OK)
  1102. {
  1103. myDisplayError(hDlg, hr, -1);
  1104. }
  1105. else if (hCertTypeNext == NULL)
  1106. {
  1107. myDisplayError(hDlg, S_OK, IDS_NO_TEMPLATES);
  1108. }
  1109. while ((hCertTypeNext != NULL) && (!FAILED(hr)))
  1110. {
  1111. //
  1112. // get the CN of the cert type being processed, and if it already
  1113. // exists in the list of currently supported types then move on
  1114. // to the next one
  1115. //
  1116. hr = CAGetCertTypeProperty(
  1117. hCertTypeNext,
  1118. CERTTYPE_PROP_DN,
  1119. &aszCertTypeCN);
  1120. if(hr == S_OK)
  1121. {
  1122. hr = CAGetCertTypePropertyEx (
  1123. hCertTypeNext,
  1124. CERTTYPE_PROP_SCHEMA_VERSION,
  1125. &dwVersion);
  1126. if(S_OK == hr &&
  1127. (m_fAdvancedServer || dwVersion==CERTTYPE_SCHEMA_VERSION_1))
  1128. {
  1129. if((aszCertTypeCN != NULL) &&
  1130. (aszCertTypeCN[0] != NULL) &&
  1131. (_wcsicmp(aszCertTypeCN[0], wszCERTTYPE_CA) != 0) &&
  1132. (!m_TemplateList.TemplateExistsName(aszCertTypeCN[0])))
  1133. {
  1134. //
  1135. // the cert type is not already supported so add it to the list of choices
  1136. //
  1137. CAGetCertTypeProperty(
  1138. hCertTypeNext,
  1139. CERTTYPE_PROP_FRIENDLY_NAME,
  1140. &aszCertTypeName);
  1141. GetIntendedUsagesString(hCertTypeNext, &szUsageString);
  1142. if (szUsageString == L"")
  1143. {
  1144. szUsageString.LoadString(IDS_ALL);
  1145. }
  1146. LVITEM lvItem;
  1147. lvItem.mask = LVIF_IMAGE | LVIF_TEXT;
  1148. lvItem.iImage = 2; // nImage - the certificate template image is #2
  1149. lvItem.iSubItem = 0;
  1150. lvItem.pszText = aszCertTypeName[0];
  1151. lvItem.iItem = ListView_NewItem(m_hwndCertTypeList, i, aszCertTypeName[0], (LPARAM)hCertTypeNext);
  1152. ListView_SetItem(m_hwndCertTypeList, &lvItem); // set other attribs
  1153. ListView_SetItemText(m_hwndCertTypeList, i++, 1, (LPWSTR)(LPCTSTR)szUsageString);
  1154. CAFreeCertTypeProperty(
  1155. hCertTypeNext,
  1156. aszCertTypeName);
  1157. }
  1158. }
  1159. CAFreeCertTypeProperty(
  1160. hCertTypeNext,
  1161. aszCertTypeCN);
  1162. }
  1163. hCertTypePrev = hCertTypeNext;
  1164. hCertTypeNext = NULL;
  1165. hr = CAEnumNextCertType(hCertTypePrev, &hCertTypeNext);
  1166. }
  1167. ListView_SetColumnWidth(m_hwndCertTypeList, 0, LVSCW_AUTOSIZE);
  1168. ListView_SetColumnWidth(m_hwndCertTypeList, 1, LVSCW_AUTOSIZE);
  1169. ListView_SortItems(m_hwndCertTypeList, CertTemplCompareFunc, TRUE);
  1170. UpdateData(FALSE);
  1171. return TRUE;
  1172. }
  1173. void CCertTemplateSelectDialog::OnDestroy()
  1174. {
  1175. int i = 0;
  1176. int iCount = ListView_GetItemCount(m_hwndCertTypeList);
  1177. for (i=0; i<iCount; i++)
  1178. {
  1179. HCERTTYPE hCT = (HCERTTYPE)ListView_GetItemData(m_hwndCertTypeList, i);
  1180. CACloseCertType(hCT);
  1181. }
  1182. //
  1183. // does this actually need to be done?
  1184. //
  1185. //(m_CertTypeCListCtrl.GetImageList(LVSIL_SMALL))->DeleteImageList();
  1186. }
  1187. void CCertTemplateSelectDialog::OnSelChange(NMHDR * pNotifyStruct/*, LRESULT * result*/)
  1188. {
  1189. LPNMLISTVIEW pListItem = (LPNMLISTVIEW) pNotifyStruct;
  1190. if (pListItem->uNewState & LVIS_SELECTED)
  1191. {
  1192. }
  1193. }
  1194. void CCertTemplateSelectDialog::OnOK()
  1195. {
  1196. int i;
  1197. HRESULT hr;
  1198. UINT cSelectedItems;
  1199. HCERTTYPE hSelectedCertType;
  1200. int itemIndex;
  1201. cSelectedItems = ListView_GetSelectedCount(m_hwndCertTypeList);
  1202. if (cSelectedItems != 0)
  1203. {
  1204. //
  1205. // get each selected item and add its cert type to the array
  1206. //
  1207. itemIndex = ListView_GetNextItem(m_hwndCertTypeList, -1, LVNI_ALL | LVNI_SELECTED);
  1208. while (itemIndex != -1)
  1209. {
  1210. HCERTTYPE hCT = (HCERTTYPE)ListView_GetItemData(m_hwndCertTypeList, itemIndex);
  1211. hr = AddToCATemplateList(m_hCAInfo, m_TemplateList, hCT);
  1212. if(FAILED(hr))
  1213. return;
  1214. itemIndex = ListView_GetNextItem(m_hwndCertTypeList, itemIndex, LVNI_ALL | LVNI_SELECTED);
  1215. }
  1216. hr = UpdateCATemplateList(m_hCAInfo, m_TemplateList);
  1217. if (FAILED(hr))
  1218. {
  1219. MyErrorBox(m_hDlg, IDS_FAILED_CA_UPDATE ,IDS_SNAPIN_NAME, hr);
  1220. // Set the old values back.
  1221. itemIndex = ListView_GetNextItem(m_hwndCertTypeList, -1, LVNI_ALL | LVNI_SELECTED);
  1222. while (itemIndex != -1)
  1223. {
  1224. HCERTTYPE hCT = (HCERTTYPE)ListView_GetItemData(m_hwndCertTypeList, itemIndex);
  1225. RemoveFromCATemplateList(m_hCAInfo, m_TemplateList, hCT);
  1226. itemIndex = ListView_GetNextItem(m_hwndCertTypeList, itemIndex, LVNI_ALL | LVNI_SELECTED);
  1227. }
  1228. }
  1229. }
  1230. }
  1231. void CCertTemplateSelectDialog::SetCA(HCAINFO hCAInfo, bool fAdvancedServer)
  1232. {
  1233. m_hCAInfo = hCAInfo;
  1234. m_fAdvancedServer = fAdvancedServer;
  1235. }
  1236. INT_PTR SelectCertTemplateDialogProc(
  1237. HWND hwndDlg,
  1238. UINT uMsg,
  1239. WPARAM wParam,
  1240. LPARAM lParam)
  1241. {
  1242. CCertTemplateSelectDialog* pParam;
  1243. switch(uMsg)
  1244. {
  1245. case WM_INITDIALOG:
  1246. {
  1247. // remember PRIVATE_DLGPROC_QUERY_LPARAM
  1248. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  1249. pParam = (CCertTemplateSelectDialog*)lParam;
  1250. return pParam->OnInitDialog(hwndDlg);
  1251. break;
  1252. }
  1253. case WM_COMMAND:
  1254. switch (LOWORD(wParam))
  1255. {
  1256. case IDOK:
  1257. pParam = (CCertTemplateSelectDialog*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  1258. if (pParam == NULL)
  1259. break;
  1260. pParam->OnOK();
  1261. EndDialog(hwndDlg, LOWORD(wParam));
  1262. break;
  1263. case IDCANCEL:
  1264. pParam = (CCertTemplateSelectDialog*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  1265. if (pParam == NULL)
  1266. break;
  1267. //pParam->OnCancel();
  1268. EndDialog(hwndDlg, LOWORD(wParam));
  1269. break;
  1270. default:
  1271. pParam = (CCertTemplateSelectDialog*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  1272. if (pParam == NULL)
  1273. break;
  1274. return pParam->OnCommand(wParam, lParam);
  1275. break;
  1276. }
  1277. case WM_NOTIFY:
  1278. pParam = (CCertTemplateSelectDialog*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  1279. if (pParam == NULL)
  1280. break;
  1281. return pParam->OnNotify((int)wParam, (NMHDR*)lParam);
  1282. break;
  1283. case WM_DESTROY:
  1284. pParam = (CCertTemplateSelectDialog*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  1285. if (pParam == NULL)
  1286. break;
  1287. pParam->OnDestroy();
  1288. break;
  1289. case WM_HELP:
  1290. {
  1291. pParam = (CCertTemplateSelectDialog*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  1292. if (pParam == NULL)
  1293. break;
  1294. pParam->OnHelp((LPHELPINFO) lParam);
  1295. break;
  1296. }
  1297. case WM_CONTEXTMENU:
  1298. {
  1299. pParam = (CCertTemplateSelectDialog*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  1300. if (pParam == NULL)
  1301. break;
  1302. pParam->OnContextHelp((HWND)wParam);
  1303. break;
  1304. }
  1305. default:
  1306. break;
  1307. }
  1308. return 0;
  1309. }