Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

868 lines
21 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: cryptui.cpp
  7. //
  8. // Contents: Cert Server wrapper routines
  9. //
  10. //---------------------------------------------------------------------------
  11. #include <pch.cpp>
  12. #pragma hdrstop
  13. #include "certmsg.h"
  14. #include "clibres.h"
  15. #include "setupids.h"
  16. #include "tfc.h"
  17. #include "Windowsx.h"
  18. #define __dwFILE__ __dwFILE_INITLIB_CERTUI_CPP__
  19. HRESULT
  20. myGetConfigStringFromPicker(
  21. OPTIONAL IN HWND hwndParent,
  22. OPTIONAL IN WCHAR const *pwszPrompt,
  23. OPTIONAL IN WCHAR const *pwszTitle,
  24. OPTIONAL IN WCHAR const *pwszSharedFolder,
  25. IN DWORD dwFlags, // GCFPF_*
  26. OUT WCHAR **ppwszConfig)
  27. {
  28. HRESULT hr;
  29. DWORD dwCACount;
  30. CRYPTUI_CA_CONTEXT const *pCAContext = NULL;
  31. hr = myGetConfigFromPicker(
  32. hwndParent,
  33. pwszPrompt,
  34. pwszTitle,
  35. pwszSharedFolder,
  36. dwFlags,
  37. FALSE,
  38. &dwCACount,
  39. &pCAContext);
  40. _JumpIfError(hr, error, "myGetConfigFromPicker");
  41. if (NULL == pCAContext)
  42. {
  43. hr = E_INVALIDARG;
  44. _JumpIfError(hr, error, "Internal error: myGetConfigFromPicker");
  45. }
  46. hr = myFormConfigString(
  47. pCAContext->pwszCAMachineName,
  48. pCAContext->pwszCAName,
  49. ppwszConfig);
  50. _JumpIfError(hr, error, "myFormConfigString");
  51. error:
  52. if (NULL != pCAContext)
  53. {
  54. CryptUIDlgFreeCAContext(pCAContext);
  55. }
  56. return(hr);
  57. }
  58. HRESULT
  59. myUIGetWindowText(
  60. IN HWND hwndCtrl,
  61. OUT WCHAR **ppwszText)
  62. {
  63. HRESULT hr;
  64. LRESULT len;
  65. WCHAR *pwszBegin;
  66. WCHAR *pwszEnd;
  67. WCHAR *pwszText = NULL;
  68. CSASSERT(NULL != hwndCtrl &&
  69. NULL != ppwszText);
  70. // init
  71. *ppwszText = NULL;
  72. // get text string size
  73. len = SendMessage(hwndCtrl, WM_GETTEXTLENGTH, 0, 0);
  74. if (0 < len)
  75. {
  76. pwszText = (WCHAR*)LocalAlloc(LMEM_FIXED, (UINT)((len+1) * sizeof(WCHAR)));
  77. if (NULL == pwszText)
  78. {
  79. hr = E_OUTOFMEMORY;
  80. _JumpError(hr, error, "LocalAlloc");
  81. }
  82. if (len !=
  83. SendMessage(hwndCtrl, WM_GETTEXT, (WPARAM)len+1, (LPARAM)pwszText))
  84. {
  85. hr = HRESULT_FROM_WIN32(ERROR_BAD_LENGTH);
  86. _JumpError(hr, error, "Internal error");
  87. }
  88. }
  89. else
  90. {
  91. goto done;
  92. }
  93. // trim trailing and heading blank strings
  94. pwszBegin = pwszText;
  95. pwszEnd = &pwszText[wcslen(pwszText) - 1];
  96. while (pwszEnd > pwszBegin && iswspace(*pwszEnd) )
  97. {
  98. *pwszEnd = L'\0';
  99. --pwszEnd;
  100. }
  101. while (pwszBegin <= pwszEnd &&
  102. L'\0' != *pwszBegin &&
  103. iswspace(*pwszBegin) )
  104. {
  105. ++pwszBegin;
  106. }
  107. if (pwszEnd >= pwszBegin)
  108. {
  109. MoveMemory(
  110. pwszText,
  111. pwszBegin,
  112. (SAFE_SUBTRACT_POINTERS(pwszEnd, pwszBegin) + 2) * sizeof(WCHAR));
  113. }
  114. else
  115. {
  116. goto done;
  117. }
  118. *ppwszText = pwszText;
  119. pwszText = NULL;
  120. done:
  121. hr = S_OK;
  122. error:
  123. if (NULL != pwszText)
  124. {
  125. LocalFree(pwszText);
  126. }
  127. return hr;
  128. }
  129. // following code for CA selection UI control
  130. HRESULT
  131. myUICASelectionUpdateCAList(
  132. HWND hwndList,
  133. WCHAR const *pwszzCAList)
  134. {
  135. HRESULT hr;
  136. int nItem;
  137. WCHAR const *pwszCA = pwszzCAList;
  138. // remove current list
  139. SendMessage(hwndList, CB_RESETCONTENT, (WPARAM) 0, (LPARAM) 0);
  140. // add to list
  141. while (NULL != pwszCA && L'\0' != pwszCA[0])
  142. {
  143. nItem = (INT)SendMessage(
  144. hwndList,
  145. CB_ADDSTRING,
  146. (WPARAM) 0,
  147. (LPARAM) pwszCA);
  148. if (LB_ERR == nItem)
  149. {
  150. hr = myHLastError();
  151. _JumpError(hr, error, "SendMessage");
  152. }
  153. pwszCA += wcslen(pwszCA) + 1;
  154. }
  155. if (NULL != pwszzCAList)
  156. {
  157. // attempt to choose the 1st one as default
  158. SendMessage(hwndList, CB_SETCURSEL, (WPARAM) 0, (LPARAM) 0);
  159. }
  160. hr = S_OK;
  161. error:
  162. return hr;
  163. }
  164. LRESULT CALLBACK
  165. myUICASelectionComputerEditFilterHook(
  166. HWND hwndComputer,
  167. UINT iMsg,
  168. WPARAM wParam,
  169. LPARAM lParam)
  170. {
  171. LRESULT lr;
  172. HRESULT hr;
  173. CERTSRVUICASELECTION *pData = (CERTSRVUICASELECTION *)
  174. GetWindowLongPtr(hwndComputer, GWLP_USERDATA);
  175. CSASSERT(NULL != pData);
  176. switch (iMsg)
  177. {
  178. case WM_CHAR:
  179. // empty ca list
  180. hr = myUICASelectionUpdateCAList(pData->hwndCAList, NULL);
  181. _PrintIfError(hr, "myUICASelectionUpdateCAList");
  182. break;
  183. }
  184. lr = CallWindowProc(
  185. pData->pfnUICASelectionComputerWndProcs,
  186. hwndComputer,
  187. iMsg,
  188. wParam,
  189. lParam);
  190. //error:
  191. return lr;
  192. }
  193. HRESULT
  194. myUICAConditionallyDisplayEnterpriseWarning(
  195. IN CERTSRVUICASELECTION *pData)
  196. {
  197. HRESULT hr = S_OK;
  198. WCHAR szCA[MAX_PATH];
  199. WCHAR szComputer[MAX_PATH];
  200. CAINFO *pCAInfo = NULL;
  201. BOOL fCoInit = FALSE;
  202. int iSel;
  203. hr = CoInitialize(NULL);
  204. if (S_OK != hr && S_FALSE != hr)
  205. {
  206. _JumpError(hr, Ret, "CoInitialize");
  207. }
  208. fCoInit = TRUE;
  209. hr = S_OK; // don't want to return this error
  210. pData->CAType = ENUM_UNKNOWN_CA;
  211. // pinging specific CA is done in both cases -- reselect or new machine
  212. // pointed at
  213. szCA[0] = L'\0';
  214. szComputer[0] = L'\0';
  215. iSel = ComboBox_GetCurSel(pData->hwndCAList);
  216. ComboBox_GetLBText(pData->hwndCAList, iSel, szCA);
  217. GetWindowText(pData->hwndComputerEdit, szComputer, MAX_PATH);
  218. if ((szCA[0] == L'\0') || (szComputer[0] == L'\0'))
  219. {
  220. ShowWindow(GetDlgItem(pData->hDlg, IDC_CLIENT_WARN_ENTERPRISE_REQUIREMENTS), SW_HIDE);
  221. goto Ret;
  222. }
  223. hr = myPingCertSrv(
  224. szCA,
  225. szComputer,
  226. NULL,
  227. NULL,
  228. &pCAInfo,
  229. NULL,
  230. NULL);
  231. if ((hr == S_OK) && (pCAInfo != NULL))
  232. {
  233. // copy catype into returned data
  234. pData->CAType = pCAInfo->CAType;
  235. if (IsEnterpriseCA(pCAInfo->CAType))
  236. {
  237. ShowWindow(
  238. GetDlgItem(
  239. pData->hDlg,
  240. IDC_CLIENT_WARN_ENTERPRISE_REQUIREMENTS),
  241. SW_SHOW);
  242. }
  243. else
  244. {
  245. ShowWindow(
  246. GetDlgItem(
  247. pData->hDlg,
  248. IDC_CLIENT_WARN_ENTERPRISE_REQUIREMENTS),
  249. SW_HIDE);
  250. }
  251. }
  252. Ret:
  253. if (NULL != pCAInfo)
  254. LocalFree(pCAInfo);
  255. if (fCoInit)
  256. CoUninitialize();
  257. return hr;
  258. }
  259. HRESULT
  260. myUICAHandleCAListDropdown(
  261. IN int iNotification,
  262. IN OUT CERTSRVUICASELECTION *pData,
  263. IN OUT BOOL *pfComputerChange)
  264. {
  265. HRESULT hr;
  266. WCHAR *pwszComputer = NULL;
  267. WCHAR *pwszzCAList = NULL;
  268. BOOL fCoInit = FALSE;
  269. WCHAR *pwszDnsName = NULL;
  270. DWORD dwVersion;
  271. CSASSERT(NULL != pData);
  272. // if this isn't a focus or selection change and computer name stayed the
  273. // same, nothing to do
  274. if ((CBN_SELCHANGE != iNotification) && !*pfComputerChange)
  275. {
  276. goto done;
  277. }
  278. ShowWindow(GetDlgItem(pData->hDlg, IDC_CLIENT_WARN_ENTERPRISE_REQUIREMENTS), SW_HIDE);
  279. SetCursor(LoadCursor(NULL, IDC_WAIT));
  280. if (NULL == pData->hwndComputerEdit)
  281. {
  282. // not init
  283. goto done;
  284. }
  285. // make sure computer edit field is not empty
  286. hr = myUIGetWindowText(pData->hwndComputerEdit,
  287. &pwszComputer);
  288. _JumpIfError(hr, error, "myUIGetWindowText");
  289. if (NULL == pwszComputer)
  290. {
  291. goto done;
  292. }
  293. if (*pfComputerChange)
  294. {
  295. // ping to get ca list
  296. hr = CoInitialize(NULL);
  297. if (S_OK != hr && S_FALSE != hr)
  298. {
  299. _JumpError(hr, error, "CoInitialize");
  300. }
  301. fCoInit = TRUE;
  302. // reset once ca list is updated. Do this now to prevent recursion
  303. *pfComputerChange = FALSE;
  304. hr = myPingCertSrv(
  305. pwszComputer,
  306. NULL,
  307. &pwszzCAList,
  308. NULL,
  309. NULL,
  310. &dwVersion,
  311. &pwszDnsName);
  312. CSILOG(hr, IDS_ILOG_GETCANAME, pwszComputer, NULL, NULL);
  313. if (S_OK != hr)
  314. {
  315. // make sure null
  316. CSASSERT(NULL == pwszzCAList);
  317. // can't ping the ca. Set focus now to prevent recursion
  318. SetFocus(pData->hwndComputerEdit);
  319. SendMessage(pData->hwndComputerEdit, EM_SETSEL, 0, -1);
  320. CertWarningMessageBox(
  321. pData->hInstance,
  322. FALSE,
  323. pData->hDlg,
  324. IDS_WRN_PINGCA_FAIL,
  325. hr,
  326. NULL);
  327. }
  328. else if (dwVersion<2 && pData->fWebProxySetup)
  329. {
  330. //bug 262316: don't allow installing Whistler proxy to an older CA
  331. hr = HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION);
  332. if (pwszzCAList)
  333. {
  334. LocalFree(pwszzCAList);
  335. pwszzCAList = NULL;
  336. }
  337. SetFocus(pData->hwndComputerEdit);
  338. SendMessage(pData->hwndComputerEdit, EM_SETSEL, 0, -1);
  339. CertWarningMessageBox(
  340. pData->hInstance,
  341. FALSE,
  342. pData->hDlg,
  343. IDS_WRN_OLD_CA,
  344. hr,
  345. NULL);
  346. }
  347. if (NULL != pwszDnsName && 0 != mylstrcmpiL(pwszComputer, pwszDnsName))
  348. {
  349. // update computer
  350. SendMessage(
  351. pData->hwndComputerEdit,
  352. WM_SETTEXT,
  353. 0,
  354. (LPARAM) pwszDnsName);
  355. }
  356. // update ca list
  357. hr = myUICASelectionUpdateCAList(pData->hwndCAList, pwszzCAList);
  358. _JumpIfError(hr, error, "myUICASelectionUpdateCAList");
  359. }
  360. // pinging specific CA is done in both cases -- reselect or new machine
  361. // pointed at
  362. hr = myUICAConditionallyDisplayEnterpriseWarning(pData);
  363. _PrintIfError(hr, "myUICAConditionallyDisplayEnterpriseWarning");
  364. done:
  365. hr = S_OK;
  366. error:
  367. SetCursor(LoadCursor(NULL, IDC_ARROW));
  368. if (fCoInit)
  369. {
  370. CoUninitialize();
  371. }
  372. if (NULL != pwszzCAList)
  373. {
  374. LocalFree(pwszzCAList);
  375. }
  376. if (NULL != pwszComputer)
  377. {
  378. LocalFree(pwszComputer);
  379. }
  380. if (NULL != pwszDnsName)
  381. {
  382. LocalFree(pwszDnsName);
  383. }
  384. return hr;
  385. }
  386. HRESULT
  387. myInitUICASelectionControls(
  388. IN OUT CERTSRVUICASELECTION *pUICASelection,
  389. IN HINSTANCE hInstance,
  390. IN HWND hDlg,
  391. IN HWND hwndBrowseButton,
  392. IN HWND hwndComputerEdit,
  393. IN HWND hwndCAList,
  394. IN BOOL fDSCA,
  395. OUT BOOL *pfCAsExist)
  396. {
  397. HRESULT hr;
  398. PCCRYPTUI_CA_CONTEXT pCAContext = NULL;
  399. DWORD dwCACount;
  400. CString cstrText;
  401. DWORD dwFlags = fDSCA? GCFPF_USEDS : 0;
  402. if (pUICASelection->fSkipLocalCA)
  403. {
  404. dwFlags |= GCFPF_SKIPLOCALCA;
  405. }
  406. SetCursor(LoadCursor(NULL, IDC_WAIT));
  407. hr = myGetConfigFromPicker(
  408. hDlg,
  409. NULL,
  410. NULL,
  411. NULL,
  412. dwFlags,
  413. TRUE, // fCountOnly
  414. &dwCACount,
  415. &pCAContext);
  416. SetCursor(LoadCursor(NULL, IDC_ARROW));
  417. if (S_OK != hr)
  418. {
  419. dwCACount = 0;
  420. _PrintError(hr, "myGetConfigFromPicker");
  421. }
  422. // enable/disable
  423. *pfCAsExist = 0 < dwCACount;
  424. EnableWindow(hwndBrowseButton, *pfCAsExist);
  425. // set computer edit control hook
  426. pUICASelection->pfnUICASelectionComputerWndProcs =
  427. (WNDPROC)SetWindowLongPtr(hwndComputerEdit,
  428. GWLP_WNDPROC, (LPARAM)myUICASelectionComputerEditFilterHook);
  429. pUICASelection->hInstance = hInstance;
  430. pUICASelection->hDlg = hDlg;
  431. pUICASelection->hwndComputerEdit = hwndComputerEdit;
  432. pUICASelection->hwndCAList = hwndCAList;
  433. // pass data to both controls
  434. SetWindowLongPtr(hwndComputerEdit, GWLP_USERDATA, (ULONG_PTR)pUICASelection);
  435. SetWindowLongPtr(hwndCAList, GWLP_USERDATA, (ULONG_PTR)pUICASelection);
  436. // by default, don't show Enterprise CA warning
  437. cstrText.LoadString(IDS_WARN_ENTERPRISE_REQUIREMENTS);
  438. SetWindowText(GetDlgItem(hDlg, IDC_CLIENT_WARN_ENTERPRISE_REQUIREMENTS), cstrText);
  439. ShowWindow(GetDlgItem(hDlg, IDC_CLIENT_WARN_ENTERPRISE_REQUIREMENTS), SW_HIDE);
  440. if (NULL != pCAContext)
  441. {
  442. CryptUIDlgFreeCAContext(pCAContext);
  443. }
  444. hr = S_OK;
  445. //error:
  446. return hr;
  447. }
  448. HRESULT
  449. myUICAHandleCABrowseButton(
  450. CERTSRVUICASELECTION *pData,
  451. IN BOOL fUseDS,
  452. OPTIONAL IN int idsPickerTitle,
  453. OPTIONAL IN int idsPickerSubTitle,
  454. OPTIONAL OUT WCHAR **ppwszSharedFolder)
  455. {
  456. HRESULT hr = S_OK;
  457. PCCRYPTUI_CA_CONTEXT pCAContext = NULL;
  458. WCHAR *pwszSubTitle = NULL;
  459. WCHAR *pwszTitle = NULL;
  460. DWORD dwCACount;
  461. WCHAR *pwszzCAList = NULL;
  462. WCHAR *pwszComputer = NULL;
  463. WCHAR *pwszTemp = NULL;
  464. BOOL fCoInit = FALSE;
  465. DWORD dwVersion;
  466. DWORD dwFlags = fUseDS? GCFPF_USEDS : 0;
  467. if (NULL != ppwszSharedFolder)
  468. {
  469. *ppwszSharedFolder = NULL;
  470. }
  471. if (pData->fSkipLocalCA)
  472. {
  473. dwFlags |= GCFPF_SKIPLOCALCA;
  474. }
  475. if (0 != idsPickerTitle)
  476. {
  477. hr = myLoadRCString(pData->hInstance, idsPickerTitle, &pwszTitle);
  478. if (S_OK != hr)
  479. {
  480. pwszTitle = NULL;
  481. _PrintError(hr, "myLoadRCString");
  482. }
  483. }
  484. if (0 != idsPickerSubTitle)
  485. {
  486. hr = myLoadRCString(pData->hInstance, idsPickerSubTitle, &pwszSubTitle);
  487. if (S_OK != hr)
  488. {
  489. pwszSubTitle = NULL;
  490. _PrintError(hr, "myLoadRCString");
  491. }
  492. }
  493. /*
  494. // REMOVED mattt 6/26/00: is this ever wanted: "Browse uses shared folder of machine editbox currently points at"?
  495. // just seems to make changing away from bad machine very very slow
  496. // get remote shared folder if possible
  497. hr = myUIGetWindowText(pData->hwndComputerEdit, &pwszComputer);
  498. _JumpIfError(hr, error, "myUIGetWindowText");
  499. if (NULL != pwszComputer)
  500. {
  501. hr = CoInitialize(NULL);
  502. if (S_OK != hr && S_FALSE != hr)
  503. {
  504. _JumpError(hr, error, "CoInitialize");
  505. }
  506. fCoInit = TRUE;
  507. // get shared folder path on remote machine here
  508. SetCursor(LoadCursor(NULL, IDC_WAIT));
  509. hr = myPingCertSrv(pwszComputer, NULL, NULL, &pwszTemp, NULL, NULL, NULL);
  510. SetCursor(LoadCursor(NULL, IDC_ARROW));
  511. if (S_OK != hr)
  512. {
  513. CSASSERT(NULL == pwszTemp);
  514. _JumpError(hr, localsharedfolder, "myPingCertSrv");
  515. }
  516. }
  517. localsharedfolder:
  518. */
  519. hr = myGetConfigFromPicker(
  520. pData->hDlg,
  521. pwszSubTitle,
  522. pwszTitle,
  523. pwszTemp,
  524. dwFlags,
  525. FALSE, // fCountOnly
  526. &dwCACount,
  527. &pCAContext);
  528. if (S_OK != hr && HRESULT_FROM_WIN32(ERROR_CANCELLED) != hr)
  529. {
  530. CSILOG(hr, IDS_ILOG_SELECTCA, NULL, NULL, NULL);
  531. _JumpError(hr, error, "myGetConfigFromPicker");
  532. }
  533. if (S_OK != hr)
  534. goto done;
  535. if (NULL == pCAContext)
  536. {
  537. CertWarningMessageBox(
  538. pData->hInstance,
  539. FALSE,
  540. pData->hDlg,
  541. IDS_WRN_CALIST_EMPTY,
  542. S_OK,
  543. NULL);
  544. SetWindowText(pData->hwndCAList, L"");
  545. SetFocus(pData->hwndComputerEdit);
  546. SendMessage(pData->hwndComputerEdit, EM_SETSEL, 0, -1);
  547. }
  548. else
  549. {
  550. CSILOG(hr, IDS_ILOG_SELECTCA, pCAContext->pwszCAMachineName, pCAContext->pwszCAName, NULL);
  551. // update computer
  552. SendMessage(pData->hwndComputerEdit, WM_SETTEXT,
  553. 0, (LPARAM)pCAContext->pwszCAMachineName);
  554. // construct a single multi string for list update
  555. DWORD len = wcslen(pCAContext->pwszCAName);
  556. pwszzCAList = (WCHAR*)LocalAlloc(LMEM_FIXED, (len+2) * sizeof(WCHAR));
  557. if (NULL == pwszzCAList)
  558. {
  559. hr = E_OUTOFMEMORY;
  560. _JumpError(hr, error, "LocalAlloc");
  561. }
  562. wcscpy(pwszzCAList, pCAContext->pwszCAName);
  563. pwszzCAList[len+1] = '\0';
  564. hr = myUICASelectionUpdateCAList(pData->hwndCAList, pwszzCAList);
  565. _JumpIfError(hr, error, "myUICASelectionUpdateCAList");
  566. LocalFree(pwszzCAList);
  567. pwszzCAList = NULL;
  568. // this thread blocks paint message, send it before ping
  569. UpdateWindow(pData->hDlg);
  570. // ping the computer to see if found a matched ca
  571. if (!fCoInit)
  572. {
  573. hr = CoInitialize(NULL);
  574. if (S_OK != hr && S_FALSE != hr)
  575. {
  576. _JumpError(hr, error, "CoInitialize");
  577. }
  578. fCoInit = TRUE;
  579. }
  580. SetCursor(LoadCursor(NULL, IDC_WAIT));
  581. // ping to get ca list
  582. hr = myPingCertSrv(
  583. pCAContext->pwszCAMachineName,
  584. NULL,
  585. &pwszzCAList,
  586. NULL,
  587. NULL,
  588. &dwVersion,
  589. NULL);
  590. SetCursor(LoadCursor(NULL, IDC_ARROW));
  591. CSILOG(hr, IDS_ILOG_GETCANAME, pCAContext->pwszCAMachineName, NULL, NULL);
  592. if (S_OK == hr)
  593. {
  594. //bug 262316: don't allow installing Whistler proxy to an older CA
  595. if (dwVersion<2 && pData->fWebProxySetup)
  596. {
  597. hr = HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION);
  598. // focus on the CA list to trigger a verification of the CA
  599. SetFocus(pData->hwndCAList);
  600. }
  601. else
  602. {
  603. // ping successful
  604. WCHAR const *pwszPingCA = pwszzCAList;
  605. // go through the list to see if any match
  606. while (NULL != pwszPingCA && L'\0' != pwszPingCA[0])
  607. {
  608. if (0 == mylstrcmpiL(pCAContext->pwszCAName, pwszPingCA))
  609. {
  610. // found matched one
  611. goto done;
  612. }
  613. pwszPingCA += wcslen(pwszPingCA) + 1;
  614. }
  615. // if we get here, either the CA is offline or the machine is
  616. // offline and another machine is using the same IP address.
  617. CertWarningMessageBox(
  618. pData->hInstance,
  619. FALSE,
  620. pData->hDlg,
  621. IDS_WRN_CANAME_NOT_MATCH,
  622. 0,
  623. NULL);
  624. // only empty combo edit field
  625. SetWindowText(pData->hwndCAList, L"");
  626. SetFocus(pData->hwndCAList);
  627. }
  628. }
  629. else
  630. {
  631. // can't ping the ca, selected an estranged ca
  632. CertWarningMessageBox(
  633. pData->hInstance,
  634. FALSE,
  635. pData->hDlg,
  636. IDS_WRN_PINGCA_FAIL,
  637. hr,
  638. NULL);
  639. // empty list anyway
  640. hr = myUICASelectionUpdateCAList(pData->hwndCAList, NULL);
  641. _JumpIfError(hr, error, "UICASelectionUpdateCAList");
  642. SetFocus(pData->hwndComputerEdit);
  643. SendMessage(pData->hwndComputerEdit, EM_SETSEL, 0, -1);
  644. }
  645. }
  646. done:
  647. hr = myUICAConditionallyDisplayEnterpriseWarning(pData);
  648. _PrintIfError(hr, "myUICAConditionallyDisplayEnterpriseWarning");
  649. if (NULL != ppwszSharedFolder)
  650. {
  651. *ppwszSharedFolder = pwszTemp;
  652. pwszTemp = NULL;
  653. }
  654. hr = S_OK;
  655. error:
  656. if (NULL != pwszzCAList)
  657. {
  658. LocalFree(pwszzCAList);
  659. }
  660. if (NULL != pwszSubTitle)
  661. {
  662. LocalFree(pwszSubTitle);
  663. }
  664. if (NULL != pwszTitle)
  665. {
  666. LocalFree(pwszTitle);
  667. }
  668. if (NULL != pwszTemp)
  669. {
  670. LocalFree(pwszTemp);
  671. }
  672. if (NULL != pwszComputer)
  673. {
  674. LocalFree(pwszComputer);
  675. }
  676. if (NULL != pCAContext)
  677. {
  678. CryptUIDlgFreeCAContext(pCAContext);
  679. }
  680. if (fCoInit)
  681. {
  682. CoUninitialize();
  683. }
  684. return hr;
  685. }
  686. HRESULT
  687. myUICASelectionValidation(
  688. CERTSRVUICASELECTION *pData,
  689. BOOL *pfValidate)
  690. {
  691. HRESULT hr;
  692. WCHAR *pwszComputer = NULL;
  693. WCHAR *pwszCA = NULL;
  694. CSASSERT(NULL != pData);
  695. *pfValidate = FALSE;
  696. // first, make sure not empty
  697. hr = myUIGetWindowText(pData->hwndComputerEdit, &pwszComputer);
  698. _JumpIfError(hr, error, "myUIGetWindowText");
  699. if (NULL == pwszComputer)
  700. {
  701. CertWarningMessageBox(
  702. pData->hInstance,
  703. FALSE,
  704. pData->hDlg,
  705. IDS_WRN_COMPUTERNAME_EMPTY,
  706. 0,
  707. NULL);
  708. SetFocus(pData->hwndComputerEdit);
  709. goto done;
  710. }
  711. hr = myUIGetWindowText(pData->hwndCAList, &pwszCA);
  712. _JumpIfError(hr, error, "myUIGetWindowText");
  713. if (NULL == pwszCA)
  714. {
  715. CertWarningMessageBox(
  716. pData->hInstance,
  717. FALSE,
  718. pData->hDlg,
  719. IDS_WRN_CANAME_EMPTY,
  720. 0,
  721. NULL);
  722. SetFocus(pData->hwndComputerEdit);
  723. SendMessage(pData->hwndComputerEdit, EM_SETSEL, 0, -1);
  724. goto done;
  725. }
  726. CSASSERT(pData->CAType != ENUM_UNKNOWN_CA);
  727. if (pData->CAType == ENUM_UNKNOWN_CA)
  728. {
  729. hr = E_UNEXPECTED;
  730. _JumpIfError(hr, error, "CAType not determined");
  731. }
  732. // if hit here
  733. *pfValidate = TRUE;
  734. done:
  735. hr = S_OK;
  736. error:
  737. if (NULL != pwszComputer)
  738. {
  739. LocalFree(pwszComputer);
  740. }
  741. if (NULL != pwszCA)
  742. {
  743. LocalFree(pwszCA);
  744. }
  745. return hr;
  746. }