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.

1072 lines
27 KiB

  1. // ChooseFileNamePage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CertWiz.h"
  5. #include "ChooseFileName.h"
  6. #include "Certificat.h"
  7. #include "Shlwapi.h"
  8. #include "strutil.h"
  9. #include "certutil.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CChooseFileNamePage property page
  17. IMPLEMENT_DYNCREATE(CChooseFileNamePage, CIISWizardPage)
  18. static BOOL
  19. AnswerIsYes(UINT id, CString& file)
  20. {
  21. CString strMessage;
  22. AfxFormatString1(strMessage, id, file);
  23. return (IDYES == AfxMessageBox(strMessage, MB_ICONEXCLAMATION | MB_YESNO));
  24. }
  25. CChooseFileNamePage::CChooseFileNamePage(UINT id,
  26. UINT defaultID,
  27. UINT extID,
  28. UINT filterID,
  29. CString * pOutFileName,
  30. CString csAdditionalInfo)
  31. : CIISWizardPage(id, IDS_CERTWIZ, TRUE),
  32. m_id(id),
  33. m_defaultID(defaultID),
  34. m_DoReplaceFile(FALSE),
  35. m_pOutFileName(pOutFileName),
  36. m_AdditionalInfo(csAdditionalInfo)
  37. {
  38. //{{AFX_DATA_INIT(CChooseFileNamePage)
  39. m_FileName = _T("");
  40. //}}AFX_DATA_INIT
  41. if (extID != 0)
  42. ext.LoadString(extID);
  43. if (filterID != 0)
  44. filter.LoadString(filterID);
  45. // replace '!'s in this string to null chars
  46. for (int i = 0; i < filter.GetLength(); i++)
  47. {
  48. if (filter[i] == L'!')
  49. filter.SetAt(i, L'\0');
  50. }
  51. }
  52. CChooseFileNamePage::~CChooseFileNamePage()
  53. {
  54. }
  55. void CChooseFileNamePage::DoDataExchange(CDataExchange* pDX)
  56. {
  57. CIISWizardPage::DoDataExchange(pDX);
  58. //{{AFX_DATA_MAP(CChooseFileNamePage)
  59. DDX_Text(pDX, IDC_FILE_NAME, m_FileName);
  60. //}}AFX_DATA_MAP
  61. }
  62. LRESULT
  63. CChooseFileNamePage::OnWizardBack()
  64. {
  65. ASSERT(FALSE);
  66. return 1;
  67. }
  68. #if 0
  69. #define SHOW_MESSAGE_BOX(id,str)\
  70. do {\
  71. CString strMessage;\
  72. AfxFormatString1(strMessage, (id), (str));\
  73. if (IDNO == AfxMessageBox(strMessage, MB_ICONEXCLAMATION | MB_YESNO))\
  74. {\
  75. CEdit * pEdit = (CEdit *)CWnd::FromHandle(GetDlgItem(IDC_FILE_NAME)->m_hWnd);\
  76. pEdit->SetSel(0, -1);\
  77. pEdit->SetFocus();\
  78. return 1;\
  79. }\
  80. } while(FALSE)
  81. #endif
  82. LRESULT CChooseFileNamePage::DoWizardNext(LRESULT id)
  83. {
  84. if (id != 1)
  85. {
  86. ASSERT(m_pOutFileName != NULL);
  87. *m_pOutFileName = m_FileName;
  88. }
  89. else
  90. {
  91. UpdateData(FALSE);
  92. SetWizardButtons(PSWIZB_BACK);
  93. GetDlgItem(IDC_FILE_NAME)->SendMessage(EM_SETSEL, 0, -1);
  94. GetDlgItem(IDC_FILE_NAME)->SetFocus();
  95. MessageBeep(MB_ICONQUESTION);
  96. }
  97. return id;
  98. }
  99. BOOL CChooseFileNamePage::OnSetActive()
  100. {
  101. SetWizardButtons(m_FileName.IsEmpty() ?
  102. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  103. return CIISWizardPage::OnSetActive();
  104. }
  105. BEGIN_MESSAGE_MAP(CChooseFileNamePage, CIISWizardPage)
  106. //{{AFX_MSG_MAP(CChooseCAPage)
  107. ON_BN_CLICKED(IDC_BROWSE_BTN, OnBrowseBtn)
  108. ON_EN_CHANGE(IDC_FILE_NAME, OnChangeFileName)
  109. //}}AFX_MSG_MAP
  110. END_MESSAGE_MAP()
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CChooseCAPage message handlers
  113. void CChooseFileNamePage::OnBrowseBtn()
  114. {
  115. ASSERT(FALSE);
  116. }
  117. void CChooseFileNamePage::Browse(CString& strPath, CString& strFile)
  118. {
  119. if (strPath.IsEmpty())
  120. {
  121. ::GetCurrentDirectory(MAX_PATH, strPath.GetBuffer(MAX_PATH + 1));
  122. strPath.ReleaseBuffer();
  123. }
  124. CFileDialog fileName(IsReadFileDlg());
  125. fileName.m_ofn.Flags |= OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT;
  126. if (IsReadFileDlg())
  127. fileName.m_ofn.Flags |= OFN_PATHMUSTEXIST;
  128. else
  129. fileName.m_ofn.Flags |= OFN_NOREADONLYRETURN;
  130. // We need to disable hook to show new style of File Dialog
  131. fileName.m_ofn.Flags &= ~(OFN_ENABLEHOOK);
  132. CString strExt = _T("*");
  133. strExt += ext;
  134. fileName.m_ofn.lpstrDefExt = strExt;
  135. fileName.m_ofn.lpstrFile = strFile.GetBuffer(MAX_PATH+1);
  136. fileName.m_ofn.nMaxFile = MAX_PATH;
  137. fileName.m_ofn.lpstrInitialDir = strPath.IsEmpty() ? NULL : (LPCTSTR)strPath;
  138. fileName.m_ofn.lpstrFilter = filter;
  139. fileName.m_ofn.nFilterIndex = 0;
  140. if (IDOK == fileName.DoModal())
  141. {
  142. ASSERT(NULL != GetDlgItem(IDC_FILE_NAME));
  143. CString strPrev;
  144. GetDlgItemText(IDC_FILE_NAME, strPrev);
  145. if (strPrev.CompareNoCase(strFile) != 0)
  146. {
  147. SetDlgItemText(IDC_FILE_NAME, strFile);
  148. m_DoReplaceFile = TRUE;
  149. FileNameChanged();
  150. }
  151. }
  152. strFile.ReleaseBuffer();
  153. }
  154. BOOL CChooseFileNamePage::OnInitDialog()
  155. {
  156. CIISWizardPage::OnInitDialog();
  157. if ( (this != NULL) && (this->m_hWnd != NULL) && (GetDlgItem(IDC_FILE_NAME) != NULL) )
  158. {
  159. SHAutoComplete(GetDlgItem(IDC_FILE_NAME)->m_hWnd, SHACF_FILESYSTEM);
  160. GetDlgItem(IDC_FILE_NAME)->SetFocus();
  161. SetWizardButtons(m_FileName.IsEmpty() ? PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  162. }
  163. return FALSE;
  164. }
  165. void CChooseFileNamePage::OnChangeFileName()
  166. {
  167. UpdateData(TRUE);
  168. //
  169. // Our replacement flag is not valid now:
  170. // It may be set to TRUE only when name was entered through
  171. // FileOpen dialog box which asks user about replacing itself
  172. //
  173. m_DoReplaceFile = FALSE;
  174. SetWizardButtons(m_FileName.IsEmpty() ?
  175. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  176. // call virtual handler to notify inherited classes
  177. FileNameChanged();
  178. }
  179. BOOL IsValidFilenameChar(TCHAR cChar)
  180. {
  181. switch (PathGetCharType((TCHAR)cChar))
  182. {
  183. case GCT_INVALID:
  184. case GCT_WILD:
  185. case GCT_SEPARATOR:
  186. return FALSE;
  187. case GCT_LFNCHAR:
  188. case GCT_SHORTCHAR:
  189. break;
  190. }
  191. return TRUE;
  192. }
  193. CString GimmieValidFilenameFromString(LPCTSTR path)
  194. {
  195. CString str;
  196. // remove all bad characters
  197. // remove forward slashes
  198. // remove commas, semicolons...
  199. str = _T("");
  200. UINT len = lstrlen(path);
  201. TCHAR c = _T('');
  202. for (UINT i = 0; i < len; i++)
  203. {
  204. c = path[i];
  205. if (c != _T('\"'))
  206. {
  207. if (TRUE == IsValidFilenameChar(c))
  208. {
  209. str = str + c;
  210. }
  211. }
  212. }
  213. return str;
  214. }
  215. void
  216. CChooseFileNamePage::GetDefaultFileName(CString& str)
  217. {
  218. if (m_defaultID != 0)
  219. {
  220. // check for special type of file
  221. // which includes a %s string...
  222. if (m_defaultID == IDS_PFX_FILE_DEFAULT)
  223. {
  224. CString str1;
  225. str1.LoadString(m_defaultID);
  226. if (str1.Find(_T("%s")) != -1)
  227. {
  228. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  229. DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
  230. if (GetComputerName(szComputerName, &dwSize))
  231. {
  232. CString csOurFileName;
  233. csOurFileName = szComputerName;
  234. // m_AdditionalInfo should contain
  235. // /LM/W3SVC/1 at this point
  236. // let's make a filename from it.
  237. if (m_AdditionalInfo.GetLength() >= 4)
  238. {
  239. CString key_path_lm = SZ_MBN_SEP_STR SZ_MBN_MACHINE SZ_MBN_SEP_STR;
  240. if (m_AdditionalInfo.Left(4) == key_path_lm)
  241. {
  242. m_AdditionalInfo = m_AdditionalInfo.Right(m_AdditionalInfo.GetLength() - 4);
  243. }
  244. else
  245. {
  246. key_path_lm = SZ_MBN_MACHINE SZ_MBN_SEP_STR;
  247. if (m_AdditionalInfo.Left(3) == key_path_lm)
  248. {
  249. m_AdditionalInfo = m_AdditionalInfo.Right(m_AdditionalInfo.GetLength() - 3);
  250. }
  251. }
  252. }
  253. csOurFileName = csOurFileName + _T("_") + GimmieValidFilenameFromString(m_AdditionalInfo);
  254. // add on other things...
  255. str.Format(str1, csOurFileName);
  256. }
  257. else
  258. {
  259. str.Format(str1, _T("1"));
  260. }
  261. }
  262. else
  263. {
  264. str.LoadString(m_defaultID);
  265. }
  266. }
  267. else
  268. {
  269. str.LoadString(m_defaultID);
  270. }
  271. }
  272. // set system disk letter to the string
  273. TCHAR sz[MAX_PATH];
  274. if (MAX_PATH >= GetSystemDirectory(sz, MAX_PATH))
  275. {
  276. str.SetAt(0, sz[0]);
  277. str.MakeLower();
  278. }
  279. }
  280. /////////////////////////////////////////////////////////////////////////////
  281. // CChooseReadFileName property page
  282. IMPLEMENT_DYNCREATE(CChooseReadFileName, CChooseFileNamePage)
  283. CChooseReadFileName::CChooseReadFileName(UINT id,
  284. UINT defaultID,
  285. UINT extID,
  286. UINT filterID,
  287. CString * pOutFileName,
  288. CString csAdditionalInfo
  289. )
  290. : CChooseFileNamePage(id, defaultID, extID, filterID, pOutFileName, csAdditionalInfo)
  291. {
  292. }
  293. BEGIN_MESSAGE_MAP(CChooseReadFileName, CChooseFileNamePage)
  294. //{{AFX_MSG_MAP(CChooseReadFileName)
  295. ON_BN_CLICKED(IDC_BROWSE_BTN, OnBrowseBtn)
  296. //}}AFX_MSG_MAP
  297. END_MESSAGE_MAP()
  298. BOOL
  299. CChooseReadFileName::OnInitDialog()
  300. {
  301. GetDefaultFileName(m_FileName);
  302. // check if this default file exists
  303. if (!PathFileExists(m_FileName))
  304. {
  305. // try to find first file with this extension
  306. CString find_str = m_FileName;
  307. WIN32_FIND_DATA find_data;
  308. PathRemoveFileSpec(find_str.GetBuffer(MAX_PATH));
  309. find_str.ReleaseBuffer();
  310. find_str += _T("*");
  311. find_str += ext;
  312. HANDLE hFind = FindFirstFile(find_str, &find_data);
  313. if ( hFind != INVALID_HANDLE_VALUE
  314. && (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0
  315. )
  316. {
  317. PathRemoveFileSpec(m_FileName.GetBuffer(MAX_PATH));
  318. m_FileName.ReleaseBuffer();
  319. m_FileName += find_data.cFileName;
  320. FindClose(hFind);
  321. }
  322. else
  323. {
  324. // if nothing found, just attach *.exe to the path
  325. // it will prevent user from just clicking Next
  326. m_FileName = find_str;
  327. }
  328. }
  329. return CChooseFileNamePage::OnInitDialog();
  330. }
  331. LRESULT
  332. CChooseReadFileName::OnWizardNext()
  333. {
  334. LRESULT id = 0;
  335. CString buf;
  336. UpdateData();
  337. // check if this file exists
  338. if ( !PathFileExists(m_FileName)
  339. && !PathIsDirectory(m_FileName)
  340. )
  341. {
  342. // try with default extension if it is just filename
  343. CString str = m_FileName;
  344. LPTSTR p = PathFindExtension(str);
  345. if (p != NULL && *p == 0)
  346. {
  347. str += ext;
  348. if (PathFileExists(str))
  349. {
  350. m_FileName = str;
  351. goto DoNext;
  352. }
  353. }
  354. AfxFormatString1(buf, IDS_FILE_DOES_NOT_EXIST, m_FileName);
  355. AfxMessageBox(buf, MB_OK);
  356. id = 1;
  357. }
  358. else if (PathIsDirectory(m_FileName))
  359. {
  360. AfxFormatString1(buf, IDS_FILE_IS_DIRECTORY, m_FileName);
  361. AfxMessageBox(buf, MB_OK);
  362. if (m_FileName.Right(1) != L'\\')
  363. m_FileName += _T("\\");
  364. id = 1;
  365. }
  366. DoNext:
  367. return DoWizardNext(id);
  368. }
  369. void CChooseReadFileName::OnBrowseBtn()
  370. {
  371. CString strFile, strPath;
  372. GetDlgItemText(IDC_FILE_NAME, m_FileName);
  373. if (!PathFileExists(m_FileName))
  374. {
  375. int n = m_FileName.ReverseFind(_T('\\'));
  376. if (n != -1)
  377. {
  378. strPath = m_FileName.Left(n);
  379. if (!PathFileExists(strPath))
  380. {
  381. strPath.Empty();
  382. strFile = m_FileName.Right(m_FileName.GetLength() - n - 1);
  383. }
  384. else if (PathIsDirectory(strPath))
  385. {
  386. strFile = m_FileName.Right(m_FileName.GetLength() - n - 1);
  387. }
  388. }
  389. else
  390. strFile = m_FileName;
  391. }
  392. else if (PathIsDirectory(m_FileName))
  393. {
  394. strPath = m_FileName;
  395. }
  396. else
  397. {
  398. // split filename and path
  399. strPath = m_FileName;
  400. PathRemoveFileSpec(strPath.GetBuffer(0));
  401. strPath.ReleaseBuffer();
  402. strFile = PathFindFileName(m_FileName);
  403. }
  404. CChooseFileNamePage::Browse(strPath, strFile);
  405. }
  406. /////////////////////////////////////////////////////////////////////////////
  407. // CChooseWriteFileName
  408. IMPLEMENT_DYNCREATE(CChooseWriteFileName, CChooseFileNamePage)
  409. CChooseWriteFileName::CChooseWriteFileName(UINT id,
  410. UINT defaultID,
  411. UINT extID,
  412. UINT filterID,
  413. CString * pOutFileName,
  414. CString csAdditionalInfo
  415. )
  416. : CChooseFileNamePage(id, defaultID, extID, filterID, pOutFileName, csAdditionalInfo)
  417. {
  418. }
  419. BEGIN_MESSAGE_MAP(CChooseWriteFileName, CChooseFileNamePage)
  420. //{{AFX_MSG_MAP(CChooseWriteFileName)
  421. ON_BN_CLICKED(IDC_BROWSE_BTN, OnBrowseBtn)
  422. //}}AFX_MSG_MAP
  423. END_MESSAGE_MAP()
  424. BOOL
  425. CChooseWriteFileName::OnInitDialog()
  426. {
  427. GetDefaultFileName(m_FileName);
  428. return CChooseFileNamePage::OnInitDialog();
  429. }
  430. LRESULT
  431. CChooseWriteFileName::OnWizardNext()
  432. {
  433. LRESULT id = 0;
  434. UpdateData();
  435. CString fileName = m_FileName, strPathOnly;
  436. if (FALSE == IsValidPathFileName(fileName))
  437. {
  438. id = 1;
  439. goto ExitPoint;
  440. }
  441. if (PathIsURL(fileName))
  442. {
  443. // we cannot use URLs
  444. id = 1;
  445. goto ExitPoint;
  446. }
  447. if (PathIsUNC(fileName))
  448. {
  449. if (PathIsUNCServer(fileName))
  450. {
  451. // path is incomplete
  452. id = 1;
  453. goto ExitPoint;
  454. }
  455. if (PathIsUNCServerShare(fileName))
  456. {
  457. // path is incomplete
  458. id = 1;
  459. goto ExitPoint;
  460. }
  461. }
  462. // If it is not an UNC, then make sure we have absolute path
  463. else if (PathIsRelative(fileName))
  464. {
  465. // We will make path from default drive root,
  466. // not from current directory
  467. CString path;
  468. if (0 != GetCurrentDirectory(MAX_PATH, path.GetBuffer(MAX_PATH)))
  469. {
  470. TCHAR szRoot[5];
  471. fileName = PathBuildRoot(szRoot, PathGetDriveNumber(path));
  472. PathAppend(fileName.GetBuffer(MAX_PATH), m_FileName);
  473. fileName.ReleaseBuffer();
  474. }
  475. else
  476. ASSERT(FALSE);
  477. }
  478. // Check if we already have file with this name
  479. if (PathFileExists(fileName))
  480. {
  481. // if it is directory, do nothing, file spec is incomplete
  482. if (PathIsDirectory(fileName))
  483. id = 1;
  484. else
  485. {
  486. if (!m_DoReplaceFile)
  487. id = AnswerIsYes(IDS_REPLACE_FILE, fileName) ? 0 : 1;
  488. }
  489. goto ExitPoint;
  490. }
  491. // File does not exists
  492. //
  493. // we should check, if target directory exists
  494. strPathOnly = fileName;
  495. if (strPathOnly.Right(1) != _T('\\'))
  496. {
  497. if (PathRemoveFileSpec(strPathOnly.GetBuffer(MAX_PATH)))
  498. {
  499. if (PathIsUNCServerShare(strPathOnly))
  500. {
  501. // check if we have write access to this
  502. if (GetFileAttributes(strPathOnly) & FILE_ATTRIBUTE_READONLY)
  503. {
  504. id = 1;
  505. goto ExitPoint;
  506. }
  507. }
  508. if (!PathIsDirectory(strPathOnly))
  509. {
  510. id = AnswerIsYes(IDS_ASK_CREATE_DIR, strPathOnly) ? 0 : 1;
  511. goto ExitPoint;
  512. }
  513. }
  514. strPathOnly.ReleaseBuffer();
  515. // If user entered filename with dot only (qqqq.) it means
  516. // that no extension should be used
  517. if (fileName.Right(1) == _T("."))
  518. {
  519. // remove this dot and check if this file exists
  520. fileName.ReleaseBuffer(fileName.GetLength() - 1);
  521. if (PathIsDirectory(fileName))
  522. {
  523. id = 1;
  524. }
  525. else if (PathFileExists(fileName))
  526. {
  527. id = AnswerIsYes(IDS_REPLACE_FILE, fileName) ? 0 : 1;
  528. }
  529. goto ExitPoint;
  530. }
  531. }
  532. else
  533. {
  534. // not clear, what to do with this
  535. id = 1;
  536. goto ExitPoint;
  537. }
  538. // It could be just a file name, without extension, try
  539. // with default extension now
  540. if (PathFindExtension(fileName) == NULL)
  541. {
  542. fileName += ext;
  543. if (PathIsDirectory(fileName))
  544. {
  545. id = 1;
  546. }
  547. else if (PathFileExists(fileName))
  548. {
  549. id = AnswerIsYes(IDS_REPLACE_FILE, fileName) ? 0 : 1;
  550. }
  551. goto ExitPoint;
  552. }
  553. ExitPoint:
  554. fileName.MakeLower();
  555. m_FileName = fileName;
  556. // prepare to go to the next page
  557. return DoWizardNext(id);
  558. }
  559. // I try to start FileOpen dialog in some reasonable directory
  560. //
  561. void CChooseWriteFileName::OnBrowseBtn()
  562. {
  563. CString strPath, strFile;
  564. UpdateData();
  565. strPath = m_FileName;
  566. if (!PathIsDirectory(strPath))
  567. {
  568. LPTSTR pPath = strPath.GetBuffer(strPath.GetLength());
  569. if (PathRemoveFileSpec(pPath))
  570. {
  571. // check if path part of filename exists
  572. if (PathIsDirectory(pPath))
  573. {
  574. // we will use non-path part of spec as a filename
  575. strFile = PathFindFileName(m_FileName);
  576. }
  577. else
  578. {
  579. // it is wrong path, use default one
  580. // TODO: actually I need to take from filespec all existent
  581. // chunks of path and filename, for example c:\aa\bb\cc\dd.txt,
  582. // if c:\aa\bb exists, then strPath should be set to c:\aa\bb,
  583. // and strFile to dd.txt
  584. strPath.Empty();
  585. }
  586. }
  587. else
  588. {
  589. // it is filename only
  590. strFile = m_FileName;
  591. strPath.Empty();
  592. }
  593. strPath.ReleaseBuffer();
  594. }
  595. CChooseFileNamePage::Browse(strPath, strFile);
  596. }
  597. /////////////////////////////////////////////////////////////////////////////
  598. // CChooseRespFile property page
  599. IMPLEMENT_DYNCREATE(CChooseRespFile, CChooseFileNamePage)
  600. CChooseRespFile::CChooseRespFile(CCertificate * pCert)
  601. : CChooseReadFileName(CChooseRespFile::IDD,
  602. IDS_RESP_FILE_DEFAULT,
  603. IDS_RESP_FILE_EXT,
  604. IDS_RESP_FILE_FILTER,
  605. &pCert->m_RespFileName,
  606. pCert->m_WebSiteInstanceName
  607. ),
  608. m_pCert(pCert)
  609. {
  610. //{{AFX_DATA_INIT(CChooseRespFile)
  611. // NOTE: the ClassWizard will add member initialization here
  612. //}}AFX_DATA_INIT
  613. }
  614. CChooseRespFile::~CChooseRespFile()
  615. {
  616. }
  617. void CChooseRespFile::FileNameChanged()
  618. {
  619. // we should remove any error messages now
  620. SetDlgItemText(IDC_ERROR_MSG, _T(""));
  621. GetDlgItem(IDC_ERROR_MSG)->InvalidateRect(NULL, TRUE);
  622. GetDlgItem(IDC_ERROR_MSG)->UpdateWindow();
  623. }
  624. void CChooseRespFile::DoDataExchange(CDataExchange* pDX)
  625. {
  626. CChooseReadFileName::DoDataExchange(pDX);
  627. //{{AFX_DATA_MAP(CChooseRespFile)
  628. //}}AFX_DATA_MAP
  629. }
  630. BEGIN_MESSAGE_MAP(CChooseRespFile, CChooseReadFileName)
  631. //{{AFX_MSG_MAP(CChooseRespFile)
  632. ON_WM_CTLCOLOR()
  633. //}}AFX_MSG_MAP
  634. END_MESSAGE_MAP()
  635. /////////////////////////////////////////////////////////////////////////////
  636. // CChooseRespFile message handlers
  637. HBRUSH
  638. CChooseRespFile::OnCtlColor(
  639. IN CDC * pDC,
  640. IN CWnd * pWnd,
  641. IN UINT nCtlColor
  642. )
  643. {
  644. if (pWnd->GetDlgCtrlID() == IDC_ERROR_MSG)
  645. {
  646. //
  647. // Default processing...
  648. //
  649. return CPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
  650. }
  651. else
  652. return CIISWizardPage::OnCtlColor(pDC, pWnd, nCtlColor);
  653. }
  654. LRESULT CChooseRespFile::OnWizardNext()
  655. {
  656. LRESULT id = 1;
  657. // Parent class will check all about files
  658. if (1 != CChooseReadFileName::OnWizardNext())
  659. {
  660. m_pCert->m_RespFileName = m_FileName;
  661. if (m_pCert->GetResponseCert() == NULL)
  662. {
  663. CString strInstanceName;
  664. CString str;
  665. // it is possible, that this is wrong response file
  666. // we will try to inform user, for which site this response
  667. // file was created
  668. if (m_pCert->FindInstanceNameForResponse(strInstanceName))
  669. {
  670. AfxFormatString1(str, IDS_CERTKEY_MISMATCH_ERROR1, strInstanceName);
  671. }
  672. // it is possible that this certificate response file already have been processed
  673. // in this case it should be in MY store
  674. else if (m_pCert->IsResponseInstalled(strInstanceName))
  675. {
  676. if (!strInstanceName.IsEmpty())
  677. AfxFormatString1(str,
  678. IDS_CERTKEY_ALREADY_INSTALLED_WHERE, strInstanceName);
  679. else
  680. str.LoadString(IDS_CERTKEY_ALREADY_INSTALLED);
  681. }
  682. else
  683. {
  684. // request probably was canceled
  685. str.LoadString(IDS_CERTKEY_MISMATCH_ERROR2);
  686. }
  687. SetDlgItemText(IDC_ERROR_MSG, str);
  688. SetWizardButtons(PSWIZB_BACK);
  689. }
  690. else
  691. {
  692. id = IDD_PAGE_NEXT;
  693. #ifdef ENABLE_W3SVC_SSL_PAGE
  694. if (IsWebServerType(m_pCert->m_WebSiteInstanceName))
  695. {
  696. id = IDD_PAGE_NEXT_INSTALL_W3SVC_ONLY;
  697. }
  698. #endif
  699. }
  700. }
  701. return id;
  702. }
  703. LRESULT
  704. CChooseRespFile::OnWizardBack()
  705. {
  706. return IDD_PAGE_PREV;
  707. }
  708. /////////////////////////////////////////////////////////////////////////////
  709. // CChooseReqFile property page
  710. IMPLEMENT_DYNCREATE(CChooseReqFile, CChooseWriteFileName)
  711. CChooseReqFile::CChooseReqFile(CCertificate * pCert)
  712. : CChooseWriteFileName(CChooseReqFile::IDD,
  713. IDS_REQ_FILE_DEFAULT,
  714. IDS_REQ_FILE_EXT,
  715. IDS_REQ_FILE_FILTER,
  716. &pCert->m_ReqFileName,
  717. pCert->m_WebSiteInstanceName
  718. ),
  719. m_pCert(pCert)
  720. {
  721. //{{AFX_DATA_INIT(CChooseRespFile)
  722. //}}AFX_DATA_INIT
  723. }
  724. CChooseReqFile::~CChooseReqFile()
  725. {
  726. }
  727. void CChooseReqFile::DoDataExchange(CDataExchange* pDX)
  728. {
  729. CChooseWriteFileName::DoDataExchange(pDX);
  730. //{{AFX_DATA_MAP(CChooseRespFile)
  731. //}}AFX_DATA_MAP
  732. }
  733. LRESULT
  734. CChooseReqFile::OnWizardBack()
  735. {
  736. return IDD_PAGE_PREV;
  737. }
  738. LRESULT
  739. CChooseReqFile::OnWizardNext()
  740. {
  741. if (CChooseWriteFileName::OnWizardNext() != 1)
  742. return IDD_PAGE_NEXT;
  743. return 1;
  744. }
  745. BEGIN_MESSAGE_MAP(CChooseReqFile, CChooseWriteFileName)
  746. //{{AFX_MSG_MAP(CChooseReqFile)
  747. //}}AFX_MSG_MAP
  748. END_MESSAGE_MAP()
  749. /////////////////////////////////////////////////////////////////////////////
  750. // CChooseReqFile property page
  751. IMPLEMENT_DYNCREATE(CChooseReqFileRenew, CChooseWriteFileName)
  752. CChooseReqFileRenew::CChooseReqFileRenew(CCertificate * pCert)
  753. : CChooseWriteFileName(CChooseReqFileRenew::IDD,
  754. IDS_REQ_FILE_DEFAULT,
  755. IDS_REQ_FILE_EXT,
  756. IDS_REQ_FILE_FILTER,
  757. &pCert->m_ReqFileName,
  758. pCert->m_WebSiteInstanceName
  759. ),
  760. m_pCert(pCert)
  761. {
  762. //{{AFX_DATA_INIT(CChooseRespFile)
  763. //}}AFX_DATA_INIT
  764. }
  765. CChooseReqFileRenew::~CChooseReqFileRenew()
  766. {
  767. }
  768. void CChooseReqFileRenew::DoDataExchange(CDataExchange* pDX)
  769. {
  770. CChooseWriteFileName::DoDataExchange(pDX);
  771. //{{AFX_DATA_MAP(CChooseRespFile)
  772. //}}AFX_DATA_MAP
  773. }
  774. LRESULT
  775. CChooseReqFileRenew::OnWizardBack()
  776. {
  777. return IDD_PAGE_PREV;
  778. }
  779. LRESULT
  780. CChooseReqFileRenew::OnWizardNext()
  781. {
  782. if (CChooseWriteFileName::OnWizardNext() != 1)
  783. return IDD_PAGE_NEXT;
  784. return 1;
  785. }
  786. BEGIN_MESSAGE_MAP(CChooseReqFileRenew, CChooseWriteFileName)
  787. //{{AFX_MSG_MAP(CChooseReqFileRenew)
  788. //}}AFX_MSG_MAP
  789. END_MESSAGE_MAP()
  790. /////////////////////////////////////////////////////////////////////////////
  791. // CChooseReqFileRenew message handlers
  792. /////////////////////////////////////////////////////////////////////////////
  793. // CChooseKeyFile property page
  794. IMPLEMENT_DYNCREATE(CChooseKeyFile, CChooseReadFileName)
  795. CChooseKeyFile::CChooseKeyFile(CCertificate * pCert)
  796. : CChooseReadFileName(CChooseKeyFile::IDD,
  797. IDS_KEY_FILE_DEFAULT,
  798. IDS_KEY_FILE_EXT,
  799. IDS_KEY_FILE_FILTER,
  800. &pCert->m_KeyFileName,
  801. pCert->m_WebSiteInstanceName),
  802. m_pCert(pCert)
  803. {
  804. }
  805. CChooseKeyFile::~CChooseKeyFile()
  806. {
  807. }
  808. void CChooseKeyFile::DoDataExchange(CDataExchange* pDX)
  809. {
  810. CChooseReadFileName::DoDataExchange(pDX);
  811. //{{AFX_DATA_MAP(CChooseRespFile)
  812. //}}AFX_DATA_MAP
  813. }
  814. LRESULT
  815. CChooseKeyFile::OnWizardBack()
  816. {
  817. return IDD_PAGE_PREV;
  818. }
  819. LRESULT
  820. CChooseKeyFile::OnWizardNext()
  821. {
  822. CString strFileName = m_pCert->m_KeyFileName;
  823. if (CChooseReadFileName::OnWizardNext() != 1)
  824. {
  825. // if file name was changed then probably password is wrong now
  826. // and if cert context was imported before -- it is also invalid
  827. //
  828. if (m_pCert->m_KeyFileName.CompareNoCase(strFileName))
  829. {
  830. m_pCert->m_KeyPassword.Empty();
  831. m_pCert->DeleteKeyRingCert();
  832. }
  833. return IDD_PAGE_NEXT;
  834. }
  835. return 1;
  836. }
  837. BEGIN_MESSAGE_MAP(CChooseKeyFile, CChooseReadFileName)
  838. //{{AFX_MSG_MAP(CChooseKeyFile)
  839. //}}AFX_MSG_MAP
  840. END_MESSAGE_MAP()
  841. /////////////////////////////////////////////////////////////////////////////
  842. // CChooseImportPFXFile property page
  843. IMPLEMENT_DYNCREATE(CChooseImportPFXFile, CChooseReadFileName)
  844. CChooseImportPFXFile::CChooseImportPFXFile(CCertificate * pCert)
  845. : CChooseReadFileName(CChooseImportPFXFile::IDD,
  846. IDS_PFX_FILE_DEFAULT,
  847. IDS_PFX_FILE_EXT,
  848. IDS_PFX_FILE_FILTER,
  849. &pCert->m_KeyFileName,
  850. pCert->m_WebSiteInstanceName),
  851. m_pCert(pCert)
  852. {
  853. //{{AFX_DATA_INIT(CChooseImportPFXFile)
  854. m_MarkAsExportable = FALSE;
  855. //}}AFX_DATA_INIT
  856. }
  857. CChooseImportPFXFile::~CChooseImportPFXFile()
  858. {
  859. }
  860. void CChooseImportPFXFile::DoDataExchange(CDataExchange* pDX)
  861. {
  862. CChooseReadFileName::DoDataExchange(pDX);
  863. //{{AFX_DATA_MAP(CChooseImportPFXFile)
  864. DDX_Check(pDX, IDC_MARK_AS_EXPORTABLE, m_MarkAsExportable);
  865. //}}AFX_DATA_MAP
  866. }
  867. LRESULT
  868. CChooseImportPFXFile::OnWizardBack()
  869. {
  870. return IDD_PAGE_PREV;
  871. }
  872. LRESULT
  873. CChooseImportPFXFile::OnWizardNext()
  874. {
  875. m_pCert->m_MarkAsExportable = m_MarkAsExportable;
  876. CString strFileName = m_pCert->m_KeyFileName;
  877. if (CChooseReadFileName::OnWizardNext() != 1)
  878. {
  879. /*
  880. // if file name was changed then probably password is wrong now
  881. // and if cert context was imported before -- it is also invalid
  882. //
  883. if (m_pCert->m_KeyFileName.CompareNoCase(strFileName))
  884. {
  885. m_pCert->m_KeyPassword.Empty();
  886. m_pCert->DeleteKeyRingCert();
  887. }
  888. */
  889. return IDD_PAGE_NEXT;
  890. }
  891. return 1;
  892. }
  893. void CChooseImportPFXFile::OnExportable()
  894. {
  895. UpdateData();
  896. }
  897. BEGIN_MESSAGE_MAP(CChooseImportPFXFile, CChooseReadFileName)
  898. //{{AFX_MSG_MAP(CChooseImportPFXFile)
  899. ON_BN_CLICKED(IDC_MARK_AS_EXPORTABLE, OnExportable)
  900. //}}AFX_MSG_MAP
  901. END_MESSAGE_MAP()
  902. /////////////////////////////////////////////////////////////////////////////
  903. // CChooseExportPFXFile property page
  904. IMPLEMENT_DYNCREATE(CChooseExportPFXFile, CChooseWriteFileName)
  905. CChooseExportPFXFile::CChooseExportPFXFile(CCertificate * pCert)
  906. : CChooseWriteFileName(CChooseExportPFXFile::IDD,
  907. IDS_PFX_FILE_DEFAULT,
  908. IDS_PFX_FILE_EXT,
  909. IDS_PFX_FILE_FILTER,
  910. &pCert->m_KeyFileName,
  911. pCert->m_WebSiteInstanceName
  912. ),
  913. m_pCert(pCert)
  914. {
  915. //{{AFX_DATA_INIT(CChooseExportPFXFile)
  916. //}}AFX_DATA_INIT
  917. }
  918. CChooseExportPFXFile::~CChooseExportPFXFile()
  919. {
  920. }
  921. void CChooseExportPFXFile::DoDataExchange(CDataExchange* pDX)
  922. {
  923. CChooseWriteFileName::DoDataExchange(pDX);
  924. //{{AFX_DATA_MAP(CChooseExportPFXFile)
  925. //}}AFX_DATA_MAP
  926. }
  927. LRESULT
  928. CChooseExportPFXFile::OnWizardBack()
  929. {
  930. return IDD_PAGE_PREV;
  931. }
  932. LRESULT
  933. CChooseExportPFXFile::OnWizardNext()
  934. {
  935. if (CChooseWriteFileName::OnWizardNext() != 1)
  936. {
  937. // Check if the file they want to save to is on a FAT drive and thus unprotected.
  938. CString strComputerName;
  939. DWORD cch = MAX_COMPUTERNAME_LENGTH + 1;
  940. BOOL bAnswer;
  941. // get the actual name of the local machine
  942. bAnswer = GetComputerName(strComputerName.GetBuffer(cch), &cch);
  943. strComputerName.ReleaseBuffer();
  944. if (bAnswer)
  945. {
  946. CString strPath;
  947. CString strInQuestion = m_pCert->m_KeyFileName;
  948. GetFullPathLocalOrRemote(strComputerName, strInQuestion, strPath);
  949. if (!SupportsSecurityACLs(strPath))
  950. {
  951. ::AfxMessageBox(IDS_FAT_DRIVE_WARNING);
  952. }
  953. }
  954. return IDD_PAGE_NEXT;
  955. }
  956. return 1;
  957. }
  958. BEGIN_MESSAGE_MAP(CChooseExportPFXFile, CChooseWriteFileName)
  959. //{{AFX_MSG_MAP(CChooseExportPFXFile)
  960. //}}AFX_MSG_MAP
  961. END_MESSAGE_MAP()