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.

9476 lines
269 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: genpage.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "resource.h"
  12. #include "genpage.h"
  13. #include "progress.h"
  14. #include "certsrv.h"
  15. #include "csdisp.h"
  16. //#include "misc.h"
  17. #include "certca.h"
  18. #include <cryptui.h>
  19. #include "csmmchlp.h"
  20. #include "cslistvw.h"
  21. #include "certmsg.h"
  22. #include "urls.h"
  23. #include "certsrvd.h"
  24. #include "certsd.h"
  25. #include "setupids.h"
  26. #include <objsel.h>
  27. #define __dwFILE__ __dwFILE_CERTMMC_GENPAGE_CPP__
  28. #ifdef _DEBUG
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. CString CSvrSettingsCertManagersPage::m_strButtonAllow;
  33. CString CSvrSettingsCertManagersPage::m_strButtonDeny;
  34. CString CSvrSettingsCertManagersPage::m_strTextAllow;
  35. CString CSvrSettingsCertManagersPage::m_strTextDeny;
  36. UINT g_aidFont[] =
  37. {
  38. IDS_LARGEFONTNAME,
  39. IDS_LARGEFONTSIZE,
  40. IDS_SMALLFONTNAME,
  41. IDS_SMALLFONTSIZE,
  42. };
  43. // forwards
  44. BOOL
  45. BrowseForDirectory(
  46. HWND hwndParent,
  47. LPCTSTR pszInitialDir,
  48. LPTSTR pszBuf,
  49. int cchBuf,
  50. LPCTSTR pszDialogTitle);
  51. HRESULT GetPolicyManageDispatch(
  52. LPCWSTR pcwszProgID,
  53. REFCLSID clsidModule,
  54. DISPATCHINTERFACE* pdi);
  55. HRESULT GetExitManageDispatch(
  56. LPCWSTR pcwszProgID,
  57. REFCLSID clsidModule,
  58. DISPATCHINTERFACE* pdi);
  59. HRESULT ThunkServerCallbacks(CertSvrCA* pCA);
  60. INT_PTR CALLBACK dlgProcChooseModule(
  61. HWND hwndDlg,
  62. UINT uMsg,
  63. WPARAM wParam,
  64. LPARAM lParam );
  65. INT_PTR CALLBACK dlgProcTimer(
  66. HWND hwndDlg,
  67. UINT uMsg,
  68. WPARAM wParam,
  69. LPARAM lParam );
  70. INT_PTR CALLBACK dlgProcQuery(
  71. HWND hwndDlg,
  72. UINT uMsg,
  73. WPARAM wParam,
  74. LPARAM lParam );
  75. INT_PTR CALLBACK dlgProcAddRestriction(
  76. HWND hwndDlg,
  77. UINT uMsg,
  78. WPARAM wParam,
  79. LPARAM lParam );
  80. INT_PTR CALLBACK dlgProcRenewReuseKeys(
  81. HWND hwndDlg,
  82. UINT uMsg,
  83. WPARAM wParam,
  84. LPARAM lParam );
  85. // Base/Delta CRL publish chooser
  86. INT_PTR CALLBACK dlgProcRevocationPublishType(
  87. HWND hwndDlg,
  88. UINT uMsg,
  89. WPARAM wParam,
  90. LPARAM lParam );
  91. #define CERTMMC_HELPFILENAME L"Certmmc.hlp"
  92. //////////////////////////////
  93. // hand-hewn pages
  94. ////
  95. // 1
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CSvrSettingsGeneralPage property page
  98. CSvrSettingsGeneralPage::CSvrSettingsGeneralPage(CertSvrCA* pCA, UINT uIDD)
  99. : CAutoDeletePropPage(uIDD), m_pCA(pCA)
  100. {
  101. m_cstrCAName = _T("");
  102. m_cstrDescription = _T("");
  103. m_cstrProvName = _T("");
  104. m_cstrHashAlg = _T("");
  105. m_hConsoleHandle = NULL;
  106. m_bUpdate = FALSE;
  107. m_fRestartServer = FALSE;
  108. m_wRestart = 0;
  109. m_fWin2kCA = FALSE;
  110. CSASSERT(m_pCA);
  111. if (NULL == m_pCA)
  112. return;
  113. // add reference to m_pParentMachine
  114. // At one time, MMC didn't protect us from
  115. // going away while proppages were open
  116. m_pCA->m_pParentMachine->AddRef();
  117. m_pReleaseMe = NULL;
  118. m_cstrCAName = m_pCA->m_strCommonName;
  119. m_cstrDescription = m_pCA->m_strComment;
  120. m_pAdmin = NULL;
  121. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTSRV_PROPPAGE1);
  122. }
  123. CSvrSettingsGeneralPage::~CSvrSettingsGeneralPage()
  124. {
  125. if(m_pAdmin)
  126. {
  127. m_pAdmin->Release();
  128. m_pAdmin = NULL;
  129. }
  130. if(m_pCA->m_pParentMachine)
  131. {
  132. // remove refcount from m_pParentMachine
  133. m_pCA->m_pParentMachine->Release();
  134. }
  135. if (m_pReleaseMe)
  136. {
  137. m_pReleaseMe->Release();
  138. m_pReleaseMe = NULL;
  139. }
  140. }
  141. // replacement for DoDataExchange
  142. BOOL CSvrSettingsGeneralPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  143. {
  144. if (fSuckFromDlg)
  145. {
  146. m_cstrCAName.FromWindow(GetDlgItem(m_hWnd, IDC_CANAME));
  147. m_cstrDescription.FromWindow(GetDlgItem(m_hWnd, IDC_DESCRIPTION));
  148. m_cstrProvName.FromWindow(GetDlgItem(m_hWnd, IDC_CSP_NAME));
  149. m_cstrHashAlg.FromWindow(GetDlgItem(m_hWnd, IDC_HASHALG));
  150. }
  151. else
  152. {
  153. m_cstrCAName.ToWindow(GetDlgItem(m_hWnd, IDC_CANAME));
  154. m_cstrDescription.ToWindow(GetDlgItem(m_hWnd, IDC_DESCRIPTION));
  155. m_cstrProvName.ToWindow(GetDlgItem(m_hWnd, IDC_CSP_NAME));
  156. m_cstrHashAlg.ToWindow(GetDlgItem(m_hWnd, IDC_HASHALG));
  157. }
  158. return TRUE;
  159. }
  160. // replacement for BEGIN_MESSAGE_MAP
  161. BOOL CSvrSettingsGeneralPage::OnCommand(WPARAM wParam, LPARAM lParam)
  162. {
  163. switch(LOWORD(wParam))
  164. {
  165. case IDC_VIEW_CERT:
  166. if (BN_CLICKED == HIWORD(wParam))
  167. OnViewCert((HWND)lParam);
  168. break;
  169. default:
  170. return FALSE;
  171. break;
  172. }
  173. return TRUE;
  174. }
  175. /////////////////////////////////////////////////////////////////////////////
  176. // CSvrSettingsGeneralPage message handlers
  177. BOOL CSvrSettingsGeneralPage::OnInitDialog()
  178. {
  179. // does parent init and UpdateData call
  180. CAutoDeletePropPage::OnInitDialog();
  181. DWORD dwProvType, dwHashAlg;
  182. DWORD dwRet;
  183. BOOL fShowErrPopup = TRUE;
  184. HWND hwndListCert;
  185. HWND hwndViewCert;
  186. DWORD cCertCount, dwCertIndex;
  187. VARIANT varPropertyValue;
  188. VariantInit(&varPropertyValue);
  189. variant_t var;
  190. //disable view button
  191. hwndViewCert = GetDlgItem(m_hWnd, IDC_VIEW_CERT);
  192. ::EnableWindow(hwndViewCert, FALSE);
  193. hwndListCert = GetDlgItem(m_hWnd, IDC_LIST_CERTS);
  194. dwRet = m_pCA->m_pParentMachine->GetAdmin2(&m_pAdmin);
  195. if (RPC_S_NOT_LISTENING == dwRet ||
  196. RPC_S_SERVER_UNAVAILABLE == dwRet)
  197. {
  198. //certsrv service is not running
  199. CString cstrMsg, cstrTitle;
  200. cstrMsg.LoadString(IDS_VIEW_CERT_NOT_RUNNING);
  201. cstrTitle.LoadString(IDS_MSG_TITLE);
  202. MessageBoxW(m_hWnd, cstrMsg, cstrTitle, MB_ICONEXCLAMATION);
  203. fShowErrPopup = FALSE;
  204. }
  205. _PrintIfError(dwRet, "GetAdmin");
  206. dwRet = m_pCA->GetConfigEntry(
  207. wszREGKEYCSP,
  208. wszREGPROVIDER,
  209. &var);
  210. _JumpIfError(dwRet, Ret, "GetConfigEntry");
  211. m_cstrProvName = V_BSTR(&var);
  212. var.Clear();
  213. dwRet = m_pCA->GetConfigEntry(
  214. wszREGKEYCSP,
  215. wszREGPROVIDERTYPE,
  216. &var);
  217. _JumpIfError(dwRet, Ret, "GetConfigEntry");
  218. dwProvType = V_I4(&var);
  219. var.Clear();
  220. dwRet = m_pCA->GetConfigEntry(
  221. wszREGKEYCSP,
  222. wszHASHALGORITHM,
  223. &var);
  224. _JumpIfError(dwRet, Ret, "GetConfigEntry");
  225. dwHashAlg = V_I4(&var);
  226. var.Clear();
  227. VERIFY (ERROR_SUCCESS ==
  228. CryptAlgToStr(&m_cstrHashAlg, m_cstrProvName, dwProvType, dwHashAlg) );
  229. if(m_pAdmin)
  230. {
  231. // load certs here
  232. dwRet = m_pAdmin->GetCAProperty(
  233. m_pCA->m_bstrConfig,
  234. CR_PROP_CASIGCERTCOUNT,
  235. 0, // (unused)
  236. PROPTYPE_LONG, // PropType
  237. CR_OUT_BINARY, // Flags
  238. &varPropertyValue);
  239. if (dwRet == RPC_E_VERSION_MISMATCH)
  240. {
  241. // if we're talking to a downlevel, keep same functionality as before: remove list
  242. m_fWin2kCA = TRUE;
  243. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_LIST_CERTS), FALSE);
  244. dwRet = ERROR_SUCCESS;
  245. goto Ret;
  246. }
  247. _JumpIfError(dwRet, Ret, "GetCAProperty");
  248. // varPropertyValue.vt will be VT_I4
  249. // varPropertyValue.lVal will be the CA signature cert count
  250. if (VT_I4 != varPropertyValue.vt)
  251. {
  252. dwRet = (DWORD) HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  253. _JumpError(dwRet, Ret, "GetCAProperty");
  254. }
  255. cCertCount = varPropertyValue.lVal;
  256. // now we have a max count; begin looping
  257. for (dwCertIndex=0; dwCertIndex<cCertCount; dwCertIndex++)
  258. {
  259. int iItemIndex;
  260. CString cstrItemName, cstrItemFmt;
  261. VariantClear(&varPropertyValue);
  262. // get each key's cert state
  263. dwRet = m_pAdmin->GetCAProperty(
  264. m_pCA->m_bstrConfig,
  265. CR_PROP_CACERTSTATE, //PropId
  266. dwCertIndex, //PropIndex
  267. PROPTYPE_LONG, // PropType
  268. CR_OUT_BINARY, // Flags
  269. &varPropertyValue);
  270. _JumpIfError(dwRet, Ret, "GetCAProperty");
  271. // varPropertyValue.vt will be VT_I4
  272. // varPropertyValue.lVal will be the cert state
  273. if (VT_I4 != varPropertyValue.vt)
  274. {
  275. dwRet = (DWORD) HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  276. _JumpError(dwRet, Ret, "GetCAProperty");
  277. }
  278. // put identifying information into dialog depending on cert state
  279. switch(varPropertyValue.lVal)
  280. {
  281. case CA_DISP_REVOKED: // This Cert has been revoked.
  282. cstrItemFmt.LoadString(IDS_CA_CERT_LISTBOX_REVOKED);
  283. break;
  284. case CA_DISP_VALID: // This Cert is still valid
  285. cstrItemFmt.LoadString(IDS_CA_CERT_LISTBOX);
  286. break;
  287. case CA_DISP_INVALID: // This Cert has expired.
  288. cstrItemFmt.LoadString(IDS_CA_CERT_LISTBOX_EXPIRED);
  289. break;
  290. case CA_DISP_ERROR:
  291. // CA_DISP_ERROR means the Cert for that index is missing.
  292. default:
  293. continue;
  294. }
  295. // sprintf the cert # into the string
  296. cstrItemName.Format(cstrItemFmt, dwCertIndex);
  297. iItemIndex = (INT)::SendMessage(hwndListCert, LB_ADDSTRING, 0, (LPARAM)(LPCWSTR)cstrItemName);
  298. // add cert # as item data
  299. ::SendMessage(hwndListCert, LB_SETITEMDATA, iItemIndex, (LPARAM)dwCertIndex);
  300. // in future, maybe we should load Certs here, suck out extra info to display,
  301. iItemIndex++;
  302. }
  303. if (0 < dwCertIndex)
  304. {
  305. int c = (int) ::SendMessage(hwndListCert, LB_GETCOUNT, (WPARAM)0, (LPARAM)0);
  306. //select last one
  307. if (LB_ERR != c)
  308. ::SendMessage(hwndListCert, LB_SETCURSEL, (WPARAM)(c-1), (LPARAM)0);
  309. //enable view button
  310. ::EnableWindow(hwndViewCert, TRUE);
  311. }
  312. }
  313. else
  314. {
  315. CString strDataUnavailable;
  316. strDataUnavailable.LoadString(IDS_DATA_UNAVAILABLE);
  317. SendMessage(hwndListCert, LB_ADDSTRING, 0, (LPARAM)(LPCWSTR)strDataUnavailable);
  318. }
  319. UpdateData(FALSE);
  320. Ret:
  321. var.Clear();
  322. VariantClear(&varPropertyValue);
  323. if (fShowErrPopup && ERROR_SUCCESS != dwRet)
  324. DisplayGenericCertSrvError(m_hWnd, dwRet);
  325. return TRUE;
  326. }
  327. void CSvrSettingsGeneralPage::OnDestroy()
  328. {
  329. // Note - This needs to be called only once.
  330. // If called more than once, it will gracefully return an error.
  331. if (m_hConsoleHandle)
  332. MMCFreeNotifyHandle(m_hConsoleHandle);
  333. m_hConsoleHandle = NULL;
  334. CAutoDeletePropPage::OnDestroy();
  335. }
  336. void CSvrSettingsGeneralPage::OnViewCert(HWND hwndCtrl)
  337. {
  338. CRYPTUI_VIEWCERTIFICATE_STRUCTW sViewCert;
  339. ZeroMemory(&sViewCert, sizeof(sViewCert));
  340. HCERTSTORE rghStores[2]; // don't bother closing these stores
  341. BSTR bstrCert; ZeroMemory(&bstrCert, sizeof(BSTR));
  342. PBYTE pbCert = NULL;
  343. DWORD cbCert;
  344. BOOL fShowErrPopup = TRUE;
  345. DWORD dw = ERROR_SUCCESS;
  346. ICertRequest* pIRequest = NULL;
  347. if (m_fWin2kCA)
  348. {
  349. dw = CoCreateInstance(
  350. CLSID_CCertRequest,
  351. NULL, // pUnkOuter
  352. CLSCTX_INPROC_SERVER,
  353. IID_ICertRequest,
  354. (VOID **) &pIRequest);
  355. // get this cert
  356. dw = pIRequest->GetCACertificate(FALSE, _bstr_t(m_pCA->m_strConfig), CR_IN_BINARY, &bstrCert);
  357. if (HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) == (HRESULT)dw)
  358. {
  359. //possible certsrv service is not running but access deny
  360. //is very confusing error code, so use our own display text
  361. CString cstrMsg, cstrTitle;
  362. cstrMsg.LoadString(IDS_VIEW_CERT_DENY_ERROR);
  363. cstrTitle.LoadString(IDS_MSG_TITLE);
  364. MessageBoxW(hwndCtrl, cstrMsg, cstrTitle, MB_OK);
  365. fShowErrPopup = FALSE;
  366. }
  367. _JumpIfError(dw, Ret, "GetCACertificate");
  368. cbCert = SysStringByteLen(bstrCert);
  369. pbCert = (PBYTE)bstrCert;
  370. sViewCert.pCertContext = CertCreateCertificateContext(
  371. CRYPT_ASN_ENCODING,
  372. pbCert,
  373. cbCert);
  374. if (sViewCert.pCertContext == NULL)
  375. {
  376. dw = GetLastError();
  377. _JumpError(dw, Ret, "CertCreateCertificateContext");
  378. }
  379. }
  380. else
  381. {
  382. VARIANT varPropertyValue;
  383. VariantInit(&varPropertyValue);
  384. int iCertIndex = 0;
  385. // get cert # from item data
  386. HWND hwndList = GetDlgItem(m_hWnd, IDC_LIST_CERTS);
  387. DWORD dwSel = (DWORD)::SendMessage(hwndList, LB_GETCURSEL, 0, 0);
  388. if (LB_ERR == dwSel)
  389. goto Ret;
  390. iCertIndex = (int)::SendMessage(hwndList, LB_GETITEMDATA, (WPARAM)dwSel, 0);
  391. // get the Cert
  392. dw = m_pCA->GetCACertByKeyIndex(&(sViewCert.pCertContext), iCertIndex);
  393. if (HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) == (HRESULT)dw)
  394. {
  395. //possible certsrv service is not running but access deny
  396. //is very confusing error code, so use our own display text
  397. CString cstrMsg, cstrTitle;
  398. cstrMsg.LoadString(IDS_VIEW_CERT_DENY_ERROR);
  399. cstrTitle.LoadString(IDS_MSG_TITLE);
  400. MessageBoxW(hwndCtrl, cstrMsg, cstrTitle, MB_OK);
  401. fShowErrPopup = FALSE;
  402. }
  403. else if (RPC_S_NOT_LISTENING == dw ||
  404. RPC_S_SERVER_UNAVAILABLE == dw)
  405. {
  406. //certsrv service is not running
  407. CString cstrMsg, cstrTitle;
  408. cstrMsg.LoadString(IDS_VIEW_CERT_NOT_RUNNING);
  409. cstrTitle.LoadString(IDS_MSG_TITLE);
  410. MessageBoxW(hwndCtrl, cstrMsg, cstrTitle, MB_OK);
  411. fShowErrPopup = FALSE;
  412. }
  413. _JumpIfError(dw, Ret, "GetCACertByKeyIndex");
  414. }
  415. sViewCert.hwndParent = m_hWnd;
  416. sViewCert.dwSize = sizeof(sViewCert);
  417. sViewCert.dwFlags = CRYPTUI_ENABLE_REVOCATION_CHECKING | CRYPTUI_DISABLE_ADDTOSTORE; // this is not the place to allow installs (kelviny discussion 12/11/98)
  418. // if we're opening remotely, don't open local stores
  419. if (! m_pCA->m_pParentMachine->IsLocalMachine())
  420. {
  421. // get remote stores
  422. dw = m_pCA->GetRootCertStore(&rghStores[0]);
  423. _PrintIfError(dw, "GetRootCertStore");
  424. if (S_OK == dw)
  425. {
  426. dw = m_pCA->GetCACertStore(&rghStores[1]);
  427. _PrintIfError(dw, "GetCACertStore");
  428. }
  429. if (S_OK == dw)
  430. {
  431. // rely only on remote machine's stores
  432. sViewCert.cStores = 2;
  433. sViewCert.rghStores = rghStores;
  434. sViewCert.dwFlags |= CRYPTUI_DONT_OPEN_STORES | CRYPTUI_WARN_UNTRUSTED_ROOT;
  435. }
  436. else
  437. {
  438. // tell user we're only doing this locally
  439. sViewCert.dwFlags |= CRYPTUI_WARN_REMOTE_TRUST;
  440. }
  441. }
  442. if (!CryptUIDlgViewCertificateW(&sViewCert, NULL))
  443. {
  444. dw = GetLastError();
  445. if (dw != ERROR_CANCELLED)
  446. _JumpError(dw, Ret, "CryptUIDlgViewCertificateW");
  447. }
  448. dw = ERROR_SUCCESS;
  449. Ret:
  450. VERIFY(CertFreeCertificateContext(sViewCert.pCertContext));
  451. if (bstrCert)
  452. SysFreeString(bstrCert);
  453. if (pIRequest)
  454. pIRequest->Release();
  455. if ((dw != ERROR_SUCCESS) && (dw != ERROR_CANCELLED) && fShowErrPopup)
  456. DisplayGenericCertSrvError(m_hWnd, dw);
  457. }
  458. BOOL CSvrSettingsGeneralPage::OnApply()
  459. {
  460. return CAutoDeletePropPage::OnApply();
  461. }
  462. BOOL CSvrSettingsGeneralPage::OnNotify(UINT idCtrl, NMHDR* pnmh)
  463. {
  464. switch(idCtrl)
  465. {
  466. //handle double click on list items
  467. case IDC_LIST_CERTS:
  468. if (pnmh->code == NM_DBLCLK)
  469. OnViewCert(pnmh->hwndFrom);
  470. break;
  471. }
  472. return FALSE;
  473. }
  474. void CSvrSettingsGeneralPage::TryServiceRestart(WORD wPage)
  475. {
  476. m_wRestart &= ~wPage; // whack off the page requesting this
  477. if (m_fRestartServer && (m_wRestart == 0)) // if we got a request to restart and all pages have agreed
  478. {
  479. if (RestartService(m_hWnd, m_pCA->m_pParentMachine))
  480. {
  481. MMCPropertyChangeNotify(m_hConsoleHandle, CERTMMC_PROPERTY_CHANGE_REFRESHVIEWS);
  482. m_fRestartServer = FALSE;
  483. }
  484. }
  485. }
  486. ////
  487. // 2
  488. /////////////////////////////////////////////////////////////////////////////
  489. // CSvrSettingsPolicyPage property page
  490. RoleAccessToControl CSvrSettingsPolicyPage::sm_ControlToRoleMap[] =
  491. {
  492. { IDC_ACTIVE_MODULE, CA_ACCESS_ADMIN },
  493. };
  494. CSvrSettingsPolicyPage::CSvrSettingsPolicyPage(CSvrSettingsGeneralPage* pControlPage, UINT uIDD)
  495. : CAutoDeletePropPage(uIDD),
  496. CRolesSupportInPropPage(
  497. pControlPage->m_pCA,
  498. sm_ControlToRoleMap,
  499. ARRAYSIZE(sm_ControlToRoleMap)),
  500. m_pControlPage(pControlPage)
  501. {
  502. m_cstrModuleName = _T("");
  503. m_cstrModuleDescr = _T("");
  504. m_cstrModuleVersion = _T("");
  505. m_cstrModuleCopyright = _T("");
  506. m_bUpdate = FALSE;
  507. m_fLoadedActiveModule = FALSE;
  508. m_pszprogidPolicyModule = NULL;
  509. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTSRV_PROPPAGE2);
  510. }
  511. CSvrSettingsPolicyPage::~CSvrSettingsPolicyPage()
  512. {
  513. if (NULL != m_pszprogidPolicyModule)
  514. {
  515. CoTaskMemFree(m_pszprogidPolicyModule);
  516. m_pszprogidPolicyModule = NULL;
  517. }
  518. }
  519. // replacement for DoDataExchange
  520. BOOL CSvrSettingsPolicyPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  521. {
  522. if (fSuckFromDlg)
  523. {
  524. m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  525. m_cstrModuleDescr.FromWindow(GetDlgItem(m_hWnd, IDC_DESCRIPTION));
  526. m_cstrModuleVersion.FromWindow(GetDlgItem(m_hWnd, IDC_VERSION));
  527. m_cstrModuleCopyright.FromWindow(GetDlgItem(m_hWnd, IDC_COPYRIGHT));
  528. }
  529. else
  530. {
  531. m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  532. m_cstrModuleDescr.ToWindow(GetDlgItem(m_hWnd, IDC_DESCRIPTION));
  533. m_cstrModuleVersion.ToWindow(GetDlgItem(m_hWnd, IDC_VERSION));
  534. m_cstrModuleCopyright.ToWindow(GetDlgItem(m_hWnd, IDC_COPYRIGHT));
  535. }
  536. return TRUE;
  537. }
  538. // replacement for BEGIN_MESSAGE_MAP
  539. BOOL
  540. CSvrSettingsPolicyPage::OnCommand(
  541. WPARAM wParam,
  542. LPARAM) // lParam
  543. {
  544. switch(LOWORD(wParam))
  545. {
  546. case IDC_ACTIVE_MODULE:
  547. if (BN_CLICKED == HIWORD(wParam))
  548. OnSetActiveModule();
  549. break;
  550. case IDC_CONFIGURE:
  551. if (BN_CLICKED == HIWORD(wParam))
  552. OnConfigureModule();
  553. break;
  554. default:
  555. return FALSE;
  556. break;
  557. }
  558. return TRUE;
  559. }
  560. HRESULT CSvrSettingsPolicyPage::GetCurrentModuleProperties()
  561. {
  562. HRESULT hr;
  563. CString cstrStoragePath;
  564. BOOL fGotName = FALSE;
  565. DISPATCHINTERFACE di;
  566. BOOL fMustRelease = FALSE;
  567. BSTR bstrTmp=NULL, bstrProperty=NULL, bstrStorageLoc = NULL;
  568. hr = GetPolicyManageDispatch(
  569. m_pszprogidPolicyModule,
  570. m_clsidPolicyModule,
  571. &di);
  572. _JumpIfError(hr, Ret, "GetPolicyManageDispatch");
  573. fMustRelease = TRUE;
  574. cstrStoragePath = wszREGKEYCONFIGPATH_BS;
  575. cstrStoragePath += m_pControlPage->m_pCA->m_strSanitizedName;
  576. cstrStoragePath += TEXT("\\");
  577. cstrStoragePath += wszREGKEYPOLICYMODULES;
  578. cstrStoragePath += TEXT("\\");
  579. cstrStoragePath += m_pszprogidPolicyModule;
  580. bstrStorageLoc = SysAllocString(cstrStoragePath);
  581. if(!bstrStorageLoc)
  582. {
  583. hr = E_OUTOFMEMORY;
  584. _JumpError(hr, Ret, "SysAllocString");
  585. }
  586. bstrProperty = SysAllocString(wszCMM_PROP_NAME);
  587. _JumpIfOutOfMemory(hr, Ret, bstrProperty);
  588. ////////////////////
  589. // NAME
  590. hr = ManageModule_GetProperty(
  591. &di,
  592. m_pControlPage->m_pCA->m_bstrConfig,
  593. bstrStorageLoc,
  594. bstrProperty,
  595. 0,
  596. PROPTYPE_STRING,
  597. &bstrTmp);
  598. if ((S_OK == hr) && (NULL != bstrTmp))
  599. {
  600. myRegisterMemAlloc(bstrTmp, -1, CSM_SYSALLOC);
  601. m_cstrModuleName = bstrTmp;
  602. fGotName = TRUE;
  603. SysFreeString(bstrTmp);
  604. bstrTmp = NULL;
  605. }
  606. else
  607. {
  608. // have a backup name to display: CLSID of interface?
  609. m_cstrModuleName = m_pszprogidPolicyModule;
  610. fGotName = TRUE;
  611. // now bail
  612. _JumpError(hr, Ret, "ManageModule_GetProperty");
  613. }
  614. ////////////////////
  615. // DESCRIPTION
  616. SysFreeString(bstrProperty);
  617. bstrProperty = SysAllocString(wszCMM_PROP_DESCRIPTION);
  618. _JumpIfOutOfMemory(hr, Ret, bstrProperty);
  619. hr = ManageModule_GetProperty(
  620. &di,
  621. m_pControlPage->m_pCA->m_bstrConfig,
  622. bstrStorageLoc,
  623. bstrProperty,
  624. 0,
  625. PROPTYPE_STRING,
  626. &bstrTmp);
  627. if ((S_OK == hr) && (NULL != bstrTmp))
  628. {
  629. myRegisterMemAlloc(bstrTmp, -1, CSM_SYSALLOC);
  630. m_cstrModuleDescr = bstrTmp;
  631. SysFreeString(bstrTmp);
  632. bstrTmp = NULL;
  633. }
  634. ////////////////////
  635. // COPYRIGHT
  636. SysFreeString(bstrProperty);
  637. bstrProperty = SysAllocString(wszCMM_PROP_COPYRIGHT);
  638. _JumpIfOutOfMemory(hr, Ret, bstrProperty);
  639. hr = ManageModule_GetProperty(
  640. &di,
  641. m_pControlPage->m_pCA->m_bstrConfig,
  642. bstrStorageLoc,
  643. bstrProperty,
  644. 0,
  645. PROPTYPE_STRING,
  646. &bstrTmp);
  647. if ((S_OK == hr) && (NULL != bstrTmp))
  648. {
  649. myRegisterMemAlloc(bstrTmp, -1, CSM_SYSALLOC);
  650. m_cstrModuleCopyright = bstrTmp;
  651. SysFreeString(bstrTmp);
  652. bstrTmp = NULL;
  653. }
  654. ////////////////////
  655. // FILEVER
  656. SysFreeString(bstrProperty);
  657. bstrProperty = SysAllocString(wszCMM_PROP_FILEVER);
  658. _JumpIfOutOfMemory(hr, Ret, bstrProperty);
  659. hr = ManageModule_GetProperty(
  660. &di,
  661. m_pControlPage->m_pCA->m_bstrConfig,
  662. bstrStorageLoc,
  663. bstrProperty,
  664. 0,
  665. PROPTYPE_STRING,
  666. &bstrTmp);
  667. if ((S_OK == hr) && (NULL != bstrTmp))
  668. {
  669. myRegisterMemAlloc(bstrTmp, -1, CSM_SYSALLOC);
  670. m_cstrModuleVersion = bstrTmp;
  671. SysFreeString(bstrTmp);
  672. bstrTmp = NULL;
  673. }
  674. Ret:
  675. if (!fGotName)
  676. {
  677. if (CO_E_CLASSSTRING == hr)
  678. {
  679. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_POLICYMODULE_NOT_REGISTERED);
  680. }
  681. else
  682. {
  683. WCHAR const *pwsz = myGetErrorMessageText(hr, TRUE);
  684. m_cstrModuleName = pwsz;
  685. if (NULL != pwsz)
  686. {
  687. LocalFree(const_cast<WCHAR *>(pwsz));
  688. }
  689. }
  690. }
  691. if (fMustRelease)
  692. ManageModule_Release(&di);
  693. if (bstrProperty)
  694. SysFreeString(bstrProperty);
  695. if (bstrStorageLoc)
  696. SysFreeString(bstrStorageLoc);
  697. return hr;
  698. }
  699. /////////////////////////////////////////////////////////////////////////////
  700. // CSvrSettingsPolicyPage message handlers
  701. BOOL CSvrSettingsPolicyPage::OnInitDialog()
  702. {
  703. HRESULT hr;
  704. // does parent init and UpdateData call
  705. CAutoDeletePropPage::OnInitDialog();
  706. // thse should be emptied
  707. m_cstrModuleName.Empty();
  708. m_cstrModuleDescr.Empty();
  709. m_cstrModuleVersion.Empty();
  710. m_cstrModuleCopyright.Empty();
  711. hr = myGetActiveModule(
  712. m_pControlPage->m_pCA,
  713. TRUE,
  714. 0,
  715. &m_pszprogidPolicyModule, // CoTaskMem*
  716. &m_clsidPolicyModule);
  717. _JumpIfError(hr, Ret, "myGetActiveModule");
  718. hr = GetCurrentModuleProperties();
  719. _JumpIfError(hr, Ret, "GetCurrentModuleProperties");
  720. Ret:
  721. ::EnableWindow(GetDlgItem(m_hWnd, IDC_CONFIGURE), (hr == S_OK) );
  722. EnableControl(m_hWnd, IDC_ACTIVE_MODULE, TRUE );
  723. UpdateData(FALSE);
  724. return TRUE;
  725. }
  726. void CSvrSettingsPolicyPage::OnDestroy()
  727. {
  728. // Note - This needs to be called only once.
  729. // If called more than once, it will gracefully return an error.
  730. // if (m_hConsoleHandle)
  731. // MMCFreeNotifyHandle(m_hConsoleHandle);
  732. // m_hConsoleHandle = NULL;
  733. CAutoDeletePropPage::OnDestroy();
  734. }
  735. void CSvrSettingsPolicyPage::OnConfigureModule()
  736. {
  737. DWORD dw;
  738. DISPATCHINTERFACE di;
  739. ZeroMemory(&di, sizeof(DISPATCHINTERFACE));
  740. BOOL fMustRelease = FALSE;
  741. BSTR bstrStorageLoc = NULL;
  742. BSTR bstrVal = NULL;
  743. DWORD dwConfigFlags = (CA_ACCESS_ADMIN&m_pCA->GetMyRoles())?0:CMM_READONLY;
  744. do {
  745. dw = GetPolicyManageDispatch(
  746. m_pszprogidPolicyModule,
  747. m_clsidPolicyModule,
  748. &di);
  749. _PrintIfError(dw, "GetPolicyManageDispatch");
  750. if (ERROR_SUCCESS != dw)
  751. break;
  752. fMustRelease = TRUE;
  753. CString cstrStoragePath;
  754. cstrStoragePath = wszREGKEYCONFIGPATH_BS;
  755. cstrStoragePath += m_pControlPage->m_pCA->m_strSanitizedName;
  756. cstrStoragePath += TEXT("\\");
  757. cstrStoragePath += wszREGKEYPOLICYMODULES;
  758. cstrStoragePath += TEXT("\\");
  759. cstrStoragePath += m_pszprogidPolicyModule;
  760. bstrStorageLoc = SysAllocString(cstrStoragePath);
  761. if (NULL == bstrStorageLoc)
  762. {
  763. dw = (DWORD) E_OUTOFMEMORY;
  764. _JumpError(dw, Ret, "SysAllocString");
  765. }
  766. // Callbacks must be initialized whenever ManageModule_Configure is called
  767. dw = ThunkServerCallbacks(m_pControlPage->m_pCA);
  768. _JumpIfError(dw, Ret, "ThunkServerCallbacks");
  769. // pass an hwnd to the policy module -- this is an optional value
  770. bstrVal = SysAllocStringByteLen(NULL, sizeof(HWND));
  771. if (NULL == bstrVal)
  772. {
  773. dw = (DWORD) E_OUTOFMEMORY;
  774. _JumpError(dw, Ret, "SysAllocStringByteLen");
  775. }
  776. *(HWND*)(bstrVal) = m_hWnd;
  777. dw = ManageModule_SetProperty(
  778. &di,
  779. m_pControlPage->m_pCA->m_bstrConfig,
  780. bstrStorageLoc,
  781. const_cast<WCHAR*>(wszCMM_PROP_DISPLAY_HWND),
  782. 0,
  783. PROPTYPE_BINARY,
  784. bstrVal);
  785. _PrintIfError(dw, "ManageModule_SetProperty(HWND)");
  786. dw = ManageModule_Configure(
  787. &di,
  788. m_pControlPage->m_pCA->m_bstrConfig,
  789. bstrStorageLoc,
  790. dwConfigFlags);
  791. _PrintIfError(dw, "ManageModule_Configure");
  792. } while(0);
  793. if (S_OK != dw)
  794. DisplayGenericCertSrvError(m_hWnd, dw);
  795. Ret:
  796. if (fMustRelease)
  797. ManageModule_Release(&di);
  798. if (bstrStorageLoc)
  799. ::SysFreeString(bstrStorageLoc);
  800. if (bstrVal)
  801. ::SysFreeString(bstrVal);
  802. }
  803. typedef struct _PRIVATE_DLGPROC_MODULESELECT_LPARAM
  804. {
  805. BOOL fIsPolicyModuleSelection;
  806. CertSvrCA* pCA;
  807. LPOLESTR* ppszProgIDModule;
  808. CLSID* pclsidModule;
  809. } PRIVATE_DLGPROC_MODULESELECT_LPARAM, *PPRIVATE_DLGPROC_MODULESELECT_LPARAM;
  810. void CSvrSettingsPolicyPage::OnSetActiveModule()
  811. {
  812. DWORD dwErr;
  813. // get currently active module
  814. PRIVATE_DLGPROC_MODULESELECT_LPARAM sParam;
  815. ZeroMemory(&sParam, sizeof(sParam));
  816. sParam.fIsPolicyModuleSelection = TRUE;
  817. sParam.pCA = m_pControlPage->m_pCA;
  818. sParam.ppszProgIDModule = &m_pszprogidPolicyModule;
  819. sParam.pclsidModule = &m_clsidPolicyModule;
  820. dwErr = (DWORD)DialogBoxParam(
  821. g_hInstance,
  822. MAKEINTRESOURCE(IDD_CHOOSE_MODULE),
  823. m_hWnd,
  824. dlgProcChooseModule,
  825. (LPARAM)&sParam);
  826. // translate ok/cancel into error codes
  827. if (IDOK == dwErr)
  828. {
  829. // dirty bit
  830. m_pControlPage->NeedServiceRestart(SERVERSETTINGS_PROPPAGE_POLICY);
  831. SetModified(TRUE);
  832. m_bUpdate = TRUE;
  833. GetCurrentModuleProperties();
  834. UpdateData(FALSE);
  835. }
  836. if ((dwErr != IDOK) && (dwErr != IDCANCEL))
  837. {
  838. _PrintIfError(dwErr, "dlgProcChooseModule");
  839. DisplayGenericCertSrvError(m_hWnd, dwErr);
  840. }
  841. return;
  842. }
  843. BOOL CSvrSettingsPolicyPage::OnApply()
  844. {
  845. if (m_bUpdate)
  846. {
  847. if (NULL != m_pszprogidPolicyModule)
  848. {
  849. HRESULT hr;
  850. variant_t var;
  851. var = m_pszprogidPolicyModule;
  852. // now we have the chosen uuid -- set as default in registry
  853. hr = m_pControlPage->m_pCA->SetConfigEntry(
  854. wszREGKEYPOLICYMODULES,
  855. wszREGACTIVE,
  856. &var);
  857. if (hr != S_OK)
  858. {
  859. DisplayGenericCertSrvError(m_hWnd, hr);
  860. return FALSE;
  861. }
  862. }
  863. m_bUpdate = FALSE;
  864. m_pControlPage->TryServiceRestart(SERVERSETTINGS_PROPPAGE_POLICY);
  865. }
  866. return CAutoDeletePropPage::OnApply();
  867. }
  868. void ClearModuleDefn(PCOM_CERTSRV_MODULEDEFN pMod)
  869. {
  870. if (pMod)
  871. {
  872. if (pMod->szModuleProgID)
  873. CoTaskMemFree(pMod->szModuleProgID);
  874. ZeroMemory(pMod, sizeof(COM_CERTSRV_MODULEDEFN));
  875. }
  876. }
  877. ////
  878. // 3
  879. /////////////////////////////////////////////////////////////////////////////
  880. // CSvrSettingsExitPage property page
  881. RoleAccessToControl CSvrSettingsExitPage::sm_ControlToRoleMap[] =
  882. {
  883. { IDC_ADD_MODULE, CA_ACCESS_ADMIN },
  884. { IDC_REMOVE_MODULE, CA_ACCESS_ADMIN },
  885. };
  886. CSvrSettingsExitPage::CSvrSettingsExitPage(CSvrSettingsGeneralPage* pControlPage, UINT uIDD)
  887. : CAutoDeletePropPage(uIDD),
  888. CRolesSupportInPropPage(
  889. pControlPage->m_pCA,
  890. sm_ControlToRoleMap,
  891. ARRAYSIZE(sm_ControlToRoleMap)),
  892. m_pControlPage(pControlPage)
  893. {
  894. m_cstrModuleName = _T("");
  895. m_cstrModuleDescr = _T("");
  896. m_cstrModuleVersion = _T("");
  897. m_cstrModuleCopyright = _T("");
  898. m_bUpdate = FALSE;
  899. m_fLoadedActiveModule = FALSE;
  900. m_iSelected = -1;
  901. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTSRV_PROPPAGE3);
  902. }
  903. CSvrSettingsExitPage::~CSvrSettingsExitPage()
  904. {
  905. int i;
  906. for(i=0; i<m_arrExitModules.GetSize(); i++)
  907. {
  908. #pragma warning(push) // BUGBUG: nonstandard extension used : class rvalue used as lvalue
  909. #pragma warning(disable: 4238) // BUGBUG: nonstandard extension used : class rvalue used as lvalue
  910. ClearModuleDefn(&m_arrExitModules[i]);
  911. #pragma warning(pop) // BUGBUG: nonstandard extension used : class rvalue used as lvalue
  912. }
  913. }
  914. // replacement for DoDataExchange
  915. BOOL CSvrSettingsExitPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  916. {
  917. if (fSuckFromDlg)
  918. {
  919. m_cstrModuleName.FromWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  920. m_cstrModuleDescr.FromWindow(GetDlgItem(m_hWnd, IDC_DESCRIPTION));
  921. m_cstrModuleVersion.FromWindow(GetDlgItem(m_hWnd, IDC_VERSION));
  922. m_cstrModuleCopyright.FromWindow(GetDlgItem(m_hWnd, IDC_COPYRIGHT));
  923. }
  924. else
  925. {
  926. m_cstrModuleName.ToWindow(GetDlgItem(m_hWnd, IDC_MODULENAME));
  927. m_cstrModuleDescr.ToWindow(GetDlgItem(m_hWnd, IDC_DESCRIPTION));
  928. m_cstrModuleVersion.ToWindow(GetDlgItem(m_hWnd, IDC_VERSION));
  929. m_cstrModuleCopyright.ToWindow(GetDlgItem(m_hWnd, IDC_COPYRIGHT));
  930. // if 0 modules, disable REMOVE button
  931. EnableControl(m_hWnd, IDC_REMOVE_MODULE, (0 != m_arrExitModules.GetSize()));
  932. }
  933. return TRUE;
  934. }
  935. // replacement for BEGIN_MESSAGE_MAP
  936. BOOL
  937. CSvrSettingsExitPage::OnCommand(
  938. WPARAM wParam,
  939. LPARAM) // lParam
  940. {
  941. switch(LOWORD(wParam))
  942. {
  943. case IDC_ADD_MODULE:
  944. case IDC_ACTIVE_MODULE:
  945. if (BN_CLICKED == HIWORD(wParam))
  946. OnAddActiveModule();
  947. break;
  948. case IDC_CONFIGURE:
  949. if (BN_CLICKED == HIWORD(wParam))
  950. OnConfigureModule();
  951. break;
  952. case IDC_REMOVE_MODULE:
  953. if (BN_CLICKED == HIWORD(wParam))
  954. OnRemoveActiveModule();
  955. break;
  956. case IDC_EXIT_LIST:
  957. if (LBN_SELCHANGE == HIWORD(wParam))
  958. {
  959. m_iSelected = (int)SendMessage(GetDlgItem(m_hWnd, IDC_EXIT_LIST), LB_GETCURSEL, 0, 0);
  960. UpdateSelectedModule();
  961. break;
  962. }
  963. default:
  964. return FALSE;
  965. break;
  966. }
  967. return TRUE;
  968. }
  969. BOOL CSvrSettingsExitPage::UpdateSelectedModule()
  970. {
  971. HRESULT hr;
  972. BOOL fGotName = FALSE;
  973. DISPATCHINTERFACE di;
  974. BOOL fMustRelease = FALSE;
  975. CString cstrStoragePath;
  976. // empty any strings
  977. m_cstrModuleName.Empty();
  978. m_cstrModuleDescr.Empty();
  979. m_cstrModuleVersion.Empty();
  980. m_cstrModuleCopyright.Empty();
  981. BSTR bstrTmp=NULL, bstrProperty=NULL, bstrStorageLoc = NULL;
  982. // no exit module
  983. if (0 == m_arrExitModules.GetSize())
  984. {
  985. hr = HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND);
  986. _JumpError(hr, Ret, "m_pszprogidExitManage");
  987. }
  988. CSASSERT(m_iSelected != -1);
  989. CSASSERT(m_iSelected <= m_arrExitModules.GetUpperBound());
  990. if (m_iSelected > m_arrExitModules.GetUpperBound())
  991. {
  992. hr = E_UNEXPECTED;
  993. _JumpError(hr, Ret, "m_iSelected > m_arrExitModules.GetUpperBound()");
  994. }
  995. cstrStoragePath = wszREGKEYCONFIGPATH_BS;
  996. cstrStoragePath += m_pControlPage->m_pCA->m_strSanitizedName;
  997. cstrStoragePath += TEXT("\\");
  998. cstrStoragePath += wszREGKEYEXITMODULES;
  999. cstrStoragePath += TEXT("\\");
  1000. cstrStoragePath += m_arrExitModules[m_iSelected].szModuleProgID; //m_pszprogidExitModule;
  1001. bstrStorageLoc = SysAllocString(cstrStoragePath);
  1002. _JumpIfOutOfMemory(hr, Ret, bstrStorageLoc);
  1003. hr = GetExitManageDispatch(
  1004. m_arrExitModules[m_iSelected].szModuleProgID,
  1005. m_arrExitModules[m_iSelected].clsidModule,
  1006. &di);
  1007. _JumpIfErrorStr(hr, Ret, "GetExitManageDispatch", m_arrExitModules[m_iSelected].szModuleProgID);
  1008. fMustRelease = TRUE;
  1009. bstrProperty = SysAllocString(wszCMM_PROP_NAME);
  1010. _JumpIfOutOfMemory(hr, Ret, bstrProperty);
  1011. ////////////////////
  1012. // NAME
  1013. hr = ManageModule_GetProperty(
  1014. &di,
  1015. m_pControlPage->m_pCA->m_bstrConfig,
  1016. bstrStorageLoc,
  1017. bstrProperty,
  1018. 0,
  1019. PROPTYPE_STRING,
  1020. &bstrTmp);
  1021. if ((S_OK == hr) && (NULL != bstrTmp))
  1022. {
  1023. myRegisterMemAlloc(bstrTmp, -1, CSM_SYSALLOC);
  1024. m_cstrModuleName = bstrTmp;
  1025. fGotName = TRUE;
  1026. SysFreeString(bstrTmp);
  1027. bstrTmp = NULL;
  1028. }
  1029. else
  1030. {
  1031. // have a backup name to display: CLSID of interface?
  1032. m_cstrModuleName = m_arrExitModules[m_iSelected].szModuleProgID;
  1033. fGotName = TRUE;
  1034. // bail
  1035. _JumpError(hr, Ret, "ManageModule_GetProperty");
  1036. }
  1037. ////////////////////
  1038. // DESCRIPTION
  1039. SysFreeString(bstrProperty);
  1040. bstrProperty = SysAllocString(wszCMM_PROP_DESCRIPTION);
  1041. _JumpIfOutOfMemory(hr, Ret, bstrProperty);
  1042. hr = ManageModule_GetProperty(
  1043. &di,
  1044. m_pControlPage->m_pCA->m_bstrConfig,
  1045. bstrStorageLoc,
  1046. bstrProperty,
  1047. 0,
  1048. PROPTYPE_STRING,
  1049. &bstrTmp);
  1050. if ((S_OK == hr) && (NULL != bstrTmp))
  1051. {
  1052. myRegisterMemAlloc(bstrTmp, -1, CSM_SYSALLOC);
  1053. m_cstrModuleDescr = bstrTmp;
  1054. SysFreeString(bstrTmp);
  1055. bstrTmp = NULL;
  1056. }
  1057. ////////////////////
  1058. // COPYRIGHT
  1059. SysFreeString(bstrProperty);
  1060. bstrProperty = SysAllocString(wszCMM_PROP_COPYRIGHT);
  1061. _JumpIfOutOfMemory(hr, Ret, bstrProperty);
  1062. hr = ManageModule_GetProperty(
  1063. &di,
  1064. m_pControlPage->m_pCA->m_bstrConfig,
  1065. bstrStorageLoc,
  1066. bstrProperty,
  1067. 0,
  1068. PROPTYPE_STRING,
  1069. &bstrTmp);
  1070. if ((S_OK == hr) && (NULL != bstrTmp))
  1071. {
  1072. myRegisterMemAlloc(bstrTmp, -1, CSM_SYSALLOC);
  1073. m_cstrModuleCopyright = bstrTmp;
  1074. SysFreeString(bstrTmp);
  1075. bstrTmp = NULL;
  1076. }
  1077. ////////////////////
  1078. // FILEVER
  1079. SysFreeString(bstrProperty);
  1080. bstrProperty = SysAllocString(wszCMM_PROP_FILEVER);
  1081. _JumpIfOutOfMemory(hr, Ret, bstrProperty);
  1082. hr = ManageModule_GetProperty(
  1083. &di,
  1084. m_pControlPage->m_pCA->m_bstrConfig,
  1085. bstrStorageLoc,
  1086. bstrProperty,
  1087. 0,
  1088. PROPTYPE_STRING,
  1089. &bstrTmp);
  1090. if ((S_OK == hr) && (NULL != bstrTmp))
  1091. {
  1092. myRegisterMemAlloc(bstrTmp, -1, CSM_SYSALLOC);
  1093. m_cstrModuleVersion = bstrTmp;
  1094. SysFreeString(bstrTmp);
  1095. bstrTmp = NULL;
  1096. }
  1097. Ret:
  1098. ::EnableWindow(GetDlgItem(m_hWnd, IDC_CONFIGURE), (hr == S_OK) );
  1099. EnableControl(m_hWnd, IDC_ADD_MODULE, TRUE);
  1100. if (!fGotName)
  1101. {
  1102. if (HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND) == hr)
  1103. {
  1104. m_cstrModuleName.LoadString(IDS_NO_EXIT_MODULE);
  1105. }
  1106. else if (CO_E_CLASSSTRING == hr)
  1107. {
  1108. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_EXITMODULE_NOT_REGISTERED);
  1109. }
  1110. else
  1111. {
  1112. WCHAR const *pwsz = myGetErrorMessageText(hr, TRUE);
  1113. m_cstrModuleName = pwsz;
  1114. if (NULL != pwsz)
  1115. {
  1116. LocalFree(const_cast<WCHAR *>(pwsz));
  1117. }
  1118. }
  1119. }
  1120. if (fMustRelease)
  1121. ManageModule_Release(&di);
  1122. if (bstrProperty)
  1123. SysFreeString(bstrProperty);
  1124. if (bstrStorageLoc)
  1125. SysFreeString(bstrStorageLoc);
  1126. UpdateData(FALSE);
  1127. return TRUE;
  1128. }
  1129. /////////////////////////////////////////////////////////////////////////////
  1130. // CSvrSettingsExitPage message handlers
  1131. BOOL CSvrSettingsExitPage::OnInitDialog()
  1132. {
  1133. HRESULT hr;
  1134. // does parent init and UpdateData call
  1135. CAutoDeletePropPage::OnInitDialog();
  1136. if (!m_fLoadedActiveModule)
  1137. {
  1138. m_fLoadedActiveModule = TRUE;
  1139. // load all of the modules
  1140. for (int i=0; ; i++)
  1141. {
  1142. COM_CERTSRV_MODULEDEFN sModule;
  1143. ZeroMemory(&sModule, sizeof(sModule));
  1144. hr = myGetActiveModule(
  1145. m_pControlPage->m_pCA,
  1146. FALSE,
  1147. i,
  1148. &sModule.szModuleProgID, // CoTaskMem*
  1149. &sModule.clsidModule);
  1150. _PrintIfError(hr, "myGetActiveModule");
  1151. if (hr != S_OK)
  1152. break;
  1153. m_arrExitModules.Add(sModule);
  1154. }
  1155. m_iSelected = 0; // select 1st element
  1156. }
  1157. InitializeExitLB();
  1158. UpdateSelectedModule();
  1159. UpdateData(FALSE);
  1160. return TRUE;
  1161. }
  1162. void CSvrSettingsExitPage::OnConfigureModule()
  1163. {
  1164. DWORD dw;
  1165. DISPATCHINTERFACE di;
  1166. BOOL fMustRelease = FALSE;
  1167. BSTR bstrStorageLoc = NULL;
  1168. BSTR bstrVal = NULL;
  1169. DWORD dwConfigFlags = (CA_ACCESS_ADMIN&m_pCA->GetMyRoles())?0:CMM_READONLY;
  1170. CSASSERT(m_iSelected <= m_arrExitModules.GetUpperBound());
  1171. if (m_iSelected > m_arrExitModules.GetUpperBound())
  1172. {
  1173. dw = (DWORD) E_UNEXPECTED;
  1174. _JumpError(dw, Ret, "m_iSelected > m_arrExitModules.GetUpperBound()");
  1175. }
  1176. if (NULL == m_arrExitModules[m_iSelected].szModuleProgID)
  1177. {
  1178. dw = ERROR_MOD_NOT_FOUND;
  1179. _JumpError(dw, Ret, "m_pszprogidExitManage");
  1180. }
  1181. do { // not a loop
  1182. dw = GetExitManageDispatch(
  1183. m_arrExitModules[m_iSelected].szModuleProgID,
  1184. m_arrExitModules[m_iSelected].clsidModule,
  1185. &di);
  1186. _PrintIfErrorStr(dw, "GetExitManageDispatch", m_arrExitModules[m_iSelected].szModuleProgID);
  1187. if (ERROR_SUCCESS != dw)
  1188. break;
  1189. fMustRelease = TRUE;
  1190. CString cstrStoragePath;
  1191. cstrStoragePath = wszREGKEYCONFIGPATH_BS;
  1192. cstrStoragePath += m_pControlPage->m_pCA->m_strSanitizedName;
  1193. cstrStoragePath += TEXT("\\");
  1194. cstrStoragePath += wszREGKEYEXITMODULES;
  1195. cstrStoragePath += TEXT("\\");
  1196. cstrStoragePath += m_arrExitModules[m_iSelected].szModuleProgID;//m_pszprogidExitModule;
  1197. bstrStorageLoc = SysAllocString(cstrStoragePath);
  1198. if (NULL == bstrStorageLoc)
  1199. {
  1200. dw = (DWORD) E_OUTOFMEMORY;
  1201. _JumpError(dw, Ret, "SysAllocString");
  1202. }
  1203. // Callbacks must be initialized whenever ManageModule_Configure is called
  1204. dw = ThunkServerCallbacks(m_pControlPage->m_pCA);
  1205. _JumpIfError(dw, Ret, "ThunkServerCallbacks");
  1206. // pass an hwnd to the exit module -- this is an optional value
  1207. bstrVal = SysAllocStringByteLen(NULL, sizeof(HWND));
  1208. if (NULL == bstrVal)
  1209. {
  1210. dw = (DWORD) E_OUTOFMEMORY;
  1211. _JumpError(dw, Ret, "SysAllocStringByteLen");
  1212. }
  1213. *(HWND*)(bstrVal) = m_hWnd;
  1214. dw = ManageModule_SetProperty(
  1215. &di,
  1216. m_pControlPage->m_pCA->m_bstrConfig,
  1217. bstrStorageLoc,
  1218. const_cast<WCHAR*>(wszCMM_PROP_DISPLAY_HWND),
  1219. 0,
  1220. PROPTYPE_BINARY,
  1221. bstrVal);
  1222. _PrintIfError(dw, "ManageModule_SetProperty(HWND)");
  1223. dw = ManageModule_Configure(
  1224. &di,
  1225. m_pControlPage->m_pCA->m_bstrConfig,
  1226. bstrStorageLoc,
  1227. dwConfigFlags);
  1228. _PrintIfError(dw, "ManageModule_Configure");
  1229. } while(0);
  1230. if (S_OK != dw)
  1231. DisplayGenericCertSrvError(m_hWnd, dw);
  1232. Ret:
  1233. if (fMustRelease)
  1234. ManageModule_Release(&di);
  1235. if (bstrStorageLoc)
  1236. ::SysFreeString(bstrStorageLoc);
  1237. if (bstrVal)
  1238. ::SysFreeString(bstrVal);
  1239. }
  1240. void CSvrSettingsExitPage::OnDestroy()
  1241. {
  1242. // Note - This needs to be called only once.
  1243. // If called more than once, it will gracefully return an error.
  1244. // if (m_hConsoleHandle)
  1245. // MMCFreeNotifyHandle(m_hConsoleHandle);
  1246. // m_hConsoleHandle = NULL;
  1247. CAutoDeletePropPage::OnDestroy();
  1248. }
  1249. HRESULT CSvrSettingsExitPage::InitializeExitLB()
  1250. {
  1251. HRESULT hr=S_OK;
  1252. SendMessage(GetDlgItem(m_hWnd, IDC_EXIT_LIST), LB_RESETCONTENT, 0, 0);
  1253. int i;
  1254. BSTR bstrProperty = SysAllocString(wszCMM_PROP_NAME);
  1255. _JumpIfOutOfMemory(hr, Ret, bstrProperty);
  1256. for (i=0; i< m_arrExitModules.GetSize(); i++)
  1257. {
  1258. LPWSTR pszDisplayString = m_arrExitModules[i].szModuleProgID; // by default, display progid
  1259. BSTR bstrName = NULL;
  1260. DISPATCHINTERFACE di;
  1261. // attempt to create object (locally)
  1262. hr = GetExitManageDispatch(
  1263. m_arrExitModules[i].szModuleProgID,
  1264. m_arrExitModules[i].clsidModule,
  1265. &di);
  1266. _PrintIfErrorStr(hr, "GetExitManageDispatch", m_arrExitModules[i].szModuleProgID);
  1267. if (hr == S_OK)
  1268. {
  1269. // get name property
  1270. hr = ManageModule_GetProperty(&di, m_pControlPage->m_pCA->m_bstrConfig, L"", bstrProperty, 0, PROPTYPE_STRING, &bstrName);
  1271. _PrintIfError(hr, "ManageModule_GetProperty");
  1272. // output successful display string
  1273. if (hr == S_OK && bstrName != NULL)
  1274. {
  1275. myRegisterMemAlloc(bstrName, -1, CSM_SYSALLOC);
  1276. pszDisplayString = bstrName;
  1277. }
  1278. ManageModule_Release(&di);
  1279. }
  1280. SendMessage(GetDlgItem(m_hWnd, IDC_EXIT_LIST), LB_ADDSTRING, 0, (LPARAM)pszDisplayString);
  1281. if (bstrName)
  1282. SysFreeString(bstrName);
  1283. }
  1284. Ret:
  1285. if (m_iSelected >= 0)
  1286. SendMessage(GetDlgItem(m_hWnd, IDC_EXIT_LIST), LB_SETCURSEL, m_iSelected, 0);
  1287. if (bstrProperty)
  1288. SysFreeString(bstrProperty);
  1289. return hr;
  1290. }
  1291. void CSvrSettingsExitPage::OnAddActiveModule()
  1292. {
  1293. DWORD dwErr;
  1294. COM_CERTSRV_MODULEDEFN sModule;
  1295. ZeroMemory(&sModule, sizeof(sModule));
  1296. // get currently active module
  1297. PRIVATE_DLGPROC_MODULESELECT_LPARAM sParam;
  1298. ZeroMemory(&sParam, sizeof(sParam));
  1299. sParam.fIsPolicyModuleSelection = FALSE;
  1300. sParam.pCA = m_pControlPage->m_pCA;
  1301. // don't support hilighting the active modules (there may be multiple)
  1302. sParam.ppszProgIDModule = &sModule.szModuleProgID;
  1303. sParam.pclsidModule = &sModule.clsidModule;
  1304. dwErr = (DWORD)DialogBoxParam(
  1305. g_hInstance,
  1306. MAKEINTRESOURCE(IDD_CHOOSE_MODULE),
  1307. m_hWnd,
  1308. dlgProcChooseModule,
  1309. (LPARAM)&sParam);
  1310. // translate ok/cancel into error codes
  1311. if (IDOK == dwErr)
  1312. {
  1313. // add to array...IFF not duplicate
  1314. for (int i=0; i<m_arrExitModules.GetSize(); i++)
  1315. {
  1316. #pragma warning(push) // BUGBUG: nonstandard extension used : class rvalue used as lvalue
  1317. #pragma warning(disable: 4238) // BUGBUG: nonstandard extension used : class rvalue used as lvalue
  1318. if (0 == memcmp(&sModule.clsidModule, &m_arrExitModules[i].clsidModule, sizeof(CLSID)) )
  1319. #pragma warning(pop) // BUGBUG: nonstandard extension used : class rvalue used as lvalue
  1320. break;
  1321. }
  1322. if (m_arrExitModules.GetSize() == i)
  1323. {
  1324. m_iSelected = m_arrExitModules.Add(sModule);
  1325. OnInitDialog();
  1326. SetModified(TRUE);
  1327. m_bUpdate = TRUE;
  1328. m_pControlPage->NeedServiceRestart(SERVERSETTINGS_PROPPAGE_EXIT);
  1329. }
  1330. }
  1331. if ((dwErr != IDOK) && (dwErr != IDCANCEL))
  1332. {
  1333. _PrintIfError(dwErr, "dlgProcChooseModule");
  1334. DisplayGenericCertSrvError(m_hWnd, dwErr);
  1335. }
  1336. return;
  1337. }
  1338. void CSvrSettingsExitPage::OnRemoveActiveModule()
  1339. {
  1340. if (m_iSelected != -1)
  1341. {
  1342. #pragma warning(push) // BUGBUG: nonstandard extension used : class rvalue used as lvalue
  1343. #pragma warning(disable: 4238) // BUGBUG: nonstandard extension used : class rvalue used as lvalue
  1344. ClearModuleDefn(&m_arrExitModules[m_iSelected]);
  1345. #pragma warning(pop) // BUGBUG: nonstandard extension used : class rvalue used as lvalue
  1346. m_arrExitModules.RemoveAt(m_iSelected);
  1347. m_iSelected--; // will either go to previous in list or -1 (NONE)
  1348. if ((m_iSelected == -1) && (m_arrExitModules.GetSize() != 0)) // if NONE and there are still modules
  1349. m_iSelected = 0; // select the first one
  1350. OnInitDialog();
  1351. SetModified(TRUE);
  1352. m_bUpdate = TRUE;
  1353. m_pControlPage->NeedServiceRestart(SERVERSETTINGS_PROPPAGE_EXIT);
  1354. }
  1355. return;
  1356. }
  1357. BOOL CSvrSettingsExitPage::OnApply()
  1358. {
  1359. HRESULT hr = S_OK;
  1360. SAFEARRAYBOUND sab;
  1361. SAFEARRAY* psa = NULL; // no cleanup, will be deleted by ~variant_t
  1362. BSTR bstr = NULL;
  1363. variant_t var;
  1364. LONG i;
  1365. if (m_bUpdate)
  1366. {
  1367. sab.cElements = m_arrExitModules.GetSize();
  1368. sab.lLbound = 0;
  1369. psa = SafeArrayCreate(
  1370. VT_BSTR,
  1371. 1,
  1372. &sab);
  1373. if(!psa)
  1374. {
  1375. hr = E_OUTOFMEMORY;
  1376. _JumpError(hr, error, "SafeArrayCreate");
  1377. }
  1378. for (i=0; i<m_arrExitModules.GetSize(); i++)
  1379. {
  1380. if(!ConvertWszToBstr(
  1381. &bstr,
  1382. m_arrExitModules[i].szModuleProgID,
  1383. -1))
  1384. {
  1385. hr = E_OUTOFMEMORY;
  1386. _JumpError(hr, error, "ConvertWszToBstr");
  1387. }
  1388. hr = SafeArrayPutElement(psa, (LONG*)&i, bstr);
  1389. _JumpIfError(hr, error, "SafeArrayPutElement");
  1390. SysFreeString(bstr);
  1391. bstr = NULL;
  1392. }
  1393. V_VT(&var) = VT_ARRAY|VT_BSTR;
  1394. V_ARRAY(&var) = psa;
  1395. psa = NULL;
  1396. // NOTE: could be NULL (no exit module)
  1397. hr = m_pControlPage->m_pCA->SetConfigEntry(
  1398. wszREGKEYEXITMODULES,
  1399. wszREGACTIVE,
  1400. &var);
  1401. _PrintIfError(hr, "SetConfigEntry");
  1402. m_bUpdate = FALSE;
  1403. m_pControlPage->TryServiceRestart(SERVERSETTINGS_PROPPAGE_EXIT);
  1404. OnInitDialog();
  1405. }
  1406. error:
  1407. if(psa)
  1408. SafeArrayDestroy(psa);
  1409. if(bstr)
  1410. SysFreeString(bstr);
  1411. if(S_OK!=hr)
  1412. {
  1413. DisplayGenericCertSrvError(m_hWnd, hr);
  1414. return FALSE;
  1415. }
  1416. return CAutoDeletePropPage::OnApply();
  1417. }
  1418. ////
  1419. // 4
  1420. /////////////////////////////////////////////////////////////////////////////
  1421. // CSvrSettingsExtensionPage property page
  1422. HRESULT
  1423. AddURLNode(
  1424. IN CSURLTEMPLATENODE **ppURLList,
  1425. IN CSURLTEMPLATENODE *pURLNode)
  1426. {
  1427. HRESULT hr = S_OK;
  1428. CSASSERT(NULL != ppURLList);
  1429. CSASSERT(NULL == pURLNode->pNext);
  1430. if (NULL == *ppURLList)
  1431. {
  1432. //empty list currently
  1433. *ppURLList = pURLNode;
  1434. }
  1435. else
  1436. {
  1437. CSURLTEMPLATENODE *pURLList = *ppURLList;
  1438. //find the end
  1439. while (NULL != pURLList->pNext)
  1440. {
  1441. pURLList = pURLList->pNext;
  1442. }
  1443. //add to the end
  1444. pURLList->pNext = pURLNode;
  1445. }
  1446. return hr;
  1447. }
  1448. ENUM_URL_TYPE rgAllPOSSIBLE_URL_PREFIXES[] =
  1449. {
  1450. URL_TYPE_HTTP,
  1451. URL_TYPE_FILE,
  1452. URL_TYPE_LDAP,
  1453. URL_TYPE_FTP,
  1454. };
  1455. HRESULT
  1456. BuildURLListFromStrings(
  1457. IN VARIANT &varURLs,
  1458. OUT CSURLTEMPLATENODE **ppURLList)
  1459. {
  1460. HRESULT hr;
  1461. CSURLTEMPLATENODE *pURLList = NULL;
  1462. CSURLTEMPLATENODE *pURLNode = NULL;
  1463. WCHAR *pwsz; // no free
  1464. WCHAR const *pwszURL;
  1465. DWORD dwFlags;
  1466. ENUM_URL_TYPE UrlType;
  1467. CSASSERT(V_VT(&varURLs)==(VT_ARRAY|VT_BSTR));
  1468. CSASSERT(NULL != ppURLList);
  1469. // init
  1470. *ppURLList = NULL;
  1471. SafeArrayEnum<BSTR> saenum(V_ARRAY(&varURLs));
  1472. while(S_OK==saenum.Next(pwsz))
  1473. {
  1474. dwFlags = _wtoi(pwsz);
  1475. pwszURL = pwsz;
  1476. while (pwszURL && iswdigit(*pwszURL))
  1477. {
  1478. pwszURL++;
  1479. }
  1480. if (pwszURL > pwsz && L':' == *pwszURL)
  1481. {
  1482. // ok, one url, create a new node
  1483. pURLNode = (CSURLTEMPLATENODE*)LocalAlloc(
  1484. LMEM_FIXED | LMEM_ZEROINIT,
  1485. sizeof(CSURLTEMPLATENODE));
  1486. if (NULL == pURLNode)
  1487. {
  1488. hr = E_OUTOFMEMORY;
  1489. _JumpError(hr, error, "LocalAlloc");
  1490. }
  1491. // skip :
  1492. ++pwszURL;
  1493. // translate %1 -> <CAName> etc.
  1494. hr = ExpandDisplayString(pwszURL, &pURLNode->URLTemplate.pwszURL);
  1495. _JumpIfError(hr, error, "ExpandDisplayString");
  1496. /*
  1497. pURLNode->URLTemplate.pwszURL = (WCHAR*)LocalAlloc(
  1498. LMEM_FIXED,
  1499. (wcslen(pwszURL) + 1) * sizeof(WCHAR));
  1500. if (NULL == pURLNode->URLTemplate.pwszURL)
  1501. {
  1502. hr = E_OUTOFMEMORY;
  1503. _JumpError(hr, error, "LocalAlloc");
  1504. }
  1505. wcscpy(pURLNode->URLTemplate.pwszURL, pwszURL);
  1506. */
  1507. pURLNode->URLTemplate.Flags = dwFlags;
  1508. //determine url type and assign enable mask
  1509. UrlType = DetermineURLType(
  1510. rgAllPOSSIBLE_URL_PREFIXES,
  1511. ARRAYSIZE(rgAllPOSSIBLE_URL_PREFIXES),
  1512. pURLNode->URLTemplate.pwszURL);
  1513. pURLNode->EnableMask = DetermineURLEnableMask(UrlType);
  1514. hr = AddURLNode(&pURLList, pURLNode);
  1515. _JumpIfError(hr , error, "AddURLNode");
  1516. }
  1517. }
  1518. //out
  1519. *ppURLList = pURLList;
  1520. hr = S_OK;
  1521. error:
  1522. return hr;
  1523. }
  1524. HRESULT
  1525. BuildURLStringFromList(
  1526. IN CSURLTEMPLATENODE *pURLList,
  1527. OUT VARIANT *pvarURLs)
  1528. {
  1529. HRESULT hr = S_OK;
  1530. WCHAR wszFlags[10];
  1531. LPWSTR pwszURL = NULL;
  1532. CSURLTEMPLATENODE *pURLNode = pURLList;
  1533. DWORD dwMaxSize = 0;
  1534. DWORD cURLs = 0;
  1535. SAFEARRAYBOUND rgsabound[1];
  1536. SAFEARRAY * psa = NULL;
  1537. long i;
  1538. CSASSERT(NULL != pvarURLs);
  1539. // init
  1540. VariantInit(pvarURLs);
  1541. while (NULL != pURLNode)
  1542. {
  1543. DWORD dwSize;
  1544. wsprintf(wszFlags, L"%d", pURLNode->URLTemplate.Flags);
  1545. dwSize = wcslen(wszFlags) +1;
  1546. // ASSUMPTION
  1547. // %1..%14 will always be = or smaller than shortest <CAName> token
  1548. dwSize += wcslen(pURLNode->URLTemplate.pwszURL) +1;
  1549. // otherwise, run code below
  1550. /*
  1551. pszThrowAway = NULL;
  1552. hr = ContractDisplayString(pURLNode->URLTemplate.pwszURL, &pszSizeComputation);
  1553. _JumpIfError(hr, error, "ContractDisplayString");
  1554. dwSize += wcslen(pszSizeComputation) + 1;
  1555. if (NULL != pszSizeComputation)
  1556. LocalFree(pszSizeComputation);
  1557. */
  1558. if(dwSize>dwMaxSize)
  1559. dwMaxSize = dwSize;
  1560. pURLNode = pURLNode->pNext;
  1561. cURLs++;
  1562. }
  1563. pwszURL = (WCHAR*)LocalAlloc(LMEM_FIXED, dwMaxSize * sizeof(WCHAR));
  1564. if (NULL == pwszURL)
  1565. {
  1566. hr = E_OUTOFMEMORY;
  1567. _JumpError(hr, error, "LocalAlloc");
  1568. }
  1569. rgsabound[0].lLbound = 0;
  1570. rgsabound[0].cElements = cURLs;
  1571. psa = SafeArrayCreate(VT_BSTR, 1, rgsabound);
  1572. if(!psa)
  1573. {
  1574. hr = E_OUTOFMEMORY;
  1575. _JumpError(hr, error, "SafeArrayCreate");
  1576. }
  1577. pURLNode = pURLList;
  1578. i=0;
  1579. while (NULL != pURLNode)
  1580. {
  1581. variant_t vtURL;
  1582. // translate <CAName> ... to %1
  1583. LPWSTR szContracted = NULL;
  1584. hr = ContractDisplayString(pURLNode->URLTemplate.pwszURL, &szContracted);
  1585. _JumpIfError(hr, error, "ContractDisplayString");
  1586. ASSERT(wcslen(szContracted) <= wcslen(pURLNode->URLTemplate.pwszURL)); // otherwise our assumption above doesn't hold
  1587. wsprintf(pwszURL, L"%d:%ws",
  1588. pURLNode->URLTemplate.Flags,
  1589. szContracted);
  1590. // free the tmp
  1591. if (NULL != szContracted)
  1592. LocalFree(szContracted);
  1593. vtURL = pwszURL;
  1594. hr = SafeArrayPutElement(psa, &i, V_BSTR(&vtURL));
  1595. _JumpIfError(hr, error, "LocalAlloc");
  1596. pURLNode = pURLNode->pNext;
  1597. i++;
  1598. }
  1599. V_VT(pvarURLs) = VT_ARRAY|VT_BSTR;
  1600. V_ARRAY(pvarURLs) = psa;
  1601. //done:
  1602. hr = S_OK;
  1603. error:
  1604. if(S_OK!=hr && psa)
  1605. {
  1606. SafeArrayDestroy(psa);
  1607. }
  1608. LOCAL_FREE(pwszURL);
  1609. return hr;
  1610. }
  1611. void
  1612. FreeURLNode(
  1613. IN CSURLTEMPLATENODE *pURLNode)
  1614. {
  1615. CSASSERT(NULL != pURLNode);
  1616. if (NULL != pURLNode->URLTemplate.pwszURL)
  1617. {
  1618. LocalFree(pURLNode->URLTemplate.pwszURL);
  1619. }
  1620. }
  1621. void
  1622. FreeURLList(
  1623. IN CSURLTEMPLATENODE *pURLList)
  1624. {
  1625. CSASSERT(NULL != pURLList);
  1626. // assume pURLList is always the 1st node
  1627. CSURLTEMPLATENODE *pURLNode = pURLList;
  1628. while (NULL != pURLNode)
  1629. {
  1630. FreeURLNode(pURLNode);
  1631. pURLNode = pURLNode->pNext;
  1632. }
  1633. LocalFree(pURLList);
  1634. }
  1635. HRESULT
  1636. RemoveURLNode(
  1637. IN OUT CSURLTEMPLATENODE **ppURLList,
  1638. IN CSURLTEMPLATENODE *pURLNode)
  1639. {
  1640. HRESULT hr;
  1641. // assume pURLList is always the 1st node
  1642. CSURLTEMPLATENODE *pURLList = *ppURLList;
  1643. BOOL fFound = FALSE;
  1644. if (pURLList == pURLNode)
  1645. {
  1646. //happen want to remove 1st one
  1647. //update the list head
  1648. *ppURLList = pURLList->pNext;
  1649. fFound = TRUE;
  1650. }
  1651. else
  1652. {
  1653. while (pURLList->pNext != NULL)
  1654. {
  1655. if (pURLList->pNext == pURLNode)
  1656. {
  1657. // found it
  1658. fFound = TRUE;
  1659. if (NULL == pURLNode->pNext)
  1660. {
  1661. // happen removed node is the last
  1662. // fix the end
  1663. pURLList->pNext = NULL;
  1664. }
  1665. else
  1666. {
  1667. // remove the node
  1668. pURLList->pNext = pURLList->pNext->pNext;
  1669. }
  1670. // out of while loop
  1671. break;
  1672. }
  1673. // go next
  1674. pURLList = pURLList->pNext;
  1675. }
  1676. }
  1677. if (!fFound)
  1678. {
  1679. hr = E_UNEXPECTED;
  1680. _JumpError(hr, error, "orphan node");
  1681. }
  1682. // remove the node
  1683. FreeURLNode(pURLNode);
  1684. hr = S_OK;
  1685. error:
  1686. return hr;
  1687. }
  1688. BOOL
  1689. IsURLInURLList(
  1690. IN CSURLTEMPLATENODE *pURLList,
  1691. IN WCHAR const *pwszURL)
  1692. {
  1693. BOOL fRet = FALSE;
  1694. // assume pURLList is always the 1st node
  1695. while (NULL != pURLList)
  1696. {
  1697. if (0 == mylstrcmpiL(pwszURL, pURLList->URLTemplate.pwszURL))
  1698. {
  1699. fRet = TRUE;
  1700. break;
  1701. }
  1702. pURLList = pURLList->pNext;
  1703. }
  1704. return fRet;
  1705. }
  1706. EXTENSIONWIZ_DATA g_ExtensionList[] =
  1707. {
  1708. {IDS_EXT_CDP,
  1709. IDS_EXT_CDP_EXPLAIN,
  1710. IDS_CDP_INCLUDE_INSTRUCTIONS,
  1711. IDS_PUBLISH_DELTAS_HERE,
  1712. wszREGCRLPUBLICATIONURLS,
  1713. CSURL_SERVERPUBLISH |
  1714. CSURL_ADDTOCERTCDP |
  1715. CSURL_ADDTOFRESHESTCRL |
  1716. CSURL_ADDTOCRLCDP |
  1717. CSURL_SERVERPUBLISHDELTA,
  1718. NULL},
  1719. {IDS_EXT_AIA,
  1720. IDS_EXT_AIA_EXPLAIN,
  1721. IDS_AIA_INCLUDE_INSTRUCTIONS,
  1722. IDS_INCLUDE_IN_OSCP_EXTENSION,
  1723. wszREGCACERTPUBLICATIONURLS,
  1724. CSURL_ADDTOCERTCDP |
  1725. CSURL_ADDTOCERTOCSP,
  1726. NULL},
  1727. {0, 0, 0, NULL, 0x0, NULL},
  1728. };
  1729. HRESULT
  1730. cuCopyToClipboard(
  1731. IN HWND hwndActive,
  1732. IN WCHAR const *pwszIn)
  1733. {
  1734. HRESULT hr;
  1735. HANDLE hData = NULL;
  1736. DWORD cwc;
  1737. WCHAR *pwszT;
  1738. BOOL fOpened = FALSE;
  1739. if (!OpenClipboard(hwndActive))
  1740. {
  1741. hr = myHLastError();
  1742. _JumpError(hr, error, "OpenClipboard");
  1743. }
  1744. fOpened = TRUE;
  1745. EmptyClipboard();
  1746. cwc = wcslen(pwszIn);
  1747. hData = GlobalAlloc(GMEM_MOVEABLE, (cwc + 1) * sizeof(WCHAR));
  1748. if (NULL == hData)
  1749. {
  1750. hr = E_OUTOFMEMORY;
  1751. _JumpError(hr, error, "GlobalAlloc");
  1752. }
  1753. pwszT = (WCHAR *) GlobalLock(hData);
  1754. if (NULL == pwszT)
  1755. {
  1756. hr = myHLastError();
  1757. _JumpError(hr, error, "GlobalLock");
  1758. }
  1759. wcscpy(pwszT, pwszIn);
  1760. GlobalUnlock(hData);
  1761. if (NULL == SetClipboardData(CF_UNICODETEXT, hData))
  1762. {
  1763. hr = myHLastError();
  1764. _JumpError(hr, error, "SetClipboardData");
  1765. }
  1766. hData = NULL; // now owned by clipboard
  1767. hr = S_OK;
  1768. error:
  1769. if (fOpened)
  1770. {
  1771. CloseClipboard();
  1772. }
  1773. if (NULL != hData)
  1774. {
  1775. GlobalFree(hData);
  1776. }
  1777. return(hr);
  1778. }
  1779. RoleAccessToControl CSvrSettingsExtensionPage::sm_ControlToRoleMap[] =
  1780. {
  1781. { IDC_URL_ADD, CA_ACCESS_ADMIN },
  1782. { IDC_URL_REMOVE, CA_ACCESS_ADMIN },
  1783. { IDC_ADDTOCERTCDP, CA_ACCESS_ADMIN },
  1784. { IDC_ADDTOCERTOCSP, CA_ACCESS_ADMIN },
  1785. { IDC_ADDTOFRESHESTCRL, CA_ACCESS_ADMIN },
  1786. { IDC_ADDTOCRLCDP, CA_ACCESS_ADMIN },
  1787. { IDC_SERVERPUBLISH, CA_ACCESS_ADMIN },
  1788. };
  1789. CSvrSettingsExtensionPage::CSvrSettingsExtensionPage(
  1790. CertSvrCA *pCertCA,
  1791. CSvrSettingsGeneralPage *pControlPage,
  1792. UINT uIDD) :
  1793. CAutoDeletePropPage(uIDD),
  1794. CRolesSupportInPropPage(
  1795. pCertCA,
  1796. sm_ControlToRoleMap,
  1797. ARRAYSIZE(sm_ControlToRoleMap)),
  1798. m_pControlPage(pControlPage)
  1799. {
  1800. m_bUpdate = FALSE;
  1801. m_nIndexReset = MAXDWORD;
  1802. m_pExtData = g_ExtensionList;
  1803. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTSRV_PROPPAGE4_CDP);
  1804. }
  1805. CSvrSettingsExtensionPage::~CSvrSettingsExtensionPage()
  1806. {
  1807. EXTENSIONWIZ_DATA *pExt = m_pExtData;
  1808. while (NULL != pExt->wszRegName)
  1809. {
  1810. if (NULL != pExt->pURLList)
  1811. {
  1812. FreeURLList(pExt->pURLList);
  1813. pExt->pURLList = NULL;
  1814. }
  1815. ++pExt;
  1816. }
  1817. }
  1818. // get current extension pointer
  1819. EXTENSIONWIZ_DATA* CSvrSettingsExtensionPage::GetCurrentExtension()
  1820. {
  1821. HWND hwndCtrl;
  1822. LRESULT nIndex;
  1823. EXTENSIONWIZ_DATA *pExt;
  1824. // get extension data
  1825. hwndCtrl = GetDlgItem(m_hWnd, IDC_EXT_SELECT);
  1826. nIndex = SendMessage(hwndCtrl, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
  1827. CSASSERT(CB_ERR != nIndex);
  1828. pExt = (EXTENSIONWIZ_DATA*)SendMessage(
  1829. hwndCtrl,
  1830. CB_GETITEMDATA,
  1831. (WPARAM)nIndex,
  1832. (LPARAM)0);
  1833. CSASSERT(NULL != pExt);
  1834. return pExt;
  1835. }
  1836. // get current url pointer
  1837. CSURLTEMPLATENODE* CSvrSettingsExtensionPage::GetCurrentURL(
  1838. OUT OPTIONAL LRESULT *pnIndex)
  1839. {
  1840. HWND hwndCtrl;
  1841. LRESULT nIndex;
  1842. CSURLTEMPLATENODE *pURLNode;
  1843. //get current url
  1844. hwndCtrl = GetDlgItem(m_hWnd, IDC_URL_LIST);
  1845. //get current url selection
  1846. nIndex = SendMessage(hwndCtrl, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
  1847. CSASSERT(LB_ERR != nIndex);
  1848. // get url data
  1849. pURLNode = (CSURLTEMPLATENODE*)SendMessage(hwndCtrl,
  1850. LB_GETITEMDATA,
  1851. (WPARAM)nIndex,
  1852. (LPARAM)0);
  1853. CSASSERT(NULL != pURLNode);
  1854. if (NULL != pnIndex)
  1855. {
  1856. *pnIndex = nIndex;
  1857. }
  1858. return pURLNode;
  1859. }
  1860. void CSvrSettingsExtensionPage::UpdateURLFlagControl(
  1861. IN int idCtrl,
  1862. IN DWORD dwFlag,
  1863. IN OPTIONAL EXTENSIONWIZ_DATA *pExt,
  1864. IN OPTIONAL CSURLTEMPLATENODE *pURLNode)
  1865. {
  1866. HWND hwndCtrl = GetDlgItem(m_hWnd, idCtrl);
  1867. // check extension type, hide/show accordingly
  1868. if (NULL == pExt || 0x0 == (dwFlag & pExt->dwFlagsMask) || NULL == pURLNode)
  1869. {
  1870. //no URLs link to the extension or
  1871. //the flag not making sense for the extension, disable it
  1872. ShowWindow(hwndCtrl, SW_HIDE);
  1873. SendMessage(hwndCtrl, BM_SETCHECK, (WPARAM)BST_UNCHECKED, (LPARAM)0);
  1874. }
  1875. else
  1876. {
  1877. //show the control first
  1878. ShowWindow(hwndCtrl, SW_SHOW);
  1879. if (0x0 == (dwFlag & pURLNode->EnableMask))
  1880. {
  1881. //this url type is not allowed, disbale it and unset it
  1882. SendMessage(hwndCtrl, BM_SETCHECK, BST_UNCHECKED, (LPARAM)0);
  1883. EnableControl(m_hWnd, idCtrl, FALSE);
  1884. }
  1885. else
  1886. {
  1887. //enable it
  1888. EnableControl(m_hWnd, idCtrl, TRUE);
  1889. WPARAM fCheck = (0x0 != (dwFlag & pURLNode->URLTemplate.Flags)) ?
  1890. BST_CHECKED : BST_UNCHECKED;
  1891. SendMessage(hwndCtrl, BM_SETCHECK, fCheck, (LPARAM)0);
  1892. }
  1893. // For ldap url, server name (ldap://server/DN...) is not supported, so disable
  1894. // the publish check boxes
  1895. LPCWSTR pcwszLDAP = L"ldap:";
  1896. LPCWSTR pcwszFwdSlashes = L"///";
  1897. if(IDS_EXT_CDP == pExt->idExtensionName &&
  1898. (IDC_SERVERPUBLISH == idCtrl ||
  1899. IDC_ADDTOCERTOCSP == idCtrl) &&
  1900. pURLNode &&
  1901. 0 == _wcsnicmp(
  1902. pURLNode->URLTemplate.pwszURL,
  1903. pcwszLDAP,
  1904. wcslen(pcwszLDAP)) &&
  1905. NULL == wcsstr(
  1906. pURLNode->URLTemplate.pwszURL,
  1907. pcwszFwdSlashes))
  1908. {
  1909. SendMessage(hwndCtrl, BM_SETCHECK, BST_UNCHECKED, (LPARAM)0);
  1910. EnableControl(m_hWnd, idCtrl, FALSE);
  1911. }
  1912. }
  1913. }
  1914. //update check controls from the flag
  1915. void
  1916. CSvrSettingsExtensionPage::UpdateURLFlags(
  1917. IN EXTENSIONWIZ_DATA *pExt,
  1918. IN OPTIONAL CSURLTEMPLATENODE *pURLNode)
  1919. {
  1920. if (NULL != pExt && NULL == pURLNode)
  1921. {
  1922. // use 1st one
  1923. pURLNode = pExt->pURLList;
  1924. }
  1925. UpdateURLFlagControl(IDC_SERVERPUBLISH,
  1926. CSURL_SERVERPUBLISH,
  1927. pExt,
  1928. pURLNode);
  1929. UpdateURLFlagControl(IDC_ADDTOCERTCDP,
  1930. CSURL_ADDTOCERTCDP,
  1931. pExt,
  1932. pURLNode);
  1933. UpdateURLFlagControl(IDC_ADDTOFRESHESTCRL,
  1934. CSURL_ADDTOFRESHESTCRL,
  1935. pExt,
  1936. pURLNode);
  1937. UpdateURLFlagControl(IDC_ADDTOCRLCDP,
  1938. CSURL_ADDTOCRLCDP,
  1939. pExt,
  1940. pURLNode);
  1941. // this chkbox is doubled up depending on mode
  1942. if (pExt && pExt->idExtensionName == IDS_EXT_AIA)
  1943. {
  1944. UpdateURLFlagControl(IDC_ADDTOCERTOCSP,
  1945. CSURL_ADDTOCERTOCSP,
  1946. pExt,
  1947. pURLNode);
  1948. }
  1949. else
  1950. {
  1951. UpdateURLFlagControl(IDC_ADDTOCERTOCSP,
  1952. CSURL_SERVERPUBLISHDELTA,
  1953. pExt,
  1954. pURLNode);
  1955. }
  1956. }
  1957. //handle url selection change
  1958. void CSvrSettingsExtensionPage::OnURLChange()
  1959. {
  1960. // update check controls
  1961. if (MAXDWORD != m_nIndexReset)
  1962. {
  1963. SendMessage(
  1964. GetDlgItem(m_hWnd, IDC_URL_LIST),
  1965. LB_SETCURSEL,
  1966. (WPARAM) m_nIndexReset,
  1967. (LPARAM) 0);
  1968. m_nIndexReset = MAXDWORD;
  1969. }
  1970. UpdateURLFlags(GetCurrentExtension(), GetCurrentURL(NULL));
  1971. }
  1972. void CSvrSettingsExtensionPage::OnURLCopy()
  1973. {
  1974. HWND hwndCtrl;
  1975. LRESULT nIndex;
  1976. hwndCtrl = GetDlgItem(m_hWnd, IDC_URL_LIST);
  1977. nIndex = SendMessage(hwndCtrl, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0);
  1978. if (LB_ERR != nIndex)
  1979. {
  1980. HRESULT hr;
  1981. CSURLTEMPLATENODE *pURL = GetCurrentURL(&nIndex);
  1982. if (NULL != pURL && NULL != pURL->URLTemplate.pwszURL)
  1983. {
  1984. hr = cuCopyToClipboard(m_hWnd, pURL->URLTemplate.pwszURL);
  1985. _PrintIfError(hr, "cuCopyToClipboard");
  1986. m_nIndexReset = nIndex;
  1987. }
  1988. }
  1989. }
  1990. void AdjustListHScrollWidth(HWND hwndList)
  1991. {
  1992. HDC hdc = GetDC(hwndList);
  1993. int cItem;
  1994. int maxWidth = 0;
  1995. int i;
  1996. SIZE sz;
  1997. WCHAR *pwszString = NULL;
  1998. if (LB_ERR == (cItem = (int)SendMessage(hwndList, LB_GETCOUNT, (WPARAM)0, (LPARAM)0)))
  1999. goto error;
  2000. //loop through all strings in list and find the largest length
  2001. for (i = 0; i < cItem; i++)
  2002. {
  2003. if (NULL != pwszString)
  2004. {
  2005. LocalFree(pwszString);
  2006. pwszString = NULL;
  2007. }
  2008. //get string length
  2009. int len = (int)SendMessage(hwndList, LB_GETTEXTLEN, (WPARAM)i, (LPARAM)0);
  2010. if (LB_ERR == len)
  2011. {
  2012. //ignore error, skip to next
  2013. continue;
  2014. }
  2015. pwszString = (WCHAR*)LocalAlloc(LMEM_FIXED, (len+1) * sizeof(WCHAR));
  2016. if (NULL == pwszString)
  2017. {
  2018. _JumpError(E_OUTOFMEMORY, error, "Out of memory");
  2019. }
  2020. //get string text
  2021. if (LB_ERR == SendMessage(hwndList, LB_GETTEXT, (WPARAM)i, (LPARAM)pwszString))
  2022. {
  2023. //skip error
  2024. continue;
  2025. }
  2026. //calculate string width
  2027. if (!GetTextExtentPoint32(hdc, pwszString, len, &sz))
  2028. {
  2029. //skip error
  2030. continue;
  2031. }
  2032. if (sz.cx > maxWidth)
  2033. {
  2034. maxWidth = sz.cx;
  2035. }
  2036. }
  2037. if (0 < maxWidth)
  2038. {
  2039. // now set horizontal scroll width
  2040. SendMessage(hwndList,
  2041. LB_SETHORIZONTALEXTENT,
  2042. (WPARAM)maxWidth,
  2043. (LPARAM)0);
  2044. }
  2045. error:
  2046. if (NULL != pwszString)
  2047. {
  2048. LocalFree(pwszString);
  2049. pwszString = NULL;
  2050. }
  2051. }
  2052. // handle extension selection change in the combo box
  2053. void CSvrSettingsExtensionPage::OnExtensionChange()
  2054. {
  2055. EXTENSIONWIZ_DATA *pExt;
  2056. LRESULT nIndex;
  2057. LRESULT nIndex0=0;
  2058. CString strExplain;
  2059. HWND hwndCtrl;
  2060. CSURLTEMPLATENODE *pURLNode;
  2061. BOOL fEnable = TRUE;
  2062. // get extension data
  2063. pExt = GetCurrentExtension();
  2064. // update extension explaination
  2065. strExplain.LoadString(pExt->idExtensionExplain);
  2066. SetWindowText(GetDlgItem(m_hWnd, IDC_EXT_EXPLAIN), strExplain);
  2067. // update default checkbox text with 'better' text
  2068. strExplain.LoadString(pExt->idCheckboxText);
  2069. SetWindowText(GetDlgItem(m_hWnd, IDC_ADDTOCERTCDP), strExplain);
  2070. // change meaning of OCSP/publish Delta CRL here text
  2071. strExplain.LoadString(pExt->idCheckboxText2);
  2072. SetWindowText(GetDlgItem(m_hWnd, IDC_ADDTOCERTOCSP), strExplain);
  2073. // remove the current URLs in the list
  2074. hwndCtrl = GetDlgItem(m_hWnd, IDC_URL_LIST);
  2075. while (0 < SendMessage(hwndCtrl, LB_GETCOUNT, (WPARAM)0, (LPARAM)0))
  2076. {
  2077. SendMessage(hwndCtrl, LB_DELETESTRING, (WPARAM)0, (LPARAM)0);
  2078. }
  2079. // list URLs of the current extension
  2080. pURLNode = pExt->pURLList;
  2081. while (NULL != pURLNode)
  2082. {
  2083. nIndex = SendMessage(hwndCtrl,
  2084. LB_ADDSTRING,
  2085. (WPARAM)0,
  2086. (LPARAM)pURLNode->URLTemplate.pwszURL);
  2087. CSASSERT(CB_ERR != nIndex);
  2088. if (pURLNode == pExt->pURLList)
  2089. {
  2090. //remember the 1st
  2091. nIndex0 = nIndex;
  2092. }
  2093. //set list item data
  2094. SendMessage(hwndCtrl, LB_SETITEMDATA, (WPARAM)nIndex, (LPARAM)pURLNode);
  2095. pURLNode = pURLNode->pNext;
  2096. }
  2097. //adjust horizontal scroll width
  2098. AdjustListHScrollWidth(hwndCtrl);
  2099. if (NULL != pExt->pURLList)
  2100. {
  2101. // select the first one
  2102. SendMessage(hwndCtrl, LB_SETCURSEL, (WPARAM)nIndex0, (LPARAM)0);
  2103. }
  2104. else
  2105. {
  2106. //empty url list
  2107. fEnable = FALSE;
  2108. }
  2109. EnableControl(m_hWnd, IDC_URL_REMOVE, fEnable);
  2110. UpdateURLFlags(pExt, NULL);
  2111. }
  2112. // handle check control change
  2113. void CSvrSettingsExtensionPage::OnFlagChange(DWORD dwFlag)
  2114. {
  2115. //get current url
  2116. CSURLTEMPLATENODE *pURLNode = GetCurrentURL(NULL);
  2117. // update flag
  2118. if (0x0 != (pURLNode->URLTemplate.Flags & dwFlag))
  2119. {
  2120. // means the current bit is on, trun it off
  2121. pURLNode->URLTemplate.Flags &= ~dwFlag;
  2122. }
  2123. else
  2124. {
  2125. // means the current bit is off, trun it on
  2126. pURLNode->URLTemplate.Flags |= dwFlag;
  2127. }
  2128. m_bUpdate = TRUE;
  2129. SetModified(m_bUpdate);
  2130. }
  2131. // handle remove url
  2132. BOOL CSvrSettingsExtensionPage::OnURLRemove()
  2133. {
  2134. LRESULT nIndex;
  2135. LRESULT nCount = 0;
  2136. HRESULT hr;
  2137. HWND hwndCtrl = GetDlgItem(m_hWnd, IDC_URL_LIST);
  2138. // get extension data
  2139. EXTENSIONWIZ_DATA *pExt = GetCurrentExtension();
  2140. //get current url
  2141. CSURLTEMPLATENODE *pURLNode = GetCurrentURL(&nIndex);
  2142. // confirm this action
  2143. CString cstrMsg, cstrTitle;
  2144. cstrMsg.LoadString(IDS_CONFIRM_REMOVE_URL);
  2145. cstrTitle.LoadString(IDS_CONFIRM_REMOVE_TITLE);
  2146. if (IDYES != MessageBox(m_hWnd, cstrMsg, cstrTitle, MB_YESNO))
  2147. goto bailout;
  2148. // remove it from the list
  2149. hr = RemoveURLNode(&pExt->pURLList, pURLNode);
  2150. if (S_OK == hr)
  2151. {
  2152. // ok, remove it from UI
  2153. nCount = SendMessage(hwndCtrl,
  2154. LB_DELETESTRING,
  2155. (WPARAM)nIndex,
  2156. (LPARAM)0);
  2157. m_bUpdate = TRUE;
  2158. SetModified(m_bUpdate);
  2159. // select a previous one, if 1st one, still 1st one
  2160. if (0 < nIndex)
  2161. {
  2162. --nIndex;
  2163. }
  2164. if (0 < nCount)
  2165. {
  2166. SendMessage(hwndCtrl, LB_SETCURSEL, (WPARAM)nIndex, (LPARAM)0);
  2167. pURLNode = GetCurrentURL(&nIndex);
  2168. UpdateURLFlags(pExt, pURLNode);
  2169. }
  2170. }
  2171. else
  2172. {
  2173. _PrintError(hr, "RemoveURLNode");
  2174. return FALSE;
  2175. }
  2176. if (0 >= nCount)
  2177. {
  2178. //now is empty list, disable remove button
  2179. EnableControl(m_hWnd, IDC_URL_REMOVE, FALSE);
  2180. //disable all check controls
  2181. UpdateURLFlags(NULL, NULL);
  2182. }
  2183. bailout:
  2184. return TRUE;
  2185. }
  2186. HRESULT
  2187. gpVerifyIA5URL(
  2188. IN WCHAR const *pwszURL)
  2189. {
  2190. HRESULT hr;
  2191. WCHAR *pwsz = NULL;
  2192. CERT_NAME_VALUE cnv;
  2193. BYTE *pb = NULL;
  2194. DWORD cb;
  2195. hr = myInternetCanonicalizeUrl(pwszURL, &pwsz);
  2196. _JumpIfError(hr, error, "myInternetCanonicalizeUrl");
  2197. // encode the string as an IA5 string
  2198. cnv.dwValueType = CERT_RDN_IA5_STRING;
  2199. cnv.Value.pbData = (BYTE *) pwsz;
  2200. cnv.Value.cbData = 0; // Use L'\0' termination for the length
  2201. if (!myEncodeObject(
  2202. X509_ASN_ENCODING,
  2203. X509_UNICODE_NAME_VALUE,
  2204. &cnv,
  2205. 0,
  2206. CERTLIB_USE_LOCALALLOC,
  2207. &pb,
  2208. &cb))
  2209. {
  2210. hr = myHLastError();
  2211. _JumpError(hr, error, "myEncodeObject");
  2212. }
  2213. hr = S_OK;
  2214. error:
  2215. if (NULL != pwsz)
  2216. {
  2217. LocalFree(pwsz);
  2218. }
  2219. if (NULL != pb)
  2220. {
  2221. LocalFree(pb);
  2222. }
  2223. return(hr);
  2224. }
  2225. INT_PTR CALLBACK dlgAddURL(
  2226. HWND hwnd,
  2227. UINT uMsg,
  2228. WPARAM wParam,
  2229. LPARAM lParam)
  2230. {
  2231. HRESULT hr;
  2232. BOOL fReturn = FALSE;
  2233. switch(uMsg)
  2234. {
  2235. case WM_INITDIALOG:
  2236. {
  2237. ::SetWindowLong(
  2238. hwnd,
  2239. GWL_EXSTYLE,
  2240. ::GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
  2241. // stash the ADDURL_DIALOGARGS pointer
  2242. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
  2243. // dump knowledge of tokens into dropdown, item data is description
  2244. HWND hCombo = GetDlgItem(hwnd, IDC_COMBO_VARIABLE);
  2245. for (int i=0; i<DISPLAYSTRINGS_TOKEN_COUNT; i++)
  2246. {
  2247. // skip invalid tokens
  2248. if (0 == wcscmp(L"", g_displayStrings[i].szContractedToken))
  2249. continue;
  2250. INT nItemIndex = (INT)SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM) (LPCWSTR) (*g_displayStrings[i].pcstrExpansionString));
  2251. if (CB_ERR == nItemIndex)
  2252. continue;
  2253. SendMessage(hCombo, CB_SETITEMDATA, (WPARAM)nItemIndex, (LPARAM) (LPCWSTR) (*g_displayStrings[i].pcstrExpansionStringDescr));
  2254. }
  2255. // set start value
  2256. SendMessage(hCombo, CB_SETCURSEL, 0, 0);
  2257. SetDlgItemText(hwnd, IDC_EDIT_VARIABLEDESCRIPTION, (LPCWSTR) (*g_displayStrings[0].pcstrExpansionStringDescr));
  2258. break;
  2259. }
  2260. case WM_HELP:
  2261. {
  2262. OnDialogHelp((LPHELPINFO)lParam,
  2263. CERTMMC_HELPFILENAME,
  2264. g_aHelpIDs_IDD_ADDURL);
  2265. break;
  2266. }
  2267. case WM_CONTEXTMENU:
  2268. {
  2269. OnDialogContextHelp((HWND)wParam,
  2270. CERTMMC_HELPFILENAME,
  2271. g_aHelpIDs_IDD_ADDURL);
  2272. break;
  2273. }
  2274. case WM_COMMAND:
  2275. switch (LOWORD(wParam))
  2276. {
  2277. case IDC_COMBO_VARIABLE:
  2278. {
  2279. if (HIWORD(wParam) == LBN_SELCHANGE)
  2280. {
  2281. // On selection change, ask for the selection idx
  2282. int nItemIndex = (INT)SendMessage((HWND)lParam,
  2283. CB_GETCURSEL,
  2284. 0,
  2285. 0);
  2286. LPCWSTR sz;
  2287. sz = (LPCWSTR) SendMessage(
  2288. (HWND)lParam,
  2289. CB_GETITEMDATA,
  2290. (WPARAM)nItemIndex,
  2291. 0);
  2292. if (CB_ERR == (DWORD_PTR)sz)
  2293. break; // get out of here
  2294. // otherwise, we just got descr... set it!
  2295. SetDlgItemText(hwnd, IDC_EDIT_VARIABLEDESCRIPTION, sz);
  2296. }
  2297. }
  2298. break;
  2299. case IDC_BUTTON_INSERTVAR:
  2300. {
  2301. WCHAR sz[64]; // ASSUME: no token is > 64 char
  2302. if (0 != GetDlgItemText(hwnd, IDC_COMBO_VARIABLE, sz, ARRAYLEN(sz)))
  2303. {
  2304. // insert <token> at cursor
  2305. SendMessage(GetDlgItem(hwnd, IDC_EDITURL), EM_REPLACESEL, TRUE, (LPARAM)sz);
  2306. }
  2307. }
  2308. break;
  2309. case IDOK:
  2310. {
  2311. // snatch the ADDURL_DIALOGARGS* we were given
  2312. ADDURL_DIALOGARGS* pArgs = (ADDURL_DIALOGARGS*)
  2313. GetWindowLongPtr(hwnd, GWLP_USERDATA);
  2314. if (pArgs == NULL)
  2315. {
  2316. hr = E_UNEXPECTED;
  2317. _PrintError(hr, "unexpected null data");
  2318. break;
  2319. }
  2320. hr = myUIGetWindowText(GetDlgItem(hwnd, IDC_EDITURL),
  2321. pArgs->ppszNewURL);
  2322. if (S_OK != hr)
  2323. {
  2324. _PrintError(hr, "myUIGetWindowText");
  2325. break;
  2326. }
  2327. if (NULL == *pArgs->ppszNewURL)
  2328. {
  2329. CertWarningMessageBox(
  2330. g_hInstance,
  2331. FALSE,
  2332. hwnd,
  2333. IDS_EMPTY_URL,
  2334. 0,
  2335. NULL);
  2336. HWND hwndCtrl = GetDlgItem(hwnd, IDC_EDITURL);
  2337. SetFocus(hwndCtrl);
  2338. break;
  2339. }
  2340. if (URL_TYPE_UNKNOWN == DetermineURLType(
  2341. pArgs->rgAllowedURLs,
  2342. pArgs->cAllowedURLs,
  2343. *pArgs->ppszNewURL))
  2344. {
  2345. // not found; bail with message
  2346. CertWarningMessageBox(
  2347. g_hInstance,
  2348. FALSE,
  2349. hwnd,
  2350. IDS_INVALID_PREFIX,
  2351. 0,
  2352. NULL);
  2353. SetFocus(GetDlgItem(hwnd, IDC_EDITURL));
  2354. break;
  2355. }
  2356. DWORD chBadBegin, chBadEnd;
  2357. if (S_OK != ValidateTokens(
  2358. *pArgs->ppszNewURL,
  2359. &chBadBegin,
  2360. &chBadEnd))
  2361. {
  2362. // not found; bail with message
  2363. CertWarningMessageBox(
  2364. g_hInstance,
  2365. FALSE,
  2366. hwnd,
  2367. IDS_INVALID_TOKEN,
  2368. 0,
  2369. NULL);
  2370. HWND hwndCtrl = GetDlgItem(hwnd, IDC_EDITURL);
  2371. // set selection starting from where validation failed
  2372. SetFocus(hwndCtrl);
  2373. SendMessage(hwndCtrl, EM_SETSEL, chBadBegin, chBadEnd);
  2374. break;
  2375. }
  2376. if (IsURLInURLList(pArgs->pURLList, *pArgs->ppszNewURL))
  2377. {
  2378. CString cstrMsg, cstrTemplate;
  2379. cstrTemplate.LoadString(IDS_SAME_URL_EXIST);
  2380. cstrMsg.Format(cstrTemplate, *pArgs->ppszNewURL);
  2381. if (IDYES != MessageBox(hwnd, cstrMsg, (LPCWSTR)g_pResources->m_DescrStr_CA, MB_YESNO))
  2382. {
  2383. HWND hwndCtrl = GetDlgItem(hwnd, IDC_EDITURL);
  2384. // set selection starting from where validation failed
  2385. SetFocus(hwndCtrl);
  2386. SendMessage(hwndCtrl, EM_SETSEL, 0, -1);
  2387. break;
  2388. }
  2389. // mattt, 1/15/01
  2390. // we want to warn but allow multiples so people can work around
  2391. // not being able to sort entries -- now they can create
  2392. // multiples of the same place but place them differently in the list
  2393. /*
  2394. // the same url is defined already
  2395. CertWarningMessageBox(
  2396. g_hInstance,
  2397. FALSE,
  2398. hwnd,
  2399. IDS_SAME_URL_EXIST,
  2400. 0,
  2401. *pArgs->ppszNewURL);
  2402. HWND hwndCtrl = GetDlgItem(hwnd, IDC_EDITURL);
  2403. // set selection starting from where validation failed
  2404. SetFocus(hwndCtrl);
  2405. SendMessage(hwndCtrl, EM_SETSEL, 0, -1);
  2406. break;
  2407. */
  2408. }
  2409. // attempt IA5 encoding
  2410. hr = gpVerifyIA5URL(*pArgs->ppszNewURL);
  2411. if (S_OK != hr)
  2412. {
  2413. _PrintError(hr, "gpVerifyIA5URL");
  2414. // encoding error; bail with message
  2415. WCHAR szMsg[MAX_PATH*2];
  2416. HWND hwndCtrl = GetDlgItem(hwnd, IDC_EDITURL);
  2417. LoadString(g_hInstance, IDS_INVALID_ENCODING, szMsg, ARRAYLEN(szMsg));
  2418. MessageBox(hwnd, szMsg, NULL, MB_OK);
  2419. // set selection starting from where validation failed
  2420. SetFocus(hwndCtrl);
  2421. SendMessage(GetDlgItem(hwnd, IDC_EDITURL), EM_SETSEL, MAXDWORD, -1);
  2422. break;
  2423. }
  2424. }
  2425. // fall through for cleanup
  2426. case IDCANCEL:
  2427. EndDialog(hwnd, LOWORD(wParam));
  2428. fReturn = TRUE;
  2429. break;
  2430. default:
  2431. break;
  2432. }
  2433. default:
  2434. break; //WM_COMMAND
  2435. }
  2436. return fReturn;
  2437. }
  2438. ENUM_URL_TYPE rgPOSSIBLE_CRL_URLs[] =
  2439. {
  2440. URL_TYPE_HTTP,
  2441. URL_TYPE_FILE,
  2442. URL_TYPE_LDAP,
  2443. URL_TYPE_FTP,
  2444. URL_TYPE_LOCAL,
  2445. URL_TYPE_UNC,
  2446. };
  2447. ENUM_URL_TYPE rgPOSSIBLE_AIA_URLs[] =
  2448. {
  2449. URL_TYPE_HTTP,
  2450. URL_TYPE_FILE,
  2451. URL_TYPE_LDAP,
  2452. URL_TYPE_FTP,
  2453. URL_TYPE_UNC,
  2454. };
  2455. // handle add url
  2456. BOOL CSvrSettingsExtensionPage::OnURLAdd()
  2457. {
  2458. HRESULT hr;
  2459. WCHAR *pwszURL = NULL;
  2460. CSURLTEMPLATENODE *pURLNode;
  2461. HWND hwndCtrl;
  2462. LRESULT nIndex;
  2463. // get current extension
  2464. EXTENSIONWIZ_DATA *pExt = GetCurrentExtension();
  2465. BOOL fCDP = (IDS_EXT_CDP == pExt->idExtensionName) ? TRUE : FALSE;
  2466. ADDURL_DIALOGARGS dlgArgs = {
  2467. fCDP ? rgPOSSIBLE_CRL_URLs : rgPOSSIBLE_AIA_URLs,
  2468. (DWORD)(fCDP ? ARRAYLEN(rgPOSSIBLE_CRL_URLs) : ARRAYLEN(rgPOSSIBLE_AIA_URLs)),
  2469. &pwszURL,
  2470. pExt->pURLList};
  2471. if (IDOK != DialogBoxParam(
  2472. g_hInstance,
  2473. MAKEINTRESOURCE(IDD_ADDURL),
  2474. m_hWnd,
  2475. dlgAddURL,
  2476. (LPARAM)&dlgArgs))
  2477. {
  2478. //cancel
  2479. return TRUE;
  2480. }
  2481. if (NULL != pwszURL && L'\0' != *pwszURL)
  2482. {
  2483. // a new url, add into the list
  2484. pURLNode = (CSURLTEMPLATENODE*)LocalAlloc(
  2485. LMEM_FIXED | LMEM_ZEROINIT,
  2486. sizeof(CSURLTEMPLATENODE));
  2487. if (NULL == pURLNode)
  2488. {
  2489. hr = E_OUTOFMEMORY;
  2490. _PrintError(hr, "LocalAlloc");
  2491. return FALSE;
  2492. }
  2493. pURLNode->URLTemplate.pwszURL = pwszURL;
  2494. pURLNode->EnableMask = DetermineURLEnableMask(
  2495. DetermineURLType(
  2496. rgAllPOSSIBLE_URL_PREFIXES,
  2497. ARRAYSIZE(rgAllPOSSIBLE_URL_PREFIXES),
  2498. pURLNode->URLTemplate.pwszURL));
  2499. //add to the data structure
  2500. hr = AddURLNode(&pExt->pURLList, pURLNode);
  2501. if (S_OK != hr)
  2502. {
  2503. _PrintError(hr, "AddURLNode");
  2504. return FALSE;
  2505. }
  2506. hwndCtrl = GetDlgItem(m_hWnd, IDC_URL_LIST);
  2507. nIndex = SendMessage(hwndCtrl,
  2508. LB_ADDSTRING,
  2509. (WPARAM)0,
  2510. (LPARAM)pURLNode->URLTemplate.pwszURL);
  2511. CSASSERT(LB_ERR != nIndex);
  2512. //set item data
  2513. SendMessage(hwndCtrl, LB_SETITEMDATA, (WPARAM)nIndex, (LPARAM)pURLNode);
  2514. //set it as current selection
  2515. SendMessage(hwndCtrl, LB_SETCURSEL, (WPARAM)nIndex, (LPARAM)0);
  2516. //update flag controls
  2517. UpdateURLFlags(pExt, pURLNode);
  2518. m_bUpdate = TRUE;
  2519. SetModified(m_bUpdate);
  2520. //alway enable remove button
  2521. EnableControl(m_hWnd, IDC_URL_REMOVE, TRUE);
  2522. //adjust list control width accordingly
  2523. AdjustListHScrollWidth(hwndCtrl);
  2524. }
  2525. return TRUE;
  2526. }
  2527. void CSvrSettingsExtensionPage::OnHelp(LPHELPINFO lpHelp)
  2528. {
  2529. // override help for _ADDCERTOCSP if chkbox is reused for _SERVERPUBLISHDELTA
  2530. if (lpHelp == NULL)
  2531. return;
  2532. if ((lpHelp->iContextType == HELPINFO_WINDOW) &&
  2533. (lpHelp->iCtrlId == IDC_ADDTOCERTOCSP))
  2534. {
  2535. EXTENSIONWIZ_DATA *pExt = GetCurrentExtension();
  2536. BOOL fCDP = (IDS_EXT_CDP == pExt->idExtensionName) ? TRUE : FALSE;
  2537. OnDialogHelp(lpHelp,
  2538. CERTMMC_HELPFILENAME,
  2539. (fCDP?
  2540. g_aHelpIDs_IDD_CERTSRV_PROPPAGE4_CDP:
  2541. g_aHelpIDs_IDD_CERTSRV_PROPPAGE4_AIA));
  2542. }
  2543. else
  2544. CAutoDeletePropPage::OnHelp(lpHelp);
  2545. }
  2546. void CSvrSettingsExtensionPage::OnContextHelp(HWND hwnd)
  2547. {
  2548. EXTENSIONWIZ_DATA *pExt = GetCurrentExtension();
  2549. BOOL fCDP = (IDS_EXT_CDP == pExt->idExtensionName) ? TRUE : FALSE;
  2550. if(hwnd == GetDlgItem(m_hWnd, IDC_ADDTOCERTOCSP))
  2551. {
  2552. ::WinHelp(
  2553. hwnd,
  2554. m_strHelpFile,
  2555. HELP_CONTEXTMENU,
  2556. (ULONG_PTR)(LPVOID)
  2557. (fCDP?m_prgzHelpIDs:g_aHelpIDs_IDD_CERTSRV_PROPPAGE4_AIA));
  2558. }
  2559. else
  2560. CAutoDeletePropPage::OnContextHelp(hwnd);
  2561. return;
  2562. }
  2563. // replacement for BEGIN_MESSAGE_MAP
  2564. BOOL
  2565. CSvrSettingsExtensionPage::OnCommand(
  2566. WPARAM wParam,
  2567. LPARAM) // lParam
  2568. {
  2569. switch(LOWORD(wParam))
  2570. {
  2571. case IDC_EXT_SELECT:
  2572. switch (HIWORD(wParam))
  2573. {
  2574. case CBN_SELCHANGE:
  2575. // extension selection is changed
  2576. OnExtensionChange();
  2577. break;
  2578. }
  2579. break;
  2580. case IDC_URL_LIST:
  2581. switch (HIWORD(wParam))
  2582. {
  2583. case LBN_SELCHANGE:
  2584. // url selection is changed
  2585. OnURLChange();
  2586. break;
  2587. }
  2588. break;
  2589. case IDC_URL_ADD:
  2590. return OnURLAdd();
  2591. break;
  2592. case IDC_URL_REMOVE:
  2593. OnURLRemove();
  2594. break;
  2595. case IDC_SERVERPUBLISH:
  2596. OnFlagChange(CSURL_SERVERPUBLISH);
  2597. break;
  2598. case IDC_ADDTOCERTCDP:
  2599. OnFlagChange(CSURL_ADDTOCERTCDP);
  2600. break;
  2601. case IDC_ADDTOFRESHESTCRL:
  2602. OnFlagChange(CSURL_ADDTOFRESHESTCRL);
  2603. break;
  2604. case IDC_ADDTOCRLCDP:
  2605. OnFlagChange(CSURL_ADDTOCRLCDP);
  2606. break;
  2607. case IDC_ADDTOCERTOCSP:
  2608. {
  2609. EXTENSIONWIZ_DATA *pExt = GetCurrentExtension();
  2610. ASSERT(pExt);
  2611. if (IDS_EXT_AIA == pExt->idExtensionName) // showing OCSP text
  2612. OnFlagChange(CSURL_ADDTOCERTOCSP);
  2613. else // delta text
  2614. OnFlagChange(CSURL_SERVERPUBLISHDELTA);
  2615. }
  2616. break;
  2617. default:
  2618. return FALSE;
  2619. }
  2620. return TRUE;
  2621. }
  2622. BOOL
  2623. CSvrSettingsExtensionPage::OnNotify(
  2624. IN UINT /* idCtrl */ ,
  2625. IN NMHDR *pnmh)
  2626. {
  2627. BOOL fHandled = FALSE;
  2628. switch (pnmh->code)
  2629. {
  2630. case PSN_TRANSLATEACCELERATOR:
  2631. {
  2632. MSG *pmsg = (MSG *) ((PSHNOTIFY *) pnmh)->lParam;
  2633. if (WM_CHAR == pmsg->message && 'C' - 0x40 == pmsg->wParam)
  2634. {
  2635. OnURLCopy();
  2636. fHandled = TRUE;
  2637. }
  2638. break;
  2639. }
  2640. }
  2641. return(fHandled);
  2642. }
  2643. /////////////////////////////////////////////////////////////////////////////
  2644. // CSvrSettingsExtensionPage message handlers
  2645. BOOL CSvrSettingsExtensionPage::OnInitDialog()
  2646. {
  2647. CSASSERT(NULL != m_pExtData);
  2648. EXTENSIONWIZ_DATA *pExt = m_pExtData;
  2649. DWORD dwRet;
  2650. HWND hwndCtrl;
  2651. CString strName;
  2652. LRESULT nIndex;
  2653. LRESULT nIndex0 = 0;
  2654. HRESULT hr;
  2655. VARIANT var;
  2656. // does parent init
  2657. CAutoDeletePropPage::OnInitDialog();
  2658. // initially disabled
  2659. UpdateURLFlags(NULL, NULL);
  2660. //go through each extension and init data from reg
  2661. while (NULL != pExt->wszRegName)
  2662. {
  2663. dwRet = m_pControlPage->m_pCA->GetConfigEntry(
  2664. NULL,
  2665. pExt->wszRegName,
  2666. &var);
  2667. if(dwRet != S_OK)
  2668. return FALSE;
  2669. CSASSERT(V_VT(&var)==(VT_ARRAY|VT_BSTR));
  2670. hr = BuildURLListFromStrings(var, &pExt->pURLList);
  2671. _PrintIfError(hr, "BuildURLListFromStrings");
  2672. ++pExt;
  2673. VariantClear(&var);
  2674. }
  2675. // add extensions into UI combo list
  2676. pExt = m_pExtData;
  2677. hwndCtrl = GetDlgItem(m_hWnd, IDC_EXT_SELECT);
  2678. while (NULL != pExt->wszRegName)
  2679. {
  2680. // load current extension display name into the list
  2681. strName.LoadString(pExt->idExtensionName);
  2682. nIndex = (INT)SendMessage(hwndCtrl,
  2683. CB_ADDSTRING,
  2684. (WPARAM)0,
  2685. (LPARAM)(LPCWSTR)strName);
  2686. CSASSERT(CB_ERR != nIndex);
  2687. //remember index of the first extension
  2688. if (pExt == m_pExtData)
  2689. {
  2690. nIndex0 = nIndex;
  2691. }
  2692. //link current extension to the item
  2693. nIndex = SendMessage(hwndCtrl,
  2694. CB_SETITEMDATA,
  2695. (WPARAM)nIndex,
  2696. (LPARAM)pExt);
  2697. CSASSERT(CB_ERR != nIndex);
  2698. ++pExt;
  2699. }
  2700. // select the 1st one as default
  2701. nIndex = SendMessage(hwndCtrl,
  2702. CB_SETCURSEL,
  2703. (WPARAM)nIndex0,
  2704. (LPARAM)0);
  2705. CSASSERT(CB_ERR != nIndex);
  2706. EnableControl(m_hWnd, IDC_URL_ADD, TRUE);
  2707. OnExtensionChange();
  2708. return TRUE;
  2709. }
  2710. void CSvrSettingsExtensionPage::OnDestroy()
  2711. {
  2712. // Note - This needs to be called only once.
  2713. // If called more than once, it will gracefully return an error.
  2714. // if (m_hConsoleHandle)
  2715. // MMCFreeNotifyHandle(m_hConsoleHandle);
  2716. // m_hConsoleHandle = NULL;
  2717. CAutoDeletePropPage::OnDestroy();
  2718. }
  2719. BOOL CSvrSettingsExtensionPage::OnApply()
  2720. {
  2721. DWORD dwRet = ERROR_SUCCESS;
  2722. EXTENSIONWIZ_DATA *pExt = m_pExtData;
  2723. WCHAR *pwszzURLs;
  2724. HRESULT hr;
  2725. variant_t varURLs;
  2726. if (m_bUpdate == TRUE)
  2727. {
  2728. //go through each extension and init data from reg
  2729. while (NULL != pExt->wszRegName)
  2730. {
  2731. pwszzURLs = NULL;
  2732. hr = BuildURLStringFromList(
  2733. pExt->pURLList,
  2734. &varURLs);
  2735. if (S_OK != hr)
  2736. {
  2737. _PrintError(hr, "BuildURLStringFromList");
  2738. return FALSE;
  2739. }
  2740. dwRet = m_pControlPage->m_pCA->SetConfigEntry(
  2741. NULL,
  2742. pExt->wszRegName,
  2743. &varURLs);
  2744. if (dwRet != ERROR_SUCCESS)
  2745. {
  2746. DisplayGenericCertSrvError(m_hWnd, dwRet);
  2747. _PrintError(dwRet, "SetConfigEntry");
  2748. return FALSE;
  2749. }
  2750. ++pExt;
  2751. varURLs.Clear();
  2752. }
  2753. //check to see if service is running
  2754. if (m_pCA->m_pParentMachine->IsCertSvrServiceRunning())
  2755. {
  2756. //throw a confirmation
  2757. CString cstrMsg;
  2758. cstrMsg.LoadString(IDS_CONFIRM_SERVICE_RESTART);
  2759. if (IDYES == ::MessageBox(m_hWnd, (LPCWSTR)cstrMsg, (LPCWSTR)g_pResources->m_DescrStr_CA, MB_YESNO | MB_ICONWARNING ))
  2760. {
  2761. //stop first
  2762. hr = m_pCA->m_pParentMachine->CertSvrStartStopService(m_hWnd, FALSE);
  2763. _PrintIfError(hr, "CertSvrStartStopService");
  2764. //should check status?
  2765. //start again
  2766. hr = m_pCA->m_pParentMachine->CertSvrStartStopService(m_hWnd, TRUE);
  2767. _PrintIfError(hr, "CertSvrStartStopService");
  2768. }
  2769. }
  2770. m_bUpdate = FALSE;
  2771. }
  2772. return CAutoDeletePropPage::OnApply();
  2773. }
  2774. ////
  2775. // 5
  2776. /////////////////////////////////////////////////////////////////////////////
  2777. // CSvrSettingsStoragePage property page
  2778. CSvrSettingsStoragePage::CSvrSettingsStoragePage(CSvrSettingsGeneralPage* pControlPage, UINT uIDD)
  2779. : CAutoDeletePropPage(uIDD), m_pControlPage(pControlPage)
  2780. {
  2781. m_cstrDatabasePath = _T("");
  2782. m_cstrLogPath = _T("");
  2783. m_cstrSharedFolder = _T("");
  2784. m_bUpdate = FALSE;
  2785. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTSRV_PROPPAGE5);
  2786. }
  2787. CSvrSettingsStoragePage::~CSvrSettingsStoragePage()
  2788. {
  2789. }
  2790. // replacement for DoDataExchange
  2791. BOOL CSvrSettingsStoragePage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  2792. {
  2793. if (fSuckFromDlg)
  2794. {
  2795. m_cstrDatabasePath.FromWindow(GetDlgItem(m_hWnd, IDC_EDIT_DATABASE_LOC));
  2796. m_cstrLogPath.FromWindow(GetDlgItem(m_hWnd, IDC_EDIT_LOG_LOC));
  2797. m_cstrSharedFolder.FromWindow(GetDlgItem(m_hWnd, IDC_EDIT_SHAREDFOLDER));
  2798. }
  2799. else
  2800. {
  2801. m_cstrDatabasePath.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_DATABASE_LOC));
  2802. m_cstrLogPath.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_LOG_LOC));
  2803. m_cstrSharedFolder.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_SHAREDFOLDER));
  2804. }
  2805. return TRUE;
  2806. }
  2807. /////////////////////////////////////////////////////////////////////////////
  2808. // CSvrSettingsStoragePage message handlers
  2809. BOOL CSvrSettingsStoragePage::OnInitDialog()
  2810. {
  2811. // does parent init and UpdateData call
  2812. CAutoDeletePropPage::OnInitDialog();
  2813. // DS or shared folder?
  2814. BOOL fUsesDS = m_pControlPage->m_pCA->FIsUsingDS();
  2815. ::SendDlgItemMessage(m_hWnd, IDC_CHECK1, BM_SETCHECK, (WPARAM) fUsesDS, 0);
  2816. HRESULT hr = S_OK;
  2817. variant_t var;
  2818. CertSvrMachine *pMachine = m_pControlPage->m_pCA->m_pParentMachine;
  2819. hr = pMachine->GetRootConfigEntry(
  2820. wszREGDIRECTORY,
  2821. &var);
  2822. // shared folder might not be configured, ignore
  2823. if(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)!=hr)
  2824. {
  2825. _JumpIfError(hr, Ret, "GetRootConfigEntry wszREGDIRECTORY");
  2826. m_cstrSharedFolder = V_BSTR(&var);
  2827. var.Clear();
  2828. }
  2829. hr = pMachine->GetRootConfigEntry(
  2830. wszREGDBDIRECTORY,
  2831. &var);
  2832. if(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)!=hr)
  2833. {
  2834. _JumpIfError(hr, Ret, "GetRootConfigEntry wszREGDBDIRECTORY");
  2835. m_cstrDatabasePath = V_BSTR(&var);
  2836. var.Clear();
  2837. }
  2838. hr = pMachine->GetRootConfigEntry(
  2839. wszREGDBLOGDIRECTORY,
  2840. &var);
  2841. if(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)!=hr)
  2842. {
  2843. _JumpIfError(hr, Ret, "GetRootConfigEntry wszREGDBLOGDIRECTORY");
  2844. m_cstrLogPath = V_BSTR(&var);
  2845. }
  2846. UpdateData(FALSE);
  2847. hr = S_OK;
  2848. Ret:
  2849. if (S_OK != hr)
  2850. return FALSE;
  2851. return TRUE;
  2852. }
  2853. ///////////////////////////////////////////
  2854. // CCRLPropPage
  2855. /////////////////////////////////////////////////////////////////////////////
  2856. // CCRLPropPage property page
  2857. RoleAccessToControl CCRLPropPage::sm_ControlToRoleMap[] =
  2858. {
  2859. { IDC_EDIT_CRLPERIODCOUNT, CA_ACCESS_ADMIN},
  2860. { IDC_COMBO_CRLPERIODSTRING, CA_ACCESS_ADMIN},
  2861. { IDC_ENABLE_DELTAPUBLISH, CA_ACCESS_ADMIN},
  2862. { IDC_EDIT_DELTACRLPERIODCOUNT, CA_ACCESS_ADMIN},
  2863. { IDC_COMBO_DELTACRLPERIODSTRING, CA_ACCESS_ADMIN},
  2864. };
  2865. CCRLPropPage::CCRLPropPage(CertSvrCA* pCA, UINT uIDD)
  2866. : CAutoDeletePropPage(uIDD),
  2867. CRolesSupportInPropPage(
  2868. pCA,
  2869. sm_ControlToRoleMap,
  2870. ARRAYSIZE(sm_ControlToRoleMap))
  2871. {
  2872. m_cstrPublishPeriodCount = "1";
  2873. m_cstrLastCRLPublish = _T("");
  2874. // m_iNoAutoPublish = BST_UNCHECKED;
  2875. m_cstrDeltaPublishPeriodCount = "1";
  2876. m_cstrDeltaLastCRLPublish = _T("");
  2877. m_iDeltaPublish = BST_CHECKED;
  2878. m_hConsoleHandle = NULL;
  2879. m_bUpdate = FALSE;
  2880. CSASSERT(m_pCA);
  2881. if (NULL == m_pCA)
  2882. return;
  2883. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CRL_PROPPAGE);
  2884. }
  2885. CCRLPropPage::~CCRLPropPage()
  2886. {
  2887. }
  2888. // replacement for DoDataExchange
  2889. BOOL CCRLPropPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  2890. {
  2891. if (fSuckFromDlg)
  2892. {
  2893. m_cstrPublishPeriodCount.FromWindow(GetDlgItem(m_hWnd, IDC_EDIT_CRLPERIODCOUNT));
  2894. m_cstrDeltaPublishPeriodCount.FromWindow(GetDlgItem(m_hWnd, IDC_EDIT_DELTACRLPERIODCOUNT));
  2895. m_iDeltaPublish = (INT)SendDlgItemMessage(IDC_ENABLE_DELTAPUBLISH, BM_GETCHECK, 0, 0);
  2896. }
  2897. else
  2898. {
  2899. m_cstrPublishPeriodCount.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_CRLPERIODCOUNT));
  2900. m_cstrLastCRLPublish.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_LASTUPDATE));
  2901. m_cstrDeltaPublishPeriodCount.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_DELTACRLPERIODCOUNT));
  2902. m_cstrDeltaLastCRLPublish.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_DELTALASTUPDATE));
  2903. SendDlgItemMessage(IDC_ENABLE_DELTAPUBLISH, BM_SETCHECK, (WPARAM)m_iDeltaPublish, 0);
  2904. }
  2905. return TRUE;
  2906. }
  2907. // replacement for BEGIN_MESSAGE_MAP
  2908. BOOL
  2909. CCRLPropPage::OnCommand(
  2910. WPARAM wParam,
  2911. LPARAM) // lParam
  2912. {
  2913. CString strCount;
  2914. switch(LOWORD(wParam))
  2915. {
  2916. case IDC_EDIT_CRLPERIODCOUNT:
  2917. case IDC_EDIT_DELTACRLPERIODCOUNT:
  2918. strCount.FromWindow(GetDlgItem(m_hWnd, LOWORD(wParam)));
  2919. if (EN_CHANGE == HIWORD(wParam) &&
  2920. m_cstrPublishPeriodCount != strCount)
  2921. {
  2922. OnEditChange();
  2923. }
  2924. break;
  2925. case IDC_COMBO_CRLPERIODSTRING:
  2926. case IDC_COMBO_DELTACRLPERIODSTRING:
  2927. if (CBN_SELCHANGE == HIWORD(wParam))
  2928. OnEditChange();
  2929. break;
  2930. case IDC_DISABLE_PUBLISH:
  2931. case IDC_DISABLE_DELTAPUBLISH:
  2932. if (BN_CLICKED == HIWORD(wParam))
  2933. OnCheckBoxChange(LOWORD(wParam) == IDC_DISABLE_PUBLISH);
  2934. break;
  2935. default:
  2936. return FALSE;
  2937. break;
  2938. }
  2939. return TRUE;
  2940. }
  2941. /////////////////////////////////////////////////////////////////////////////
  2942. // CCRLPropPage message handlers
  2943. void CCRLPropPage::OnDestroy()
  2944. {
  2945. // Note - This needs to be called only once.
  2946. // If called more than once, it will gracefully return an error.
  2947. if (m_hConsoleHandle)
  2948. MMCFreeNotifyHandle(m_hConsoleHandle);
  2949. m_hConsoleHandle = NULL;
  2950. CAutoDeletePropPage::OnDestroy();
  2951. }
  2952. BOOL CCRLPropPage::OnInitDialog()
  2953. {
  2954. // does parent init and UpdateData call
  2955. CAutoDeletePropPage::OnInitDialog();
  2956. m_cboxPublishPeriodString.Init(GetDlgItem(m_hWnd, IDC_COMBO_CRLPERIODSTRING));
  2957. m_cboxDeltaPublishPeriodString.Init(GetDlgItem(m_hWnd, IDC_COMBO_DELTACRLPERIODSTRING));
  2958. int iPublishPeriodCount = 0, iDeltaPublishPeriodCount = 0;
  2959. CString cstr;
  2960. HRESULT hr = S_OK;
  2961. variant_t var;
  2962. FILETIME ftBase, ftDelta;
  2963. ZeroMemory(&ftBase, sizeof(ftBase));
  2964. ZeroMemory(&ftDelta, sizeof(ftDelta));
  2965. // add strings to dropdown
  2966. m_cboxPublishPeriodString.ResetContent();
  2967. m_cboxDeltaPublishPeriodString.ResetContent();
  2968. int iEnum;
  2969. // y
  2970. iEnum = m_cboxPublishPeriodString.AddString(g_pResources->m_szPeriod_Years);
  2971. if (iEnum >= 0)
  2972. m_cboxPublishPeriodString.SetItemData(iEnum, ENUM_PERIOD_YEARS);
  2973. iEnum = m_cboxDeltaPublishPeriodString.AddString(g_pResources->m_szPeriod_Years);
  2974. if (iEnum >= 0)
  2975. m_cboxDeltaPublishPeriodString.SetItemData(iEnum, ENUM_PERIOD_YEARS);
  2976. // m
  2977. iEnum = m_cboxPublishPeriodString.AddString(g_pResources->m_szPeriod_Months);
  2978. if (iEnum >= 0)
  2979. m_cboxPublishPeriodString.SetItemData(iEnum, ENUM_PERIOD_MONTHS);
  2980. iEnum = m_cboxDeltaPublishPeriodString.AddString(g_pResources->m_szPeriod_Months);
  2981. if (iEnum >= 0)
  2982. m_cboxDeltaPublishPeriodString.SetItemData(iEnum, ENUM_PERIOD_MONTHS);
  2983. // w
  2984. iEnum = m_cboxPublishPeriodString.AddString(g_pResources->m_szPeriod_Weeks);
  2985. if (iEnum >= 0)
  2986. m_cboxPublishPeriodString.SetItemData(iEnum, ENUM_PERIOD_WEEKS);
  2987. iEnum = m_cboxDeltaPublishPeriodString.AddString(g_pResources->m_szPeriod_Weeks);
  2988. if (iEnum >= 0)
  2989. m_cboxDeltaPublishPeriodString.SetItemData(iEnum, ENUM_PERIOD_WEEKS);
  2990. // d
  2991. iEnum = m_cboxPublishPeriodString.AddString(g_pResources->m_szPeriod_Days);
  2992. if (iEnum >= 0)
  2993. m_cboxPublishPeriodString.SetItemData(iEnum, ENUM_PERIOD_DAYS);
  2994. iEnum = m_cboxDeltaPublishPeriodString.AddString(g_pResources->m_szPeriod_Days);
  2995. if (iEnum >= 0)
  2996. m_cboxDeltaPublishPeriodString.SetItemData(iEnum, ENUM_PERIOD_DAYS);
  2997. // h
  2998. iEnum = m_cboxPublishPeriodString.AddString(g_pResources->m_szPeriod_Hours);
  2999. if (iEnum >= 0)
  3000. m_cboxPublishPeriodString.SetItemData(iEnum, ENUM_PERIOD_HOURS);
  3001. iEnum = m_cboxDeltaPublishPeriodString.AddString(g_pResources->m_szPeriod_Hours);
  3002. if (iEnum >= 0)
  3003. m_cboxDeltaPublishPeriodString.SetItemData(iEnum, ENUM_PERIOD_HOURS);
  3004. // base period count
  3005. hr = m_pCA->GetConfigEntry(
  3006. NULL,
  3007. wszREGCRLPERIODCOUNT,
  3008. &var);
  3009. _JumpIfError(hr, error, "GetConfigEntry");
  3010. CSASSERT(V_VT(&var)==VT_I4);
  3011. iPublishPeriodCount = V_I4(&var);
  3012. var.Clear();
  3013. // Base CRL Period
  3014. hr = m_pCA->GetConfigEntry(
  3015. NULL,
  3016. wszREGCRLPERIODSTRING,
  3017. &var);
  3018. _JumpIfError(hr, error, "GetConfigEntry");
  3019. CSASSERT(V_VT(&var)== VT_BSTR);
  3020. // match validity internally, select combo
  3021. if (StringFromDurationEnum( DurationEnumFromNonLocalizedString(V_BSTR(&var)), &cstr, TRUE))
  3022. {
  3023. m_cboxPublishPeriodString.SelectString(
  3024. -1,
  3025. cstr);
  3026. }
  3027. // create comparison value for later
  3028. myMakeExprDateTime(
  3029. &ftBase,
  3030. iPublishPeriodCount,
  3031. DurationEnumFromNonLocalizedString(V_BSTR(&var)));
  3032. var.Clear();
  3033. // DELTA period count
  3034. hr = m_pCA->GetConfigEntry(
  3035. NULL,
  3036. wszREGCRLDELTAPERIODCOUNT,
  3037. &var);
  3038. _JumpIfError(hr, error, "GetConfigEntry");
  3039. CSASSERT(V_VT(&var)==VT_I4);
  3040. iDeltaPublishPeriodCount = V_I4(&var);
  3041. var.Clear();
  3042. // delta CRL Period
  3043. hr = m_pCA->GetConfigEntry(
  3044. NULL,
  3045. wszREGCRLDELTAPERIODSTRING,
  3046. &var);
  3047. _JumpIfError(hr, error, "GetConfigEntry");
  3048. CSASSERT(V_VT(&var)== VT_BSTR);
  3049. // create comparison value for later
  3050. myMakeExprDateTime(
  3051. &ftDelta,
  3052. iDeltaPublishPeriodCount,
  3053. DurationEnumFromNonLocalizedString(V_BSTR(&var)));
  3054. // match validity internally, select combo
  3055. // clamp delta <= Base
  3056. BOOL fSetDeltaString = TRUE;
  3057. if (0 >= CompareFileTime(&ftDelta, &ftBase))
  3058. {
  3059. fSetDeltaString = StringFromDurationEnum(
  3060. DurationEnumFromNonLocalizedString(V_BSTR(&var)),
  3061. &cstr,
  3062. TRUE);
  3063. }
  3064. else
  3065. {
  3066. if (0 != iDeltaPublishPeriodCount)
  3067. {
  3068. iDeltaPublishPeriodCount = iPublishPeriodCount;
  3069. }
  3070. }
  3071. if (fSetDeltaString)
  3072. {
  3073. m_cboxDeltaPublishPeriodString.SelectString(
  3074. -1,
  3075. cstr);
  3076. }
  3077. var.Clear();
  3078. // base Next publish
  3079. hr = m_pCA->GetConfigEntry(
  3080. NULL,
  3081. wszREGCRLNEXTPUBLISH,
  3082. &var);
  3083. _PrintIfError(hr, "GetConfigEntry");
  3084. // optional value: might have never been published
  3085. if (hr == S_OK)
  3086. {
  3087. CSASSERT(V_VT(&var)==(VT_ARRAY|VT_UI1));
  3088. DWORD dwType, dwSize;
  3089. BYTE *pbTmp = NULL;
  3090. hr = myVariantToRegValue(
  3091. &var,
  3092. &dwType,
  3093. &dwSize,
  3094. &pbTmp);
  3095. _JumpIfError(hr, error, "myGMTFileTimeToWszLocalTime");
  3096. CSASSERT(dwType == REG_BINARY);
  3097. // push result into FileTime
  3098. CSASSERT(dwSize == sizeof(FILETIME));
  3099. FILETIME ftGMT;
  3100. CopyMemory(&ftGMT, pbTmp, sizeof(FILETIME));
  3101. LOCAL_FREE(pbTmp);
  3102. // Convert to localized time localized string
  3103. hr = myGMTFileTimeToWszLocalTime(&ftGMT, FALSE, (LPWSTR*) &pbTmp);
  3104. _PrintIfError(hr, "myGMTFileTimeToWszLocalTime");
  3105. if (S_OK == hr)
  3106. {
  3107. m_cstrLastCRLPublish = (LPWSTR)pbTmp;
  3108. LOCAL_FREE(pbTmp);
  3109. }
  3110. }
  3111. var.Clear();
  3112. GetDeltaNextPublish();
  3113. // base autopublish
  3114. // don't allow 0 : use chkbox
  3115. // m_iNoAutoPublish = (iPublishPeriodCount == 0) ? BST_CHECKED : BST_UNCHECKED;
  3116. if (iPublishPeriodCount <= 0)
  3117. iPublishPeriodCount = 1;
  3118. m_cstrPublishPeriodCount.Format(L"%i", iPublishPeriodCount);
  3119. // ::EnableWindow(::GetDlgItem(m_hWnd, IDC_COMBO_CRLPERIODSTRING), (m_iNoAutoPublish == BST_UNCHECKED));
  3120. // ::EnableWindow(::GetDlgItem(m_hWnd, IDC_EDIT_CRLPERIODCOUNT), (m_iNoAutoPublish == BST_UNCHECKED));
  3121. // ::EnableWindow(::GetDlgItem(m_hWnd, IDC_EDIT_LASTUPDATE), (m_iNoAutoPublish == BST_UNCHECKED));
  3122. // DELTA autopublish
  3123. // don't allow 0 : use chkbox
  3124. m_iDeltaPublish = iDeltaPublishPeriodCount == 0? // if disabled
  3125. BST_UNCHECKED : BST_CHECKED;
  3126. if (iDeltaPublishPeriodCount <= 0)
  3127. iDeltaPublishPeriodCount = 1;
  3128. m_cstrDeltaPublishPeriodCount.Format(L"%i", iDeltaPublishPeriodCount);
  3129. EnableControl(m_hWnd, IDC_EDIT_CRLPERIODCOUNT, TRUE);
  3130. EnableControl(m_hWnd, IDC_COMBO_CRLPERIODSTRING, TRUE);
  3131. EnableControl(m_hWnd, IDC_ENABLE_DELTAPUBLISH, TRUE);
  3132. EnableControl(m_hWnd, IDC_COMBO_DELTACRLPERIODSTRING, (m_iDeltaPublish == BST_CHECKED));
  3133. EnableControl(m_hWnd, IDC_EDIT_DELTACRLPERIODCOUNT, (m_iDeltaPublish == BST_CHECKED));
  3134. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_EDIT_DELTALASTUPDATE), (m_iDeltaPublish == BST_CHECKED));
  3135. UpdateData(FALSE);
  3136. return TRUE;
  3137. error:
  3138. DisplayGenericCertSrvError(m_hWnd, hr);
  3139. return TRUE;
  3140. }
  3141. void CCRLPropPage::GetDeltaNextPublish()
  3142. {
  3143. HRESULT hr = S_OK;
  3144. variant_t var;
  3145. DWORD dwType, dwSize;
  3146. BYTE* pbTmp = NULL;
  3147. // DELTA Next publish
  3148. hr = m_pCA->GetConfigEntry(
  3149. NULL,
  3150. wszREGCRLDELTANEXTPUBLISH,
  3151. &var);
  3152. _JumpIfError(hr, error, "GetConfigEntry");
  3153. CSASSERT(V_VT(&var)==(VT_ARRAY|VT_UI1));
  3154. hr = myVariantToRegValue(
  3155. &var,
  3156. &dwType,
  3157. &dwSize,
  3158. &pbTmp);
  3159. _JumpIfError(hr, error, "myGMTFileTimeToWszLocalTime");
  3160. CSASSERT(dwType == REG_BINARY);
  3161. // push result into FileTime
  3162. CSASSERT(dwSize == sizeof(FILETIME));
  3163. FILETIME ftGMT;
  3164. CopyMemory(&ftGMT, pbTmp, sizeof(FILETIME));
  3165. LOCAL_FREE(pbTmp);
  3166. pbTmp=NULL;
  3167. // Convert to localized time localized string
  3168. hr = myGMTFileTimeToWszLocalTime(&ftGMT, FALSE, (LPWSTR*) &pbTmp);
  3169. _JumpIfError(hr, error, "myGMTFileTimeToWszLocalTime");
  3170. m_cstrDeltaLastCRLPublish = (LPWSTR)pbTmp;
  3171. error:
  3172. LOCAL_FREE(pbTmp);
  3173. return; // ignore errors
  3174. }
  3175. void
  3176. CCRLPropPage::OnCheckBoxChange(
  3177. BOOL) // fDisableBaseCRL
  3178. {
  3179. UpdateData(TRUE);
  3180. if(m_iDeltaPublish == BST_UNCHECKED)
  3181. {
  3182. m_cstrDeltaLastCRLPublish = L"";
  3183. m_cstrDeltaLastCRLPublish.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_DELTALASTUPDATE));
  3184. }
  3185. // pull in new selection
  3186. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_COMBO_DELTACRLPERIODSTRING), (m_iDeltaPublish == BST_CHECKED));
  3187. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_EDIT_DELTACRLPERIODCOUNT), (m_iDeltaPublish == BST_CHECKED));
  3188. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_EDIT_DELTALASTUPDATE), (m_iDeltaPublish == BST_CHECKED));
  3189. // call normal edit change to whack modified bit
  3190. OnEditChange();
  3191. }
  3192. void CCRLPropPage::OnEditChange()
  3193. {
  3194. // Page is dirty, mark it.
  3195. SetModified();
  3196. m_bUpdate = TRUE;
  3197. }
  3198. BOOL CCRLPropPage::OnApply()
  3199. {
  3200. HRESULT hr = S_OK;
  3201. BOOL fValidDigitString;
  3202. variant_t var;
  3203. FILETIME ftBase, ftDelta;
  3204. ZeroMemory(&ftBase, sizeof(ftBase));
  3205. ZeroMemory(&ftDelta, sizeof(ftDelta));
  3206. if (m_bUpdate == TRUE)
  3207. {
  3208. int iPublishPeriodCount, iDeltaPublishPeriodCount;
  3209. // check for invalid data in IDC_EDIT_CRLPERIODCOUNT if not autopublishing
  3210. iPublishPeriodCount = myWtoI(m_cstrPublishPeriodCount, &fValidDigitString);
  3211. // if (!m_iNoAutoPublish)
  3212. {
  3213. // invalid data is zero, negative, or not reproducible
  3214. if (!fValidDigitString || 0 == iPublishPeriodCount)
  3215. {
  3216. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_POSITIVE_NUMBER);
  3217. ::SetFocus(::GetDlgItem(m_hWnd, IDC_EDIT_CRLPERIODCOUNT));
  3218. return FALSE;
  3219. }
  3220. }
  3221. // check for invalid data in IDC_EDIT_DELTACRLPERIODCOUNT if not autopublishing
  3222. iDeltaPublishPeriodCount = myWtoI(m_cstrDeltaPublishPeriodCount, &fValidDigitString);
  3223. if (m_iDeltaPublish)
  3224. {
  3225. if (!fValidDigitString || 0 == iDeltaPublishPeriodCount)
  3226. {
  3227. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_POSITIVE_NUMBER);
  3228. ::SetFocus(::GetDlgItem(m_hWnd, IDC_EDIT_DELTACRLPERIODCOUNT));
  3229. return FALSE;
  3230. }
  3231. }
  3232. CString cstrTmp;
  3233. ENUM_PERIOD iEnum = (ENUM_PERIOD) m_cboxPublishPeriodString.GetItemData(m_cboxPublishPeriodString.GetCurSel());
  3234. if (StringFromDurationEnum(iEnum, &cstrTmp, FALSE))
  3235. {
  3236. // DWORD dwPublishPeriodCount = (m_iNoAutoPublish == BST_CHECKED) ? 0 : iPublishPeriodCount;
  3237. DWORD dwPublishPeriodCount = iPublishPeriodCount;
  3238. var = cstrTmp;
  3239. // create comparison value for later
  3240. myMakeExprDateTime(
  3241. &ftBase,
  3242. dwPublishPeriodCount,
  3243. iEnum);
  3244. hr = m_pCA->SetConfigEntry(
  3245. NULL,
  3246. wszREGCRLPERIODSTRING,
  3247. &var);
  3248. _JumpIfError(hr, Ret, "SetConfigEntry");
  3249. var.Clear();
  3250. V_VT(&var) = VT_I4;
  3251. V_I4(&var) = dwPublishPeriodCount;
  3252. // use chkbox
  3253. hr = m_pCA->SetConfigEntry(
  3254. NULL,
  3255. wszREGCRLPERIODCOUNT,
  3256. &var);
  3257. _JumpIfError(hr, Ret, "SetConfigEntry");
  3258. }
  3259. iEnum = (ENUM_PERIOD)m_cboxDeltaPublishPeriodString.GetItemData(m_cboxDeltaPublishPeriodString.GetCurSel());
  3260. if (StringFromDurationEnum(iEnum, &cstrTmp, FALSE))
  3261. {
  3262. DWORD dwDeltaPublishPeriodCount = (m_iDeltaPublish == BST_UNCHECKED) ? 0 : iDeltaPublishPeriodCount;
  3263. var = cstrTmp;
  3264. // create comparison value for later
  3265. myMakeExprDateTime(
  3266. &ftDelta,
  3267. dwDeltaPublishPeriodCount,
  3268. iEnum);
  3269. if (-1 != CompareFileTime(&ftDelta,&ftBase)) // if delta not less
  3270. {
  3271. dwDeltaPublishPeriodCount = 0; // disable
  3272. m_iDeltaPublish = BST_UNCHECKED;
  3273. }
  3274. // else
  3275. // m_iDeltaPublish = BST_CHECKED;
  3276. hr = m_pCA->SetConfigEntry(
  3277. NULL,
  3278. wszREGCRLDELTAPERIODSTRING,
  3279. &var);
  3280. _JumpIfError(hr, Ret, "SetConfigEntry");
  3281. var.Clear();
  3282. V_VT(&var) = VT_I4;
  3283. V_I4(&var) = dwDeltaPublishPeriodCount;
  3284. // use chkbox
  3285. hr = m_pCA->SetConfigEntry(
  3286. NULL,
  3287. wszREGCRLDELTAPERIODCOUNT,
  3288. &var);
  3289. _JumpIfError(hr, Ret, "SetConfigEntry");
  3290. if(!m_iDeltaPublish)
  3291. {
  3292. var.Clear();
  3293. V_VT(&var) = VT_EMPTY; // delete entry
  3294. hr = m_pCA->SetConfigEntry(
  3295. NULL,
  3296. wszREGCRLDELTANEXTPUBLISH,
  3297. &var);
  3298. if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
  3299. hr = S_OK; // if already deleted, don't care.
  3300. _JumpIfError(hr, Ret, "SetConfigEntry");
  3301. }
  3302. }
  3303. m_bUpdate = FALSE;
  3304. }
  3305. Ret:
  3306. if (hr != S_OK)
  3307. {
  3308. DisplayGenericCertSrvError(m_hWnd, hr);
  3309. return FALSE;
  3310. }
  3311. return CAutoDeletePropPage::OnApply();
  3312. }
  3313. ///////////////////////////////////////////
  3314. // CCRLViewPage
  3315. /////////////////////////////////////////////////////////////////////////////
  3316. // CCRLViewPage property page
  3317. CCRLViewPage::CCRLViewPage(CCRLPropPage* pControlPage, UINT uIDD)
  3318. : CAutoDeletePropPage(uIDD), m_pControlPage(pControlPage)
  3319. {
  3320. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CRL_VIEWPAGE);
  3321. }
  3322. CCRLViewPage::~CCRLViewPage()
  3323. {
  3324. }
  3325. // replacement for DoDataExchange
  3326. BOOL CCRLViewPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  3327. {
  3328. if (fSuckFromDlg)
  3329. {
  3330. }
  3331. else
  3332. {
  3333. }
  3334. return TRUE;
  3335. }
  3336. // replacement for BEGIN_MESSAGE_MAP
  3337. BOOL
  3338. CCRLViewPage::OnCommand(
  3339. WPARAM wParam,
  3340. LPARAM) // lParam
  3341. {
  3342. BOOL fBaseCRL = TRUE;
  3343. switch(LOWORD(wParam))
  3344. {
  3345. case IDC_CRL_VIEW_BTN_VIEWDELTA:
  3346. fBaseCRL = FALSE;
  3347. //fall through
  3348. case IDC_CRL_VIEW_BTN_VIEWCRL:
  3349. if (BN_CLICKED == HIWORD(wParam))
  3350. OnViewCRL(fBaseCRL);
  3351. break;
  3352. default:
  3353. //return FALSE;
  3354. return TRUE;
  3355. break;
  3356. }
  3357. return TRUE;
  3358. }
  3359. BOOL CCRLViewPage::OnNotify(UINT idCtrl, NMHDR* pnmh)
  3360. {
  3361. BOOL fBaseCRL = TRUE;
  3362. switch(idCtrl)
  3363. {
  3364. //handle double click on list items
  3365. case IDC_CRL_VIEW_LIST_DELTA:
  3366. fBaseCRL = FALSE;
  3367. //fall through
  3368. case IDC_CRL_VIEW_LIST_CRL:
  3369. switch (pnmh->code)
  3370. {
  3371. case NM_DBLCLK:
  3372. OnViewCRL(fBaseCRL);
  3373. break;
  3374. case LVN_ITEMCHANGED:
  3375. OnSelectCRL(fBaseCRL);
  3376. break;
  3377. }
  3378. break;
  3379. }
  3380. return FALSE;
  3381. }
  3382. /////////////////////////////////////////////////////////////////////////////
  3383. // CCRLViewPage message handlers
  3384. /*
  3385. To get the CA signature cert count, use ICertAdmin::GetCAProperty(
  3386. strConfig,
  3387. PropId == CR_PROP_CASIGCERTCOUNT,
  3388. PropIndex == 0 (unused),
  3389. PropType == PROPTYPE_LONG,
  3390. Flags == CR_OUT_BINARY,
  3391. &varPropertyValue);
  3392. varPropertyValue.vt will be VT_I4
  3393. varPropertyValue.lVal will be the CA signature cert count
  3394. then step key index from 0 to 1 less than the count of signature certs to determine which key indices have valid CRLs:
  3395. To get each key's CRL state, call ICertAdmin2::GetCAProperty(
  3396. strConfig,
  3397. PropId == CR_PROP_CRLSTATE,
  3398. PropIndex == key index (MAXDWORD for current key),
  3399. PropType == PROPTYPE_LONG,
  3400. Flags == CR_OUT_BINARY,
  3401. &varPropertyValue);
  3402. varPropertyValue.vt will be VT_I4
  3403. varPropertyValue.lVal will be the CRL state, CA_DISP_VALID means you can fetch the CRL for that index.
  3404. To get each key's CRL, call ICertAdmin2::GetCAProperty(
  3405. strConfig,
  3406. PropId == CR_PROP_BASECRL or CR_PROP_DELTACRL,
  3407. PropIndex == key index (MAXDWORD for current key),
  3408. PropType == PROPTYPE_BINARY,
  3409. Flags == CR_OUT_BINARY,
  3410. &varPropertyValue);
  3411. varPropertyValue.vt will be VT_BSTR
  3412. varPropertyValue.bstrVal can be cast to BYTE *pbCRL
  3413. SysStringByteLen(varPropertyValue.bstrVal) will be cbCRL
  3414. If the server is down level, all GetCAProperty method calls will return RPC_E_VERSION_MISMATCH. Then you have two choices:
  3415. use ICertAdmin::GetCRL, which will only retrieve the current key's base CRL
  3416. to fetch a CAINFO structure to get the CA signature cert count, use ICertRequest::GetCACertificate(
  3417. fExchangeCertificate == GETCERT_CAINFO,
  3418. strConfig,
  3419. Flags == CR_OUT_BINARY,
  3420. &strOut);
  3421. strCACertificate will be a Unicode BSTR, something like: L"3,1". The first number is the CA Type, and the second is the count of CA signature certs.
  3422. then step key index from 0 to 1 less than the count of signature certs to determine which key indices have valid CRLs:
  3423. To get each key's CRL state, call ICertRequest::GetCACertificate(
  3424. fExchangeCertificate == GETCERT_CRLSTATEBYINDEX | key index),
  3425. strConfig,
  3426. Flags == CR_OUT_BINARY,
  3427. &strOut);
  3428. strCACertificate will be a Unicode BSTR, something like: L"3". After converting to a DWORD, CA_DISP_VALID means you can fetch the CRL for that index.
  3429. To get each key's CRL, call ICertRequest::GetCACertificate( // can retrieve only base CRLs for all server keys
  3430. fExchangeCertificate == GETCERT_CRLBYINDEX | key index (MAXDWORD not supported here),
  3431. strConfig,
  3432. Flags == CR_OUT_BINARY,
  3433. &strOut);
  3434. strOut can be cast to BYTE *pbCRL
  3435. SysStringByteLen(strOut) will be cbCRL
  3436. */
  3437. void MapCRLPublishStatusToString(DWORD dwStatus, CString& strStatus)
  3438. {
  3439. strStatus.LoadString(
  3440. dwStatus?
  3441. ((dwStatus&CPF_COMPLETE)?
  3442. IDS_CRLPUBLISHSTATUS_OK:
  3443. IDS_CRLPUBLISHSTATUS_FAILED):
  3444. IDS_CRLPUBLISHSTATUS_UNKNOWN);
  3445. }
  3446. void
  3447. ListView_AddCRLItem(
  3448. IN HWND hwndList,
  3449. IN int iItem,
  3450. IN DWORD dwIndex,
  3451. IN PCCRL_CONTEXT pCRLContext,
  3452. IN DWORD dwCRLPublishStatus)
  3453. {
  3454. CString cstrItemName;
  3455. CString cstrCRLPublishStatus;
  3456. MapCRLPublishStatusToString(dwCRLPublishStatus, cstrCRLPublishStatus);
  3457. // add column data for crl
  3458. // renew index
  3459. cstrItemName.Format(L"%d", dwIndex);
  3460. ListView_NewItem(hwndList, iItem, cstrItemName, (LPARAM)pCRLContext);
  3461. if (pCRLContext) // on error, don't add these
  3462. {
  3463. // crl effective date
  3464. ListView_SetItemFiletime(hwndList, iItem, 1, &pCRLContext->pCrlInfo->ThisUpdate);
  3465. // crl expiration date
  3466. ListView_SetItemFiletime(hwndList, iItem, 2, &pCRLContext->pCrlInfo->NextUpdate);
  3467. }
  3468. // crl publish status
  3469. ListView_SetItemText(hwndList, iItem, 3, cstrCRLPublishStatus.GetBuffer());
  3470. }
  3471. void
  3472. ListView_AddFailedCRLItem(
  3473. IN HWND hwndList,
  3474. IN int iItem,
  3475. IN DWORD dwIndex,
  3476. LPCWSTR pcwszMessage
  3477. )
  3478. {
  3479. CString cstrItemName;
  3480. // add column data for crl
  3481. // renew index
  3482. cstrItemName.Format(L"%d", dwIndex);
  3483. ListView_NewItem(hwndList, iItem, cstrItemName, NULL);
  3484. ListView_SetItemText(hwndList, iItem, 1, const_cast<LPWSTR>(pcwszMessage));
  3485. }
  3486. void
  3487. ListView_AddFailedCRLItem2(
  3488. IN HWND hwndList,
  3489. IN int iItem,
  3490. IN DWORD dwIndex,
  3491. HRESULT hr
  3492. )
  3493. {
  3494. CString strMsg;
  3495. CString strFormat;
  3496. LPCWSTR pcwszError;
  3497. pcwszError = myGetErrorMessageText(hr, TRUE);
  3498. strFormat.LoadString(IDS_CRLERROR_FORMAT);
  3499. strMsg.Format(strFormat, pcwszError?pcwszError:L"");
  3500. ListView_AddFailedCRLItem(
  3501. hwndList,
  3502. iItem,
  3503. dwIndex,
  3504. strMsg);
  3505. LOCAL_FREE(const_cast<LPWSTR>(pcwszError));
  3506. }
  3507. BOOL CCRLViewPage::OnInitDialog()
  3508. {
  3509. HRESULT hr;
  3510. ICertAdmin2* pAdmin = NULL;
  3511. VARIANT varPropertyValue, varCRLStatus;
  3512. VariantInit(&varPropertyValue);
  3513. VariantInit(&varCRLStatus);
  3514. DWORD cCertCount, dwCertIndex;
  3515. CString cstrItemName;
  3516. int iItem = 0, iDeltaItem = 0;
  3517. HWND hwndListCRL, hwndListDeltaCRL;
  3518. PCCRL_CONTEXT pCRLContext = NULL;
  3519. PCCRL_CONTEXT pDeltaCRLContext = NULL;
  3520. CWaitCursor WaitCursor;
  3521. CString strMessage;
  3522. // does parent init and UpdateData call
  3523. CAutoDeletePropPage::OnInitDialog();
  3524. // init listview
  3525. hwndListCRL = GetDlgItem(m_hWnd, IDC_CRL_VIEW_LIST_CRL);
  3526. hwndListDeltaCRL = GetDlgItem(m_hWnd, IDC_CRL_VIEW_LIST_DELTA);
  3527. //make listviews whole row selection
  3528. ListView_SetExtendedListViewStyle(hwndListCRL, LVS_EX_FULLROWSELECT);
  3529. ListView_SetExtendedListViewStyle(hwndListDeltaCRL, LVS_EX_FULLROWSELECT);
  3530. //add multiple columns
  3531. //column 0
  3532. cstrItemName.LoadString(IDS_CRL_LISTCOL_INDEX);
  3533. ListView_NewColumn(hwndListCRL, 0, 60, (LPWSTR)(LPCWSTR)cstrItemName);
  3534. ListView_NewColumn(hwndListDeltaCRL, 0, 60, (LPWSTR)(LPCWSTR)cstrItemName);
  3535. //column 1
  3536. cstrItemName.LoadString(IDS_LISTCOL_EFFECTIVE_DATE);
  3537. ListView_NewColumn(hwndListCRL, 1, 105, (LPWSTR)(LPCWSTR)cstrItemName);
  3538. ListView_NewColumn(hwndListDeltaCRL, 1, 105, (LPWSTR)(LPCWSTR)cstrItemName);
  3539. //column 2
  3540. cstrItemName.LoadString(IDS_LISTCOL_EXPIRATION_DATE);
  3541. ListView_NewColumn(hwndListCRL, 2, 105, (LPWSTR)(LPCWSTR)cstrItemName);
  3542. ListView_NewColumn(hwndListDeltaCRL, 2, 105, (LPWSTR)(LPCWSTR)cstrItemName);
  3543. //column 3
  3544. cstrItemName.LoadString(IDS_LISTCOL_PUBLISH_STATUS);
  3545. ListView_NewColumn(hwndListCRL, 3, 83, (LPWSTR)(LPCWSTR)cstrItemName);
  3546. ListView_NewColumn(hwndListDeltaCRL, 3, 83, (LPWSTR)(LPCWSTR)cstrItemName);
  3547. hr = m_pControlPage->m_pCA->m_pParentMachine->GetAdmin2(&pAdmin);
  3548. _JumpIfError(hr, Ret, "GetAdmin");
  3549. // load crls here
  3550. hr = pAdmin->GetCAProperty(
  3551. m_pControlPage->m_pCA->m_bstrConfig,
  3552. CR_PROP_CASIGCERTCOUNT,
  3553. 0, // (unused)
  3554. PROPTYPE_LONG, // PropType
  3555. CR_OUT_BINARY, // Flags
  3556. &varPropertyValue);
  3557. _JumpIfErrorStr(hr, Ret, "GetCAProperty", L"CR_PROP_CASIGCERTCOUNT");
  3558. CSASSERT(VT_I4 == V_VT(&varPropertyValue));
  3559. cCertCount = varPropertyValue.lVal;
  3560. iItem = 0;
  3561. iDeltaItem = 0;
  3562. for (dwCertIndex=0; dwCertIndex<cCertCount; dwCertIndex++)
  3563. {
  3564. VariantClear(&varPropertyValue);
  3565. VariantClear(&varCRLStatus);
  3566. bool fFetchBaseCRL = false;
  3567. bool fFetchDeltaCRL = false;
  3568. CERT_EXTENSION *pExt = NULL;
  3569. // get each key's CRL state
  3570. hr = pAdmin->GetCAProperty(
  3571. m_pControlPage->m_pCA->m_bstrConfig,
  3572. CR_PROP_CRLSTATE, //PropId
  3573. dwCertIndex, //PropIndex
  3574. PROPTYPE_LONG, // PropType
  3575. CR_OUT_BINARY, // Flags
  3576. &varPropertyValue);
  3577. _PrintIfErrorStr(hr, "GetCAProperty", L"CR_PROP_CRLSTATE");
  3578. if(S_OK == hr)
  3579. {
  3580. CSASSERT(VT_I4 == V_VT(&varPropertyValue));
  3581. switch(V_I4(&varPropertyValue))
  3582. {
  3583. case CA_DISP_ERROR:
  3584. continue;
  3585. case CA_DISP_REVOKED:
  3586. strMessage.LoadString(IDS_CRLSTATE_REVOKED);
  3587. break;
  3588. case CA_DISP_INVALID:
  3589. case CA_DISP_VALID:
  3590. fFetchBaseCRL = true;
  3591. break;
  3592. }
  3593. if(fFetchBaseCRL)
  3594. {
  3595. hr = m_pControlPage->m_pCA->GetCRLByKeyIndex(&pCRLContext, TRUE, dwCertIndex);
  3596. if (S_OK != hr)
  3597. {
  3598. _PrintError(hr, "GetCRLByKeyIndex (base)");
  3599. if (CA_DISP_INVALID == V_I4(&varPropertyValue))
  3600. {
  3601. continue;
  3602. }
  3603. }
  3604. else
  3605. {
  3606. // zero means Unknown error
  3607. V_VT(&varCRLStatus) = VT_I4;
  3608. V_I4(&varCRLStatus) = 0;
  3609. hr = pAdmin->GetCAProperty(
  3610. m_pControlPage->m_pCA->m_bstrConfig,
  3611. CR_PROP_BASECRLPUBLISHSTATUS,
  3612. dwCertIndex,
  3613. PROPTYPE_LONG,
  3614. CR_OUT_BINARY,
  3615. &varCRLStatus);
  3616. _PrintIfErrorStr(hr, "GetCAProperty (base)",
  3617. L"CR_PROP_BASECRLPUBLISHSTATUS"); // in case of error, will show "Unknown"
  3618. ListView_AddCRLItem(
  3619. hwndListCRL,
  3620. iItem,
  3621. dwCertIndex,
  3622. pCRLContext,
  3623. V_I4(&varCRLStatus));
  3624. pExt = CertFindExtension(
  3625. szOID_FRESHEST_CRL,
  3626. pCRLContext->pCrlInfo->cExtension,
  3627. pCRLContext->pCrlInfo->rgExtension);
  3628. fFetchDeltaCRL = (NULL != pExt);
  3629. pCRLContext = NULL;
  3630. hr = S_OK;
  3631. }
  3632. }
  3633. else
  3634. {
  3635. ListView_AddFailedCRLItem(
  3636. hwndListCRL,
  3637. iItem,
  3638. dwCertIndex,
  3639. strMessage);
  3640. hr = S_OK;
  3641. }
  3642. }
  3643. if(S_OK != hr)
  3644. {
  3645. ListView_AddFailedCRLItem2(
  3646. hwndListCRL,
  3647. iItem,
  3648. dwCertIndex,
  3649. hr);
  3650. }
  3651. iItem++;
  3652. if(fFetchDeltaCRL)
  3653. {
  3654. if(fFetchBaseCRL)
  3655. {
  3656. // Delta
  3657. VariantClear(&varCRLStatus);
  3658. hr = m_pControlPage->m_pCA->GetCRLByKeyIndex(&pDeltaCRLContext, FALSE, dwCertIndex);
  3659. _PrintIfError(hr, "GetCRLByKeyIndex (delta)");
  3660. if(S_OK == hr)
  3661. {
  3662. // zero is status Unknown
  3663. V_VT(&varCRLStatus) = VT_I4;
  3664. V_I4(&varCRLStatus) = 0;
  3665. hr = pAdmin->GetCAProperty(
  3666. m_pControlPage->m_pCA->m_bstrConfig,
  3667. CR_PROP_DELTACRLPUBLISHSTATUS,
  3668. dwCertIndex,
  3669. PROPTYPE_LONG,
  3670. CR_OUT_BINARY,
  3671. &varCRLStatus);
  3672. _PrintIfErrorStr(hr, "GetCAProperty (delta)",
  3673. L"CR_PROP_DELTACRLPUBLISHSTATUS"); // in case of error will show "Unknown"
  3674. ListView_AddCRLItem(
  3675. hwndListDeltaCRL,
  3676. iDeltaItem,
  3677. dwCertIndex,
  3678. pDeltaCRLContext,
  3679. V_I4(&varCRLStatus));
  3680. //don't free, they are used as item data, will free in OnDestroy
  3681. pDeltaCRLContext = NULL;
  3682. }
  3683. else
  3684. {
  3685. ListView_AddFailedCRLItem2(
  3686. hwndListDeltaCRL,
  3687. iDeltaItem,
  3688. dwCertIndex,
  3689. hr);
  3690. }
  3691. }
  3692. else
  3693. {
  3694. ListView_AddFailedCRLItem(
  3695. hwndListDeltaCRL,
  3696. iDeltaItem,
  3697. dwCertIndex,
  3698. strMessage);
  3699. }
  3700. iDeltaItem++;
  3701. }
  3702. hr = S_OK;
  3703. }
  3704. if (0 < iItem)
  3705. {
  3706. //select most recent item
  3707. ListView_SetItemState(
  3708. hwndListCRL,
  3709. iItem-1,
  3710. LVIS_SELECTED|LVIS_FOCUSED,
  3711. LVIS_SELECTED|LVIS_FOCUSED);
  3712. // make sure it's visible
  3713. ListView_EnsureVisible(
  3714. hwndListCRL,
  3715. iItem-1,
  3716. FALSE); // fPartialOK
  3717. }
  3718. if(0 < iDeltaItem)
  3719. {
  3720. ListView_SetItemState(
  3721. hwndListDeltaCRL,
  3722. iDeltaItem-1,
  3723. LVIS_SELECTED|LVIS_FOCUSED,
  3724. LVIS_SELECTED|LVIS_FOCUSED);
  3725. // make sure it's visible
  3726. ListView_EnsureVisible(
  3727. hwndListDeltaCRL,
  3728. iDeltaItem-1,
  3729. FALSE); // fPartialOK
  3730. }
  3731. UpdateData(FALSE);
  3732. hr = S_OK;
  3733. Ret:
  3734. if (NULL != pCRLContext)
  3735. {
  3736. CertFreeCRLContext(pCRLContext);
  3737. }
  3738. if (NULL != pDeltaCRLContext)
  3739. {
  3740. CertFreeCRLContext(pDeltaCRLContext);
  3741. }
  3742. if (pAdmin)
  3743. pAdmin->Release();
  3744. VariantClear(&varPropertyValue);
  3745. if (hr != S_OK)
  3746. {
  3747. HideControls();
  3748. EnableWindow(GetDlgItem(IDC_UNAVAILABLE), TRUE);
  3749. ShowWindow(GetDlgItem(IDC_UNAVAILABLE), SW_SHOW);
  3750. }
  3751. return TRUE;
  3752. }
  3753. DWORD CertAdminViewCRL(CertSvrCA* pCertCA, HWND hwnd, PCCRL_CONTEXT pCRLContext)
  3754. {
  3755. DWORD dwErr;
  3756. HCERTSTORE rghStores[2];
  3757. CRYPTUI_VIEWCRL_STRUCT sViewCRL;
  3758. ZeroMemory(&sViewCRL, sizeof(sViewCRL));
  3759. if (pCRLContext == NULL)
  3760. {
  3761. _PrintError(E_POINTER, "pCRLContext");
  3762. dwErr = S_OK;
  3763. goto Ret;
  3764. }
  3765. sViewCRL.dwSize = sizeof(sViewCRL);
  3766. sViewCRL.hwndParent = hwnd;
  3767. sViewCRL.pCRLContext = pCRLContext;
  3768. sViewCRL.dwFlags = CRYPTUI_ENABLE_REVOCATION_CHECKING |
  3769. CRYPTUI_DISABLE_ADDTOSTORE;
  3770. // if we're opening remotely, don't open local stores
  3771. if (! pCertCA->m_pParentMachine->IsLocalMachine())
  3772. {
  3773. DWORD dw;
  3774. // get remote stores
  3775. dw = pCertCA->GetRootCertStore(&rghStores[0]);
  3776. _PrintIfError(dw, "GetRootCertStore");
  3777. if (S_OK == dw)
  3778. {
  3779. dw = pCertCA->GetCACertStore(&rghStores[1]);
  3780. _PrintIfError(dw, "GetCACertStore");
  3781. }
  3782. if (S_OK == dw)
  3783. {
  3784. // rely only on remote machine's stores
  3785. sViewCRL.cStores = 2;
  3786. sViewCRL.rghStores = rghStores;
  3787. sViewCRL.dwFlags |= CRYPTUI_DONT_OPEN_STORES | CRYPTUI_WARN_UNTRUSTED_ROOT;
  3788. }
  3789. else
  3790. {
  3791. // tell user we're only doing this locally
  3792. sViewCRL.dwFlags |= CRYPTUI_WARN_REMOTE_TRUST;
  3793. }
  3794. }
  3795. if (!CryptUIDlgViewCRL(&sViewCRL))
  3796. {
  3797. dwErr = GetLastError();
  3798. if (dwErr != ERROR_CANCELLED)
  3799. _JumpError(dwErr, Ret, "CryptUIDlgViewCRL");
  3800. }
  3801. dwErr = ERROR_SUCCESS;
  3802. Ret:
  3803. return dwErr;
  3804. }
  3805. void CCRLViewPage::OnSelectCRL(BOOL fBaseCRL)
  3806. {
  3807. PCCRL_CONTEXT pCRLContext;
  3808. BOOL fEnable = FALSE;
  3809. HWND hwndList = GetDlgItem(m_hWnd, (fBaseCRL ?
  3810. IDC_CRL_VIEW_LIST_CRL : IDC_CRL_VIEW_LIST_DELTA));
  3811. // get cert # from item data
  3812. int iSel = ListView_GetCurSel(hwndList);
  3813. if (-1 != iSel)
  3814. {
  3815. // get item data
  3816. pCRLContext = (PCCRL_CONTEXT)ListView_GetItemData(hwndList, iSel);
  3817. if (NULL != pCRLContext)
  3818. fEnable = TRUE;
  3819. }
  3820. ::EnableWindow(
  3821. GetDlgItem(m_hWnd,
  3822. fBaseCRL?
  3823. IDC_CRL_VIEW_BTN_VIEWCRL:
  3824. IDC_CRL_VIEW_BTN_VIEWDELTA),
  3825. fEnable);
  3826. }
  3827. void CCRLViewPage::OnViewCRL(BOOL fViewBaseCRL)
  3828. {
  3829. DWORD dw;
  3830. PCCRL_CONTEXT pCRLContext;
  3831. HWND hwndList = GetDlgItem(m_hWnd, (fViewBaseCRL ?
  3832. IDC_CRL_VIEW_LIST_CRL : IDC_CRL_VIEW_LIST_DELTA));
  3833. // get cert # from item data
  3834. int iSel = ListView_GetCurSel(hwndList);
  3835. if (-1 == iSel)
  3836. return;
  3837. // get item data
  3838. pCRLContext = (PCCRL_CONTEXT)ListView_GetItemData(hwndList, iSel);
  3839. if (NULL == pCRLContext)
  3840. return;
  3841. dw = CertAdminViewCRL(m_pControlPage->m_pCA, m_hWnd, pCRLContext);
  3842. _PrintIfError(dw, "CertAdminViewCRL");
  3843. if ((dw != ERROR_SUCCESS) && (dw != ERROR_CANCELLED))
  3844. DisplayGenericCertSrvError(m_hWnd, dw);
  3845. }
  3846. void
  3847. FreeListViewCRL(HWND hwndList, int iItem)
  3848. {
  3849. PCCRL_CONTEXT pCRLContext;
  3850. pCRLContext = (PCCRL_CONTEXT)ListView_GetItemData(hwndList, iItem);
  3851. if (pCRLContext != NULL)
  3852. CertFreeCRLContext(pCRLContext);
  3853. }
  3854. void CCRLViewPage::OnDestroy()
  3855. {
  3856. int i;
  3857. HWND hwndListCRL = GetDlgItem(m_hWnd, IDC_CRL_VIEW_LIST_CRL);
  3858. HWND hwndListDeltaCRL = GetDlgItem(m_hWnd, IDC_CRL_VIEW_LIST_DELTA);
  3859. int iCRLCount = ListView_GetItemCount(hwndListCRL);
  3860. int iDeltaCRLCount = ListView_GetItemCount(hwndListDeltaCRL);
  3861. //free all crl context
  3862. for (i = 0; i < iCRLCount; ++i)
  3863. {
  3864. FreeListViewCRL(hwndListCRL, i);
  3865. }
  3866. for (i = 0; i < iDeltaCRLCount; ++i)
  3867. {
  3868. FreeListViewCRL(hwndListDeltaCRL, i);
  3869. }
  3870. CAutoDeletePropPage::OnDestroy();
  3871. }
  3872. ///////////////////////////////////////////
  3873. // CBackupWizPage1
  3874. /////////////////////////////////////////////////////////////////////////////
  3875. // CBackupWizPage1 property page
  3876. CBackupWizPage1::CBackupWizPage1(
  3877. BACKUPWIZ_STATE* pState,
  3878. CWizard97PropertySheet *pcDlg,
  3879. UINT uIDD) :
  3880. CWizard97PropertyPage(g_hInstance, uIDD, g_aidFont),
  3881. m_pState(pState),
  3882. m_pParentSheet(pcDlg)
  3883. {
  3884. InitWizard97 (TRUE); // firstlast page
  3885. // SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTIFICATE_TEMPLATE_PROPERTIES_GENERAL_PAGE);
  3886. }
  3887. CBackupWizPage1::~CBackupWizPage1()
  3888. {
  3889. }
  3890. // replacement for DoDataExchange
  3891. BOOL CBackupWizPage1::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  3892. {
  3893. if (fSuckFromDlg)
  3894. {
  3895. }
  3896. else
  3897. {
  3898. }
  3899. return TRUE;
  3900. }
  3901. // replacement for BEGIN_MESSAGE_MAP
  3902. BOOL
  3903. CBackupWizPage1::OnCommand(
  3904. WPARAM, // wParam
  3905. LPARAM) // lParam
  3906. {
  3907. // switch(LOWORD(wParam))
  3908. {
  3909. // default:
  3910. return FALSE;
  3911. // break;
  3912. }
  3913. // return TRUE;
  3914. }
  3915. BOOL CBackupWizPage1::OnInitDialog()
  3916. {
  3917. // does parent init and UpdateData call
  3918. CWizard97PropertyPage::OnInitDialog();
  3919. // firstlast page
  3920. //(GetDlgItem(IDC_TEXT_BIGBOLD))->SetFont(&(GetBigBoldFont()), TRUE);
  3921. SendMessage(GetDlgItem(IDC_TEXT_BIGBOLD), WM_SETFONT, (WPARAM)GetBigBoldFont(), MAKELPARAM(TRUE, 0));
  3922. return TRUE;
  3923. }
  3924. BOOL CBackupWizPage1::OnSetActive()
  3925. {
  3926. PropertyPage::OnSetActive();
  3927. PropSheet_SetWizButtons(GetParent(), PSWIZB_NEXT);
  3928. return TRUE;
  3929. }
  3930. ///////////////////////////////////////////
  3931. // CBackupWizPage2
  3932. /////////////////////////////////////////////////////////////////////////////
  3933. // CBackupWizPage2 property page
  3934. CBackupWizPage2::CBackupWizPage2(
  3935. PBACKUPWIZ_STATE pState,
  3936. CWizard97PropertySheet *pcDlg,
  3937. UINT uIDD) :
  3938. CWizard97PropertyPage(g_hInstance, uIDD, g_aidFont),
  3939. m_pState(pState),
  3940. m_pParentSheet(pcDlg)
  3941. {
  3942. m_szHeaderTitle.LoadString(IDS_WIZ97TITLE_BACKUPWIZPG2);
  3943. m_szHeaderSubTitle.LoadString(IDS_WIZ97SUBTITLE_BACKUPWIZPG2);
  3944. InitWizard97 (FALSE);
  3945. m_cstrLogsPath = L"";
  3946. m_iKeyCertCheck = BST_UNCHECKED;
  3947. m_iLogsCheck = BST_UNCHECKED;
  3948. m_iIncrementalCheck = BST_UNCHECKED;
  3949. DWORD dwRet;
  3950. m_fIncrementalAllowed = FALSE;
  3951. variant_t var;
  3952. dwRet = m_pState->pCA->m_pParentMachine->GetRootConfigEntry(
  3953. wszREGDBLASTFULLBACKUP,
  3954. &var);
  3955. if(S_OK==dwRet)
  3956. {
  3957. m_fIncrementalAllowed = TRUE;
  3958. }
  3959. // SetHelp(CERTMMC_HELPFILENAME , g_aHelpIDs_IDD_CERTIFICATE_TEMPLATE_PROPERTIES_GENERAL_PAGE);
  3960. }
  3961. // replacement for DoDataExchange
  3962. BOOL CBackupWizPage2::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  3963. {
  3964. if (fSuckFromDlg)
  3965. {
  3966. m_cstrLogsPath.FromWindow(GetDlgItem(m_hWnd, IDC_EDIT_LOGS));
  3967. m_iKeyCertCheck = (INT)SendDlgItemMessage(IDC_CHECK_KEYCERT, BM_GETCHECK, 0, 0);
  3968. m_iLogsCheck = (INT)SendDlgItemMessage(IDC_CHECK_LOGS, BM_GETCHECK, 0, 0);
  3969. m_iIncrementalCheck = (INT)SendDlgItemMessage(IDC_CHECK_INCREMENTAL, BM_GETCHECK, 0, 0);
  3970. }
  3971. else
  3972. {
  3973. m_cstrLogsPath.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_LOGS));
  3974. SendDlgItemMessage(IDC_CHECK_KEYCERT, BM_SETCHECK, (WPARAM)m_iKeyCertCheck, 0);
  3975. SendDlgItemMessage(IDC_CHECK_LOGS, BM_SETCHECK, (WPARAM)m_iLogsCheck, 0);
  3976. SendDlgItemMessage(IDC_CHECK_INCREMENTAL, BM_SETCHECK, (WPARAM)m_iIncrementalCheck, 0);
  3977. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_CHECK_INCREMENTAL), m_fIncrementalAllowed && (m_iLogsCheck == BST_CHECKED) );
  3978. }
  3979. return TRUE;
  3980. }
  3981. // replacement for BEGIN_MESSAGE_MAP
  3982. BOOL
  3983. CBackupWizPage2::OnCommand(
  3984. WPARAM wParam,
  3985. LPARAM) // lParam
  3986. {
  3987. switch(LOWORD(wParam))
  3988. {
  3989. case IDC_BROWSE_LOGS:
  3990. if (BN_CLICKED == HIWORD(wParam))
  3991. OnBrowse();
  3992. break;
  3993. case IDC_CHECK_LOGS:
  3994. if (BN_CLICKED == HIWORD(wParam))
  3995. {
  3996. m_iLogsCheck = (INT)SendDlgItemMessage(IDC_CHECK_LOGS, BM_GETCHECK, 0, 0);
  3997. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_CHECK_INCREMENTAL), m_fIncrementalAllowed && (m_iLogsCheck == BST_CHECKED) );
  3998. }
  3999. default:
  4000. return FALSE;
  4001. break;
  4002. }
  4003. return TRUE;
  4004. }
  4005. BOOL CBackupWizPage2::OnInitDialog()
  4006. {
  4007. // does parent init and UpdateData call
  4008. CWizard97PropertyPage::OnInitDialog();
  4009. return TRUE;
  4010. }
  4011. BOOL CBackupWizPage2::OnSetActive()
  4012. {
  4013. PropertyPage::OnSetActive();
  4014. PropSheet_SetWizButtons(GetParent(), (PSWIZB_BACK | PSWIZB_NEXT));
  4015. // don't allow PFX across machines
  4016. if (! m_pState->pCA->m_pParentMachine->IsLocalMachine())
  4017. ::EnableWindow(::GetDlgItem(m_hWnd, IDC_CHECK_KEYCERT), FALSE);
  4018. // get from state
  4019. m_iKeyCertCheck = (m_pState->fBackupKeyCert) ? BST_CHECKED : BST_UNCHECKED;
  4020. m_iLogsCheck = (m_pState->fBackupLogs) ? BST_CHECKED : BST_UNCHECKED;
  4021. m_iIncrementalCheck = (m_pState->fIncremental) ? BST_CHECKED : BST_UNCHECKED;
  4022. if (m_pState->szLogsPath)
  4023. m_cstrLogsPath = m_pState->szLogsPath;
  4024. return TRUE;
  4025. }
  4026. void CBackupWizPage2::OnBrowse()
  4027. {
  4028. UpdateData(TRUE);
  4029. LPCWSTR pszInitialDir;
  4030. WCHAR szCurDir[MAX_PATH];
  4031. if (m_cstrLogsPath.IsEmpty())
  4032. {
  4033. if (0 == GetCurrentDirectory(MAX_PATH, szCurDir) )
  4034. pszInitialDir = L"C:\\";
  4035. else
  4036. pszInitialDir = szCurDir;
  4037. }
  4038. else
  4039. pszInitialDir = m_cstrLogsPath;
  4040. WCHAR szFileBuf[MAX_PATH+1]; szFileBuf[0] = L'\0';
  4041. if (!BrowseForDirectory(
  4042. m_hWnd,
  4043. pszInitialDir,
  4044. szFileBuf,
  4045. MAX_PATH,
  4046. NULL))
  4047. return;
  4048. m_cstrLogsPath = szFileBuf;
  4049. UpdateData(FALSE);
  4050. return;
  4051. }
  4052. HRESULT CBackupWizPage2::ConvertLogsPathToFullPath()
  4053. {
  4054. LPWSTR pwszFullPath = NULL;
  4055. DWORD cFullPath = 0;
  4056. HRESULT hr;
  4057. cFullPath = GetFullPathName(
  4058. m_cstrLogsPath,
  4059. 0,
  4060. NULL,
  4061. NULL);
  4062. if(!cFullPath)
  4063. return(myHLastError());
  4064. pwszFullPath = (LPWSTR)LocalAlloc(LMEM_FIXED, cFullPath*sizeof(WCHAR));
  4065. if(!pwszFullPath)
  4066. return E_OUTOFMEMORY;
  4067. cFullPath = GetFullPathName(
  4068. m_cstrLogsPath,
  4069. cFullPath,
  4070. pwszFullPath,
  4071. NULL);
  4072. if(cFullPath == 0)
  4073. {
  4074. hr = myHLastError();
  4075. goto Ret;
  4076. }
  4077. m_cstrLogsPath = pwszFullPath;
  4078. hr = S_OK;
  4079. Ret:
  4080. if(pwszFullPath)
  4081. LocalFree(pwszFullPath);
  4082. return hr;
  4083. }
  4084. LRESULT CBackupWizPage2::OnWizardNext()
  4085. {
  4086. HRESULT hr;
  4087. UpdateData(TRUE);
  4088. // persist to state structure
  4089. m_pState->fBackupKeyCert = (m_iKeyCertCheck == BST_CHECKED);
  4090. m_pState->fBackupLogs = (m_iLogsCheck == BST_CHECKED);
  4091. m_pState->fIncremental = (m_iIncrementalCheck == BST_CHECKED);
  4092. if (!
  4093. (m_pState->fBackupKeyCert ||
  4094. m_pState->fBackupLogs) )
  4095. {
  4096. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_REQUIRE_ONE_SELECTION);
  4097. return -1;
  4098. }
  4099. // empty?
  4100. if ( m_cstrLogsPath.IsEmpty() )
  4101. {
  4102. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_NEED_FILEPATH);
  4103. return -1;
  4104. }
  4105. hr = ConvertLogsPathToFullPath();
  4106. if(S_OK != hr)
  4107. {
  4108. DisplayGenericCertSrvError(m_hWnd, hr);
  4109. return -1;
  4110. }
  4111. // make sure we're a valid directory
  4112. if (!myIsDirectory(m_cstrLogsPath))
  4113. {
  4114. CString cstrTitle, cstrFmt, cstrMsg;
  4115. cstrTitle.FromWindow(m_hWnd); // use same title as parent has
  4116. cstrFmt.LoadString(IDS_DIR_CREATE);
  4117. cstrMsg.Format(cstrFmt, m_cstrLogsPath);
  4118. if (IDOK != MessageBox(m_hWnd, cstrMsg, cstrTitle, MB_OKCANCEL))
  4119. return -1;
  4120. hr = myCreateNestedDirectories(m_cstrLogsPath);
  4121. _PrintIfError(hr, "myCreateNestedDirectories");
  4122. if (hr != S_OK)
  4123. {
  4124. DisplayGenericCertSrvError(m_hWnd, hr);
  4125. return -1;
  4126. }
  4127. }
  4128. hr = myIsDirWriteable(
  4129. m_cstrLogsPath,
  4130. FALSE);
  4131. _PrintIfError(hr, "myIsDirWriteable");
  4132. if (hr != S_OK)
  4133. {
  4134. DisplayCertSrvErrorWithContext(m_hWnd, hr, IDS_DIR_NOT_WRITEABLE);
  4135. return -1;
  4136. }
  4137. // if backing up db, make sure there's no \DataBase folder here
  4138. if (m_pState->fBackupLogs)
  4139. {
  4140. DWORD dwFlags = CDBBACKUP_VERIFYONLY;
  4141. dwFlags |= m_pState->fIncremental ? CDBBACKUP_INCREMENTAL : 0;
  4142. hr = myBackupDB(
  4143. (LPCWSTR)m_pState->pCA->m_strConfig,
  4144. dwFlags,
  4145. m_cstrLogsPath,
  4146. NULL);
  4147. _PrintIfError(hr, "myBackupDB");
  4148. if (hr != S_OK)
  4149. {
  4150. DisplayCertSrvErrorWithContext(m_hWnd, hr, IDS_CANT_ACCESS_BACKUP_DIR);
  4151. return -1;
  4152. }
  4153. }
  4154. if (m_pState->fBackupKeyCert ||
  4155. m_pState->fBackupLogs)
  4156. {
  4157. // free if exists
  4158. if (m_pState->szLogsPath)
  4159. LocalFree(m_pState->szLogsPath);
  4160. // alloc anew
  4161. m_pState->szLogsPath = (LPWSTR)LocalAlloc(LMEM_FIXED, WSZ_BYTECOUNT((LPCWSTR)m_cstrLogsPath));
  4162. // copy
  4163. if (m_pState->szLogsPath)
  4164. wcscpy(m_pState->szLogsPath, (LPCWSTR)m_cstrLogsPath);
  4165. }
  4166. // skip "get password"?
  4167. if (!m_pState->fBackupKeyCert)
  4168. return IDD_BACKUPWIZ_COMPLETION;
  4169. return 0;
  4170. }
  4171. ///////////////////////////////////////////
  4172. // CBackupWizPage3
  4173. /////////////////////////////////////////////////////////////////////////////
  4174. // CBackupWizPage3 property page
  4175. CBackupWizPage3::CBackupWizPage3(
  4176. PBACKUPWIZ_STATE pState,
  4177. CWizard97PropertySheet *pcDlg,
  4178. UINT uIDD) :
  4179. CWizard97PropertyPage(g_hInstance, uIDD, g_aidFont),
  4180. m_pState(pState),
  4181. m_pParentSheet(pcDlg)
  4182. {
  4183. m_szHeaderTitle.LoadString(IDS_WIZ97TITLE_BACKUPWIZPG3);
  4184. m_szHeaderSubTitle.LoadString(IDS_WIZ97SUBTITLE_BACKUPWIZPG3);
  4185. InitWizard97 (FALSE);
  4186. m_cstrPwd = L"";
  4187. m_cstrPwdVerify = L"";
  4188. // SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTIFICATE_TEMPLATE_PROPERTIES_GENERAL_PAGE);
  4189. }
  4190. // replacement for DoDataExchange
  4191. BOOL CBackupWizPage3::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  4192. {
  4193. if (fSuckFromDlg)
  4194. {
  4195. m_cstrPwd.FromWindow(GetDlgItem(m_hWnd, IDC_NEW_PASSWORD));
  4196. m_cstrPwdVerify.FromWindow(GetDlgItem(m_hWnd, IDC_CONFIRM_PASSWORD));
  4197. }
  4198. else
  4199. {
  4200. m_cstrPwd.ToWindow(GetDlgItem(m_hWnd, IDC_NEW_PASSWORD));
  4201. m_cstrPwdVerify.ToWindow(GetDlgItem(m_hWnd, IDC_CONFIRM_PASSWORD));
  4202. }
  4203. return TRUE;
  4204. }
  4205. // replacement for BEGIN_MESSAGE_MAP
  4206. BOOL
  4207. CBackupWizPage3::OnCommand(
  4208. WPARAM, // wParam
  4209. LPARAM) // lParam
  4210. {
  4211. // switch(LOWORD(wParam))
  4212. {
  4213. // default:
  4214. return FALSE;
  4215. // break;
  4216. }
  4217. // return TRUE;
  4218. }
  4219. BOOL CBackupWizPage3::OnInitDialog()
  4220. {
  4221. // does parent init and UpdateData call
  4222. CWizard97PropertyPage::OnInitDialog();
  4223. return TRUE;
  4224. }
  4225. BOOL CBackupWizPage3::OnSetActive()
  4226. {
  4227. PropertyPage::OnSetActive();
  4228. PropSheet_SetWizButtons(GetParent(), (PSWIZB_BACK | PSWIZB_NEXT));
  4229. return TRUE;
  4230. }
  4231. LRESULT CBackupWizPage3::OnWizardNext()
  4232. {
  4233. UpdateData(TRUE);
  4234. if (! m_cstrPwd.IsEqual(m_cstrPwdVerify))
  4235. {
  4236. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_PASSWORD_NOMATCH);
  4237. m_cstrPwd.Empty();
  4238. m_cstrPwdVerify.Empty();
  4239. UpdateData(FALSE);
  4240. return -1; // stay here
  4241. }
  4242. // free if exists
  4243. if (m_pState->szPassword)
  4244. {
  4245. SecureZeroMemory(m_pState->szPassword, wcslen(m_pState->szPassword)*sizeof(WCHAR));
  4246. LocalFree(m_pState->szPassword);
  4247. }
  4248. // alloc anew
  4249. m_pState->szPassword = (LPWSTR)LocalAlloc(LMEM_FIXED, WSZ_BYTECOUNT((LPCWSTR)m_cstrPwd));
  4250. // copy
  4251. if (m_pState->szPassword)
  4252. wcscpy(m_pState->szPassword, (LPCWSTR)m_cstrPwd);
  4253. return 0; // advance
  4254. }
  4255. ///////////////////////////////////////////
  4256. // CBackupWizPage5
  4257. /////////////////////////////////////////////////////////////////////////////
  4258. // CBackupWizPage5 property page
  4259. CBackupWizPage5::CBackupWizPage5(
  4260. PBACKUPWIZ_STATE pState,
  4261. CWizard97PropertySheet *pcDlg,
  4262. UINT uIDD) :
  4263. CWizard97PropertyPage(g_hInstance, uIDD, g_aidFont),
  4264. m_pState(pState),
  4265. m_pParentSheet(pcDlg)
  4266. {
  4267. InitWizard97 (TRUE); // firstlast page
  4268. // SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTIFICATE_TEMPLATE_PROPERTIES_GENERAL_PAGE);
  4269. }
  4270. // replacement for DoDataExchange
  4271. BOOL CBackupWizPage5::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  4272. {
  4273. if (fSuckFromDlg)
  4274. {
  4275. }
  4276. else
  4277. {
  4278. }
  4279. return TRUE;
  4280. }
  4281. // replacement for BEGIN_MESSAGE_MAP
  4282. BOOL
  4283. CBackupWizPage5::OnCommand(
  4284. WPARAM, // wParam
  4285. LPARAM) // lParam
  4286. {
  4287. // switch(LOWORD(wParam))
  4288. {
  4289. // default:
  4290. return FALSE;
  4291. // break;
  4292. }
  4293. // return TRUE;
  4294. }
  4295. BOOL CBackupWizPage5::OnInitDialog()
  4296. {
  4297. // does parent init and UpdateData call
  4298. CWizard97PropertyPage::OnInitDialog();
  4299. // firstlast page
  4300. SendMessage(GetDlgItem(IDC_TEXT_BIGBOLD), WM_SETFONT, (WPARAM)GetBigBoldFont(), MAKELPARAM(TRUE, 0));
  4301. HWND hList = ::GetDlgItem(m_hWnd, IDC_COMPLETION_LIST);
  4302. LV_COLUMN lvC = { (LVCF_FMT|LVCF_WIDTH), LVCFMT_LEFT, 0, NULL, 0, 0};
  4303. lvC.cx = 675;
  4304. ListView_InsertColumn(hList, 0, &lvC);
  4305. return TRUE;
  4306. }
  4307. BOOL CBackupWizPage5::OnSetActive()
  4308. {
  4309. PropertyPage::OnSetActive();
  4310. PropSheet_SetWizButtons(GetParent(), (PSWIZB_BACK | PSWIZB_FINISH));
  4311. CString cstrDialogMsg;
  4312. HWND hList = ::GetDlgItem(m_hWnd, IDC_COMPLETION_LIST);
  4313. LV_ITEM sItem; ZeroMemory(&sItem, sizeof(sItem));
  4314. ListView_DeleteAllItems(hList);
  4315. if (m_pState->fBackupKeyCert)
  4316. {
  4317. sItem.iItem = ListView_InsertItem(hList, &sItem);
  4318. cstrDialogMsg.LoadString(IDS_KEYANDCERT);
  4319. ListView_SetItemText(hList, sItem.iItem, 0, (LPWSTR)(LPCWSTR)cstrDialogMsg);
  4320. sItem.iItem++;
  4321. }
  4322. if (m_pState->fBackupLogs)
  4323. {
  4324. sItem.iItem = ListView_InsertItem(hList, &sItem);
  4325. cstrDialogMsg.LoadString(IDS_CALOGS);
  4326. ListView_SetItemText(hList, sItem.iItem, 0, (LPWSTR)(LPCWSTR)cstrDialogMsg);
  4327. sItem.iItem++;
  4328. }
  4329. if (m_pState->fIncremental)
  4330. {
  4331. sItem.iItem = ListView_InsertItem(hList, &sItem);
  4332. cstrDialogMsg.LoadString(IDS_INCREMENTAL_BACKUP);
  4333. ListView_SetItemText(hList, sItem.iItem, 0, (LPWSTR)(LPCWSTR)cstrDialogMsg);
  4334. sItem.iItem++;
  4335. }
  4336. return TRUE;
  4337. }
  4338. LRESULT CBackupWizPage5::OnWizardBack()
  4339. {
  4340. if (!m_pState->fBackupKeyCert)
  4341. return IDD_BACKUPWIZ_SELECT_DATA;
  4342. return 0;
  4343. }
  4344. ///////////////////////////////////////////
  4345. // CRestoreWizPage1
  4346. /////////////////////////////////////////////////////////////////////////////
  4347. // CRestoreWizPage1 property page
  4348. CRestoreWizPage1::CRestoreWizPage1(
  4349. PRESTOREWIZ_STATE pState,
  4350. CWizard97PropertySheet *pcDlg,
  4351. UINT uIDD) :
  4352. CWizard97PropertyPage(g_hInstance, uIDD, g_aidFont),
  4353. m_pState(pState),
  4354. m_pParentSheet(pcDlg)
  4355. {
  4356. InitWizard97 (TRUE); // firstlast page
  4357. // SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTIFICATE_TEMPLATE_PROPERTIES_GENERAL_PAGE);
  4358. }
  4359. CRestoreWizPage1::~CRestoreWizPage1()
  4360. {
  4361. }
  4362. // replacement for DoDataExchange
  4363. BOOL CRestoreWizPage1::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  4364. {
  4365. if (fSuckFromDlg)
  4366. {
  4367. }
  4368. else
  4369. {
  4370. }
  4371. return TRUE;
  4372. }
  4373. // replacement for BEGIN_MESSAGE_MAP
  4374. BOOL
  4375. CRestoreWizPage1::OnCommand(
  4376. WPARAM, // wParam
  4377. LPARAM) // lParam
  4378. {
  4379. // switch(LOWORD(wParam))
  4380. {
  4381. // default:
  4382. return FALSE;
  4383. // break;
  4384. }
  4385. // return TRUE;
  4386. }
  4387. BOOL CRestoreWizPage1::OnInitDialog()
  4388. {
  4389. // does parent init and UpdateData call
  4390. CWizard97PropertyPage::OnInitDialog();
  4391. // firstlast page
  4392. SendMessage(GetDlgItem(IDC_TEXT_BIGBOLD), WM_SETFONT, (WPARAM)GetBigBoldFont(), MAKELPARAM(TRUE, 0));
  4393. return TRUE;
  4394. }
  4395. BOOL CRestoreWizPage1::OnSetActive()
  4396. {
  4397. PropertyPage::OnSetActive();
  4398. PropSheet_SetWizButtons(GetParent(), PSWIZB_NEXT);
  4399. return TRUE;
  4400. }
  4401. ///////////////////////////////////////////
  4402. // CRestoreWizPage2
  4403. /////////////////////////////////////////////////////////////////////////////
  4404. // CRestoreWizPage2 property page
  4405. CRestoreWizPage2::CRestoreWizPage2(
  4406. PRESTOREWIZ_STATE pState,
  4407. CWizard97PropertySheet *pcDlg,
  4408. UINT uIDD) :
  4409. CWizard97PropertyPage(g_hInstance, uIDD, g_aidFont),
  4410. m_pState(pState),
  4411. m_pParentSheet(pcDlg)
  4412. {
  4413. m_szHeaderTitle.LoadString(IDS_WIZ97TITLE_RESTOREWIZPG2);
  4414. m_szHeaderSubTitle.LoadString(IDS_WIZ97SUBTITLE_RESTOREWIZPG2);
  4415. InitWizard97 (FALSE);
  4416. m_cstrLogsPath = L"";
  4417. m_iKeyCertCheck = BST_UNCHECKED;
  4418. m_iLogsCheck = BST_UNCHECKED;
  4419. // SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTIFICATE_TEMPLATE_PROPERTIES_GENERAL_PAGE);
  4420. }
  4421. // replacement for DoDataExchange
  4422. BOOL CRestoreWizPage2::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  4423. {
  4424. if (fSuckFromDlg)
  4425. {
  4426. m_cstrLogsPath.FromWindow(GetDlgItem(m_hWnd, IDC_EDIT_LOGS));
  4427. m_iKeyCertCheck = (INT)SendDlgItemMessage(IDC_CHECK_KEYCERT, BM_GETCHECK, 0, 0);
  4428. m_iLogsCheck = (INT)SendDlgItemMessage(IDC_CHECK_LOGS, BM_GETCHECK, 0, 0);
  4429. }
  4430. else
  4431. {
  4432. m_cstrLogsPath.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_LOGS));
  4433. SendDlgItemMessage(IDC_CHECK_KEYCERT, BM_SETCHECK, (WPARAM)m_iKeyCertCheck, 0);
  4434. SendDlgItemMessage(IDC_CHECK_LOGS, BM_SETCHECK, (WPARAM)m_iLogsCheck, 0);
  4435. }
  4436. return TRUE;
  4437. }
  4438. // replacement for BEGIN_MESSAGE_MAP
  4439. BOOL
  4440. CRestoreWizPage2::OnCommand(
  4441. WPARAM wParam,
  4442. LPARAM) // lParam
  4443. {
  4444. switch(LOWORD(wParam))
  4445. {
  4446. case IDC_BROWSE_LOGS:
  4447. if (BN_CLICKED == HIWORD(wParam))
  4448. OnBrowse();
  4449. break;
  4450. default:
  4451. return FALSE;
  4452. break;
  4453. }
  4454. return TRUE;
  4455. }
  4456. BOOL CRestoreWizPage2::OnInitDialog()
  4457. {
  4458. // does parent init and UpdateData call
  4459. CWizard97PropertyPage::OnInitDialog();
  4460. return TRUE;
  4461. }
  4462. BOOL CRestoreWizPage2::OnSetActive()
  4463. {
  4464. PropertyPage::OnSetActive();
  4465. PropSheet_SetWizButtons(GetParent(), (PSWIZB_BACK | PSWIZB_NEXT));
  4466. // get from state
  4467. m_iKeyCertCheck = (m_pState->fRestoreKeyCert) ? BST_CHECKED : BST_UNCHECKED;
  4468. m_iLogsCheck = (m_pState->fRestoreLogs) ? BST_CHECKED : BST_UNCHECKED;
  4469. if (m_pState->szLogsPath)
  4470. m_cstrLogsPath = m_pState->szLogsPath;
  4471. return TRUE;
  4472. }
  4473. void CRestoreWizPage2::OnBrowse()
  4474. {
  4475. UpdateData(TRUE);
  4476. LPCWSTR pszInitialDir;
  4477. WCHAR szCurDir[MAX_PATH];
  4478. if (m_cstrLogsPath.IsEmpty())
  4479. {
  4480. if (0 == GetCurrentDirectory(MAX_PATH, szCurDir) )
  4481. pszInitialDir = L"C:\\";
  4482. else
  4483. pszInitialDir = szCurDir;
  4484. }
  4485. else
  4486. pszInitialDir = (LPCWSTR)m_cstrLogsPath;
  4487. WCHAR szFileBuf[MAX_PATH+1]; szFileBuf[0] = L'\0';
  4488. if (!BrowseForDirectory(
  4489. m_hWnd,
  4490. pszInitialDir,
  4491. szFileBuf,
  4492. MAX_PATH,
  4493. NULL))
  4494. return;
  4495. m_cstrLogsPath = szFileBuf;
  4496. UpdateData(FALSE);
  4497. return;
  4498. }
  4499. LRESULT CRestoreWizPage2::OnWizardNext()
  4500. {
  4501. HRESULT hr;
  4502. UpdateData(TRUE);
  4503. // persist to state structure
  4504. m_pState->fRestoreKeyCert = (m_iKeyCertCheck == BST_CHECKED);
  4505. m_pState->fRestoreLogs = (m_iLogsCheck == BST_CHECKED);
  4506. if (!
  4507. (m_pState->fRestoreKeyCert ||
  4508. m_pState->fRestoreLogs) )
  4509. {
  4510. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_REQUIRE_ONE_SELECTION);
  4511. return -1;
  4512. }
  4513. if ( m_cstrLogsPath.IsEmpty() )
  4514. {
  4515. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_NEED_FILEPATH);
  4516. return -1;
  4517. }
  4518. if (!myIsDirectory(m_cstrLogsPath))
  4519. {
  4520. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_INVALID_DIRECTORY);
  4521. return -1;
  4522. }
  4523. // validate pfx blob
  4524. if (m_pState->fRestoreKeyCert)
  4525. {
  4526. // if pfx not here -- FAIL
  4527. if (myIsDirEmpty(m_cstrLogsPath))
  4528. {
  4529. DisplayCertSrvErrorWithContext(m_hWnd, S_OK, IDS_DIRECTORY_CONTENTS_UNEXPECTED);
  4530. return -1;
  4531. }
  4532. }
  4533. // validate logs path
  4534. if (m_pState->fRestoreLogs)
  4535. {
  4536. // If CDBBACKUP_VERIFYONLY, only verify the passed directory contains valid files
  4537. // and detect INCREMENTAL
  4538. hr = myRestoreDB(
  4539. (LPCWSTR)m_pState->pCA->m_strConfig,
  4540. CDBBACKUP_VERIFYONLY,
  4541. (LPCWSTR)m_cstrLogsPath,
  4542. NULL,
  4543. NULL,
  4544. NULL,
  4545. NULL);
  4546. _PrintIfError(hr, "myRestoreDB Full Restore");
  4547. if (hr != S_OK)
  4548. {
  4549. hr = myRestoreDB(
  4550. (LPCWSTR)m_pState->pCA->m_strConfig,
  4551. CDBBACKUP_VERIFYONLY | CDBBACKUP_INCREMENTAL,
  4552. (LPCWSTR)m_cstrLogsPath,
  4553. NULL,
  4554. NULL,
  4555. NULL,
  4556. NULL);
  4557. _PrintIfError(hr, "myRestoreDB Incremental Restore");
  4558. if (hr != S_OK)
  4559. {
  4560. DisplayCertSrvErrorWithContext(m_hWnd, hr, IDS_DIRECTORY_CONTENTS_UNEXPECTED);
  4561. return -1;
  4562. }
  4563. // if incremental, set struct bool
  4564. m_pState->fIncremental = TRUE;
  4565. }
  4566. }
  4567. if (m_pState->fRestoreKeyCert ||
  4568. m_pState->fRestoreLogs)
  4569. {
  4570. // free if exists
  4571. if (m_pState->szLogsPath)
  4572. LocalFree(m_pState->szLogsPath);
  4573. // alloc anew
  4574. m_pState->szLogsPath = (LPWSTR)LocalAlloc(LMEM_FIXED, WSZ_BYTECOUNT((LPCWSTR)m_cstrLogsPath));
  4575. // copy
  4576. if (m_pState->szLogsPath)
  4577. wcscpy(m_pState->szLogsPath, (LPCWSTR)m_cstrLogsPath);
  4578. }
  4579. // skip get password?
  4580. if (!m_pState->fRestoreKeyCert)
  4581. return IDD_RESTOREWIZ_COMPLETION;
  4582. return 0;
  4583. }
  4584. ///////////////////////////////////////////
  4585. // CRestoreWizPage3
  4586. /////////////////////////////////////////////////////////////////////////////
  4587. // CRestoreWizPage3 property page
  4588. CRestoreWizPage3::CRestoreWizPage3(
  4589. PRESTOREWIZ_STATE pState,
  4590. CWizard97PropertySheet *pcDlg,
  4591. UINT uIDD) :
  4592. CWizard97PropertyPage(g_hInstance, uIDD, g_aidFont),
  4593. m_pState(pState),
  4594. m_pParentSheet(pcDlg)
  4595. {
  4596. m_szHeaderTitle.LoadString(IDS_WIZ97TITLE_RESTOREWIZPG3);
  4597. m_szHeaderSubTitle.LoadString(IDS_WIZ97SUBTITLE_RESTOREWIZPG3);
  4598. InitWizard97 (FALSE);
  4599. m_cstrPwd = L"";
  4600. // SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTIFICATE_TEMPLATE_PROPERTIES_GENERAL_PAGE);
  4601. }
  4602. // replacement for DoDataExchange
  4603. BOOL CRestoreWizPage3::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  4604. {
  4605. if (fSuckFromDlg)
  4606. {
  4607. m_cstrPwd.FromWindow(GetDlgItem(m_hWnd, IDC_EDIT_PASSWORD));
  4608. }
  4609. else
  4610. {
  4611. m_cstrPwd.ToWindow(GetDlgItem(m_hWnd, IDC_EDIT_PASSWORD));
  4612. }
  4613. return TRUE;
  4614. }
  4615. // replacement for BEGIN_MESSAGE_MAP
  4616. BOOL
  4617. CRestoreWizPage3::OnCommand(
  4618. WPARAM, // wParam
  4619. LPARAM) // lParam
  4620. {
  4621. // switch(LOWORD(wParam))
  4622. {
  4623. // default:
  4624. return FALSE;
  4625. // break;
  4626. }
  4627. // return TRUE;
  4628. }
  4629. BOOL CRestoreWizPage3::OnInitDialog()
  4630. {
  4631. // does parent init and UpdateData call
  4632. CWizard97PropertyPage::OnInitDialog();
  4633. return TRUE;
  4634. }
  4635. BOOL CRestoreWizPage3::OnSetActive()
  4636. {
  4637. PropertyPage::OnSetActive();
  4638. PropSheet_SetWizButtons(GetParent(), (PSWIZB_BACK | PSWIZB_NEXT));
  4639. return TRUE;
  4640. }
  4641. LRESULT CRestoreWizPage3::OnWizardNext()
  4642. {
  4643. UpdateData(TRUE);
  4644. // free if exists
  4645. if (m_pState->szPassword)
  4646. {
  4647. SecureZeroMemory(m_pState->szPassword, wcslen(m_pState->szPassword)*sizeof(WCHAR));
  4648. LocalFree(m_pState->szPassword);
  4649. }
  4650. // alloc anew
  4651. m_pState->szPassword = (LPWSTR)LocalAlloc(LMEM_FIXED, WSZ_BYTECOUNT((LPCWSTR)m_cstrPwd));
  4652. // copy
  4653. if (m_pState->szPassword)
  4654. wcscpy(m_pState->szPassword, (LPCWSTR)m_cstrPwd);
  4655. return 0; // advance
  4656. }
  4657. ///////////////////////////////////////////
  4658. // CRestoreWizPage5
  4659. /////////////////////////////////////////////////////////////////////////////
  4660. // CRestoreWizPage5 property page
  4661. CRestoreWizPage5::CRestoreWizPage5(
  4662. PRESTOREWIZ_STATE pState,
  4663. CWizard97PropertySheet *pcDlg, UINT uIDD) :
  4664. CWizard97PropertyPage(g_hInstance, uIDD, g_aidFont),
  4665. m_pState(pState),
  4666. m_pParentSheet(pcDlg)
  4667. {
  4668. InitWizard97 (TRUE); // firstlast page
  4669. // SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTIFICATE_TEMPLATE_PROPERTIES_GENERAL_PAGE);
  4670. }
  4671. // replacement for DoDataExchange
  4672. BOOL CRestoreWizPage5::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  4673. {
  4674. if (fSuckFromDlg)
  4675. {
  4676. }
  4677. else
  4678. {
  4679. }
  4680. return TRUE;
  4681. }
  4682. // replacement for BEGIN_MESSAGE_MAP
  4683. BOOL
  4684. CRestoreWizPage5::OnCommand(
  4685. WPARAM, // wParam
  4686. LPARAM) // lParam
  4687. {
  4688. // switch(LOWORD(wParam))
  4689. {
  4690. // default:
  4691. return FALSE;
  4692. // break;
  4693. }
  4694. // return TRUE;
  4695. }
  4696. BOOL CRestoreWizPage5::OnInitDialog()
  4697. {
  4698. // does parent init and UpdateData call
  4699. CWizard97PropertyPage::OnInitDialog();
  4700. // firstlast page
  4701. SendMessage(GetDlgItem(IDC_TEXT_BIGBOLD), WM_SETFONT, (WPARAM)GetBigBoldFont(), MAKELPARAM(TRUE, 0));
  4702. HWND hList = ::GetDlgItem(m_hWnd, IDC_COMPLETION_LIST);
  4703. LV_COLUMN lvC = { (LVCF_FMT|LVCF_WIDTH), LVCFMT_LEFT, 0, NULL, 0, 0};
  4704. lvC.cx = 675;
  4705. ListView_InsertColumn(hList, 0, &lvC);
  4706. return TRUE;
  4707. }
  4708. BOOL CRestoreWizPage5::OnSetActive()
  4709. {
  4710. PropertyPage::OnSetActive();
  4711. PropSheet_SetWizButtons(GetParent(), (PSWIZB_BACK | PSWIZB_FINISH));
  4712. CString cstrDialogMsg;
  4713. HWND hList = ::GetDlgItem(m_hWnd, IDC_COMPLETION_LIST);
  4714. LV_ITEM sItem; ZeroMemory(&sItem, sizeof(sItem));
  4715. ListView_DeleteAllItems(hList);
  4716. if (m_pState->fRestoreKeyCert)
  4717. {
  4718. sItem.iItem = ListView_InsertItem(hList, &sItem);
  4719. cstrDialogMsg.LoadString(IDS_KEYANDCERT);
  4720. ListView_SetItemText(hList, sItem.iItem, 0, (LPWSTR)(LPCWSTR)cstrDialogMsg);
  4721. sItem.iItem++;
  4722. }
  4723. if (m_pState->fRestoreLogs)
  4724. {
  4725. sItem.iItem = ListView_InsertItem(hList, &sItem);
  4726. cstrDialogMsg.LoadString(IDS_CALOGS);
  4727. ListView_SetItemText(hList, sItem.iItem, 0, (LPWSTR)(LPCWSTR)cstrDialogMsg);
  4728. sItem.iItem++;
  4729. }
  4730. return TRUE;
  4731. }
  4732. LRESULT CRestoreWizPage5::OnWizardBack()
  4733. {
  4734. if (!m_pState->fRestoreKeyCert)
  4735. return IDD_RESTOREWIZ_SELECT_DATA;
  4736. return 0;
  4737. }
  4738. ////////////////////////////////////////////////////////////////////
  4739. // misc UI throwing routines
  4740. DWORD CABackupWizard(CertSvrCA* pCertCA, HWND hwnd)
  4741. {
  4742. HRESULT hr;
  4743. BACKUPWIZ_STATE sBackupState; ZeroMemory(&sBackupState, sizeof(sBackupState));
  4744. sBackupState.pCA = pCertCA;
  4745. InitCommonControls();
  4746. CWizard97PropertySheet cDlg(
  4747. g_hInstance,
  4748. IDS_BACKUP_WIZARD,
  4749. IDB_WIZ,
  4750. IDB_WIZ_HEAD,
  4751. TRUE);
  4752. CBackupWizPage1 sPg1(&sBackupState, &cDlg);
  4753. CBackupWizPage2 sPg2(&sBackupState, &cDlg);
  4754. CBackupWizPage3 sPg3(&sBackupState, &cDlg);
  4755. CBackupWizPage5 sPg5(&sBackupState, &cDlg);
  4756. cDlg.AddPage(&sPg1);
  4757. cDlg.AddPage(&sPg2);
  4758. cDlg.AddPage(&sPg3);
  4759. cDlg.AddPage(&sPg5);
  4760. // if not started, start service
  4761. if (!pCertCA->m_pParentMachine->IsCertSvrServiceRunning())
  4762. {
  4763. CString cstrMsg, cstrTitle;
  4764. cstrTitle.LoadString(IDS_BACKUP_WIZARD);
  4765. cstrMsg.LoadString(IDS_START_SERVER_WARNING);
  4766. if (IDOK != MessageBox(hwnd, (LPCWSTR)cstrMsg, (LPCWSTR)cstrTitle, MB_OKCANCEL))
  4767. return ERROR_CANCELLED;
  4768. hr = pCertCA->m_pParentMachine->CertSvrStartStopService(hwnd, TRUE);
  4769. _JumpIfError(hr, Ret, "CertSvrStartStopService");
  4770. }
  4771. // should return value >0 on success
  4772. if (0 >= cDlg.DoWizard(hwnd))
  4773. return ERROR_CANCELLED;
  4774. if (sBackupState.fBackupKeyCert)
  4775. {
  4776. hr = myCertServerExportPFX(
  4777. (LPCWSTR)pCertCA->m_strCommonName,
  4778. sBackupState.szLogsPath,
  4779. sBackupState.szPassword,
  4780. TRUE, // fEnhancedStrength
  4781. TRUE, // fForceOverWrite
  4782. TRUE, // fMustExportPrivateKeys
  4783. 0, // dwmsTimeout (use default)
  4784. NULL); // ppwszPFXFile
  4785. if (hr != S_OK)
  4786. {
  4787. CString cstrMsg, cstrTitle;
  4788. cstrTitle.LoadString(IDS_BACKUP_WIZARD);
  4789. cstrMsg.LoadString(IDS_PFX_EXPORT_PRIVKEY_WARNING);
  4790. if (IDOK != MessageBox(hwnd, (LPCWSTR)cstrMsg, (LPCWSTR)cstrTitle, MB_ICONWARNING|MB_OKCANCEL))
  4791. {
  4792. hr = ERROR_CANCELLED;
  4793. _JumpError(hr, Ret, "myCertServerExportPFX user cancel");
  4794. }
  4795. hr = myCertServerExportPFX(
  4796. (LPCWSTR)pCertCA->m_strCommonName,
  4797. sBackupState.szLogsPath,
  4798. sBackupState.szPassword,
  4799. TRUE, // fEnhancedStrength
  4800. TRUE, // fForceOverWrite
  4801. FALSE, // fMustExportPrivateKeys (don't require private keys)
  4802. 0, // dwmsTimeout (use default)
  4803. NULL); // ppwszPFXFile
  4804. _JumpIfError(hr, Ret, "myCertServerExportPFX");
  4805. }
  4806. } // sBackupState.fBackupKeyCert
  4807. if (sBackupState.fBackupLogs)
  4808. {
  4809. DBBACKUPPROGRESS dbp;
  4810. ZeroMemory(&dbp, sizeof(dbp));
  4811. DWORD dwBackupFlags;
  4812. dwBackupFlags = sBackupState.fIncremental ? CDBBACKUP_INCREMENTAL : 0;
  4813. HANDLE hProgressThread = NULL;
  4814. hProgressThread = StartPercentCompleteDlg(g_hInstance, hwnd, IDS_BACKUP_PROGRESS, &dbp);
  4815. if (hProgressThread == NULL)
  4816. {
  4817. hr = GetLastError();
  4818. _JumpError(hr, Ret, "StartPercentCompleteDlg");
  4819. }
  4820. hr = myBackupDB(
  4821. (LPCWSTR)pCertCA->m_strConfig,
  4822. dwBackupFlags,
  4823. sBackupState.szLogsPath,
  4824. &dbp);
  4825. CSASSERT( (S_OK != hr) || (
  4826. (dbp.dwDBPercentComplete == 100) &&
  4827. (dbp.dwLogPercentComplete == 100) &&
  4828. (dbp.dwTruncateLogPercentComplete == 100) )
  4829. );
  4830. if (S_OK != hr)
  4831. {
  4832. dbp.dwDBPercentComplete = 100;
  4833. dbp.dwLogPercentComplete = 100;
  4834. dbp.dwTruncateLogPercentComplete = 100;
  4835. }
  4836. // pause for progress dlg to finish
  4837. EndPercentCompleteDlg(hProgressThread);
  4838. _JumpIfError(hr, Ret, "myBackupDB");
  4839. }
  4840. hr = S_OK;
  4841. Ret:
  4842. if (sBackupState.szLogsPath)
  4843. LocalFree(sBackupState.szLogsPath);
  4844. if (sBackupState.szPassword)
  4845. {
  4846. SecureZeroMemory(sBackupState.szPassword, wcslen(sBackupState.szPassword)*sizeof(WCHAR));
  4847. LocalFree(sBackupState.szPassword);
  4848. }
  4849. return hr;
  4850. }
  4851. DWORD CARestoreWizard(CertSvrCA* pCertCA, HWND hwnd)
  4852. {
  4853. HRESULT hr;
  4854. RESTOREWIZ_STATE sRestoreState; ZeroMemory(&sRestoreState, sizeof(sRestoreState));
  4855. sRestoreState.pCA = pCertCA;
  4856. InitCommonControls();
  4857. CWizard97PropertySheet cDlg(
  4858. g_hInstance,
  4859. IDS_RESTORE_WIZARD,
  4860. IDB_WIZ,
  4861. IDB_WIZ_HEAD,
  4862. TRUE);
  4863. CRestoreWizPage1 sPg1(&sRestoreState, &cDlg);
  4864. CRestoreWizPage2 sPg2(&sRestoreState, &cDlg);
  4865. CRestoreWizPage3 sPg3(&sRestoreState, &cDlg);
  4866. CRestoreWizPage5 sPg5(&sRestoreState, &cDlg);
  4867. cDlg.AddPage(&sPg1);
  4868. cDlg.AddPage(&sPg2);
  4869. cDlg.AddPage(&sPg3);
  4870. cDlg.AddPage(&sPg5);
  4871. // if not halted, stop service
  4872. if (pCertCA->m_pParentMachine->IsCertSvrServiceRunning())
  4873. {
  4874. CString cstrMsg, cstrTitle;
  4875. cstrTitle.LoadString(IDS_RESTORE_WIZARD);
  4876. cstrMsg.LoadString(IDS_STOP_SERVER_WARNING);
  4877. if (IDOK != MessageBox(hwnd, (LPCWSTR)cstrMsg, (LPCWSTR)cstrTitle, MB_OKCANCEL))
  4878. return ERROR_CANCELLED;
  4879. hr = pCertCA->m_pParentMachine->CertSvrStartStopService(hwnd, FALSE);
  4880. _JumpIfError(hr, Ret, "CertSvrStartStopService");
  4881. }
  4882. // should return value >0 on success
  4883. if (0 >= cDlg.DoWizard(hwnd))
  4884. return ERROR_CANCELLED;
  4885. if (sRestoreState.fRestoreKeyCert)
  4886. {
  4887. hr = myCertServerImportPFX(
  4888. sRestoreState.szLogsPath,
  4889. sRestoreState.szPassword,
  4890. TRUE,
  4891. NULL,
  4892. NULL,
  4893. NULL);
  4894. _JumpIfError(hr, Ret, "myCertServerImportPFX");
  4895. if (!sRestoreState.fRestoreLogs)
  4896. {
  4897. // if we're not restoring db, restart svc now
  4898. hr = pCertCA->m_pParentMachine->CertSvrStartStopService(hwnd, TRUE);
  4899. _JumpIfError(hr, Ret, "CertSvrStartStopService");
  4900. }
  4901. }
  4902. if (sRestoreState.fRestoreLogs)
  4903. {
  4904. DBBACKUPPROGRESS dbp;
  4905. ZeroMemory(&dbp, sizeof(dbp));
  4906. DWORD dwFlags = CDBBACKUP_OVERWRITE;
  4907. dwFlags |= sRestoreState.fIncremental ? CDBBACKUP_INCREMENTAL : 0;
  4908. HANDLE hProgressThread = NULL;
  4909. hProgressThread = StartPercentCompleteDlg(g_hInstance, hwnd, IDS_RESTORE_PROGRESS, &dbp);
  4910. if (hProgressThread == NULL)
  4911. {
  4912. hr = GetLastError();
  4913. _JumpError(hr, Ret, "StartPercentCompleteDlg");
  4914. }
  4915. hr = myRestoreDB(
  4916. (LPCWSTR)pCertCA->m_strConfig,
  4917. dwFlags,
  4918. sRestoreState.szLogsPath,
  4919. NULL,
  4920. NULL,
  4921. NULL,
  4922. &dbp);
  4923. CSASSERT( (S_OK != hr) || (
  4924. (dbp.dwDBPercentComplete == 100) &&
  4925. (dbp.dwLogPercentComplete == 100) &&
  4926. (dbp.dwTruncateLogPercentComplete == 100) )
  4927. );
  4928. if (S_OK != hr)
  4929. {
  4930. dbp.dwDBPercentComplete = 100;
  4931. dbp.dwLogPercentComplete = 100;
  4932. dbp.dwTruncateLogPercentComplete = 100;
  4933. }
  4934. // pause for progress dlg to finish
  4935. EndPercentCompleteDlg(hProgressThread);
  4936. _JumpIfError(hr, Ret, "myRestoreDB");
  4937. {
  4938. CString cstrMsg, cstrTitle;
  4939. cstrTitle.LoadString(IDS_RESTORE_WIZARD);
  4940. cstrMsg.LoadString(IDS_INCRRESTORE_RESTART_SERVER_WARNING);
  4941. if (IDYES == MessageBox(hwnd, (LPCWSTR)cstrMsg, (LPCWSTR)cstrTitle, MB_ICONWARNING|MB_YESNO))
  4942. {
  4943. // start svc to complete db restore
  4944. hr = pCertCA->m_pParentMachine->CertSvrStartStopService(hwnd, TRUE);
  4945. _PrintIfError(hr, "CertSvrStartStopService Restore");
  4946. if (hr != S_OK)
  4947. {
  4948. // remove "restore pending" mark
  4949. myRestoreDB(
  4950. pCertCA->m_strConfig,
  4951. 0,
  4952. NULL,
  4953. NULL,
  4954. NULL,
  4955. NULL,
  4956. NULL);
  4957. goto Ret;
  4958. }
  4959. }
  4960. }
  4961. }
  4962. hr = S_OK;
  4963. Ret:
  4964. if (sRestoreState.szLogsPath)
  4965. LocalFree(sRestoreState.szLogsPath);
  4966. if (sRestoreState.szPassword)
  4967. {
  4968. SecureZeroMemory(sRestoreState.szPassword, wcslen(sRestoreState.szPassword)*sizeof(WCHAR));
  4969. LocalFree(sRestoreState.szPassword);
  4970. }
  4971. return hr;
  4972. }
  4973. DWORD CARequestInstallHierarchyWizard(CertSvrCA* pCertCA, HWND hwnd, BOOL fRenewal, BOOL fAttemptRestart)
  4974. {
  4975. DWORD dwErr = ERROR_SUCCESS;
  4976. DWORD dwFlags = CSRF_INSTALLCACERT;
  4977. BOOL fServiceWasRunning = FALSE;
  4978. // stop/start msg
  4979. if (pCertCA->m_pParentMachine->IsCertSvrServiceRunning())
  4980. {
  4981. fServiceWasRunning = TRUE;
  4982. // service must be stopped to complete hierarchy
  4983. CString cstrMsg, cstrTitle;
  4984. cstrMsg.LoadString(IDS_STOP_SERVER_WARNING);
  4985. cstrTitle.LoadString(IDS_INSTALL_HIERARCHY_TITLE);
  4986. if (IDYES != MessageBox(hwnd, cstrMsg, cstrTitle, MB_YESNO))
  4987. return ERROR_CANCELLED;
  4988. // stop
  4989. dwErr = pCertCA->m_pParentMachine->CertSvrStartStopService(hwnd, FALSE);
  4990. _JumpIfError(dwErr, Ret, "CertSvrStartStopService");
  4991. }
  4992. LogOpen(TRUE);
  4993. if (fRenewal)
  4994. {
  4995. BOOL fReuseKeys = FALSE;
  4996. dwErr = (DWORD)DialogBoxParam(
  4997. g_hInstance,
  4998. MAKEINTRESOURCE(IDD_RENEW_REUSEKEYS),
  4999. hwnd,
  5000. dlgProcRenewReuseKeys,
  5001. (LPARAM)&fReuseKeys);
  5002. // translate ok/cancel into error codes
  5003. if (dwErr == IDOK)
  5004. dwErr = ERROR_SUCCESS;
  5005. else if (dwErr == IDCANCEL)
  5006. dwErr = ERROR_CANCELLED;
  5007. _JumpIfError(dwErr, Ret, "dlgProcRenewalReuseKeys");
  5008. dwFlags = CSRF_RENEWCACERT | CSRF_OVERWRITE;
  5009. if (!fReuseKeys)
  5010. dwFlags |= CSRF_NEWKEYS;
  5011. }
  5012. // do actual install
  5013. dwErr = CertServerRequestCACertificateAndComplete(
  5014. g_hInstance, // hInstance
  5015. hwnd, // hwnd
  5016. dwFlags, // Flags
  5017. pCertCA->m_strCommonName, // pwszCAName
  5018. NULL, // pwszParentMachine
  5019. NULL, // pwszParentCA
  5020. NULL, // pwszCAChainFile
  5021. NULL); // pwszRequestFile
  5022. _JumpIfError(dwErr, Ret, "CertServerRequestCACertificateAndComplete");
  5023. Ret:
  5024. // start svc
  5025. if ((fAttemptRestart) && fServiceWasRunning)
  5026. {
  5027. DWORD dwErr2;
  5028. dwErr2 = pCertCA->m_pParentMachine->CertSvrStartStopService(hwnd, TRUE);
  5029. if (dwErr == S_OK)
  5030. {
  5031. dwErr = dwErr2;
  5032. _PrintIfError(dwErr2, "CertSvrStartStopService");
  5033. }
  5034. }
  5035. return dwErr;
  5036. }
  5037. typedef struct _PRIVATE_DLGPROC_CHOOSECRLPUBLISHTYPE_LPARAM
  5038. {
  5039. BOOL fCurrentCRLValid; // IN
  5040. BOOL fDeltaCRLEnabled; // IN
  5041. BOOL fPublishBaseCRL; // OUT
  5042. } PRIVATE_DLGPROC_CHOOSECRLPUBLISHTYPE_LPARAM, *PPRIVATE_DLGPROC_CHOOSECRLPUBLISHTYPE_LPARAM;
  5043. DWORD PublishCRLWizard(CertSvrCA* pCertCA, HWND hwnd)
  5044. {
  5045. DWORD dwErr = ERROR_SUCCESS;
  5046. ICertAdmin2* pAdmin = NULL; // free this
  5047. PCCRL_CONTEXT pCRLCtxt = NULL; // free this
  5048. DATE dateGMT = 0.0;
  5049. DWORD dwCRLFlags;
  5050. variant_t var;
  5051. // UNDONE: might need to check validity of DELTA crl as well as base
  5052. PRIVATE_DLGPROC_CHOOSECRLPUBLISHTYPE_LPARAM sParam = {FALSE, FALSE, FALSE};
  5053. // grab DELTA period count to see if deltas are enabled
  5054. dwErr = pCertCA->GetConfigEntry(
  5055. NULL,
  5056. wszREGCRLDELTAPERIODCOUNT,
  5057. &var);
  5058. _JumpIfError(dwErr, Ret, "GetConfigEntry");
  5059. CSASSERT(V_VT(&var)==VT_I4);
  5060. sParam.fDeltaCRLEnabled = ( -1 != (V_I4(&var)) ) && (0 != (V_I4(&var))); //0, -1 mean disabled
  5061. // now check validity and determine whether to display warning
  5062. // UNDONE: check validity of delta crls?
  5063. dwErr = pCertCA->GetCurrentCRL(&pCRLCtxt, TRUE);
  5064. _PrintIfError(dwErr, "GetCurrentCRL");
  5065. if ((dwErr == S_OK) && (NULL != pCRLCtxt))
  5066. {
  5067. // check validity of outstanding CRL
  5068. dwErr = CertVerifyCRLTimeValidity(
  5069. NULL,
  5070. pCRLCtxt->pCrlInfo);
  5071. // 0 -> current CRL already exists
  5072. if (dwErr == 0)
  5073. sParam.fCurrentCRLValid = TRUE;
  5074. }
  5075. else
  5076. {
  5077. // assume this is funky overwrite case
  5078. sParam.fCurrentCRLValid = TRUE;
  5079. }
  5080. dwErr = (DWORD)DialogBoxParam(
  5081. g_hInstance,
  5082. MAKEINTRESOURCE(IDD_CHOOSE_PUBLISHCRL),
  5083. hwnd,
  5084. dlgProcRevocationPublishType,
  5085. (LPARAM)&sParam);
  5086. // translate ok/cancel into error codes
  5087. if (dwErr == IDOK)
  5088. dwErr = ERROR_SUCCESS;
  5089. else if (dwErr == IDCANCEL)
  5090. dwErr = ERROR_CANCELLED;
  5091. _JumpIfError(dwErr, Ret, "dlgProcRevocationPublishType");
  5092. // publish Delta CRLs if ( !sParam.fPublishBaseCRL )
  5093. dwErr = pCertCA->m_pParentMachine->GetAdmin2(&pAdmin);
  5094. _JumpIfError(dwErr, Ret, "GetAdmin");
  5095. // now publish CRL valid for normal period (dateGMT=0.0 defaults to regular period length)
  5096. dwCRLFlags = 0;
  5097. if (sParam.fDeltaCRLEnabled)
  5098. dwCRLFlags |= CA_CRL_DELTA;
  5099. if (sParam.fPublishBaseCRL)
  5100. dwCRLFlags |= CA_CRL_BASE;
  5101. {
  5102. CWaitCursor hourglass;
  5103. dwErr = pAdmin->PublishCRLs(pCertCA->m_bstrConfig, dateGMT, dwCRLFlags);
  5104. _JumpIfError(dwErr, Ret, "PublishCRLs");
  5105. }
  5106. Ret:
  5107. if (pAdmin)
  5108. pAdmin->Release();
  5109. if (pCRLCtxt)
  5110. CertFreeCRLContext(pCRLCtxt);
  5111. return dwErr;
  5112. }
  5113. DWORD
  5114. CertAdminRevokeCert(
  5115. CertSvrCA *pCertCA,
  5116. ICertAdmin *pAdmin,
  5117. LONG lReasonCode,
  5118. LPWSTR szCertSerNum)
  5119. {
  5120. DWORD dwErr;
  5121. BSTR bstrSerNum = NULL;
  5122. DATE dateNow = 0.0; // now
  5123. if (pAdmin == NULL)
  5124. return ERROR_INVALID_PARAMETER;
  5125. bstrSerNum = SysAllocString(szCertSerNum);
  5126. if (NULL == bstrSerNum)
  5127. {
  5128. dwErr = (DWORD) E_OUTOFMEMORY;
  5129. _JumpError(dwErr, Ret, "SysAllocString");
  5130. }
  5131. dwErr = pAdmin->RevokeCertificate(
  5132. pCertCA->m_bstrConfig,
  5133. bstrSerNum,
  5134. lReasonCode,
  5135. dateNow);
  5136. _JumpIfError(dwErr, Ret, "RevokeCertificate");
  5137. Ret:
  5138. if (bstrSerNum)
  5139. SysFreeString(bstrSerNum);
  5140. return dwErr;
  5141. }
  5142. DWORD CertAdminResubmitRequest(CertSvrCA* pCertCA, ICertAdmin* pAdmin, LONG lRequestID)
  5143. {
  5144. DWORD dwErr;
  5145. LONG lDisposition;
  5146. dwErr = pAdmin->ResubmitRequest(
  5147. pCertCA->m_bstrConfig,
  5148. lRequestID,
  5149. &lDisposition);
  5150. _JumpIfError(dwErr, Ret, "ResubmitRequest");
  5151. Ret:
  5152. return dwErr;
  5153. }
  5154. DWORD CertAdminDenyRequest(CertSvrCA* pCertCA, ICertAdmin* pAdmin, LONG lRequestID)
  5155. {
  5156. DWORD dwErr;
  5157. dwErr = pAdmin->DenyRequest(
  5158. pCertCA->m_bstrConfig,
  5159. lRequestID);
  5160. _JumpIfError(dwErr, Ret, "DenyRequest");
  5161. Ret:
  5162. return dwErr;
  5163. }
  5164. typedef struct _QUERY_COLUMN_HEADINGS
  5165. {
  5166. UINT iRscID;
  5167. DWORD cbColWidth;
  5168. } QUERY_COLUMN_HEADINGS;
  5169. QUERY_COLUMN_HEADINGS g_colHeadings[] =
  5170. {
  5171. { IDS_COLUMNCHOOSER_FIELDNAME, 90 },
  5172. { IDS_COLUMNCHOOSER_OPERATOR, 55 },
  5173. { IDS_COLUMNCHOOSER_VALUE, 150 },
  5174. };
  5175. void RefreshListView(HWND hwndList, QUERY_RESTRICTION* pRestrict)
  5176. {
  5177. HRESULT hr;
  5178. ListView_DeleteAllItems(hwndList);
  5179. LVITEM sNewItem;
  5180. ZeroMemory(&sNewItem, sizeof(sNewItem));
  5181. int iSubItem;
  5182. // while there are restrictions
  5183. while(pRestrict)
  5184. {
  5185. iSubItem = 0;
  5186. ListView_InsertItem(hwndList, &sNewItem);
  5187. LPCWSTR szLocalizedCol;
  5188. hr = myGetColumnDisplayName(
  5189. pRestrict->szField,
  5190. &szLocalizedCol);
  5191. _PrintIfError(hr, "myGetColumnDisplayName");
  5192. if (S_OK == hr)
  5193. {
  5194. ListView_SetItemText(hwndList, sNewItem.iItem, iSubItem++, (LPWSTR)szLocalizedCol);
  5195. ListView_SetItemText(hwndList, sNewItem.iItem, iSubItem++, (LPWSTR)OperationToStr(pRestrict->iOperation));
  5196. VARIANT vtString;
  5197. VariantInit(&vtString);
  5198. if (MakeDisplayStrFromDBVariant(&pRestrict->varValue, &vtString))
  5199. {
  5200. ListView_SetItemText(hwndList, sNewItem.iItem, iSubItem++, vtString.bstrVal);
  5201. VariantClear(&vtString);
  5202. }
  5203. sNewItem.iItem++;
  5204. }
  5205. // fwd to next elt
  5206. pRestrict = pRestrict->pNext;
  5207. }
  5208. return;
  5209. }
  5210. #define MAX_FIELD_SIZE 128
  5211. typedef struct _PRIVATE_DLGPROC_QUERY_LPARAM
  5212. {
  5213. // this is the restriction, modify in-place
  5214. PQUERY_RESTRICTION* ppRestrict;
  5215. // CFolder for read-only data
  5216. // CFolder* pFolder;
  5217. CComponentDataImpl* pCompData;
  5218. } PRIVATE_DLGPROC_QUERY_LPARAM, *PPRIVATE_DLGPROC_QUERY_LPARAM;
  5219. //////////////////////////////////////////////////////////////////
  5220. // New Query Dialog
  5221. INT_PTR CALLBACK
  5222. dlgProcQuery(
  5223. HWND hwndDlg,
  5224. UINT uMsg,
  5225. WPARAM wParam,
  5226. LPARAM lParam)
  5227. {
  5228. PQUERY_RESTRICTION* ppRestrict = NULL;
  5229. switch(uMsg)
  5230. {
  5231. case WM_INITDIALOG:
  5232. {
  5233. ::SetWindowLong(hwndDlg, GWL_EXSTYLE, ::GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
  5234. // remember PRIVATE_DLGPROC_QUERY_LPARAM
  5235. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  5236. ppRestrict = ((PRIVATE_DLGPROC_QUERY_LPARAM*)lParam)->ppRestrict;
  5237. HWND hwndList = GetDlgItem(hwndDlg, IDC_QUERY_LIST);
  5238. // insert possible operators
  5239. for (int i=0; i<ARRAYLEN(g_colHeadings); i++)
  5240. {
  5241. CString cstrTmp;
  5242. cstrTmp.LoadString(g_colHeadings[i].iRscID);
  5243. ListView_NewColumn(hwndList, i, g_colHeadings[i].cbColWidth, (LPWSTR)(LPCWSTR)cstrTmp);
  5244. }
  5245. // don't show deletion buttons if no items to delete
  5246. ::EnableWindow(GetDlgItem(hwndDlg, IDC_RESET_BUTTON), (*ppRestrict!=NULL));
  5247. ::EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_RESTRICTION), (*ppRestrict!=NULL));
  5248. ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT);
  5249. RefreshListView(hwndList, *ppRestrict);
  5250. return 1;
  5251. }
  5252. case WM_HELP:
  5253. {
  5254. OnDialogHelp((LPHELPINFO) lParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_DEFINE_QUERY);
  5255. break;
  5256. }
  5257. case WM_CONTEXTMENU:
  5258. {
  5259. OnDialogContextHelp((HWND)wParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_DEFINE_QUERY);
  5260. break;
  5261. }
  5262. case WM_COMMAND:
  5263. switch (LOWORD(wParam))
  5264. {
  5265. case IDC_DELETE_RESTRICTION:
  5266. {
  5267. ppRestrict = (PQUERY_RESTRICTION*) ((PRIVATE_DLGPROC_QUERY_LPARAM*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA))->ppRestrict;
  5268. PQUERY_RESTRICTION pPrevRestriction = NULL, pRestriction = ppRestrict[0];
  5269. LRESULT iSel;
  5270. HWND hwndList = GetDlgItem(hwndDlg, IDC_QUERY_LIST);
  5271. int iItems = ListView_GetItemCount(hwndList);
  5272. // find selected item
  5273. for(iSel=0; iSel<(LRESULT)iItems; iSel++)
  5274. {
  5275. UINT ui = ListView_GetItemState(hwndList, iSel, LVIS_SELECTED);
  5276. if (ui == LVIS_SELECTED)
  5277. break;
  5278. }
  5279. // no selected item
  5280. if (iSel == iItems)
  5281. break;
  5282. // walk to it in the list
  5283. for(LRESULT lr=0; lr<iSel; lr++)
  5284. {
  5285. // walked off end of list
  5286. if (NULL == pRestriction)
  5287. break;
  5288. // step fwd in list
  5289. pPrevRestriction = pRestriction;
  5290. pRestriction = pRestriction->pNext;
  5291. }
  5292. // if item exists, remove from list & free it
  5293. if (pRestriction)
  5294. {
  5295. if (pPrevRestriction)
  5296. {
  5297. // ppRestrict is still valid, this wasn't the head elt
  5298. pPrevRestriction->pNext = pRestriction->pNext;
  5299. }
  5300. else
  5301. {
  5302. // reset NEXT as the head elt
  5303. *ppRestrict = pRestriction->pNext;
  5304. }
  5305. FreeQueryRestriction(pRestriction);
  5306. // don't show deletion buttons if no items to delete
  5307. ::EnableWindow(GetDlgItem(hwndDlg, IDC_RESET_BUTTON), (*ppRestrict!=NULL));
  5308. ::EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_RESTRICTION), (*ppRestrict!=NULL));
  5309. RefreshListView(hwndList, *ppRestrict);
  5310. if(*ppRestrict!=NULL)
  5311. {
  5312. int c = ListView_GetItemCount(hwndList);
  5313. ListView_SetItemState(hwndList, c-1, LVIS_SELECTED|LVIS_FOCUSED , LVIS_SELECTED|LVIS_FOCUSED);
  5314. SetFocus(hwndList);
  5315. }
  5316. }
  5317. }
  5318. break;
  5319. case IDC_RESET_BUTTON:
  5320. {
  5321. ppRestrict = (PQUERY_RESTRICTION*) ((PRIVATE_DLGPROC_QUERY_LPARAM*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA))->ppRestrict;
  5322. FreeQueryRestrictionList(*ppRestrict);
  5323. *ppRestrict = NULL;
  5324. ::EnableWindow(GetDlgItem(hwndDlg, IDC_RESET_BUTTON), FALSE);
  5325. ::EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_RESTRICTION), FALSE);
  5326. HWND hwndList = GetDlgItem(hwndDlg, IDC_QUERY_LIST);
  5327. RefreshListView(hwndList, *ppRestrict);
  5328. }
  5329. break;
  5330. case IDC_ADD_RESTRICTION:
  5331. {
  5332. LPARAM mylParam = GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  5333. ppRestrict = (PQUERY_RESTRICTION*) ((PRIVATE_DLGPROC_QUERY_LPARAM*)mylParam)->ppRestrict;
  5334. if (IDOK == DialogBoxParam(
  5335. g_hInstance,
  5336. MAKEINTRESOURCE(IDD_NEW_RESTRICTION),
  5337. hwndDlg,
  5338. dlgProcAddRestriction,
  5339. mylParam))
  5340. {
  5341. // show deletion buttons if items to delete
  5342. ::EnableWindow(GetDlgItem(hwndDlg, IDC_RESET_BUTTON), (*ppRestrict!=NULL));
  5343. ::EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_RESTRICTION), (*ppRestrict!=NULL));
  5344. HWND hwndList = GetDlgItem(hwndDlg, IDC_QUERY_LIST);
  5345. RefreshListView(hwndList, *ppRestrict);
  5346. int c = ListView_GetItemCount(hwndList);
  5347. ListView_SetItemState(hwndList, c-1, LVIS_SELECTED|LVIS_FOCUSED , LVIS_SELECTED|LVIS_FOCUSED);
  5348. SetFocus(hwndList);
  5349. }
  5350. }
  5351. break;
  5352. case IDOK:
  5353. case IDCANCEL:
  5354. EndDialog(hwndDlg, LOWORD(wParam));
  5355. break;
  5356. default:
  5357. break;
  5358. }
  5359. default:
  5360. break;
  5361. }
  5362. return 0;
  5363. }
  5364. HRESULT SetTimePickerNoSeconds(HWND hwndPicker)
  5365. {
  5366. HRESULT hr = S_OK;
  5367. //
  5368. // Setup the time picker controls to use a short time format with no seconds.
  5369. //
  5370. WCHAR szTimeFormat[MAX_PATH] = {0};
  5371. LPTSTR pszTimeFormat = szTimeFormat;
  5372. WCHAR szTimeSep[MAX_PATH] = {0};
  5373. int cchTimeSep;
  5374. WCHAR szShortTimeFormat[MAX_PATH];
  5375. LPWSTR pszShortTimeFormat = szShortTimeFormat;
  5376. if(0 == GetLocaleInfo( LOCALE_USER_DEFAULT,
  5377. LOCALE_STIMEFORMAT,
  5378. szTimeFormat,
  5379. ARRAYLEN(szTimeFormat)))
  5380. {
  5381. hr = GetLastError();
  5382. _JumpError(hr, Ret, "GetLocaleInfo");
  5383. }
  5384. cchTimeSep = GetLocaleInfo( LOCALE_USER_DEFAULT,
  5385. LOCALE_STIME,
  5386. szTimeSep,
  5387. ARRAYLEN(szTimeSep));
  5388. if (0 == cchTimeSep)
  5389. {
  5390. hr = GetLastError();
  5391. _JumpError(hr, Ret, "GetLocaleInfo");
  5392. }
  5393. cchTimeSep--; // number of chars not including NULL
  5394. //
  5395. // Remove the seconds format string and preceeding separator.
  5396. //
  5397. while (*pszTimeFormat)
  5398. {
  5399. if ((*pszTimeFormat != L's') && (*pszTimeFormat != L'S'))
  5400. {
  5401. *pszShortTimeFormat++ = *pszTimeFormat;
  5402. }
  5403. else
  5404. {
  5405. // NULL terminate here so we can strcmp
  5406. *pszShortTimeFormat = L'\0';
  5407. LPWSTR p = pszShortTimeFormat;
  5408. // trim preceeding off
  5409. // rewind one char
  5410. p--;
  5411. if (p >= szShortTimeFormat) // we didn't rewind too far
  5412. {
  5413. if (*p == L' ')
  5414. pszShortTimeFormat = p; // skip space
  5415. else
  5416. {
  5417. p -= (cchTimeSep-1); // p already backstepped one char
  5418. if (0 == lstrcmp(p, szTimeSep))
  5419. pszShortTimeFormat = p; // skip szTimeSep
  5420. }
  5421. }
  5422. }
  5423. pszTimeFormat++;
  5424. }
  5425. // zero-terminate
  5426. *pszShortTimeFormat = L'\0';
  5427. //
  5428. // If we have retrived a valid time format string then use it,
  5429. // else use the default format string implemented by common control.
  5430. //
  5431. DateTime_SetFormat(hwndPicker, szShortTimeFormat);
  5432. Ret:
  5433. return hr;
  5434. }
  5435. INT_PTR CALLBACK dlgProcAddRestriction(
  5436. HWND hwndDlg,
  5437. UINT uMsg,
  5438. WPARAM wParam,
  5439. LPARAM lParam )
  5440. {
  5441. typedef struct _DROPDOWN_FIELD_PARAM
  5442. {
  5443. DWORD dwPropType;
  5444. DWORD dwIndexed;
  5445. LPWSTR szUnlocalized;
  5446. } DROPDOWN_FIELD_PARAM, *PDROPDOWN_FIELD_PARAM;
  5447. HRESULT hr;
  5448. PQUERY_RESTRICTION* ppRestrict = NULL;
  5449. switch(uMsg)
  5450. {
  5451. case WM_INITDIALOG:
  5452. {
  5453. ::SetWindowLong(hwndDlg, GWL_EXSTYLE, ::GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
  5454. // remember PQUERY_RESTRICTION
  5455. ppRestrict = ((PRIVATE_DLGPROC_QUERY_LPARAM*)lParam)->ppRestrict;
  5456. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)ppRestrict);
  5457. // Not a huge failure, worst case:
  5458. // we don't call DateTime_SetFormat and the user gets a seconds picker
  5459. SetTimePickerNoSeconds(GetDlgItem(hwndDlg, IDC_TIMEPICKER_NEWQUERY));
  5460. {
  5461. // insert all column names
  5462. CComponentDataImpl* pCompData = ((PRIVATE_DLGPROC_QUERY_LPARAM*)lParam)->pCompData;
  5463. HWND hFieldDropdown = GetDlgItem(hwndDlg, IDC_EDIT_NEWQUERY_FIELD);
  5464. for(DWORD i=0; i<pCompData->GetSchemaEntries(); i++)
  5465. {
  5466. LPCWSTR pszLocal;
  5467. LPCWSTR szColName=NULL;
  5468. LONG lType, lIndexed;
  5469. if (S_OK == pCompData->GetDBSchemaEntry(i, &szColName, &lType, (BOOL*)&lIndexed))
  5470. {
  5471. // skip filter types we can't parse
  5472. if (PROPTYPE_BINARY == lType)
  5473. continue;
  5474. hr = myGetColumnDisplayName(
  5475. szColName,
  5476. &pszLocal);
  5477. _PrintIfError(hr, "myGetColumnDisplayName");
  5478. if (S_OK != hr)
  5479. continue;
  5480. INT nItemIndex = (INT)SendMessage(hFieldDropdown, CB_ADDSTRING, 0, (LPARAM)pszLocal);
  5481. // prepare the data parameter
  5482. PDROPDOWN_FIELD_PARAM pField = (PDROPDOWN_FIELD_PARAM)new BYTE[sizeof(DROPDOWN_FIELD_PARAM) + WSZ_BYTECOUNT(szColName)];
  5483. if (pField != NULL)
  5484. {
  5485. pField->dwPropType = lType;
  5486. pField->dwIndexed = lIndexed;
  5487. pField->szUnlocalized = (LPWSTR)((BYTE*)pField + sizeof(DROPDOWN_FIELD_PARAM));
  5488. wcscpy(pField->szUnlocalized, szColName);
  5489. SendMessage(hFieldDropdown, CB_SETITEMDATA, (WPARAM)nItemIndex, (LPARAM) pField);
  5490. }
  5491. }
  5492. }
  5493. // set a default selection
  5494. SendMessage(hFieldDropdown, CB_SETCURSEL, 0, 0);
  5495. SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_EDIT_NEWQUERY_FIELD, LBN_SELCHANGE), (LPARAM)hFieldDropdown);
  5496. HWND hOperationDropdown = GetDlgItem(hwndDlg, IDC_EDIT_NEWQUERY_OPERATION);
  5497. SendMessage(hOperationDropdown, CB_ADDSTRING, 0, (LPARAM)L"<");
  5498. SendMessage(hOperationDropdown, CB_ADDSTRING, 0, (LPARAM)L"<=");
  5499. SendMessage(hOperationDropdown, CB_ADDSTRING, 0, (LPARAM)L">=");
  5500. SendMessage(hOperationDropdown, CB_ADDSTRING, 0, (LPARAM)L">");
  5501. INT iDefSel = (INT)SendMessage(hOperationDropdown, CB_ADDSTRING, 0, (LPARAM)L"=");
  5502. SendMessage(hOperationDropdown, CB_SETCURSEL, iDefSel, 0);
  5503. }
  5504. return 1;
  5505. }
  5506. case WM_HELP:
  5507. {
  5508. OnDialogHelp((LPHELPINFO) lParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_NEW_RESTRICTION);
  5509. break;
  5510. }
  5511. case WM_CONTEXTMENU:
  5512. {
  5513. OnDialogContextHelp((HWND)wParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_NEW_RESTRICTION);
  5514. break;
  5515. }
  5516. case WM_COMMAND:
  5517. switch (LOWORD(wParam))
  5518. {
  5519. case IDC_EDIT_NEWQUERY_FIELD:
  5520. {
  5521. if (HIWORD(wParam) == LBN_SELCHANGE)
  5522. {
  5523. // On selection change, ask for the right format
  5524. int nItemIndex;
  5525. nItemIndex = (INT)SendMessage((HWND)lParam,
  5526. CB_GETCURSEL,
  5527. 0,
  5528. 0);
  5529. DROPDOWN_FIELD_PARAM* pField = NULL;
  5530. pField = (PDROPDOWN_FIELD_PARAM) SendMessage(
  5531. (HWND)lParam,
  5532. CB_GETITEMDATA,
  5533. (WPARAM)nItemIndex,
  5534. 0);
  5535. if (CB_ERR == (DWORD_PTR)pField)
  5536. break; // get out of here
  5537. BOOL fShowPickers = (pField->dwPropType == PROPTYPE_DATE);
  5538. // swap entry mode to/from datetime pickers
  5539. ShowWindow(GetDlgItem(hwndDlg, IDC_EDIT_NEWQUERY_VALUE), fShowPickers ? SW_HIDE : SW_SHOW);
  5540. ShowWindow(GetDlgItem(hwndDlg, IDC_DATEPICKER_NEWQUERY), fShowPickers ? SW_SHOW : SW_HIDE);
  5541. ShowWindow(GetDlgItem(hwndDlg, IDC_TIMEPICKER_NEWQUERY), fShowPickers ? SW_SHOW : SW_HIDE);
  5542. }
  5543. }
  5544. break;
  5545. case IDOK:
  5546. {
  5547. ppRestrict = (PQUERY_RESTRICTION*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  5548. WCHAR szFieldName[MAX_FIELD_SIZE+1];
  5549. WCHAR szValue[MAX_FIELD_SIZE+1];
  5550. WCHAR szOp[10];
  5551. GetDlgItemText(hwndDlg, IDC_EDIT_NEWQUERY_VALUE, szValue, MAX_FIELD_SIZE);
  5552. GetDlgItemText(hwndDlg, IDC_EDIT_NEWQUERY_OPERATION, szOp, ARRAYLEN(szOp)-1);
  5553. GetDlgItemText(hwndDlg, IDC_EDIT_NEWQUERY_FIELD, szFieldName, MAX_FIELD_SIZE);
  5554. DROPDOWN_FIELD_PARAM* pField = NULL;
  5555. VARIANT vt;
  5556. VariantInit(&vt);
  5557. // parsing code
  5558. {
  5559. HWND hFieldDropdown = GetDlgItem(hwndDlg, IDC_EDIT_NEWQUERY_FIELD);
  5560. BOOL fValidDigitString;
  5561. INT nItemIndex = (INT)SendMessage(hFieldDropdown,
  5562. CB_GETCURSEL,
  5563. 0,
  5564. 0);
  5565. pField = (PDROPDOWN_FIELD_PARAM)SendMessage(
  5566. hFieldDropdown,
  5567. CB_GETITEMDATA,
  5568. (WPARAM)nItemIndex,
  5569. 0);
  5570. if ((NULL == pField) || (CB_ERR == (DWORD_PTR)pField))
  5571. break;
  5572. switch(pField->dwPropType)
  5573. {
  5574. case PROPTYPE_LONG:
  5575. vt.vt = VT_I4;
  5576. vt.lVal = myWtoI(szValue, &fValidDigitString);
  5577. break;
  5578. case PROPTYPE_STRING:
  5579. vt.vt = VT_BSTR;
  5580. vt.bstrVal = _wcslwr(szValue);
  5581. break;
  5582. case PROPTYPE_DATE:
  5583. {
  5584. SYSTEMTIME stDate, stTime;
  5585. hr = DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DATEPICKER_NEWQUERY), &stDate);
  5586. _PrintIfError(hr, "DateTime_GetSystemtime");
  5587. if (hr != S_OK)
  5588. break;
  5589. hr = DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_TIMEPICKER_NEWQUERY), &stTime);
  5590. _PrintIfError(hr, "DateTime_GetSystemtime");
  5591. if (hr != S_OK)
  5592. break;
  5593. // merge the two structures
  5594. stTime.wYear = stDate.wYear;
  5595. stTime.wMonth = stDate.wMonth;
  5596. stTime.wDayOfWeek = stDate.wDayOfWeek;
  5597. stTime.wDay = stDate.wDay;
  5598. // convert to GMT
  5599. hr = mySystemTimeToGMTSystemTime(&stTime);
  5600. _PrintIfError(hr, "mySystemTimeToGMTSystemTime");
  5601. if (hr != S_OK)
  5602. break;
  5603. stTime.wSecond = 0;
  5604. stTime.wMilliseconds = 0;
  5605. // inject into variant
  5606. if (!SystemTimeToVariantTime(&stTime, &vt.date))
  5607. {
  5608. hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  5609. _PrintError(hr, "SystemTimeToVariantTime");
  5610. break;
  5611. }
  5612. vt.vt = VT_DATE;
  5613. }
  5614. break;
  5615. case PROPTYPE_BINARY:
  5616. {
  5617. CString cstrMsg, cstrTitle;
  5618. cstrMsg.LoadString(IDS_FILTER_NOT_SUPPORTED);
  5619. cstrTitle.LoadString(IDS_MSG_TITLE);
  5620. MessageBoxW(hwndDlg, cstrMsg, cstrTitle, MB_OK);
  5621. }
  5622. break;
  5623. default:
  5624. break;
  5625. }
  5626. }
  5627. // if we didn't get column
  5628. if (VT_EMPTY == vt.vt)
  5629. break;
  5630. // copy into new struct
  5631. QUERY_RESTRICTION* pNewRestrict = NewQueryRestriction(
  5632. pField->szUnlocalized, // UnlocalizeColName(szFieldName),
  5633. StrToOperation(szOp),
  5634. &vt);
  5635. if (pNewRestrict)
  5636. {
  5637. // add restriction only if not already present
  5638. if(!QueryRestrictionFound(pNewRestrict, *ppRestrict))
  5639. {
  5640. // don't call VarClear -- it'll try to SysFree the non-bstr!
  5641. VariantInit(&vt);
  5642. // insert into list
  5643. ListInsertAtEnd((void**)ppRestrict, pNewRestrict);
  5644. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)ppRestrict);
  5645. }
  5646. else
  5647. {
  5648. FreeQueryRestriction(pNewRestrict);
  5649. }
  5650. }
  5651. }
  5652. case IDCANCEL:
  5653. // cleanup
  5654. {
  5655. INT cItems = (INT)::SendDlgItemMessage(hwndDlg, IDC_EDIT_NEWQUERY_FIELD, CB_GETCOUNT, 0, 0);
  5656. while(cItems--)
  5657. {
  5658. PBYTE pb = (PBYTE)::SendDlgItemMessage(hwndDlg, IDC_EDIT_NEWQUERY_FIELD, CB_GETITEMDATA, (WPARAM)cItems, 0);
  5659. delete [] pb;
  5660. }
  5661. }
  5662. EndDialog(hwndDlg, LOWORD(wParam));
  5663. break;
  5664. default:
  5665. break;
  5666. }
  5667. default:
  5668. break;
  5669. }
  5670. return 0;
  5671. }
  5672. typedef struct _CHOOSEMODULE_MODULEDEF
  5673. {
  5674. LPOLESTR pszprogidModule;
  5675. CLSID clsidModule;
  5676. } CHOOSEMODULE_MODULEDEF, *PCHOOSEMODULE_MODULEDEF;
  5677. void FreeChooseModuleDef(PCHOOSEMODULE_MODULEDEF psModuleDef)
  5678. {
  5679. if (psModuleDef)
  5680. {
  5681. if (psModuleDef->pszprogidModule)
  5682. {
  5683. CoTaskMemFree(psModuleDef->pszprogidModule);
  5684. }
  5685. LocalFree(psModuleDef);
  5686. }
  5687. }
  5688. INT_PTR CALLBACK dlgProcChooseModule(
  5689. HWND hwndDlg,
  5690. UINT uMsg,
  5691. WPARAM wParam,
  5692. LPARAM lParam )
  5693. {
  5694. BOOL fReturn = FALSE;
  5695. HRESULT hr;
  5696. PPRIVATE_DLGPROC_MODULESELECT_LPARAM pParam = NULL;
  5697. HKEY hRemoteMachine = NULL;
  5698. switch(uMsg)
  5699. {
  5700. case WM_INITDIALOG:
  5701. {
  5702. ::SetWindowLong(hwndDlg, GWL_EXSTYLE, ::GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
  5703. pParam = (PRIVATE_DLGPROC_MODULESELECT_LPARAM*)lParam;
  5704. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)pParam);
  5705. ::SendDlgItemMessage(hwndDlg, IDC_MODULE_LIST, LB_RESETCONTENT, 0, 0);
  5706. CString cstrTitle;
  5707. if (pParam->fIsPolicyModuleSelection)
  5708. cstrTitle.LoadString(IDS_CHOOSEMODULE_POLICY_TITLE);
  5709. else
  5710. cstrTitle.LoadString(IDS_CHOOSEMODULE_EXIT_TITLE);
  5711. ::SetWindowText(hwndDlg, (LPCWSTR)cstrTitle);
  5712. // grab current default, watch for it to float by during enum
  5713. DWORD dwCurrentSelection = 0;
  5714. LPWSTR pszKeyName = NULL;
  5715. DISPATCHINTERFACE di;
  5716. BOOL fMustRelease = FALSE;
  5717. PCHOOSEMODULE_MODULEDEF psModuleDef = NULL;
  5718. if (! pParam->pCA->m_pParentMachine->IsLocalMachine())
  5719. {
  5720. hr = RegConnectRegistry(
  5721. pParam->pCA->m_pParentMachine->m_strMachineName,
  5722. HKEY_CLASSES_ROOT,
  5723. &hRemoteMachine);
  5724. _PrintIfError(hr, "RegConnectRegistry");
  5725. if (S_OK != hr)
  5726. break;
  5727. }
  5728. for (DWORD dwIndex=0; ; /*dwIndex++*/)
  5729. {
  5730. if (NULL != pszKeyName)
  5731. {
  5732. LocalFree(pszKeyName);
  5733. pszKeyName = NULL;
  5734. }
  5735. if (fMustRelease)
  5736. {
  5737. ManageModule_Release(&di);
  5738. fMustRelease = FALSE;
  5739. }
  5740. FreeChooseModuleDef(psModuleDef);
  5741. psModuleDef = (PCHOOSEMODULE_MODULEDEF)LocalAlloc(LMEM_FIXED|LMEM_ZEROINIT, sizeof(CHOOSEMODULE_MODULEDEF));
  5742. if (NULL == psModuleDef)
  5743. {
  5744. hr = E_OUTOFMEMORY;
  5745. _PrintError(hr, "LocalAlloc");
  5746. break;
  5747. }
  5748. pszKeyName = RegEnumKeyContaining(
  5749. (hRemoteMachine != NULL) ? hRemoteMachine : HKEY_CLASSES_ROOT,
  5750. pParam->fIsPolicyModuleSelection? wszCERTPOLICYMODULE_POSTFIX : wszCERTEXITMODULE_POSTFIX,
  5751. &dwIndex);
  5752. if (NULL == pszKeyName)
  5753. {
  5754. break;
  5755. }
  5756. // make sure it _ends_ with the specified string
  5757. DWORD chSubStrShouldStartAt = (wcslen(pszKeyName) -
  5758. wcslen(pParam->fIsPolicyModuleSelection ? wszCERTPOLICYMODULE_POSTFIX : wszCERTEXITMODULE_POSTFIX) );
  5759. if (0 != wcscmp(
  5760. &pszKeyName[chSubStrShouldStartAt],
  5761. pParam->fIsPolicyModuleSelection?
  5762. wszCERTPOLICYMODULE_POSTFIX : wszCERTEXITMODULE_POSTFIX))
  5763. continue;
  5764. psModuleDef->pszprogidModule = (LPOLESTR)CoTaskMemAlloc(WSZ_BYTECOUNT(pszKeyName));
  5765. if (NULL == psModuleDef->pszprogidModule)
  5766. {
  5767. hr = E_OUTOFMEMORY;
  5768. _PrintError(hr, "CoTaskMemAlloc");
  5769. break;
  5770. }
  5771. wcscpy(psModuleDef->pszprogidModule, pszKeyName);
  5772. hr = CLSIDFromProgID(psModuleDef->pszprogidModule, &psModuleDef->clsidModule);
  5773. _PrintIfError(hr, "CLSIDFromProgID");
  5774. if (S_OK != hr)
  5775. continue; // module clsid not found? ouch!
  5776. if(pParam->fIsPolicyModuleSelection)
  5777. {
  5778. hr = GetPolicyManageDispatch(
  5779. psModuleDef->pszprogidModule,
  5780. psModuleDef->clsidModule,
  5781. &di);
  5782. _PrintIfErrorStr(hr, "GetPolicyManageDispatch", psModuleDef->pszprogidModule);
  5783. }
  5784. else
  5785. {
  5786. hr = GetExitManageDispatch(
  5787. psModuleDef->pszprogidModule,
  5788. psModuleDef->clsidModule,
  5789. &di);
  5790. _PrintIfErrorStr(hr, "GetExitManageDispatch", psModuleDef->pszprogidModule);
  5791. }
  5792. if (hr != S_OK)
  5793. continue;
  5794. fMustRelease = TRUE;
  5795. BSTR bstrName = NULL;
  5796. BSTR bstrStorageLoc = NULL;
  5797. // ASSERT( pParam->pCA->m_pParentMachine->IsLocalMachine());
  5798. // get the storage path
  5799. CString cstrStoragePath;
  5800. cstrStoragePath = wszREGKEYCONFIGPATH_BS;
  5801. cstrStoragePath += pParam->pCA->m_strSanitizedName;
  5802. cstrStoragePath += TEXT("\\");
  5803. cstrStoragePath += pParam->fIsPolicyModuleSelection?
  5804. wszREGKEYPOLICYMODULES:
  5805. wszREGKEYEXITMODULES;
  5806. cstrStoragePath += TEXT("\\");
  5807. cstrStoragePath += psModuleDef->pszprogidModule;
  5808. bstrStorageLoc = SysAllocString(cstrStoragePath);
  5809. if (bstrStorageLoc == NULL)
  5810. {
  5811. _PrintError(E_OUTOFMEMORY, "SysAllocString");
  5812. continue;
  5813. }
  5814. BSTR bstrPropertyName = SysAllocString(wszCMM_PROP_NAME);
  5815. if (bstrPropertyName == NULL)
  5816. {
  5817. _PrintError(E_OUTOFMEMORY, "SysAllocString");
  5818. continue;
  5819. }
  5820. // get name property
  5821. hr = ManageModule_GetProperty(&di, pParam->pCA->m_bstrConfig, bstrStorageLoc, bstrPropertyName, 0, PROPTYPE_STRING, &bstrName);
  5822. _PrintIfError(hr, "ManageModule_GetProperty");
  5823. if(S_OK==hr)
  5824. {
  5825. myRegisterMemAlloc(bstrName, -1, CSM_SYSALLOC);
  5826. }
  5827. if (bstrStorageLoc)
  5828. {
  5829. SysFreeString(bstrStorageLoc);
  5830. bstrStorageLoc = NULL;
  5831. }
  5832. if (bstrPropertyName)
  5833. {
  5834. SysFreeString(bstrPropertyName);
  5835. bstrPropertyName = NULL;
  5836. }
  5837. if (hr != S_OK)
  5838. {
  5839. // Bug #236267: module instantiated but GetProperty returns error
  5840. // notify user and continue
  5841. CString cstrMsg, cstrFmt;
  5842. cstrFmt.LoadString(IDS_ICMM_GETNAMEPROPERTY_FAILED);
  5843. cstrMsg.Format(cstrFmt, psModuleDef->pszprogidModule);
  5844. DisplayCertSrvErrorWithContext(hwndDlg, hr, (LPCWSTR)cstrMsg);
  5845. if (bstrName)
  5846. SysFreeString(bstrName);
  5847. continue;
  5848. }
  5849. // No error (but no name)
  5850. if (bstrName == NULL)
  5851. continue;
  5852. // add to listbox
  5853. INT idxInsertion;
  5854. idxInsertion = (INT)::SendDlgItemMessage(hwndDlg, IDC_MODULE_LIST, LB_ADDSTRING, 0, (LPARAM)bstrName);
  5855. SysFreeString(bstrName);
  5856. bstrName = NULL;
  5857. // add module defn as item data
  5858. ::SendDlgItemMessage(hwndDlg, IDC_MODULE_LIST, LB_SETITEMDATA, idxInsertion, (LPARAM)psModuleDef);
  5859. if (0 == memcmp(&psModuleDef->clsidModule, pParam->pclsidModule, sizeof(CLSID)))
  5860. dwCurrentSelection = idxInsertion;
  5861. psModuleDef = NULL; // dlg owns memory
  5862. }
  5863. FreeChooseModuleDef(psModuleDef);
  5864. if (NULL != pszKeyName)
  5865. LocalFree(pszKeyName);
  5866. if (fMustRelease)
  5867. {
  5868. ManageModule_Release(&di);
  5869. }
  5870. ::SendDlgItemMessage(hwndDlg, IDC_MODULE_LIST, LB_SETCURSEL, (WPARAM)dwCurrentSelection, 0);
  5871. // no other work to be done
  5872. fReturn = TRUE;
  5873. }
  5874. case WM_HELP:
  5875. {
  5876. OnDialogHelp((LPHELPINFO) lParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CHOOSE_MODULE);
  5877. break;
  5878. }
  5879. case WM_CONTEXTMENU:
  5880. {
  5881. OnDialogContextHelp((HWND)wParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CHOOSE_MODULE);
  5882. break;
  5883. }
  5884. case WM_COMMAND:
  5885. switch (LOWORD(wParam))
  5886. {
  5887. case IDOK:
  5888. {
  5889. pParam = (PPRIVATE_DLGPROC_MODULESELECT_LPARAM)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  5890. // detect selection, chg registry settings
  5891. DWORD dwSel = (DWORD)::SendDlgItemMessage(hwndDlg, IDC_MODULE_LIST, LB_GETCURSEL, 0, 0);
  5892. if (LB_ERR != dwSel)
  5893. {
  5894. PCHOOSEMODULE_MODULEDEF psModuleDef = NULL;
  5895. psModuleDef = (PCHOOSEMODULE_MODULEDEF)::SendDlgItemMessage(hwndDlg, IDC_MODULE_LIST, LB_GETITEMDATA, (WPARAM)dwSel, 0);
  5896. // we own memory now, delete this guy
  5897. ::SendDlgItemMessage(hwndDlg, IDC_MODULE_LIST, LB_DELETESTRING, (WPARAM)dwSel, 0);
  5898. // if (moduledef) OR (exit module "no exit module" selection)
  5899. if ((psModuleDef) || (!pParam->fIsPolicyModuleSelection))
  5900. {
  5901. // free what was passed in
  5902. if (*pParam->ppszProgIDModule)
  5903. {
  5904. CoTaskMemFree(*pParam->ppszProgIDModule);
  5905. }
  5906. if (psModuleDef)
  5907. {
  5908. *pParam->ppszProgIDModule = psModuleDef->pszprogidModule;
  5909. CopyMemory(pParam->pclsidModule, &psModuleDef->clsidModule, sizeof(CLSID));
  5910. // all other memory is owned by pParam
  5911. LocalFree(psModuleDef);
  5912. }
  5913. else
  5914. {
  5915. *pParam->ppszProgIDModule = NULL;
  5916. ZeroMemory(pParam->pclsidModule, sizeof(CLSID));
  5917. }
  5918. } // no moduledef found; error!
  5919. }
  5920. }
  5921. // fall through for cleanup
  5922. case IDCANCEL:
  5923. {
  5924. PCHOOSEMODULE_MODULEDEF psModuleDef = NULL;
  5925. // listbox cleanup
  5926. INT cItems = (INT)::SendDlgItemMessage(hwndDlg, IDC_MODULE_LIST, LB_GETCOUNT, 0, 0);
  5927. while(cItems--)
  5928. {
  5929. psModuleDef = (PCHOOSEMODULE_MODULEDEF)::SendDlgItemMessage(hwndDlg, IDC_MODULE_LIST, LB_GETITEMDATA, (WPARAM)cItems, 0);
  5930. FreeChooseModuleDef(psModuleDef);
  5931. }
  5932. }
  5933. EndDialog(hwndDlg, LOWORD(wParam));
  5934. break;
  5935. default:
  5936. break;
  5937. }
  5938. default:
  5939. break;
  5940. }
  5941. if (NULL != hRemoteMachine)
  5942. RegCloseKey(hRemoteMachine);
  5943. return fReturn;
  5944. }
  5945. DWORD
  5946. ModifyQueryFilter(
  5947. HWND hwnd,
  5948. CertViewRowEnum *pRowEnum,
  5949. CComponentDataImpl *pCompData,
  5950. int i)
  5951. {
  5952. // copy m_pRestrictions to pRestrictionHead
  5953. DWORD dwErr = ERROR_SUCCESS;
  5954. PRIVATE_DLGPROC_QUERY_LPARAM sParam;
  5955. PQUERY_RESTRICTION pRestrictionHead = NULL, pTmpRestriction, pCurRestriction;
  5956. PQUERY_RESTRICTION pFolderRestrictions = pRowEnum->GetQueryRestrictions(i);
  5957. pCurRestriction = NULL;
  5958. if (pFolderRestrictions)
  5959. {
  5960. pRestrictionHead = NewQueryRestriction(
  5961. pFolderRestrictions->szField,
  5962. pFolderRestrictions->iOperation,
  5963. &pFolderRestrictions->varValue);
  5964. if (NULL == pRestrictionHead)
  5965. {
  5966. dwErr = (DWORD) E_OUTOFMEMORY;
  5967. _JumpError(dwErr, Ret, "NewQueryRestriction");
  5968. }
  5969. pCurRestriction = pRestrictionHead;
  5970. pFolderRestrictions = pFolderRestrictions->pNext;
  5971. }
  5972. while(pFolderRestrictions)
  5973. {
  5974. pTmpRestriction = NewQueryRestriction(
  5975. pFolderRestrictions->szField,
  5976. pFolderRestrictions->iOperation,
  5977. &pFolderRestrictions->varValue);
  5978. if (NULL == pTmpRestriction)
  5979. {
  5980. dwErr = (DWORD) E_OUTOFMEMORY;
  5981. _JumpError(dwErr, Ret, "NewQueryRestriction");
  5982. }
  5983. pCurRestriction->pNext = pTmpRestriction;
  5984. pCurRestriction = pCurRestriction->pNext;
  5985. pFolderRestrictions = pFolderRestrictions->pNext;
  5986. }
  5987. InitCommonControls(); // dialog uses comctl32
  5988. sParam.ppRestrict = &pRestrictionHead;
  5989. sParam.pCompData = pCompData;
  5990. dwErr = (DWORD)DialogBoxParam(
  5991. g_hInstance,
  5992. MAKEINTRESOURCE(IDD_DEFINE_QUERY),
  5993. hwnd,
  5994. dlgProcQuery,
  5995. (LPARAM)&sParam);
  5996. if (dwErr == IDOK)
  5997. {
  5998. // copy pRestrictionHead back to GetCA()->m_pRestrictions on OK
  5999. pRowEnum->SetQueryRestrictions(pRestrictionHead, i);
  6000. // trigger active flag
  6001. pRowEnum->SetQueryRestrictionsActive(pRestrictionHead != NULL, i);
  6002. }
  6003. else
  6004. {
  6005. FreeQueryRestrictionList(pRestrictionHead);
  6006. }
  6007. // translate ok/cancel into error codes
  6008. if (dwErr == IDOK)
  6009. dwErr = ERROR_SUCCESS;
  6010. else if (dwErr == IDCANCEL)
  6011. dwErr = ERROR_CANCELLED;
  6012. _PrintIfError(dwErr, "dlgProcQuery");
  6013. Ret:
  6014. return dwErr;
  6015. }
  6016. BOOL
  6017. SwapSelectedListboxItem(
  6018. HWND hFrom,
  6019. HWND hTo,
  6020. LPWSTR szItem,
  6021. DWORD DBGCODE(chItem))
  6022. {
  6023. // find selected item in from list
  6024. INT nIndex = (INT)SendMessage(hFrom, LB_GETCURSEL, 0, 0);
  6025. if (nIndex == LB_ERR)
  6026. return FALSE;
  6027. // dblchk text buf long enough
  6028. #if DBG
  6029. INT nChars = (INT)SendMessage(hFrom, LB_GETTEXTLEN, (WPARAM)nIndex, 0);
  6030. if (nChars == LB_ERR)
  6031. return FALSE;
  6032. CSASSERT( (nChars +1) <= (int)chItem);
  6033. #endif
  6034. // retrieve text
  6035. if(LB_ERR == SendMessage(hFrom, LB_GETTEXT, (WPARAM)nIndex, (LPARAM)szItem))
  6036. goto Ret;
  6037. // add to target
  6038. if(LB_ERR == SendMessage(hTo, LB_ADDSTRING, 0, (LPARAM)szItem))
  6039. goto Ret;
  6040. // remove from old
  6041. if(LB_ERR == SendMessage(hFrom, LB_DELETESTRING, (WPARAM)nIndex, 0))
  6042. goto Ret;
  6043. Ret:
  6044. return TRUE;
  6045. }
  6046. //////////////////////////////////////////////////////////////////
  6047. // Base/Delta CRL publish chooser
  6048. INT_PTR CALLBACK dlgProcRevocationPublishType(
  6049. HWND hwndDlg,
  6050. UINT uMsg,
  6051. WPARAM wParam,
  6052. LPARAM lParam )
  6053. {
  6054. switch(uMsg)
  6055. {
  6056. case WM_INITDIALOG:
  6057. {
  6058. // no help here, it's self-explanitory (per mikedan)
  6059. // ::SetWindowLong(hwndDlg, GWL_EXSTYLE, ::GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
  6060. // remember param
  6061. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  6062. // only show warning if current CRL still valid
  6063. PPRIVATE_DLGPROC_CHOOSECRLPUBLISHTYPE_LPARAM psParam = (PPRIVATE_DLGPROC_CHOOSECRLPUBLISHTYPE_LPARAM)lParam;
  6064. ShowWindow(GetDlgItem(hwndDlg, IDC_VALID_LASTPUBLISHED), psParam->fCurrentCRLValid ? SW_SHOW : SW_HIDE);
  6065. // select the 1st element
  6066. HWND hRadioBase = GetDlgItem(hwndDlg, IDC_RADIO_NEWBASE);
  6067. SendMessage(hRadioBase, BM_SETCHECK, TRUE, 0); // Yes by default
  6068. if (!psParam->fDeltaCRLEnabled)
  6069. {
  6070. ::EnableWindow(GetDlgItem(hwndDlg, IDC_RADIO_NEWDELTA), FALSE);
  6071. ::EnableWindow(GetDlgItem(hwndDlg, IDC_DELTA_EXPLANATION), FALSE);
  6072. }
  6073. return 1;
  6074. }
  6075. break;
  6076. case WM_HELP:
  6077. {
  6078. // UNDONE
  6079. //OnDialogHelp((LPHELPINFO) lParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_REVOCATION_DIALOG);
  6080. break;
  6081. }
  6082. case WM_CONTEXTMENU:
  6083. {
  6084. // UNDONE
  6085. //OnDialogContextHelp((HWND)wParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_REVOCATION_DIALOG);
  6086. break;
  6087. }
  6088. case WM_COMMAND:
  6089. switch(LOWORD(wParam))
  6090. {
  6091. case IDOK:
  6092. {
  6093. PPRIVATE_DLGPROC_CHOOSECRLPUBLISHTYPE_LPARAM psParam = (PPRIVATE_DLGPROC_CHOOSECRLPUBLISHTYPE_LPARAM)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  6094. HWND hRadioBase = GetDlgItem(hwndDlg, IDC_RADIO_NEWBASE);
  6095. psParam->fPublishBaseCRL = (BOOL)SendMessage(hRadioBase, BM_GETCHECK, 0, 0);
  6096. // fall through
  6097. }
  6098. case IDCANCEL:
  6099. EndDialog(hwndDlg, LOWORD(wParam));
  6100. break;
  6101. default:
  6102. break;
  6103. }
  6104. default:
  6105. break;
  6106. }
  6107. return 0;
  6108. }
  6109. //////////////////////////////////////////////////////////////////
  6110. // Revocation Reason Chooser
  6111. INT_PTR CALLBACK dlgProcRevocationReason(
  6112. HWND hwndDlg,
  6113. UINT uMsg,
  6114. WPARAM wParam,
  6115. LPARAM lParam )
  6116. {
  6117. switch(uMsg)
  6118. {
  6119. case WM_INITDIALOG:
  6120. {
  6121. ::SetWindowLong(hwndDlg, GWL_EXSTYLE, ::GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
  6122. // remember param
  6123. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  6124. HWND hCombo = GetDlgItem(hwndDlg, IDC_COMBO_REASON);
  6125. // from WINCRYPT.H
  6126. // CRL_REASON_UNSPECIFIED 0
  6127. // CRL_REASON_KEY_COMPROMISE 1
  6128. // CRL_REASON_CA_COMPROMISE 2
  6129. // CRL_REASON_AFFILIATION_CHANGED 3
  6130. // CRL_REASON_SUPERSEDED 4
  6131. // CRL_REASON_CESSATION_OF_OPERATION 5
  6132. // CRL_REASON_CERTIFICATE_HOLD 6
  6133. INT itemidx;
  6134. itemidx = (INT)SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCWSTR)g_pResources->m_szRevokeReason_Unspecified);
  6135. SendMessage(hCombo, CB_SETITEMDATA, itemidx, CRL_REASON_UNSPECIFIED);
  6136. itemidx = (INT)SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCWSTR)g_pResources->m_szRevokeReason_KeyCompromise);
  6137. SendMessage(hCombo, CB_SETITEMDATA, itemidx, CRL_REASON_KEY_COMPROMISE);
  6138. itemidx = (INT)SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCWSTR)g_pResources->m_szRevokeReason_CaCompromise);
  6139. SendMessage(hCombo, CB_SETITEMDATA, itemidx, CRL_REASON_CA_COMPROMISE);
  6140. itemidx = (INT)SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCWSTR)g_pResources->m_szRevokeReason_Affiliation);
  6141. SendMessage(hCombo, CB_SETITEMDATA, itemidx, CRL_REASON_AFFILIATION_CHANGED);
  6142. itemidx = (INT)SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCWSTR)g_pResources->m_szRevokeReason_Superseded);
  6143. SendMessage(hCombo, CB_SETITEMDATA, itemidx, CRL_REASON_SUPERSEDED);
  6144. itemidx = (INT)SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCWSTR)g_pResources->m_szRevokeReason_Cessatation);
  6145. SendMessage(hCombo, CB_SETITEMDATA, itemidx, CRL_REASON_CESSATION_OF_OPERATION);
  6146. itemidx = (INT)SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)(LPCWSTR)g_pResources->m_szRevokeReason_CertHold);
  6147. SendMessage(hCombo, CB_SETITEMDATA, itemidx, CRL_REASON_CERTIFICATE_HOLD);
  6148. // select the 1st element
  6149. SendMessage(hCombo, CB_SETCURSEL, 0, 0);
  6150. return 1;
  6151. }
  6152. break;
  6153. case WM_HELP:
  6154. {
  6155. OnDialogHelp((LPHELPINFO) lParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_REVOCATION_DIALOG);
  6156. break;
  6157. }
  6158. case WM_CONTEXTMENU:
  6159. {
  6160. OnDialogContextHelp((HWND)wParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_REVOCATION_DIALOG);
  6161. break;
  6162. }
  6163. case WM_COMMAND:
  6164. switch(LOWORD(wParam))
  6165. {
  6166. case IDOK:
  6167. {
  6168. LONG* plRevocationReason = (LONG*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  6169. HWND hCombo = GetDlgItem(hwndDlg, IDC_COMBO_REASON);
  6170. *plRevocationReason = (LONG)SendMessage(hCombo, CB_GETCURSEL, 0, 0);
  6171. if (*plRevocationReason == CB_ERR)
  6172. *plRevocationReason = CRL_REASON_UNSPECIFIED;
  6173. // fall through
  6174. }
  6175. case IDCANCEL:
  6176. EndDialog(hwndDlg, LOWORD(wParam));
  6177. break;
  6178. default:
  6179. break;
  6180. }
  6181. default:
  6182. break;
  6183. }
  6184. return 0;
  6185. }
  6186. DWORD GetUserConfirmRevocationReason(LONG* plReasonCode, HWND hwnd)
  6187. {
  6188. DWORD dwErr;
  6189. dwErr = (DWORD)DialogBoxParam(
  6190. g_hInstance,
  6191. MAKEINTRESOURCE(IDD_REVOCATION_DIALOG),
  6192. hwnd,
  6193. dlgProcRevocationReason,
  6194. (LPARAM)plReasonCode);
  6195. // translate ok/cancel into error codes
  6196. if (dwErr == IDOK)
  6197. dwErr = ERROR_SUCCESS;
  6198. else if (dwErr == IDCANCEL)
  6199. dwErr = ERROR_CANCELLED;
  6200. _PrintIfError(dwErr, "dlgProcRevocationReason");
  6201. //Ret:
  6202. return dwErr;
  6203. }
  6204. //////////////////////////////////////////////////////////////////
  6205. // Renewal: Reuse Keys Chooser
  6206. INT_PTR CALLBACK dlgProcRenewReuseKeys(
  6207. HWND hwndDlg,
  6208. UINT uMsg,
  6209. WPARAM wParam,
  6210. LPARAM lParam )
  6211. {
  6212. switch(uMsg)
  6213. {
  6214. case WM_INITDIALOG:
  6215. {
  6216. // self-explanitory page, no help needed
  6217. // ::SetWindowLong(hwndDlg, GWL_EXSTYLE, ::GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
  6218. // remember param
  6219. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  6220. HWND hNew = GetDlgItem(hwndDlg, IDC_RADIO_NEWKEY);
  6221. SendMessage(hNew, BM_SETCHECK, BST_CHECKED, 0); // Default: New key
  6222. return 1;
  6223. }
  6224. break;
  6225. case WM_HELP:
  6226. {
  6227. OnDialogHelp((LPHELPINFO) lParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_RENEW_REUSEKEYS);
  6228. break;
  6229. }
  6230. case WM_CONTEXTMENU:
  6231. {
  6232. OnDialogContextHelp((HWND)wParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_RENEW_REUSEKEYS);
  6233. break;
  6234. }
  6235. case WM_COMMAND:
  6236. switch(LOWORD(wParam))
  6237. {
  6238. case IDOK:
  6239. {
  6240. BOOL* pfReuseKeys = (BOOL*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  6241. HWND hReuse = GetDlgItem(hwndDlg, IDC_RADIO_REUSEKEY);
  6242. *pfReuseKeys = (BOOL)SendMessage(hReuse, BM_GETCHECK, 0, 0);
  6243. // fall through
  6244. }
  6245. case IDCANCEL:
  6246. EndDialog(hwndDlg, LOWORD(wParam));
  6247. break;
  6248. default:
  6249. break;
  6250. }
  6251. default:
  6252. break;
  6253. }
  6254. return 0;
  6255. }
  6256. typedef struct _CERTMMC_BINARYCOLCHOOSER{
  6257. CComponentDataImpl* pComp;
  6258. LPCWSTR wszCol;
  6259. BOOL fSaveOnly;
  6260. } CERTMMC_BINARYCOLCHOOSER, *PCERTMMC_BINARYCOLCHOOSER;
  6261. //////////////////////////////////////////////////////////////////
  6262. // Binary Dump: Column Chooser
  6263. INT_PTR CALLBACK dlgProcBinaryColChooser(
  6264. HWND hwndDlg,
  6265. UINT uMsg,
  6266. WPARAM wParam,
  6267. LPARAM lParam )
  6268. {
  6269. switch(uMsg)
  6270. {
  6271. case WM_INITDIALOG:
  6272. {
  6273. // self-explanitory page, no help needed
  6274. // ::SetWindowLong(hwndDlg, GWL_EXSTYLE, ::GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
  6275. // remember param
  6276. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); // PCERTMMC_BINARYCOLCHOOSER
  6277. PCERTMMC_BINARYCOLCHOOSER pData = (PCERTMMC_BINARYCOLCHOOSER)lParam;
  6278. HWND hColumnCombo = GetDlgItem(hwndDlg, IDC_COMBO_BINARY_COLUMN_CHOICE);
  6279. BOOL fInsertedOne = FALSE; // must insert one or bail
  6280. // insert all known binary columns in this view
  6281. for(int i=0; ;i++)
  6282. {
  6283. LRESULT lr;
  6284. HRESULT hr;
  6285. LPCWSTR szCol, szLocalizedCol;
  6286. LONG lType;
  6287. hr = pData->pComp->GetDBSchemaEntry(i,&szCol, &lType, NULL);
  6288. if (hr != S_OK)
  6289. break;
  6290. if (lType != PROPTYPE_BINARY)
  6291. continue;
  6292. // bug 462781: don't show archived key column since you can't really
  6293. // fetch the archived key this way, just a bool
  6294. if(wcsstr(szCol, wszPROPREQUESTRAWARCHIVEDKEY))
  6295. continue;
  6296. // Q: see if this is included in the current view?
  6297. // convert to localized name
  6298. hr = myGetColumnDisplayName(szCol, &szLocalizedCol);
  6299. if (hr != S_OK)
  6300. continue;
  6301. // add loc name to combobox with szCol as data ptr
  6302. lr = SendMessage(hColumnCombo, CB_ADDSTRING, 0, (LPARAM)szLocalizedCol);
  6303. if ((lr != CB_ERR) && (lr != CB_ERRSPACE))
  6304. {
  6305. SendMessage(hColumnCombo, CB_SETITEMDATA, lr, (LPARAM)szCol);
  6306. fInsertedOne = TRUE;
  6307. }
  6308. }
  6309. if (!fInsertedOne)
  6310. EndDialog(hwndDlg, IDOK); // bail here
  6311. else
  6312. SendMessage(hColumnCombo, CB_SETCURSEL, 0, 0);
  6313. // by default: view
  6314. SendDlgItemMessage(hwndDlg, IDC_RADIO_BINARY_VIEW, BM_SETCHECK, BST_CHECKED, 0);
  6315. return 1;
  6316. }
  6317. break;
  6318. case WM_HELP:
  6319. {
  6320. OnDialogHelp((LPHELPINFO) lParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_RENEW_REUSEKEYS);
  6321. break;
  6322. }
  6323. case WM_CONTEXTMENU:
  6324. {
  6325. OnDialogContextHelp((HWND)wParam, CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_RENEW_REUSEKEYS);
  6326. break;
  6327. }
  6328. case WM_COMMAND:
  6329. switch(LOWORD(wParam))
  6330. {
  6331. case IDOK:
  6332. {
  6333. PCERTMMC_BINARYCOLCHOOSER pData = (PCERTMMC_BINARYCOLCHOOSER)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  6334. HWND hColumnCombo = GetDlgItem(hwndDlg, IDC_COMBO_BINARY_COLUMN_CHOICE);
  6335. LRESULT lr;
  6336. lr = SendMessage(hColumnCombo, CB_GETCURSEL, 0, 0);
  6337. if (lr != CB_ERR)
  6338. {
  6339. pData->wszCol = (LPCWSTR)SendMessage(hColumnCombo, CB_GETITEMDATA, lr, 0);
  6340. if (pData->wszCol == (LPCWSTR)CB_ERR)
  6341. pData->wszCol = NULL;
  6342. // if view unchecked, save only
  6343. pData->fSaveOnly = (BST_UNCHECKED == SendDlgItemMessage(hwndDlg, IDC_RADIO_BINARY_VIEW, BM_GETCHECK, 0, 0));
  6344. //pData->fSaveOnly = (BOOL)SendMessage(GetDlgItem(hwndDlg, IDC_CHECK_BINARY_SAVETOFILE), BM_GETCHECK, 0, 0);
  6345. }
  6346. // fall through
  6347. }
  6348. case IDCANCEL:
  6349. EndDialog(hwndDlg, LOWORD(wParam));
  6350. break;
  6351. default:
  6352. break;
  6353. }
  6354. default:
  6355. break;
  6356. }
  6357. return 0;
  6358. }
  6359. /////////////////////////////////////////////////////////////////////////////////////
  6360. // View Attributes and extensions associated with a request
  6361. DWORD
  6362. ViewRowAttributesExtensions(
  6363. HWND hwnd,
  6364. IEnumCERTVIEWATTRIBUTE *pAttr,
  6365. IEnumCERTVIEWEXTENSION *pExtn,
  6366. LPCWSTR szReqID)
  6367. {
  6368. DWORD dwErr = S_OK;
  6369. HPROPSHEETPAGE hPages[2];
  6370. CString cstrCaption, cstrCaptionTemplate;
  6371. CViewAttrib *psPg1;
  6372. CViewExtn *psPg2;
  6373. InitCommonControls();
  6374. // page 1 initialization
  6375. psPg1 = new CViewAttrib(); // autodeleted
  6376. if (psPg1 == NULL)
  6377. {
  6378. dwErr = (DWORD) E_OUTOFMEMORY;
  6379. goto error;
  6380. }
  6381. psPg1->m_pAttr = pAttr;
  6382. hPages[0] = CreatePropertySheetPage(&psPg1->m_psp);
  6383. if (hPages[0] == NULL)
  6384. {
  6385. dwErr = GetLastError();
  6386. goto error;
  6387. }
  6388. // page 2 initialization
  6389. psPg2 = new CViewExtn(); // autodeleted
  6390. if (psPg2 == NULL)
  6391. {
  6392. dwErr = (DWORD) E_OUTOFMEMORY;
  6393. goto error;
  6394. }
  6395. psPg2->m_pExtn = pExtn;
  6396. hPages[1] = CreatePropertySheetPage(&psPg2->m_psp);
  6397. if (hPages[1] == NULL)
  6398. {
  6399. dwErr = GetLastError();
  6400. goto error;
  6401. }
  6402. cstrCaptionTemplate.LoadString(IDS_CERT_PROP_CAPTION);
  6403. cstrCaption.Format(cstrCaptionTemplate, szReqID);
  6404. PROPSHEETHEADER sPsh;
  6405. ZeroMemory(&sPsh, sizeof(sPsh));
  6406. sPsh.dwSize = sizeof(sPsh);
  6407. sPsh.dwFlags = PSH_DEFAULT | PSH_PROPTITLE | PSH_NOAPPLYNOW ;
  6408. sPsh.hwndParent = hwnd;
  6409. sPsh.hInstance = g_hInstance;
  6410. sPsh.nPages = ARRAYLEN(hPages);
  6411. sPsh.phpage = hPages;
  6412. sPsh.pszCaption = (LPCWSTR)cstrCaption;
  6413. dwErr = (DWORD)PropertySheet(&sPsh);
  6414. if (dwErr == -1)
  6415. {
  6416. // error
  6417. dwErr = GetLastError();
  6418. goto error;
  6419. }
  6420. if (dwErr == 0)
  6421. {
  6422. // cancel
  6423. dwErr = (DWORD)ERROR_CANCELLED;
  6424. goto error;
  6425. }
  6426. dwErr = S_OK;
  6427. error:
  6428. return dwErr;
  6429. }
  6430. DWORD
  6431. ChooseBinaryColumnToDump(
  6432. IN HWND hwnd,
  6433. IN CComponentDataImpl *pComp,
  6434. OUT LPCWSTR *pcwszColumn,
  6435. OUT BOOL *pfSaveToFileOnly)
  6436. {
  6437. DWORD dwErr;
  6438. if ((NULL == pcwszColumn) || (NULL == pfSaveToFileOnly))
  6439. return((DWORD) E_POINTER);
  6440. CERTMMC_BINARYCOLCHOOSER sParam = {0};
  6441. sParam.pComp = pComp;
  6442. dwErr = (DWORD)DialogBoxParam(
  6443. g_hInstance,
  6444. MAKEINTRESOURCE(IDD_CHOOSE_BINARY_COLUMN),
  6445. hwnd,
  6446. dlgProcBinaryColChooser,
  6447. (LPARAM)&sParam);
  6448. // translate ok/cancel into error codes
  6449. if (dwErr == IDOK)
  6450. dwErr = ERROR_SUCCESS;
  6451. else if (dwErr == IDCANCEL)
  6452. dwErr = ERROR_CANCELLED;
  6453. _JumpIfError(dwErr, Ret, "dlgProcBinaryColChooser");
  6454. // copy out params, even if null
  6455. *pcwszColumn = sParam.wszCol;
  6456. *pfSaveToFileOnly = sParam.fSaveOnly;
  6457. Ret:
  6458. return dwErr;
  6459. }
  6460. DWORD ViewRowRequestASN(HWND hwnd, LPCWSTR szTempFileName, PBYTE pbRequest, DWORD cbRequest, IN BOOL fSaveToFileOnly)
  6461. {
  6462. #define P_WAIT 0
  6463. #define P_NOWAIT 1
  6464. DWORD dwErr = S_OK;
  6465. WCHAR szTmpPath[MAX_PATH], szReqFile[MAX_PATH], szTmpFile[MAX_PATH];
  6466. WCHAR szCmdLine[MAX_PATH], szSysDir[MAX_PATH];
  6467. LPWSTR pszReqFile = szReqFile;
  6468. STARTUPINFO sStartup;
  6469. ZeroMemory(&sStartup, sizeof(sStartup));
  6470. PROCESS_INFORMATION sProcess;
  6471. ZeroMemory(&sProcess, sizeof(sProcess));
  6472. sStartup.cb = sizeof(sStartup);
  6473. HANDLE hFile = NULL;
  6474. SECURITY_ATTRIBUTES sa;
  6475. // Set up the security attributes struct.
  6476. sa.nLength= sizeof(SECURITY_ATTRIBUTES);
  6477. sa.lpSecurityDescriptor = NULL;
  6478. sa.bInheritHandle = TRUE;
  6479. if (fSaveToFileOnly)
  6480. {
  6481. // Put up a file dialog to prompt the user for Cert file
  6482. // 0 == hr means dialog was cancelled, we cheat because S_OK == 0
  6483. dwErr = myGetSaveFileName(
  6484. hwnd,
  6485. g_hInstance, // hInstance
  6486. IDS_BINARYFILE_OUTPUT_TITLE,
  6487. IDS_BINARYFILE_OUTPUT_FILTER,
  6488. 0, //no def ext
  6489. OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT,
  6490. szTempFileName, // default file
  6491. &pszReqFile);
  6492. _JumpIfError(dwErr, error, "myGetSaveFileName");
  6493. if (NULL == pszReqFile)
  6494. {
  6495. // cancelled:
  6496. // see public\sdk\inc\cderr.h for real CommDlgExtendedError errors
  6497. dwErr = CommDlgExtendedError();
  6498. _JumpError(dwErr, error, "myGetSaveFileName");
  6499. }
  6500. }
  6501. else
  6502. {
  6503. if (0 == GetSystemDirectory(szSysDir, ARRAYSIZE(szSysDir)))
  6504. {
  6505. dwErr = GetLastError();
  6506. goto error;
  6507. }
  6508. if (0 == GetTempPath(ARRAYSIZE(szTmpPath), szTmpPath))
  6509. {
  6510. dwErr = GetLastError();
  6511. goto error;
  6512. }
  6513. // gen one unique filename
  6514. if (0 == GetTempFileName(
  6515. szTmpPath,
  6516. L"TMP",
  6517. 0,
  6518. szReqFile)) // binary goo
  6519. {
  6520. dwErr = GetLastError();
  6521. goto error;
  6522. }
  6523. // c:\temp\foo.tmp
  6524. wcscpy(szTmpFile, szTmpPath);
  6525. wcscat(szTmpFile, szTempFileName);
  6526. // this file should never exist
  6527. DeleteFile(szTmpFile);
  6528. }
  6529. dwErr = EncodeToFileW(
  6530. pszReqFile,
  6531. pbRequest,
  6532. cbRequest,
  6533. CRYPT_STRING_BINARY|DECF_FORCEOVERWRITE);
  6534. _JumpIfError(dwErr, error, "EncodeToFile");
  6535. if (fSaveToFileOnly)
  6536. {
  6537. // done saving, bail!
  6538. dwErr = S_OK;
  6539. goto error;
  6540. }
  6541. // open up the output file
  6542. hFile = CreateFile(
  6543. szTmpFile,
  6544. GENERIC_ALL,
  6545. FILE_SHARE_WRITE|FILE_SHARE_READ,
  6546. &sa, // must make inheritable for other process to write to
  6547. OPEN_ALWAYS,
  6548. FILE_ATTRIBUTE_TEMPORARY,
  6549. NULL);
  6550. if (hFile == INVALID_HANDLE_VALUE)
  6551. {
  6552. dwErr = GetLastError();
  6553. goto error;
  6554. }
  6555. // set as output
  6556. sStartup.dwFlags = STARTF_USESTDHANDLES;
  6557. sStartup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
  6558. sStartup.hStdError = GetStdHandle(STD_ERROR_HANDLE);
  6559. sStartup.hStdOutput = hFile;
  6560. // exec "certutil -dump szReqFile szTempFile"
  6561. wsprintf(szCmdLine, L"%ws\\certutil.exe -dump \"%ws\"", szSysDir, szReqFile);
  6562. wcscat(szSysDir, L"\\certutil.exe");
  6563. if (!CreateProcess(
  6564. szSysDir, // exe
  6565. szCmdLine, // full cmd line
  6566. NULL,
  6567. NULL,
  6568. TRUE, // use hStdOut
  6569. CREATE_NO_WINDOW,
  6570. NULL,
  6571. NULL,
  6572. &sStartup,
  6573. &sProcess))
  6574. {
  6575. dwErr = GetLastError();
  6576. _JumpError(dwErr, error, "EncodeToFile");
  6577. }
  6578. // wait up to 2 sec for certutil to finish
  6579. if (WAIT_OBJECT_0 != WaitForSingleObject(sProcess.hProcess, INFINITE))
  6580. {
  6581. dwErr = ERROR_TIMEOUT;
  6582. _JumpError(dwErr, error, "EncodeToFile");
  6583. }
  6584. CloseHandle(sProcess.hProcess);
  6585. CloseHandle(hFile);
  6586. hFile=NULL;
  6587. // exec "notepad tmpfil2"
  6588. if (-1 == _wspawnlp(P_NOWAIT, L"notepad.exe", L"notepad.exe", szTmpFile, NULL))
  6589. dwErr = errno;
  6590. // give notepad 2 sec to open before we delete his szTmpFile out from under him
  6591. // use waitforinputidle?
  6592. Sleep(2000);
  6593. // delete the binary file
  6594. DeleteFile(szReqFile);
  6595. // delete the tmp file
  6596. DeleteFile(szTmpFile);
  6597. dwErr = S_OK;
  6598. error:
  6599. if (hFile != NULL)
  6600. CloseHandle(hFile);
  6601. // originally points to []
  6602. if ((pszReqFile != NULL) && (pszReqFile != szReqFile))
  6603. LocalFree(pszReqFile);
  6604. return dwErr;
  6605. }
  6606. ///////////////////////////////////////////
  6607. // CViewAttrib
  6608. /////////////////////////////////////////////////////////////////////////////
  6609. // CViewAttrib property page
  6610. CViewAttrib::CViewAttrib(UINT uIDD)
  6611. : CAutoDeletePropPage(uIDD)
  6612. {
  6613. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_ATTR_PROPPAGE);
  6614. }
  6615. // replacement for DoDataExchange
  6616. BOOL CViewAttrib::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  6617. {
  6618. if (fSuckFromDlg)
  6619. {
  6620. }
  6621. else
  6622. {
  6623. }
  6624. return TRUE;
  6625. }
  6626. // replacement for BEGIN_MESSAGE_MAP
  6627. BOOL
  6628. CViewAttrib::OnCommand(
  6629. WPARAM, // wParam
  6630. LPARAM) // lParam
  6631. {
  6632. // switch(LOWORD(wParam))
  6633. {
  6634. // default:
  6635. // return FALSE;
  6636. // break;
  6637. }
  6638. return TRUE;
  6639. }
  6640. /////////////////////////////////////////////////////////////////////////////
  6641. // CViewAttrib message handlers
  6642. BOOL CViewAttrib::OnInitDialog()
  6643. {
  6644. HRESULT hr;
  6645. // does parent init and UpdateData call
  6646. CAutoDeletePropPage::OnInitDialog();
  6647. IEnumCERTVIEWATTRIBUTE* pAttr = m_pAttr;
  6648. BSTR bstrName = NULL, bstrValue = NULL;
  6649. LPWSTR pszName = NULL;
  6650. HWND hwndList = GetDlgItem(m_hWnd, IDC_LIST_ATTR);
  6651. CString cstrTmp;
  6652. int iItem =0, iSubItem;
  6653. cstrTmp.LoadString(IDS_LISTCOL_TAG);
  6654. ListView_NewColumn(hwndList, 0, 150, (LPWSTR)(LPCWSTR)cstrTmp);
  6655. cstrTmp.LoadString(IDS_LISTCOL_VALUE);
  6656. ListView_NewColumn(hwndList, 1, 250, (LPWSTR)(LPCWSTR)cstrTmp);
  6657. ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT);
  6658. while(TRUE)
  6659. {
  6660. LONG lIndex = 0;
  6661. // set up for next loop
  6662. hr = pAttr->Next(&lIndex);
  6663. if (hr == S_FALSE)
  6664. break;
  6665. _JumpIfError(hr, initerror, "pAttr->Next");
  6666. hr = pAttr->GetName(&bstrName);
  6667. _JumpIfError(hr, initerror, "pAttr->GetName");
  6668. hr = pAttr->GetValue(&bstrValue);
  6669. _JumpIfError(hr, initerror, "pAttr->GetValue");
  6670. // have all info, populate row
  6671. ListView_NewItem(hwndList, iItem, (LPWSTR)bstrName);
  6672. iSubItem = 1;
  6673. ListView_SetItemText(hwndList, iItem++, iSubItem, (LPWSTR)bstrValue);
  6674. // not necessary to free in the loop
  6675. }
  6676. hr = S_OK;
  6677. initerror:
  6678. if (pszName)
  6679. LocalFree(pszName);
  6680. if (bstrName)
  6681. SysFreeString(bstrName);
  6682. if (bstrValue)
  6683. SysFreeString(bstrValue);
  6684. if (hr != S_OK)
  6685. {
  6686. DisplayGenericCertSrvError(m_hWnd, hr);
  6687. DestroyWindow(m_hWnd);
  6688. }
  6689. return TRUE;
  6690. }
  6691. ///////////////////////////////////////////
  6692. // CViewExtn
  6693. /////////////////////////////////////////////////////////////////////////////
  6694. // CViewExtn property page
  6695. CViewExtn::CViewExtn(UINT uIDD)
  6696. : CAutoDeletePropPage(uIDD)
  6697. {
  6698. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_EXTN_PROPPAGE);
  6699. if (NULL == g_hmodRichEdit)
  6700. {
  6701. g_hmodRichEdit = LoadLibrary(L"RichEd32.dll");
  6702. if (NULL == g_hmodRichEdit)
  6703. {
  6704. HRESULT hr = myHLastError();
  6705. _PrintErrorStr(hr, "LoadLibrary", L"RichEd32.dll");
  6706. }
  6707. }
  6708. INITCOMMONCONTROLSEX initcomm = {
  6709. sizeof(initcomm),
  6710. ICC_NATIVEFNTCTL_CLASS | ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES
  6711. };
  6712. InitCommonControlsEx(&initcomm);
  6713. }
  6714. CViewExtn::~CViewExtn()
  6715. {
  6716. int i;
  6717. for (i=0; i<m_carrExtnValues.GetUpperBound(); i++)
  6718. delete m_carrExtnValues.GetAt(i);
  6719. m_carrExtnValues.Init();
  6720. }
  6721. // replacement for DoDataExchange
  6722. BOOL CViewExtn::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  6723. {
  6724. if (fSuckFromDlg)
  6725. {
  6726. }
  6727. else
  6728. {
  6729. }
  6730. return TRUE;
  6731. }
  6732. BOOL CViewExtn::OnNotify(UINT idCtrl, NMHDR* pnmh)
  6733. {
  6734. switch(idCtrl)
  6735. {
  6736. case IDC_LIST_EXTN:
  6737. if (pnmh->code == LVN_ITEMCHANGED)
  6738. OnReselectItem();
  6739. break;
  6740. }
  6741. return FALSE;
  6742. }
  6743. // replacement for BEGIN_MESSAGE_MAP
  6744. BOOL
  6745. CViewExtn::OnCommand(
  6746. WPARAM, // wParam
  6747. LPARAM) // lParam
  6748. {
  6749. /*
  6750. switch(LOWORD(wParam))
  6751. {
  6752. default:
  6753. return FALSE;
  6754. break;
  6755. }
  6756. */
  6757. return TRUE;
  6758. }
  6759. void CViewExtn::OnReselectItem()
  6760. {
  6761. HWND hwndList = GetDlgItem(m_hWnd, IDC_LIST_EXTN);
  6762. int iSel, iItems = ListView_GetItemCount(hwndList);
  6763. // find selected item
  6764. for(iSel=0; iSel<(LRESULT)iItems; iSel++)
  6765. {
  6766. UINT ui = ListView_GetItemState(hwndList, iSel, LVIS_SELECTED);
  6767. if (ui == LVIS_SELECTED)
  6768. break;
  6769. }
  6770. // selected item
  6771. if (iSel != iItems)
  6772. {
  6773. CSASSERT(m_carrExtnValues.GetUpperBound() >= iSel);
  6774. if (m_carrExtnValues.GetUpperBound() >= iSel)
  6775. {
  6776. CString* pcstr = m_carrExtnValues.GetAt(iSel);
  6777. CSASSERT(pcstr);
  6778. if (pcstr != NULL)
  6779. SetDlgItemText(m_hWnd, IDC_EDIT_EXTN, *pcstr);
  6780. }
  6781. }
  6782. return;
  6783. }
  6784. /////////////////////////////////////////////////////////////////////////////
  6785. // CViewExtn message handlers
  6786. BOOL CViewExtn::OnInitDialog()
  6787. {
  6788. HRESULT hr = S_OK;
  6789. // does parent init and UpdateData call
  6790. CAutoDeletePropPage::OnInitDialog();
  6791. IEnumCERTVIEWEXTENSION* pExtn = m_pExtn;
  6792. BSTR bstrName = NULL, bstrValue = NULL;
  6793. LPWSTR pszName = NULL;
  6794. LPWSTR pszFormattedExtn = NULL;
  6795. VARIANT varExtn;
  6796. VariantInit(&varExtn);
  6797. HWND hwndList = GetDlgItem(m_hWnd, IDC_LIST_EXTN);
  6798. CString cstrTmp;
  6799. int iItem = 0;
  6800. cstrTmp.LoadString(IDS_LISTCOL_TAG);
  6801. ListView_NewColumn(hwndList, 0, 150, (LPWSTR)(LPCWSTR)cstrTmp);
  6802. cstrTmp.LoadString(IDS_LISTCOL_ORGIN);
  6803. ListView_NewColumn(hwndList, 1, 70, (LPWSTR)(LPCWSTR)cstrTmp);
  6804. cstrTmp.LoadString(IDS_LISTCOL_CRITICAL);
  6805. ListView_NewColumn(hwndList, 2, 70, (LPWSTR)(LPCWSTR)cstrTmp);
  6806. cstrTmp.LoadString(IDS_LISTCOL_ENABLED);
  6807. ListView_NewColumn(hwndList, 3, 70, (LPWSTR)(LPCWSTR)cstrTmp);
  6808. //set whole row selection
  6809. ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT);
  6810. while(TRUE)
  6811. {
  6812. CString cstrOrigin;
  6813. CString cstrCritical;
  6814. CString cstrEnabled;
  6815. CString* pcstr;
  6816. LONG lIndex = 0, lExtFlags;
  6817. // set up for next loop
  6818. hr = pExtn->Next(&lIndex);
  6819. if (hr == S_FALSE)
  6820. break;
  6821. _JumpIfError(hr, initerror, "pExtn->Next");
  6822. hr = pExtn->GetName(&bstrName);
  6823. _JumpIfError(hr, initerror, "pExtn->GetName");
  6824. if (pszName)
  6825. LocalFree(pszName);
  6826. pszName = NULL;
  6827. hr = myOIDToName(bstrName, &pszName);
  6828. _PrintIfError(hr, "myOIDToName");
  6829. hr = pExtn->GetFlags(&lExtFlags);
  6830. _JumpIfError(hr, initerror, "pExtn->GetFlags");
  6831. switch ( lExtFlags & EXTENSION_ORIGIN_MASK )
  6832. {
  6833. case EXTENSION_ORIGIN_REQUEST:
  6834. cstrOrigin.LoadString(IDS_EXT_ORIGIN_REQUEST);
  6835. break;
  6836. case EXTENSION_ORIGIN_POLICY:
  6837. cstrOrigin.LoadString(IDS_EXT_ORIGIN_POLICY);
  6838. break;
  6839. case EXTENSION_ORIGIN_ADMIN:
  6840. cstrOrigin.LoadString(IDS_EXT_ORIGIN_ADMIN);
  6841. break;
  6842. case EXTENSION_ORIGIN_SERVER:
  6843. cstrOrigin.LoadString(IDS_EXT_ORIGIN_SERVER);
  6844. break;
  6845. case EXTENSION_ORIGIN_RENEWALCERT:
  6846. cstrOrigin.LoadString(IDS_EXT_ORIGIN_RENEWAL);
  6847. break;
  6848. case EXTENSION_ORIGIN_IMPORTEDCERT:
  6849. cstrOrigin.LoadString(IDS_EXT_ORIGIN_IMPORTED_CERT);
  6850. break;
  6851. case EXTENSION_ORIGIN_PKCS7:
  6852. cstrOrigin.LoadString(IDS_EXT_ORIGIN_PKCS7);
  6853. break;
  6854. case EXTENSION_ORIGIN_CMC:
  6855. cstrOrigin.LoadString(IDS_EXT_ORIGIN_CMC);
  6856. break;
  6857. case EXTENSION_ORIGIN_CACERT:
  6858. cstrOrigin.LoadString(IDS_EXT_ORIGIN_CACERT);
  6859. break;
  6860. default:
  6861. cstrOrigin.LoadString(IDS_EXT_ORIGIN_UNKNOWN);
  6862. DBGPRINT((DBG_SS_CERTMMC, "Unknown extension orgin: 0x%x\n", (lExtFlags & EXTENSION_ORIGIN_MASK)));
  6863. break;
  6864. }
  6865. // possible to be both crit & disabled
  6866. if ( (lExtFlags & EXTENSION_CRITICAL_FLAG) != 0)
  6867. cstrCritical.LoadString(IDS_YES);
  6868. else
  6869. cstrCritical.LoadString(IDS_NO);
  6870. if ( (lExtFlags & EXTENSION_DISABLE_FLAG) != 0)
  6871. cstrEnabled.LoadString(IDS_NO);
  6872. else
  6873. cstrEnabled.LoadString(IDS_YES);
  6874. hr = pExtn->GetValue(
  6875. PROPTYPE_BINARY,
  6876. CV_OUT_BINARY,
  6877. &varExtn);
  6878. _JumpIfError(hr, initerror, "pExtn->GetValue");
  6879. if (varExtn.vt == VT_BSTR)
  6880. {
  6881. if (pszFormattedExtn)
  6882. LocalFree(pszFormattedExtn);
  6883. pszFormattedExtn = NULL;
  6884. hr = myDumpFormattedObject(
  6885. bstrName,
  6886. (PBYTE)varExtn.bstrVal,
  6887. SysStringByteLen(varExtn.bstrVal),
  6888. &pszFormattedExtn);
  6889. _PrintIfError(hr, "myDumpFormattedObject");
  6890. }
  6891. // have all info, populate row
  6892. // tag name (subitem 0)
  6893. ListView_NewItem(hwndList, iItem, (pszName!=NULL) ? pszName : (LPWSTR)bstrName);
  6894. // origin (subitem 1)
  6895. ListView_SetItemText(hwndList, iItem, 1, (LPWSTR)(LPCWSTR)cstrOrigin);
  6896. // critical flag (subitem 2)
  6897. ListView_SetItemText(hwndList, iItem, 2, (LPWSTR)(LPCWSTR)cstrCritical);
  6898. // enabled flag (subitem 3)
  6899. ListView_SetItemText(hwndList, iItem, 3, (LPWSTR)(LPCWSTR)cstrEnabled);
  6900. // value
  6901. pcstr = new CString;
  6902. if (pcstr != NULL)
  6903. {
  6904. *pcstr = pszFormattedExtn;
  6905. m_carrExtnValues.Add(pcstr); // arr owns pcstr memory
  6906. pcstr = NULL;
  6907. }
  6908. else
  6909. {
  6910. hr = E_OUTOFMEMORY;
  6911. _JumpError(hr, initerror, "new CString");
  6912. }
  6913. iItem++;
  6914. // not necessary to free in the loop
  6915. }
  6916. hr = S_OK;
  6917. initerror:
  6918. VariantClear(&varExtn);
  6919. if (pszName)
  6920. LocalFree(pszName);
  6921. if (bstrName)
  6922. SysFreeString(bstrName);
  6923. if (pszFormattedExtn)
  6924. LocalFree(pszFormattedExtn);
  6925. if (bstrValue)
  6926. SysFreeString(bstrValue);
  6927. if (hr != S_OK)
  6928. {
  6929. DisplayGenericCertSrvError(m_hWnd, hr);
  6930. DestroyWindow(m_hWnd);
  6931. }
  6932. return TRUE;
  6933. }
  6934. ///////////////////////////////////////////
  6935. // CViewCertManagers
  6936. /////////////////////////////////////////////////////////////////////////////
  6937. // CSvrSettingsGeneralPage property page
  6938. RoleAccessToControl CSvrSettingsCertManagersPage::sm_ControlToRoleMap[] =
  6939. {
  6940. { IDC_RADIO_DISABLEOFFICERS, CA_ACCESS_ADMIN },
  6941. { IDC_RADIO_ENABLEOFFICERS, CA_ACCESS_ADMIN },
  6942. { IDC_ALLOWDENY, CA_ACCESS_ADMIN },
  6943. { IDC_ADDSUBJECT, CA_ACCESS_ADMIN },
  6944. { IDC_REMOVESUBJECT, CA_ACCESS_ADMIN },
  6945. };
  6946. CSvrSettingsCertManagersPage::CSvrSettingsCertManagersPage(CSvrSettingsGeneralPage* pControlPage, UINT uIDD)
  6947. : CAutoDeletePropPage(uIDD),
  6948. CRolesSupportInPropPage(
  6949. pControlPage->m_pCA,
  6950. sm_ControlToRoleMap,
  6951. ARRAYSIZE(sm_ControlToRoleMap)),
  6952. m_pControlPage(pControlPage),
  6953. m_fEnabled(FALSE),
  6954. m_fDirty(FALSE)
  6955. {
  6956. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTSRV_PROPPAGE6);
  6957. if(m_strButtonAllow.IsEmpty())
  6958. m_strButtonAllow.LoadString(IDS_BUTTONTEXT_ALLOW);
  6959. if(m_strButtonDeny.IsEmpty())
  6960. m_strButtonDeny.LoadString(IDS_BUTTONTEXT_DENY);
  6961. if(m_strTextAllow.IsEmpty())
  6962. m_strTextAllow.LoadString(IDS_TEXT_ALLOW);
  6963. if(m_strTextDeny.IsEmpty())
  6964. m_strTextDeny.LoadString(IDS_TEXT_DENY);
  6965. }
  6966. CSvrSettingsCertManagersPage::~CSvrSettingsCertManagersPage()
  6967. {
  6968. }
  6969. // replacement for BEGIN_MESSAGE_MAP
  6970. BOOL
  6971. CSvrSettingsCertManagersPage::OnCommand(
  6972. WPARAM wParam,
  6973. LPARAM) // lParam
  6974. {
  6975. switch(LOWORD(wParam))
  6976. {
  6977. case IDC_ADDSUBJECT:
  6978. OnAddSubject();
  6979. break;
  6980. case IDC_REMOVESUBJECT:
  6981. OnRemoveSubject();
  6982. break;
  6983. case IDC_ALLOWDENY:
  6984. OnAllowDeny();
  6985. break;
  6986. case IDC_RADIO_ENABLEOFFICERS:
  6987. OnEnableOfficers(true);
  6988. break;
  6989. case IDC_RADIO_DISABLEOFFICERS:
  6990. OnEnableOfficers(false);
  6991. break;
  6992. case IDC_LIST_CERTMANAGERS:
  6993. switch (HIWORD(wParam))
  6994. {
  6995. case CBN_SELCHANGE:
  6996. // extension selection is changed
  6997. OnOfficerChange();
  6998. break;
  6999. }
  7000. break;
  7001. default:
  7002. return FALSE;
  7003. break;
  7004. }
  7005. return TRUE;
  7006. }
  7007. void CSvrSettingsCertManagersPage::OnOfficerChange()
  7008. {
  7009. DWORD dwOfficerIndex = GetCurrentOfficerIndex();
  7010. if(-1!=dwOfficerIndex)
  7011. {
  7012. FillClientList(GetCurrentOfficerIndex());
  7013. }
  7014. SetAllowDeny();
  7015. }
  7016. BOOL CSvrSettingsCertManagersPage::OnNotify(UINT idCtrl, NMHDR* pnmh)
  7017. {
  7018. LPNM_LISTVIEW pnmlv = (LPNM_LISTVIEW)pnmh;
  7019. switch(idCtrl)
  7020. {
  7021. case IDC_LIST_SUBJECTS:
  7022. if (pnmh->code == LVN_ITEMCHANGED)
  7023. {
  7024. if(pnmlv->uChanged & LVIF_STATE)
  7025. {
  7026. if ((pnmlv->uNewState & LVIS_SELECTED) &&
  7027. !(pnmlv->uOldState & LVIS_SELECTED))
  7028. {
  7029. SetAllowDeny();
  7030. }
  7031. }
  7032. }
  7033. break;
  7034. default:
  7035. return CAutoDeletePropPage::OnNotify(idCtrl, pnmh);
  7036. }
  7037. return FALSE;
  7038. }
  7039. /////////////////////////////////////////////////////////////////////////////
  7040. // CSvrSettingsCertManagersPage message handlers
  7041. BOOL CSvrSettingsCertManagersPage::OnInitDialog()
  7042. {
  7043. HWND hwndClients = GetDlgItem(m_hWnd, IDC_LIST_SUBJECTS);
  7044. RECT rc;
  7045. LV_COLUMN col;
  7046. GetClientRect(hwndClients, &rc);
  7047. CString strHeader;
  7048. CString strAccess;
  7049. strHeader.LoadString(IDS_LIST_NAME);
  7050. strAccess.LoadString(IDS_LIST_ACCESS);
  7051. col.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
  7052. col.fmt = LVCFMT_LEFT;
  7053. col.pszText = strHeader.GetBuffer();
  7054. col.iSubItem = 0;
  7055. col.cx = rc.right*3/4;
  7056. ListView_InsertColumn(hwndClients, 0, &col);
  7057. col.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
  7058. col.fmt = LVCFMT_LEFT;
  7059. col.pszText = strAccess.GetBuffer();
  7060. col.iSubItem = 0;
  7061. col.cx = rc.right*1/4;
  7062. ListView_InsertColumn(hwndClients, 1, &col);
  7063. ListView_SetExtendedListViewStyle(hwndClients, LVS_EX_FULLROWSELECT);
  7064. UpdateData(FALSE);
  7065. return TRUE;
  7066. }
  7067. BOOL CSvrSettingsCertManagersPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  7068. {
  7069. if (!fSuckFromDlg)
  7070. {
  7071. HRESULT hr = GetOfficerRights();
  7072. _PrintIfError(hr, "GetOfficerRights");
  7073. if(S_OK!=hr)
  7074. {
  7075. // hide all controls and show error text
  7076. HideControls();
  7077. EnableWindow(GetDlgItem(IDC_UNAVAILABLE), TRUE);
  7078. ShowWindow(GetDlgItem(IDC_UNAVAILABLE), SW_SHOW);
  7079. }
  7080. else
  7081. {
  7082. EnableControls();
  7083. }
  7084. }
  7085. return TRUE;
  7086. }
  7087. void CSvrSettingsCertManagersPage::OnDestroy()
  7088. {
  7089. CAutoDeletePropPage::OnDestroy();
  7090. }
  7091. BOOL CSvrSettingsCertManagersPage::OnApply()
  7092. {
  7093. if(IsDirty())
  7094. {
  7095. HRESULT hr = SetOfficerRights();
  7096. if (hr != S_OK)
  7097. {
  7098. DisplayGenericCertSrvError(m_hWnd, hr);
  7099. return FALSE;
  7100. }
  7101. }
  7102. UpdateData(FALSE);
  7103. return CAutoDeletePropPage::OnApply();
  7104. }
  7105. void CSvrSettingsCertManagersPage::OnAddSubject()
  7106. {
  7107. PSID pSid = NULL;
  7108. HRESULT hr;
  7109. DWORD dwIndex;
  7110. CertSrv::COfficerRights* pOfficer;
  7111. hr = BrowseForSubject(m_hWnd, pSid);
  7112. _JumpIfError(hr, err, "BrowseForSubject");
  7113. if(S_OK==hr)
  7114. {
  7115. HWND hwnd = GetDlgItem(m_hWnd, IDC_LIST_SUBJECTS);
  7116. pOfficer = m_OfficerRightsList.GetAt(GetCurrentOfficerIndex());
  7117. dwIndex = pOfficer->Find(pSid);
  7118. if(DWORD_MAX==dwIndex)
  7119. {
  7120. dwIndex = pOfficer->GetCount();
  7121. pOfficer->Add(pSid, TRUE);
  7122. ListView_NewItem(hwnd, dwIndex,
  7123. pOfficer->GetAt(dwIndex)->GetName());
  7124. ListView_SetItemText(hwnd, dwIndex, 1,
  7125. pOfficer->GetAt(dwIndex)->GetPermission()?
  7126. m_strTextAllow.GetBuffer():
  7127. m_strTextDeny.GetBuffer());
  7128. SetAllowDeny();
  7129. SetDirty();
  7130. }
  7131. ::EnableWindow(GetDlgItem(m_hWnd, IDC_REMOVESUBJECT), TRUE);
  7132. ::EnableWindow(GetDlgItem(m_hWnd, IDC_ALLOWDENY), TRUE);
  7133. ListView_SetItemState(hwnd, dwIndex,
  7134. LVIS_SELECTED|LVIS_FOCUSED , LVIS_SELECTED|LVIS_FOCUSED);
  7135. SetFocus(hwnd);
  7136. }
  7137. else
  7138. {
  7139. DisplayGenericCertSrvError(m_hWnd, hr);
  7140. }
  7141. err:
  7142. if(pSid)
  7143. LocalFree(pSid);
  7144. }
  7145. void CSvrSettingsCertManagersPage::OnRemoveSubject()
  7146. {
  7147. DWORD dwClientIndex = GetCurrentClientIndex();
  7148. DWORD dwOfficerIndex = GetCurrentOfficerIndex();
  7149. HWND hwndListClients = GetDlgItem(m_hWnd, IDC_LIST_SUBJECTS);
  7150. m_OfficerRightsList.GetAt(dwOfficerIndex)->
  7151. RemoveAt(dwClientIndex);
  7152. ListView_DeleteItem(hwndListClients, dwClientIndex);
  7153. if(0==m_OfficerRightsList.GetAt(dwOfficerIndex)->GetCount())
  7154. {
  7155. EnableControl(m_hWnd, IDC_REMOVESUBJECT, FALSE);
  7156. EnableControl(m_hWnd, IDC_ALLOWDENY, FALSE);
  7157. SetFocus(GetDlgItem(m_hWnd, IDC_ADDSUBJECT));
  7158. }
  7159. else
  7160. {
  7161. if(dwClientIndex==
  7162. m_OfficerRightsList.GetAt(dwOfficerIndex)->GetCount())
  7163. dwClientIndex--;
  7164. ListView_SetItemState(hwndListClients, dwClientIndex,
  7165. LVIS_SELECTED|LVIS_FOCUSED , LVIS_SELECTED|LVIS_FOCUSED);
  7166. SetFocus(hwndListClients);
  7167. }
  7168. SetDirty();
  7169. }
  7170. void CSvrSettingsCertManagersPage::OnAllowDeny()
  7171. {
  7172. DWORD dwCrtClient = GetCurrentClientIndex();
  7173. DWORD dwCrtOfficer = GetCurrentOfficerIndex();
  7174. CertSrv::CClientPermission *pClient =
  7175. m_OfficerRightsList.GetAt(dwCrtOfficer)->GetAt(dwCrtClient);
  7176. m_OfficerRightsList.GetAt(dwCrtOfficer)->
  7177. SetAt(dwCrtClient, !pClient->GetPermission());
  7178. SetAllowDeny();
  7179. ListView_SetItemText(
  7180. GetDlgItem(m_hWnd, IDC_LIST_SUBJECTS),
  7181. dwCrtClient,
  7182. 1,
  7183. pClient->GetPermission()?
  7184. m_strTextAllow.GetBuffer():
  7185. m_strTextDeny.GetBuffer());
  7186. SetDirty();
  7187. }
  7188. void CSvrSettingsCertManagersPage::OnEnableOfficers(bool fEnable)
  7189. {
  7190. // only if switching enable -> disable or the other way
  7191. if(m_fEnabled && !fEnable ||
  7192. !m_fEnabled && fEnable)
  7193. {
  7194. if(fEnable)
  7195. {
  7196. HRESULT hr = BuildVirtualOfficerRights();
  7197. if(S_OK!=hr)
  7198. {
  7199. DisplayGenericCertSrvError(m_hWnd, hr);
  7200. return;
  7201. }
  7202. }
  7203. m_fEnabled = fEnable;
  7204. EnableControls();
  7205. SetDirty();
  7206. }
  7207. }
  7208. void CSvrSettingsCertManagersPage::EnableControls()
  7209. {
  7210. ::EnableWindow(GetDlgItem(m_hWnd, IDC_LIST_CERTMANAGERS), m_fEnabled);
  7211. ::EnableWindow(GetDlgItem(m_hWnd, IDC_LIST_SUBJECTS), m_fEnabled);
  7212. EnableControl(m_hWnd, IDC_ADDSUBJECT, m_fEnabled);
  7213. EnableControl(m_hWnd, IDC_REMOVESUBJECT, m_fEnabled);
  7214. EnableControl(m_hWnd, IDC_ALLOWDENY, m_fEnabled);
  7215. EnableControl(m_hWnd, IDC_RADIO_DISABLEOFFICERS, TRUE);
  7216. EnableControl(m_hWnd, IDC_RADIO_ENABLEOFFICERS, TRUE);
  7217. SendMessage(
  7218. GetDlgItem(m_hWnd, IDC_RADIO_ENABLEOFFICERS),
  7219. BM_SETCHECK,
  7220. m_fEnabled?TRUE:FALSE, 0);
  7221. SendMessage(
  7222. GetDlgItem(m_hWnd, IDC_RADIO_DISABLEOFFICERS),
  7223. BM_SETCHECK,
  7224. m_fEnabled?FALSE:TRUE, 0);
  7225. FillOfficerList();
  7226. FillClientList(0);
  7227. SetAllowDeny();
  7228. }
  7229. /////////////////////////////////////////////////////////////////////////////
  7230. // CSvrSettingsCertManagersPage utilities
  7231. HRESULT CSvrSettingsCertManagersPage::BrowseForSubject(HWND hwnd, PSID &rpSid)
  7232. {
  7233. HRESULT hr;
  7234. CComPtr<IDsObjectPicker> pObjPicker;
  7235. CComPtr<IDataObject> pdo;
  7236. BOOL fCurrentMachine = m_pControlPage->m_pCA->m_pParentMachine->IsLocalMachine();
  7237. STGMEDIUM stgmedium = {TYMED_HGLOBAL, NULL};
  7238. BOOL bAllocatedStgMedium = FALSE;
  7239. PDS_SELECTION_LIST pDsSelList = NULL;
  7240. static PCWSTR pwszObjSID = L"ObjectSid";
  7241. SAFEARRAY *saSid = NULL;
  7242. void HUGEP *pArray = NULL;
  7243. const int MAX_SCOPE_INIT_COUNT = 10;
  7244. ULONG scopesDomain[] =
  7245. {
  7246. DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN,
  7247. DSOP_SCOPE_TYPE_TARGET_COMPUTER,
  7248. DSOP_SCOPE_TYPE_GLOBAL_CATALOG,
  7249. DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN,
  7250. DSOP_SCOPE_TYPE_WORKGROUP,
  7251. };
  7252. ULONG scopesStandalone[] =
  7253. {
  7254. DSOP_SCOPE_TYPE_TARGET_COMPUTER,
  7255. };
  7256. bool fStandalone = (S_OK != myDoesDSExist(FALSE));
  7257. ULONG *pScopes = fStandalone?scopesStandalone:scopesDomain;
  7258. int nScopes = (int)(fStandalone?ARRAYSIZE(scopesStandalone):ARRAYSIZE(scopesDomain));
  7259. hr = CoCreateInstance (CLSID_DsObjectPicker,
  7260. NULL,
  7261. CLSCTX_INPROC_SERVER,
  7262. IID_IDsObjectPicker,
  7263. (void **) &pObjPicker);
  7264. _JumpIfError(hr, err, "CoCreateInstance(IID_IDsObjectPicker");
  7265. DSOP_SCOPE_INIT_INFO aScopeInit[MAX_SCOPE_INIT_COUNT];
  7266. ZeroMemory(aScopeInit, sizeof(DSOP_SCOPE_INIT_INFO) * MAX_SCOPE_INIT_COUNT);
  7267. aScopeInit[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  7268. aScopeInit[0].flScope =
  7269. DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS |
  7270. DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS |
  7271. DSOP_SCOPE_FLAG_DEFAULT_FILTER_COMPUTERS;
  7272. aScopeInit[0].flType = pScopes[0];
  7273. aScopeInit[0].FilterFlags.Uplevel.flBothModes =
  7274. DSOP_FILTER_USERS|
  7275. DSOP_FILTER_COMPUTERS|
  7276. DSOP_FILTER_BUILTIN_GROUPS|
  7277. DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE|
  7278. DSOP_FILTER_GLOBAL_GROUPS_SE|
  7279. DSOP_FILTER_UNIVERSAL_GROUPS_SE|
  7280. DSOP_FILTER_WELL_KNOWN_PRINCIPALS;
  7281. aScopeInit[0].FilterFlags.flDownlevel =
  7282. DSOP_DOWNLEVEL_FILTER_USERS |
  7283. DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS |
  7284. DSOP_DOWNLEVEL_FILTER_COMPUTERS |
  7285. DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS |
  7286. DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS;
  7287. for(int c=1;c<nScopes;c++)
  7288. {
  7289. aScopeInit[c] = aScopeInit[0];
  7290. aScopeInit[c].flType = pScopes[c];
  7291. }
  7292. aScopeInit[0].flScope |= DSOP_SCOPE_FLAG_STARTING_SCOPE;
  7293. DSOP_INIT_INFO initInfo;
  7294. ZeroMemory(&initInfo, sizeof(initInfo));
  7295. initInfo.cbSize = sizeof(initInfo);
  7296. initInfo.pwzTargetComputer = fCurrentMachine ?
  7297. NULL : (LPCWSTR)m_pControlPage->m_pCA->m_strServer,
  7298. initInfo.cDsScopeInfos = nScopes;
  7299. initInfo.aDsScopeInfos = aScopeInit;
  7300. initInfo.cAttributesToFetch = 1;
  7301. initInfo.apwzAttributeNames = &pwszObjSID;
  7302. hr = pObjPicker->Initialize(&initInfo);
  7303. _JumpIfError(hr, err, "IDsObjectPicker::Initialize");
  7304. hr = pObjPicker->InvokeDialog(hwnd, &pdo);
  7305. _JumpIfError(hr, err, "IDsObjectPicker::InvokeDialog");
  7306. if(S_OK==hr)
  7307. {
  7308. UINT cf = 0;
  7309. FORMATETC formatetc = {
  7310. (CLIPFORMAT)cf,
  7311. NULL,
  7312. DVASPECT_CONTENT,
  7313. -1,
  7314. TYMED_HGLOBAL
  7315. };
  7316. PDS_SELECTION pDsSelection = NULL;
  7317. cf = RegisterClipboardFormat (CFSTR_DSOP_DS_SELECTION_LIST);
  7318. if (0 == cf)
  7319. {
  7320. hr = myHLastError();
  7321. _JumpIfError(hr, err, "RegisterClipboardFormat");
  7322. }
  7323. //set the clipformat for the formatetc structure
  7324. formatetc.cfFormat = (CLIPFORMAT)cf;
  7325. hr = pdo->GetData (&formatetc, &stgmedium);
  7326. _JumpIfError(hr, err, "IDataObject::GetData");
  7327. bAllocatedStgMedium = TRUE;
  7328. pDsSelList = (PDS_SELECTION_LIST) GlobalLock (stgmedium.hGlobal);
  7329. if (NULL == pDsSelList)
  7330. {
  7331. hr = myHLastError();
  7332. _JumpIfError(hr, err, "GlobalLock");
  7333. }
  7334. if (!pDsSelList->cItems) //some item must have been selected
  7335. {
  7336. hr = E_UNEXPECTED;
  7337. _JumpIfError(hr, err, "no items selected in object picker");
  7338. }
  7339. pDsSelection = &(pDsSelList->aDsSelection[0]);
  7340. saSid = V_ARRAY(pDsSelection->pvarFetchedAttributes);
  7341. hr = SafeArrayAccessData(saSid, &pArray);
  7342. _JumpIfError(hr, err, "SafeArrayAccessData");
  7343. CSASSERT(IsValidSid((PSID)pArray));
  7344. rpSid = LocalAlloc(LMEM_FIXED, GetLengthSid((PSID)pArray));
  7345. if(!CopySid(GetLengthSid((PSID)pArray),
  7346. rpSid,
  7347. pArray))
  7348. {
  7349. hr = myHLastError();
  7350. _JumpIfError(hr, err, "GlobalLock");
  7351. }
  7352. }
  7353. err:
  7354. if(pArray)
  7355. SafeArrayUnaccessData(saSid);
  7356. if(pDsSelList)
  7357. GlobalUnlock(stgmedium.hGlobal);
  7358. if (bAllocatedStgMedium)
  7359. ReleaseStgMedium (&stgmedium);
  7360. return hr;
  7361. }
  7362. HRESULT CSvrSettingsCertManagersPage::GetOfficerRights()
  7363. {
  7364. HRESULT hr = S_OK;
  7365. ICertAdminD2 *pICertAdminD = NULL;
  7366. DWORD dwServerVersion = 2; // 0 required by myOpenAdminDComConnection
  7367. WCHAR const *pwszAuthority;
  7368. CERTTRANSBLOB ctbSD;
  7369. ZeroMemory(&ctbSD, sizeof(CERTTRANSBLOB));
  7370. hr = myOpenAdminDComConnection(
  7371. m_pControlPage->m_pCA->m_bstrConfig,
  7372. &pwszAuthority,
  7373. NULL,
  7374. &dwServerVersion,
  7375. &pICertAdminD);
  7376. _JumpIfError(hr, error, "myOpenAdminDComConnection");
  7377. if (2 > dwServerVersion)
  7378. {
  7379. hr = RPC_E_VERSION_MISMATCH;
  7380. _JumpError(hr, error, "old server");
  7381. }
  7382. __try
  7383. {
  7384. hr = pICertAdminD->GetOfficerRights(
  7385. pwszAuthority,
  7386. &m_fEnabled,
  7387. &ctbSD);
  7388. }
  7389. __except(hr = myHEXCEPTIONCODE(), EXCEPTION_EXECUTE_HANDLER)
  7390. {
  7391. }
  7392. _JumpIfError(hr, error, "pICertAdminD->GetOfficerRights");
  7393. myRegisterMemAlloc(ctbSD.pb, ctbSD.cb, CSM_COTASKALLOC);
  7394. m_OfficerRightsList.Cleanup();
  7395. if(m_fEnabled)
  7396. {
  7397. hr = m_OfficerRightsList.Load(ctbSD.pb);
  7398. _JumpIfError(hr, error, "COfficerRightsList::Init");
  7399. }
  7400. error:
  7401. if(pICertAdminD)
  7402. {
  7403. myCloseDComConnection((IUnknown **) &pICertAdminD, NULL);
  7404. }
  7405. if (NULL != ctbSD.pb)
  7406. {
  7407. CoTaskMemFree(ctbSD.pb);
  7408. }
  7409. return hr;
  7410. }
  7411. HRESULT CSvrSettingsCertManagersPage::SetOfficerRights()
  7412. {
  7413. HRESULT hr = S_OK;
  7414. PSECURITY_DESCRIPTOR pSD = NULL;
  7415. ICertAdminD2 *pICertAdminD = NULL;
  7416. DWORD dwServerVersion = 2; // 0 required by myOpenAdminDComConnection
  7417. WCHAR const *pwszAuthority;
  7418. CERTTRANSBLOB ctbSD;
  7419. ZeroMemory(&ctbSD, sizeof(CERTTRANSBLOB));
  7420. if(m_fEnabled)
  7421. {
  7422. hr = m_OfficerRightsList.Save(pSD);
  7423. _JumpIfError(hr, error, "COfficerRightsList::Save");
  7424. ctbSD.cb = GetSecurityDescriptorLength(pSD);
  7425. ctbSD.pb = (BYTE*)pSD;
  7426. }
  7427. else
  7428. {
  7429. ZeroMemory(&ctbSD, sizeof(ctbSD));
  7430. }
  7431. hr = myOpenAdminDComConnection(
  7432. m_pControlPage->m_pCA->m_bstrConfig,
  7433. &pwszAuthority,
  7434. NULL,
  7435. &dwServerVersion,
  7436. &pICertAdminD);
  7437. _JumpIfError(hr, error, "myOpenAdminDComConnection");
  7438. if (2 > dwServerVersion)
  7439. {
  7440. hr = RPC_E_VERSION_MISMATCH;
  7441. _JumpError(hr, error, "old server");
  7442. }
  7443. __try
  7444. {
  7445. hr = pICertAdminD->SetOfficerRights(
  7446. pwszAuthority,
  7447. m_fEnabled,
  7448. &ctbSD);
  7449. }
  7450. __except(hr = myHEXCEPTIONCODE(), EXCEPTION_EXECUTE_HANDLER)
  7451. {
  7452. }
  7453. _JumpIfError(hr, error, "pICertAdminD->GetOfficerRights");
  7454. error:
  7455. myCloseDComConnection((IUnknown **) &pICertAdminD, NULL);
  7456. if(pSD)
  7457. {
  7458. LocalFree(pSD);
  7459. }
  7460. return hr;
  7461. }
  7462. #pragma warning(push)
  7463. #pragma warning(disable: 4509) // nonstandard extension used: uses SEH and has destructor
  7464. HRESULT
  7465. CSvrSettingsCertManagersPage::BuildVirtualOfficerRights()
  7466. {
  7467. HRESULT hr = S_OK;
  7468. CertSrv::COfficerRightsSD VirtOfficerRightsSD;
  7469. ICertAdminD2 *pICertAdminD = NULL;
  7470. DWORD dwServerVersion = 2; // 0 required by myOpenAdminDComConnection
  7471. WCHAR const *pwszAuthority;
  7472. CERTTRANSBLOB ctbSD;
  7473. ZeroMemory(&ctbSD, sizeof(CERTTRANSBLOB));
  7474. PSECURITY_DESCRIPTOR pVirtOfficerRights;
  7475. hr = myOpenAdminDComConnection(
  7476. m_pControlPage->m_pCA->m_bstrConfig,
  7477. &pwszAuthority,
  7478. NULL,
  7479. &dwServerVersion,
  7480. &pICertAdminD);
  7481. _JumpIfError(hr, error, "myOpenAdminDComConnection");
  7482. if (2 > dwServerVersion)
  7483. {
  7484. hr = RPC_E_VERSION_MISMATCH;
  7485. _JumpError(hr, error, "old server");
  7486. }
  7487. __try
  7488. {
  7489. hr = pICertAdminD->GetCASecurity(
  7490. pwszAuthority,
  7491. &ctbSD);
  7492. }
  7493. __except(hr = myHEXCEPTIONCODE(), EXCEPTION_EXECUTE_HANDLER)
  7494. {
  7495. }
  7496. _JumpIfError(hr, error, "pICertAdminD->GetOfficerRights");
  7497. // BuildVirtualOfficerRights should be called only when transitioning
  7498. // from not enabled to enabled, before enabling on the server side
  7499. CSASSERT(!m_fEnabled);
  7500. myRegisterMemAlloc(ctbSD.pb, ctbSD.cb, CSM_COTASKALLOC);
  7501. m_OfficerRightsList.Cleanup();
  7502. hr = VirtOfficerRightsSD.InitializeEmpty();
  7503. _JumpIfError(hr, error, "CProtectedSecurityDescriptor::Initialize");
  7504. hr = VirtOfficerRightsSD.Adjust(ctbSD.pb);
  7505. _JumpIfError(hr, error, "COfficerRightsSD::Adjust");
  7506. pVirtOfficerRights = VirtOfficerRightsSD.Get();
  7507. CSASSERT(pVirtOfficerRights);
  7508. hr = m_OfficerRightsList.Load(pVirtOfficerRights);
  7509. _JumpIfError(hr, error, "COfficerRightsList::Load");
  7510. error:
  7511. myCloseDComConnection((IUnknown **) &pICertAdminD, NULL);
  7512. if (NULL != ctbSD.pb)
  7513. {
  7514. CoTaskMemFree(ctbSD.pb);
  7515. }
  7516. return hr;
  7517. }
  7518. #pragma warning(pop)
  7519. void CSvrSettingsCertManagersPage::FillOfficerList()
  7520. {
  7521. HWND hwnd= GetDlgItem(m_hWnd, IDC_LIST_CERTMANAGERS);
  7522. SendMessage(hwnd, CB_RESETCONTENT, 0, 0);
  7523. if(m_fEnabled)
  7524. {
  7525. for(DWORD cManagers=0;
  7526. cManagers<m_OfficerRightsList.GetCount();
  7527. cManagers++)
  7528. {
  7529. CSASSERT(m_OfficerRightsList.GetAt(cManagers));
  7530. DBGCODE(LRESULT nIndex =) SendMessage(hwnd, CB_ADDSTRING, 0,
  7531. (LPARAM)m_OfficerRightsList.GetAt(cManagers)->GetName());
  7532. CSASSERT(nIndex != CB_ERR);
  7533. }
  7534. SendMessage(hwnd, CB_SETCURSEL, 0, 0);
  7535. }
  7536. }
  7537. void CSvrSettingsCertManagersPage::FillClientList(DWORD dwOfficerIndex)
  7538. {
  7539. HWND hwnd= GetDlgItem(m_hWnd, IDC_LIST_SUBJECTS);
  7540. CertSrv::COfficerRights *pOfficer = NULL;
  7541. DWORD dwClientCount, cClients;
  7542. ListView_DeleteAllItems(hwnd);
  7543. if(m_fEnabled)
  7544. {
  7545. if(dwOfficerIndex<m_OfficerRightsList.GetCount())
  7546. {
  7547. pOfficer = m_OfficerRightsList.GetAt(dwOfficerIndex);
  7548. CSASSERT(pOfficer);
  7549. dwClientCount = pOfficer->GetCount();
  7550. for(cClients=0;cClients<dwClientCount;cClients++)
  7551. {
  7552. ListView_NewItem(hwnd, cClients,
  7553. pOfficer->GetAt(cClients)->GetName());
  7554. ListView_SetItemText(hwnd, cClients, 1,
  7555. pOfficer->GetAt(cClients)->GetPermission()?
  7556. m_strTextAllow.GetBuffer():
  7557. m_strTextDeny.GetBuffer());
  7558. }
  7559. ListView_SetItemState(hwnd, 0,
  7560. LVIS_SELECTED|LVIS_FOCUSED , LVIS_SELECTED|LVIS_FOCUSED);
  7561. }
  7562. }
  7563. }
  7564. void CSvrSettingsCertManagersPage::SetAllowDeny()
  7565. {
  7566. if(m_fEnabled && 0!=m_OfficerRightsList.GetCount())
  7567. {
  7568. DWORD dwIndex = GetCurrentOfficerIndex();
  7569. if(0!=m_OfficerRightsList.GetAt(dwIndex)->GetCount())
  7570. {
  7571. BOOL fPermission = m_OfficerRightsList.GetAt(dwIndex)->
  7572. GetAt(GetCurrentClientIndex())->GetPermission();
  7573. EnableControl(m_hWnd, IDC_ALLOWDENY, TRUE);
  7574. SetDlgItemText(
  7575. m_hWnd,
  7576. IDC_ALLOWDENY,
  7577. fPermission?m_strButtonDeny:m_strButtonAllow);
  7578. return;
  7579. }
  7580. }
  7581. EnableControl(m_hWnd, IDC_ALLOWDENY, FALSE);
  7582. }
  7583. /////////////////////////////////////////////////////////////////////////////
  7584. // CSvrSettingsAuditFilterPage property page
  7585. RoleAccessToControl CSvrSettingsAuditFilterPage::sm_ControlToRoleMap[] =
  7586. {
  7587. { IDC_AUDIT_BACKUPRESTORE, CA_ACCESS_AUDITOR},
  7588. { IDC_AUDIT_CACONFIG, CA_ACCESS_AUDITOR},
  7589. { IDC_AUDIT_CASEC, CA_ACCESS_AUDITOR},
  7590. { IDC_AUDIT_CERTIFICATE, CA_ACCESS_AUDITOR},
  7591. { IDC_AUDIT_CRL, CA_ACCESS_AUDITOR},
  7592. { IDC_AUDIT_KEYARCHIVAL, CA_ACCESS_AUDITOR},
  7593. { IDC_AUDIT_STARTSTOP, CA_ACCESS_AUDITOR},
  7594. };
  7595. CSvrSettingsAuditFilterPage::CSvrSettingsAuditFilterPage(CSvrSettingsGeneralPage* pControlPage, UINT uIDD)
  7596. : CAutoDeletePropPage(uIDD),
  7597. CRolesSupportInPropPage(
  7598. pControlPage->m_pCA,
  7599. sm_ControlToRoleMap,
  7600. ARRAYSIZE(sm_ControlToRoleMap)),
  7601. m_pControlPage(pControlPage),
  7602. m_fDirty(FALSE),
  7603. m_dwFilter(0)
  7604. {
  7605. SetHelp(CERTMMC_HELPFILENAME, g_aHelpIDs_IDD_CERTSRV_PROPPAGE7);
  7606. }
  7607. CSvrSettingsAuditFilterPage::~CSvrSettingsAuditFilterPage()
  7608. {
  7609. }
  7610. int CSvrSettingsAuditFilterPage::m_iCheckboxID[] =
  7611. {
  7612. // ID order must match bit order in audit flag DWORD, see
  7613. // AUDIT_FILTER_* in include\audit.h
  7614. IDC_AUDIT_STARTSTOP,
  7615. IDC_AUDIT_BACKUPRESTORE,
  7616. IDC_AUDIT_CERTIFICATE,
  7617. IDC_AUDIT_CRL,
  7618. IDC_AUDIT_CASEC,
  7619. IDC_AUDIT_KEYARCHIVAL,
  7620. IDC_AUDIT_CACONFIG
  7621. };
  7622. BOOL CSvrSettingsAuditFilterPage::OnInitDialog()
  7623. {
  7624. GetAuditFilter();
  7625. // does parent init and UpdateData call
  7626. CAutoDeletePropPage::OnInitDialog();
  7627. for(int i=0; i<ARRAYLEN(m_iCheckboxID); i++)
  7628. EnableControl(m_hWnd, m_iCheckboxID[i], TRUE);
  7629. UpdateData(FALSE);
  7630. return TRUE;
  7631. }
  7632. HRESULT CSvrSettingsAuditFilterPage::GetAuditFilterDCOM()
  7633. {
  7634. HRESULT hr = S_OK;
  7635. ICertAdminD2* pAdminD = NULL;
  7636. WCHAR const *pwszAuthority;
  7637. DWORD dwServerVersion = 2;
  7638. LPCWSTR pcwszPriv = SE_SECURITY_NAME;
  7639. HANDLE hToken = EnablePrivileges(&pcwszPriv, 1);
  7640. hr = myOpenAdminDComConnection(
  7641. m_pControlPage->m_pCA->m_bstrConfig,
  7642. &pwszAuthority,
  7643. NULL,
  7644. &dwServerVersion,
  7645. &pAdminD);
  7646. _JumpIfError(hr, Ret, "myOpenAdminDComConnection");
  7647. if (2 > dwServerVersion)
  7648. {
  7649. hr = RPC_E_VERSION_MISMATCH;
  7650. _JumpError(hr, Ret, "old server");
  7651. }
  7652. // load certs here
  7653. hr = pAdminD->GetAuditFilter(
  7654. pwszAuthority,
  7655. &m_dwFilter);
  7656. _JumpIfError(hr, Ret, "ICertAdminD2::GetAuditFilter");
  7657. Ret:
  7658. if (pAdminD)
  7659. {
  7660. pAdminD->Release();
  7661. }
  7662. ReleasePrivileges(hToken);
  7663. return hr;
  7664. }
  7665. HRESULT CSvrSettingsAuditFilterPage::GetAuditFilterRegistry()
  7666. {
  7667. HRESULT hr = S_OK;
  7668. variant_t var;
  7669. hr = m_pCA->GetConfigEntry(
  7670. NULL,
  7671. wszREGAUDITFILTER,
  7672. &var);
  7673. _JumpIfError(hr, Ret, "GetConfigEntry");
  7674. m_dwFilter = (DWORD)V_I4(&var);
  7675. Ret:
  7676. return hr;
  7677. }
  7678. HRESULT CSvrSettingsAuditFilterPage::GetAuditFilter()
  7679. {
  7680. HRESULT hr = S_OK;
  7681. hr = GetAuditFilterDCOM();
  7682. _PrintIfError(hr, "GetAuditFilterDCOM");
  7683. if(S_OK!=hr)
  7684. {
  7685. hr = GetAuditFilterRegistry();
  7686. _PrintIfError(hr, "GetAuditFilterRegistry");
  7687. }
  7688. return hr;
  7689. }
  7690. HRESULT CSvrSettingsAuditFilterPage::SetAuditFilterDCOM()
  7691. {
  7692. HRESULT hr = S_OK;
  7693. ICertAdminD2* pAdminD = NULL;
  7694. WCHAR const *pwszAuthority;
  7695. DWORD dwServerVersion = 2;
  7696. LPCWSTR pcwszPriv = SE_SECURITY_NAME;
  7697. HANDLE hToken = INVALID_HANDLE_VALUE;
  7698. hToken = EnablePrivileges(&pcwszPriv, 1);
  7699. hr = myOpenAdminDComConnection(
  7700. m_pControlPage->m_pCA->m_bstrConfig,
  7701. &pwszAuthority,
  7702. NULL,
  7703. &dwServerVersion,
  7704. &pAdminD);
  7705. _JumpIfError(hr, Ret, "myOpenAdminDComConnection");
  7706. if (2 > dwServerVersion)
  7707. {
  7708. hr = RPC_E_VERSION_MISMATCH;
  7709. _JumpError(hr, Ret, "old server");
  7710. }
  7711. // load certs here
  7712. hr = pAdminD->SetAuditFilter(
  7713. pwszAuthority,
  7714. m_dwFilter);
  7715. _JumpIfError(hr, Ret, "ICertAdminD2::SetAuditFilter");
  7716. Ret:
  7717. if (pAdminD)
  7718. {
  7719. pAdminD->Release();
  7720. }
  7721. ReleasePrivileges(hToken);
  7722. return hr;
  7723. }
  7724. HRESULT CSvrSettingsAuditFilterPage::SetAuditFilterRegistry()
  7725. {
  7726. HRESULT hr = S_OK;
  7727. variant_t var;
  7728. V_VT(&var) = VT_I4;
  7729. V_I4(&var) = m_dwFilter;
  7730. hr = m_pCA->SetConfigEntry(
  7731. NULL,
  7732. wszREGAUDITFILTER,
  7733. &var);
  7734. _JumpIfError(hr, Ret, "SetConfigEntry");
  7735. Ret:
  7736. return hr;
  7737. }
  7738. HRESULT CSvrSettingsAuditFilterPage::SetAuditFilter()
  7739. {
  7740. HRESULT hr = S_OK;
  7741. hr = SetAuditFilterDCOM();
  7742. _PrintIfError(hr, "SetAuditFilterDCOM");
  7743. if(S_OK!=hr)
  7744. {
  7745. hr = SetAuditFilterRegistry();
  7746. _PrintIfError(hr, "SetAuditFilterRegistry");
  7747. }
  7748. return hr;
  7749. }
  7750. BOOL CSvrSettingsAuditFilterPage::OnApply()
  7751. {
  7752. HRESULT hr = S_OK;
  7753. if (TRUE==m_fDirty)
  7754. {
  7755. UpdateData(TRUE);
  7756. hr = SetAuditFilter();
  7757. _JumpIfError(hr, Ret, "SetAuditFilter");
  7758. m_fDirty = FALSE;
  7759. }
  7760. Ret:
  7761. if (S_OK != hr)
  7762. {
  7763. DisplayGenericCertSrvError(m_hWnd, hr);
  7764. return FALSE;
  7765. }
  7766. return CAutoDeletePropPage::OnApply();
  7767. }
  7768. BOOL CSvrSettingsAuditFilterPage::UpdateData(BOOL fSuckFromDlg /*= TRUE*/)
  7769. {
  7770. int c;
  7771. DWORD dwBit;
  7772. if (fSuckFromDlg)
  7773. {
  7774. m_dwFilter = 0;
  7775. for(c=0, dwBit=1; c<ARRAYLEN(m_iCheckboxID); c++, dwBit<<=1)
  7776. {
  7777. // set corresponding bit in filter DWORD
  7778. m_dwFilter = m_dwFilter |
  7779. ((INT)SendDlgItemMessage(m_iCheckboxID[c], BM_GETCHECK, 0, 0)?dwBit:0);
  7780. }
  7781. }
  7782. else
  7783. {
  7784. for(c=0, dwBit=1; c<ARRAYLEN(m_iCheckboxID); c++, dwBit<<=1)
  7785. {
  7786. // set checkbox corresponding to bit in filter DWORD
  7787. SendDlgItemMessage(m_iCheckboxID[c], BM_SETCHECK,
  7788. (m_dwFilter&dwBit)?BST_CHECKED:BST_UNCHECKED, 0);
  7789. }
  7790. }
  7791. return TRUE;
  7792. }
  7793. BOOL
  7794. CSvrSettingsAuditFilterPage::OnCommand(
  7795. WPARAM wParam,
  7796. LPARAM) // lParam
  7797. {
  7798. int c;
  7799. static s_fAlreadyWarnedStartStopPerf = false;
  7800. if (BN_CLICKED == HIWORD(wParam))
  7801. {
  7802. // walk the checkbox list and set dirty flag
  7803. for(c=0; c<ARRAYLEN(m_iCheckboxID); c++)
  7804. {
  7805. // if audit start/stop is checked the first time, warn the user
  7806. // that auditing start/stop can be expensive due to lengthy database hash
  7807. // computation
  7808. if(!s_fAlreadyWarnedStartStopPerf &&
  7809. LOWORD(wParam)==IDC_AUDIT_STARTSTOP &&
  7810. BST_CHECKED==SendDlgItemMessage(IDC_AUDIT_STARTSTOP, BM_GETCHECK, 0, 0))
  7811. {
  7812. CString cstrMsg, cstrTitle;
  7813. cstrMsg.LoadString(IDS_WARN_START_STOP_PERFORMANCE);
  7814. cstrTitle.LoadString(IDS_MSG_TITLE);
  7815. MessageBoxW(GetParent(), cstrMsg, cstrTitle, MB_ICONWARNING|MB_OK);
  7816. s_fAlreadyWarnedStartStopPerf = true;
  7817. }
  7818. if(LOWORD(wParam)==m_iCheckboxID[c])
  7819. {
  7820. m_fDirty = TRUE;
  7821. SendMessage (GetParent(), PSM_CHANGED, (WPARAM) m_hWnd, 0);
  7822. return TRUE;
  7823. }
  7824. }
  7825. }
  7826. return FALSE;
  7827. }
  7828. HRESULT GetPolicyManageDispatch(
  7829. LPCWSTR pcwszProgID,
  7830. REFCLSID clsidModule,
  7831. DISPATCHINTERFACE* pdi)
  7832. {
  7833. HRESULT hr;
  7834. DISPATCHINTERFACE di;
  7835. bool fRelease = false;
  7836. CString pszprogidPolicyManage;
  7837. CLSID clsidPolicyManage;
  7838. hr = Policy_Init(
  7839. DISPSETUP_COMFIRST,
  7840. pcwszProgID,
  7841. &clsidModule,
  7842. &di);
  7843. _JumpIfErrorStr(hr, Ret, "Policy_Init", pcwszProgID);
  7844. fRelease = true;
  7845. hr = Policy2_GetManageModule(
  7846. &di,
  7847. pdi);
  7848. // For backward compatibility, try the old way
  7849. if(S_OK != hr)
  7850. {
  7851. // build manage progid from policy/exit progid + "Manage"
  7852. pszprogidPolicyManage = pcwszProgID;
  7853. pszprogidPolicyManage += wszCERTMANAGE_SUFFIX;
  7854. hr = CLSIDFromProgID(pszprogidPolicyManage, &clsidPolicyManage);
  7855. _PrintIfError(hr, "CLSIDFromProgID");
  7856. hr = ManageModule_Init(
  7857. DISPSETUP_COMFIRST,
  7858. pszprogidPolicyManage,
  7859. &clsidPolicyManage,
  7860. pdi);
  7861. _JumpIfError(hr, Ret, "ManageModule_Init");
  7862. }
  7863. Ret:
  7864. if(fRelease)
  7865. Policy_Release(&di);
  7866. return hr;
  7867. }
  7868. HRESULT GetExitManageDispatch(
  7869. LPCWSTR pcwszProgID,
  7870. REFCLSID clsidModule,
  7871. DISPATCHINTERFACE* pdi)
  7872. {
  7873. HRESULT hr;
  7874. DISPATCHINTERFACE di;
  7875. bool fRelease = false;
  7876. CString pszprogidExitManage;
  7877. CLSID clsidExitManage;
  7878. hr = Exit_Init(
  7879. DISPSETUP_COMFIRST,
  7880. pcwszProgID,
  7881. &clsidModule,
  7882. &di);
  7883. _JumpIfErrorStr(hr, Ret, "Policy_Init", pcwszProgID);
  7884. fRelease = true;
  7885. hr = Exit2_GetManageModule(
  7886. &di,
  7887. pdi);
  7888. // For backward compatibility, try the old way
  7889. if(S_OK != hr)
  7890. {
  7891. // build manage progid from policy/exit progid + "Manage"
  7892. pszprogidExitManage = pcwszProgID;
  7893. pszprogidExitManage += wszCERTMANAGE_SUFFIX;
  7894. hr = CLSIDFromProgID(pszprogidExitManage, &clsidExitManage);
  7895. _PrintIfError(hr, "CLSIDFromProgID");
  7896. hr = ManageModule_Init(
  7897. DISPSETUP_COMFIRST,
  7898. pszprogidExitManage,
  7899. &clsidExitManage,
  7900. pdi);
  7901. _JumpIfError(hr, Ret, "ManageModule_Init");
  7902. }
  7903. Ret:
  7904. if(fRelease)
  7905. Exit_Release(&di);
  7906. return hr;
  7907. }