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.

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