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.

304 lines
7.0 KiB

  1. #include "stdafx.h"
  2. #include "CertWiz.h"
  3. #include "SSLPortPage.h"
  4. #include "Certificat.h"
  5. #include "certutil.h"
  6. #include "strutil.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. #define DEFAULT_SSL_PORT _T("443")
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CSSLPortPage property page
  15. void AFXAPI
  16. DDXV_UINT(
  17. IN CDataExchange * pDX,
  18. IN UINT nID,
  19. IN OUT UINT & uValue,
  20. IN UINT uMin,
  21. IN UINT uMax,
  22. IN UINT nEmptyErrorMsg OPTIONAL
  23. )
  24. /*++
  25. Routine Description:
  26. DDX/DDV Function that uses a space to denote a 0 value
  27. Arguments:
  28. CDataExchange * pDX : Data exchange object
  29. UINT nID : Resource ID
  30. OUT UINT & uValue : Value
  31. UINT uMin : Minimum value
  32. UINT uMax : Maximum value
  33. UINT nEmptyErrorMsg : Error message ID for empty unit, or 0 if empty OK
  34. Return Value:
  35. None.
  36. --*/
  37. {
  38. ASSERT(uMin <= uMax);
  39. CWnd * pWnd = CWnd::FromHandle(pDX->PrepareEditCtrl(nID));
  40. ASSERT(pWnd != NULL);
  41. if (pDX->m_bSaveAndValidate)
  42. {
  43. if (pWnd->GetWindowTextLength() > 0)
  44. {
  45. // this needs to come before DDX_TextBalloon
  46. DDV_MinMaxBalloon(pDX, nID, uMin, uMax);
  47. DDX_TextBalloon(pDX, nID, uValue);
  48. }
  49. else
  50. {
  51. uValue = 0;
  52. if (nEmptyErrorMsg)
  53. {
  54. DDV_ShowBalloonAndFail(pDX, nEmptyErrorMsg);
  55. }
  56. }
  57. }
  58. else
  59. {
  60. if (uValue != 0)
  61. {
  62. DDX_TextBalloon(pDX, nID, uValue);
  63. }
  64. else
  65. {
  66. pWnd->SetWindowText(_T(""));
  67. }
  68. }
  69. }
  70. IMPLEMENT_DYNCREATE(CSSLPortPage, CIISWizardPage)
  71. CSSLPortPage::CSSLPortPage(CCertificate * pCert)
  72. : CIISWizardPage(CSSLPortPage::IDD, IDS_CERTWIZ, TRUE),
  73. m_pCert(pCert)
  74. {
  75. //{{AFX_DATA_INIT(CSSLPortPage)
  76. m_SSLPort = _T("");
  77. //}}AFX_DATA_INIT
  78. IDD_PAGE_PREV = IDD_PAGE_WIZ_CHOOSE_CERT;
  79. IDD_PAGE_NEXT = IDD_PAGE_WIZ_INSTALL_CERT;
  80. }
  81. CSSLPortPage::~CSSLPortPage()
  82. {
  83. }
  84. BOOL CSSLPortPage::OnInitDialog()
  85. {
  86. CIISWizardPage::OnInitDialog();
  87. // If m_SSLPort is empty, then look it up from the metabase...
  88. if (m_SSLPort.IsEmpty())
  89. {
  90. HRESULT hr = 0;
  91. if (m_pCert)
  92. {
  93. GetSSLPortFromSite(m_pCert->m_MachineName,m_pCert->m_WebSiteInstanceName,m_pCert->m_SSLPort,&hr);
  94. }
  95. }
  96. return FALSE;
  97. }
  98. void CSSLPortPage::DoDataExchange(CDataExchange* pDX)
  99. {
  100. CIISWizardPage::DoDataExchange(pDX);
  101. //{{AFX_DATA_MAP(CSSLPortPage)
  102. DDX_Text(pDX, IDC_SSL_PORT, m_SSLPort);
  103. DDV_MaxChars(pDX, m_SSLPort, 32);
  104. UINT nSSLPort = StrToInt(m_SSLPort);
  105. DDXV_UINT(pDX, IDC_SSL_PORT, nSSLPort, 1, 65535, IDS_NO_PORT);
  106. //}}AFX_DATA_MAP
  107. }
  108. LRESULT
  109. CSSLPortPage::OnWizardBack()
  110. /*++
  111. Routine Description:
  112. Prev button handler
  113. Arguments:
  114. None
  115. Return Value:
  116. 0 to automatically advance to the prev page;
  117. 1 to prevent the page from changing.
  118. To jump to a page other than the prev one,
  119. return the identifier of the dialog to be displayed.
  120. --*/
  121. {
  122. return IDD_PAGE_PREV;
  123. }
  124. LRESULT
  125. CSSLPortPage::OnWizardNext()
  126. /*++
  127. Routine Description:
  128. Next button handler
  129. Arguments:
  130. None
  131. Return Value:
  132. 0 to automatically advance to the next page;
  133. 1 to prevent the page from changing.
  134. To jump to a page other than the next one,
  135. return the identifier of the dialog to be displayed.
  136. --*/
  137. {
  138. LRESULT lres = 1;
  139. UpdateData(TRUE);
  140. if (m_pCert)
  141. {
  142. m_pCert->m_SSLPort = m_SSLPort;
  143. }
  144. CString buf;
  145. buf.LoadString(IDS_NO_PORT);
  146. if (!IsValidPort((LPCTSTR) m_SSLPort))
  147. {
  148. GetDlgItem(IDC_SSL_PORT)->SetFocus();
  149. AfxMessageBox(buf, MB_OK);
  150. }
  151. else
  152. {
  153. // Check for if it's already being used on other port!
  154. HRESULT hr;
  155. if (TRUE == IsSSLPortBeingUsedOnNonSSLPort(m_pCert->m_MachineName,m_pCert->m_WebSiteInstanceName,m_SSLPort,&hr))
  156. {
  157. GetDlgItem(IDC_SSL_PORT)->SetFocus();
  158. buf.LoadString(IDS_PORT_ALREADY_USED);
  159. AfxMessageBox(buf, MB_OK);
  160. }
  161. else
  162. {
  163. lres = IDD_PAGE_NEXT;
  164. }
  165. }
  166. return lres;
  167. }
  168. BOOL
  169. CSSLPortPage::OnSetActive()
  170. /*++
  171. Routine Description:
  172. Activation handler
  173. We could have empty name field on entrance, so we should
  174. disable Back button
  175. Arguments:
  176. None
  177. Return Value:
  178. TRUE for success, FALSE for failure
  179. --*/
  180. {
  181. ASSERT(m_pCert != NULL);
  182. if (m_pCert)
  183. {
  184. m_SSLPort = m_pCert->m_SSLPort;
  185. switch (m_pCert->GetStatusCode())
  186. {
  187. case CCertificate::REQUEST_INSTALL_CERT:
  188. // this is valid...
  189. IDD_PAGE_PREV = IDD_PAGE_WIZ_CHOOSE_CERT;
  190. IDD_PAGE_NEXT = IDD_PAGE_WIZ_INSTALL_CERT;
  191. break;
  192. case CCertificate::REQUEST_NEW_CERT:
  193. // this is also valid....
  194. //if (m_pCert->m_CAType == CCertificate::CA_ONLINE)
  195. {
  196. IDD_PAGE_PREV = IDD_PAGE_WIZ_GEO_INFO;
  197. IDD_PAGE_NEXT = IDD_PAGE_WIZ_CHOOSE_ONLINE;
  198. }
  199. break;
  200. case CCertificate::REQUEST_PROCESS_PENDING:
  201. // this is valid too...
  202. IDD_PAGE_PREV = IDD_PAGE_WIZ_GETRESP_FILE;
  203. IDD_PAGE_NEXT = IDD_PAGE_WIZ_INSTALL_RESP;
  204. break;
  205. case CCertificate::REQUEST_IMPORT_KEYRING:
  206. // this is valid too...
  207. IDD_PAGE_PREV = IDD_PAGE_WIZ_GET_PASSWORD;
  208. IDD_PAGE_NEXT = IDD_PAGE_WIZ_INSTALL_KEYCERT;
  209. break;
  210. case CCertificate::REQUEST_IMPORT_CERT:
  211. // this is valid too...
  212. IDD_PAGE_PREV = IDD_PAGE_WIZ_GET_IMPORT_PFX_PASSWORD;
  213. IDD_PAGE_NEXT = IDD_PAGE_WIZ_INSTALL_IMPORT_PFX;
  214. break;
  215. // none of these have been implemented to show ssl port
  216. case CCertificate::REQUEST_RENEW_CERT:
  217. case CCertificate::REQUEST_REPLACE_CERT:
  218. case CCertificate::REQUEST_EXPORT_CERT:
  219. case CCertificate::REQUEST_COPY_MOVE_FROM_REMOTE:
  220. case CCertificate::REQUEST_COPY_MOVE_TO_REMOTE:
  221. default:
  222. IDD_PAGE_PREV = IDD_PAGE_WIZ_CHOOSE_CERT;
  223. IDD_PAGE_NEXT = IDD_PAGE_WIZ_INSTALL_CERT;
  224. break;
  225. }
  226. }
  227. if (m_SSLPort.IsEmpty())
  228. {
  229. m_SSLPort = DEFAULT_SSL_PORT;
  230. }
  231. UpdateData(FALSE);
  232. SetWizardButtons(m_SSLPort.IsEmpty() ?
  233. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  234. return CIISWizardPage::OnSetActive();
  235. }
  236. BOOL
  237. CSSLPortPage::OnKillActive()
  238. /*++
  239. Routine Description:
  240. Activation handler
  241. We could leave this page only if we have good names
  242. entered or when Back button is clicked. In both cases
  243. we should enable both buttons
  244. Arguments:
  245. None
  246. Return Value:
  247. TRUE for success, FALSE for failure
  248. --*/
  249. {
  250. SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
  251. return CIISWizardPage::OnSetActive();
  252. }
  253. BEGIN_MESSAGE_MAP(CSSLPortPage, CIISWizardPage)
  254. //{{AFX_MSG_MAP(CSSLPortPage)
  255. ON_EN_CHANGE(IDC_SSL_PORT, OnEditChangeSSLPort)
  256. //}}AFX_MSG_MAP
  257. END_MESSAGE_MAP()
  258. /////////////////////////////////////////////////////////////////////////////
  259. // CSSLPortPage message handlers
  260. void CSSLPortPage::OnEditChangeSSLPort()
  261. {
  262. UpdateData(TRUE);
  263. SetWizardButtons(m_SSLPort.IsEmpty() ?
  264. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  265. }