Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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