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.

645 lines
16 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : DlgSMTPConfig.cpp //
  3. // //
  4. // DESCRIPTION : The CBosSmtpConfigDlg class implements the //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Jul 20 2000 yossg Create //
  10. // //
  11. // Copyright (C) 2000 Microsoft Corporation All Rights Reserved //
  12. /////////////////////////////////////////////////////////////////////////////
  13. #include "StdAfx.h"
  14. #include "BosSmtpConfigDlg.h"
  15. #include "DlgConfirmPassword.h"
  16. #include "FxsValid.h"
  17. #include "dlgutils.h"
  18. #include <htmlHelp.h>
  19. #include <faxreg.h>
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CBosSmtpConfigDlg
  22. CBosSmtpConfigDlg::CBosSmtpConfigDlg()
  23. {
  24. m_fIsPasswordDirty = FALSE;
  25. m_fIsDialogInitiated = FALSE;
  26. m_fIsUnderLocalUserAccount = FALSE;
  27. }
  28. CBosSmtpConfigDlg::~CBosSmtpConfigDlg()
  29. {
  30. }
  31. /*
  32. - CBosSmtpConfigDlg::InitSmtpDlg
  33. -
  34. * Purpose:
  35. * Initiates the configuration structure from RPC get Call,
  36. * and current assined devices own parameters
  37. *
  38. * Arguments:
  39. *
  40. * Return:
  41. * OLE error code
  42. */
  43. HRESULT
  44. CBosSmtpConfigDlg::InitSmtpDlg (
  45. FAX_ENUM_SMTP_AUTH_OPTIONS enumAuthOption,
  46. BSTR bstrUserName,
  47. BOOL fIsUnderLocalUserAccount)
  48. {
  49. DEBUG_FUNCTION_NAME( _T("CBosSmtpConfigDlg::InitSmtpDlg"));
  50. HRESULT hRc = S_OK;
  51. m_enumAuthOption = enumAuthOption;
  52. m_fIsUnderLocalUserAccount = fIsUnderLocalUserAccount;
  53. m_bstrUserName = bstrUserName;
  54. if (!m_bstrUserName )
  55. {
  56. DebugPrintEx(DEBUG_ERR,
  57. _T("Out of memory - Failed to Init m_bstrUserName. (ec: %0X8)"), hRc);
  58. //MsgBox by Caller Function
  59. hRc = E_OUTOFMEMORY;
  60. goto Exit;
  61. }
  62. ATLASSERT(S_OK == hRc);
  63. Exit:
  64. return hRc;
  65. }
  66. /*
  67. + CBosSmtpConfigDlg::OnInitDialog
  68. +
  69. * Purpose:
  70. * Initiate all dialog controls.
  71. *
  72. * Arguments:
  73. * [in] uMsg : Value identifying the event.
  74. * [in] lParam : Message-specific value.
  75. * [in] wParam : Message-specific value.
  76. * [in] bHandled : bool value.
  77. *
  78. - Return:
  79. - 0 or 1
  80. */
  81. LRESULT
  82. CBosSmtpConfigDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  83. {
  84. DEBUG_FUNCTION_NAME( _T("CBosSmtpConfigDlg::OnInitDialog"));
  85. HRESULT hRc = S_OK;
  86. //
  87. // Attach controls
  88. //
  89. m_UserNameBox.Attach(GetDlgItem(IDC_SMTP_USERNAME_EDIT));
  90. m_PasswordBox.Attach(GetDlgItem(IDC_SMTP_PASSWORD_EDIT));
  91. //
  92. // Set length limit to area code
  93. //
  94. //
  95. // Limit text length
  96. //
  97. m_UserNameBox.SetLimitText(FXS_MAX_USERNAME_LENGTH);
  98. m_PasswordBox.SetLimitText(FXS_MAX_PASSWORD_LENGTH);
  99. if (FAX_SMTP_AUTH_BASIC == m_enumAuthOption)
  100. {
  101. CheckDlgButton(IDC_SMTP_BASIC_RADIO2, BST_CHECKED);
  102. ::SetFocus(GetDlgItem(IDC_GROUPNAME_EDIT));
  103. }
  104. else // not FAX_SMTP_AUTH_BASIC
  105. {
  106. //Graying all the authenticated access area
  107. EnableBasicAuthenticationControls(FALSE);
  108. if (FAX_SMTP_AUTH_ANONYMOUS == m_enumAuthOption)
  109. {
  110. CheckDlgButton(IDC_SMTP_ANONIM_RADIO1, BST_CHECKED);
  111. }
  112. else if ( FAX_SMTP_AUTH_NTLM == m_enumAuthOption )
  113. {
  114. CheckDlgButton(IDC_SMTP_NTLM_RADIO3, BST_CHECKED);
  115. }
  116. else
  117. {
  118. ATLASSERT(FALSE);
  119. }
  120. }
  121. m_UserNameBox.SetWindowText( m_bstrUserName);
  122. m_PasswordBox.SetWindowText( TEXT("******"));
  123. // Free Buffer in the destructor.
  124. if (!m_fIsUnderLocalUserAccount )
  125. {
  126. //
  127. // Hide the dialog items
  128. //
  129. ::ShowWindow(::GetDlgItem(m_hWnd, IDC_SMTP_NTLM_TIP_STATIC), SW_HIDE);
  130. ::ShowWindow(::GetDlgItem(m_hWnd, IDC_SMTP_INFO_ICON), SW_HIDE);
  131. }
  132. else
  133. {
  134. ::EnableWindow(GetDlgItem(IDC_SMTP_NTLM_RADIO3), FALSE);
  135. ::EnableWindow(GetDlgItem(IDC_SMTP_NTLM_STATIC), FALSE);
  136. }
  137. m_fIsDialogInitiated = TRUE;
  138. EnableOK(FALSE);
  139. return 1; // Let the system set the focus
  140. }
  141. /*
  142. + CBosSmtpConfigDlg::OnOK
  143. +
  144. * Purpose:
  145. * Initiate all dialog controls.
  146. *
  147. * Arguments:
  148. * [in] uMsg : Value identifying the event.
  149. * [in] lParam : Message-specific value.
  150. * [in] wParam : Message-specific value.
  151. * [in] bHandled : bool value.
  152. *
  153. - Return:
  154. - 0 or 1
  155. */
  156. LRESULT
  157. CBosSmtpConfigDlg::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  158. {
  159. DEBUG_FUNCTION_NAME( _T("CBosSmtpConfigDlg::OnOK"));
  160. HRESULT hRc = S_OK;
  161. CComBSTR bstrUserName;
  162. CComBSTR bstrPassword;
  163. BOOL fSkipMessage = FALSE;
  164. int CtrlFocus = 0;
  165. if (IsDlgButtonChecked(IDC_SMTP_BASIC_RADIO2) == BST_CHECKED)
  166. {
  167. //
  168. // Advanced authentication details
  169. //
  170. if ( !m_UserNameBox.GetWindowText(&bstrUserName))
  171. {
  172. CtrlFocus = IDC_SMTP_USERNAME_EDIT;
  173. DebugPrintEx(
  174. DEBUG_ERR,
  175. TEXT("Failed to GetWindowText(&bstrUserName)"));
  176. hRc = E_OUTOFMEMORY;
  177. goto Error;
  178. }
  179. if (m_fIsPasswordDirty)
  180. {
  181. //
  182. // Only is the password changed, we collect the new text from the control.
  183. // Otherwise, we leave the string as NULL so that the server won't set it.
  184. //
  185. if ( !m_PasswordBox.GetWindowText(&bstrPassword))
  186. {
  187. CtrlFocus = IDC_SMTP_PASSWORD_EDIT;
  188. DebugPrintEx(
  189. DEBUG_ERR,
  190. TEXT("Failed to GetWindowText(&bstrPassword)"));
  191. hRc = E_OUTOFMEMORY;
  192. goto Error;
  193. }
  194. //
  195. // To avoid any non controled password insertion we ask for
  196. // password confirmation
  197. //
  198. INT_PTR rc = IDOK;
  199. WCHAR * pszNewPassword;
  200. CDlgConfirmPassword DlgConfirmPassword;
  201. rc = DlgConfirmPassword.DoModal();
  202. if (rc != IDOK)
  203. {
  204. DebugPrintEx(
  205. DEBUG_MSG,
  206. _T("Password confirmation canceled by the user."));
  207. goto Exit;
  208. }
  209. pszNewPassword = DlgConfirmPassword.GetPassword();
  210. ATLASSERT(NULL != pszNewPassword);
  211. if ( 0 != wcscmp( pszNewPassword , bstrPassword ) )
  212. {
  213. DebugPrintEx(
  214. DEBUG_MSG,
  215. _T("The passwords entered are not the same."));
  216. DlgMsgBox(this, IDS_PASSWORD_NOT_MATCH, MB_OK|MB_ICONEXCLAMATION);
  217. goto Exit;
  218. }
  219. }
  220. }
  221. //
  222. // Step 2: Input Validation
  223. //
  224. if (!IsValidData(bstrUserName,
  225. bstrPassword,
  226. &CtrlFocus)
  227. )
  228. {
  229. hRc = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  230. //in this case detailed message box was given by the called functions
  231. fSkipMessage = TRUE;
  232. goto Error;
  233. }
  234. //
  235. // Step 3: Set data to parent property page
  236. //
  237. if (IsDlgButtonChecked(IDC_SMTP_ANONIM_RADIO1) == BST_CHECKED)
  238. {
  239. m_enumAuthOption = FAX_SMTP_AUTH_ANONYMOUS;
  240. }
  241. else
  242. {
  243. if (IsDlgButtonChecked(IDC_SMTP_NTLM_RADIO3) == BST_CHECKED)
  244. {
  245. m_enumAuthOption = FAX_SMTP_AUTH_NTLM;
  246. }
  247. else // IsDlgButtonChecked(IDC_SMTP_BASIC_RADIO2) == BST_CHECKED
  248. {
  249. m_enumAuthOption = FAX_SMTP_AUTH_BASIC;
  250. }
  251. m_bstrUserName = bstrUserName;
  252. if (!m_bstrUserName)
  253. {
  254. DebugPrintEx(
  255. DEBUG_ERR,
  256. TEXT("Out of memory: Failed to allocate m_bstrUserName"));
  257. hRc = E_OUTOFMEMORY;
  258. goto Error;
  259. }
  260. if (m_fIsPasswordDirty)
  261. {
  262. m_bstrPassword = bstrPassword;
  263. if (!m_bstrPassword)
  264. {
  265. DebugPrintEx(
  266. DEBUG_ERR,
  267. TEXT("Out of memory: Failed to allocate m_bstrPassword"));
  268. hRc = E_OUTOFMEMORY;
  269. goto Error;
  270. }
  271. }
  272. // else
  273. // m_bstrPassword = NULL;
  274. // by default
  275. }
  276. //
  277. // Step 4: Close the dialog
  278. //
  279. ATLASSERT(S_OK == hRc );
  280. EndDialog(wID);
  281. goto Exit;
  282. Error:
  283. ATLASSERT(S_OK != hRc);
  284. if (!fSkipMessage)
  285. {
  286. if (E_OUTOFMEMORY == hRc)
  287. {
  288. DlgMsgBox(this, IDS_MEMORY);
  289. }
  290. else
  291. {
  292. DlgMsgBox(this, IDS_FAIL2UPDATE_SMTP_CONFIG);
  293. }
  294. }
  295. ::SetFocus(GetDlgItem(CtrlFocus));
  296. Exit:
  297. return FAILED(hRc) ? 0 : 1;
  298. }
  299. /*
  300. - CBosSmtpConfigDlg::OnPasswordChanged
  301. -
  302. * Purpose:
  303. * Catch changes to the password edit box.
  304. *
  305. * Arguments:
  306. *
  307. * Return:
  308. * 1
  309. */
  310. LRESULT CBosSmtpConfigDlg::OnPasswordChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  311. {
  312. DEBUG_FUNCTION_NAME( _T("CBosSmtpConfigDlg::OnPasswordChanged"));
  313. if (!m_fIsDialogInitiated) // Event receieved in a too early stage
  314. {
  315. return 0;
  316. }
  317. m_fIsPasswordDirty = TRUE;
  318. return OnTextChanged (wNotifyCode, wID, hWndCtl, bHandled);
  319. }
  320. /*
  321. - CBosSmtpConfigDlg::OnTextChanged
  322. -
  323. * Purpose:
  324. * Check the validity of text in side the text box.
  325. *
  326. * Arguments:
  327. *
  328. * Return:
  329. * 1
  330. */
  331. LRESULT
  332. CBosSmtpConfigDlg::OnTextChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  333. {
  334. DEBUG_FUNCTION_NAME( _T("CBosSmtpConfigDlg::OnTextChanged"));
  335. UINT fEnableOK;
  336. if (!m_fIsDialogInitiated) //event receieved in too early stage
  337. {
  338. return 0;
  339. }
  340. fEnableOK = ( m_UserNameBox.GetWindowTextLength() );
  341. EnableOK(!!fEnableOK);
  342. return 0;
  343. }
  344. /*
  345. - CBosSmtpConfigDlg::OnRadioButtonClicked
  346. -
  347. * Purpose:
  348. * .
  349. *
  350. * Arguments:
  351. *
  352. * Return:
  353. * 1
  354. */
  355. LRESULT
  356. CBosSmtpConfigDlg::OnRadioButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  357. {
  358. UNREFERENCED_PARAMETER (wNotifyCode);
  359. UNREFERENCED_PARAMETER (wID);
  360. UNREFERENCED_PARAMETER (hWndCtl);
  361. UNREFERENCED_PARAMETER (bHandled);
  362. DEBUG_FUNCTION_NAME( _T("CBosSmtpConfigDlg::OnRadioButtonClicked"));
  363. UINT fEnableOK;
  364. if (!m_fIsDialogInitiated) //event receieved in too early stage
  365. {
  366. return 0;
  367. }
  368. if ( IsDlgButtonChecked(IDC_SMTP_BASIC_RADIO2) == BST_CHECKED )
  369. {
  370. EnableBasicAuthenticationControls(TRUE);
  371. fEnableOK = ( m_UserNameBox.GetWindowTextLength() );
  372. EnableOK(!!fEnableOK);
  373. }
  374. else //Anonim or NTLM
  375. {
  376. EnableBasicAuthenticationControls(FALSE);
  377. EnableOK(TRUE);
  378. }
  379. return 0;
  380. }
  381. /*
  382. - CBosSmtpConfigDlg::EnableOK
  383. -
  384. * Purpose:
  385. * Enable (disable) apply button.
  386. *
  387. * Arguments:
  388. * [in] fEnable - the value to enable the button
  389. *
  390. * Return:
  391. * void
  392. */
  393. VOID
  394. CBosSmtpConfigDlg::EnableOK(BOOL fEnable)
  395. {
  396. HWND hwndOK = GetDlgItem(IDOK);
  397. ::EnableWindow(hwndOK, fEnable);
  398. }
  399. /*
  400. - CBosSmtpConfigDlg::OnCancel
  401. -
  402. * Purpose:
  403. * End dialog OnCancel.
  404. *
  405. * Arguments:
  406. *
  407. * Return:
  408. * 0
  409. */
  410. LRESULT
  411. CBosSmtpConfigDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  412. {
  413. DEBUG_FUNCTION_NAME( _T("CBosSmtpConfigDlg::OnCancel"));
  414. EndDialog(wID);
  415. return 0;
  416. }
  417. /*
  418. - CBosSmtpConfigDlg::EnableBasicAuthenticationControls
  419. -
  420. * Purpose:
  421. * Enable/dissable Basic Authentication dialog controls.
  422. *
  423. * Arguments:
  424. * [in] state - boolean value to enable TRUE or FALSE to disable
  425. *
  426. * Return:
  427. * void
  428. */
  429. VOID CBosSmtpConfigDlg::EnableBasicAuthenticationControls(BOOL state)
  430. {
  431. ::EnableWindow(GetDlgItem(IDC_SMTP_USERNAME_STATIC), state);
  432. ::EnableWindow(GetDlgItem(IDC_SMTP_USERNAME_EDIT), state);
  433. ::EnableWindow(GetDlgItem(IDC_SMTP_PASSWORD_STATIC), state);
  434. ::EnableWindow(GetDlgItem(IDC_SMTP_PASSWORD_EDIT), state);
  435. }
  436. /*
  437. - CBosSmtpConfigDlg::IsValidData
  438. -
  439. * Purpose:
  440. * To validate all data types before save data.
  441. * This level should be responsible that detailed
  442. * error description will be shown to user.
  443. *
  444. * Arguments:
  445. * [in] BSTRs and DWORDs
  446. * [out] iFocus
  447. *
  448. * Return:
  449. * BOOOLEAN
  450. */
  451. BOOL CBosSmtpConfigDlg::IsValidData( BSTR bstrUserName,
  452. BSTR bstrPassword,
  453. int * pCtrlFocus)
  454. {
  455. DEBUG_FUNCTION_NAME( _T("CBosSmtpConfigDlg::IsValidData"));
  456. UINT uRetIDS = 0;
  457. ATLASSERT(pCtrlFocus);
  458. if (IsDlgButtonChecked(IDC_SMTP_BASIC_RADIO2) == BST_CHECKED)
  459. {
  460. //
  461. // User Name
  462. //
  463. if (!IsNotEmptyString(bstrUserName))
  464. {
  465. DebugPrintEx( DEBUG_ERR,
  466. _T("Username string empty or spaces only."));
  467. uRetIDS = IDS_USERNAME_EMPTY;
  468. *pCtrlFocus = IDC_SMTP_USERNAME_EDIT;
  469. goto Error;
  470. }
  471. //
  472. // Password
  473. //
  474. if (m_fIsPasswordDirty)
  475. {
  476. /*if ( !IsNotEmptyString(bstrPassword))
  477. {
  478. DebugPrintEx( DEBUG_ERR,
  479. _T("Password string empty or spaces only."));
  480. uRetIDS = IDS_PASSWORD_EMPTY;
  481. *pCtrlFocus = IDC_SMTP_PASSWORD_EDIT;
  482. goto Error;
  483. }*/
  484. }
  485. }
  486. ATLASSERT(0 == uRetIDS);
  487. goto Exit;
  488. Error:
  489. ATLASSERT(0 != uRetIDS);
  490. DlgMsgBox(this, uRetIDS);
  491. return FALSE;
  492. Exit:
  493. return TRUE;
  494. }
  495. //////////////////////////////////////////////////////////////////////////////
  496. /*++
  497. CBosSmtpConfigDlg::OnHelpRequest
  498. This is called in response to the WM_HELP Notify
  499. message and to the WM_CONTEXTMENU Notify message.
  500. WM_HELP Notify message.
  501. This message is sent when the user presses F1 or <Shift>-F1
  502. over an item or when the user clicks on the ? icon and then
  503. presses the mouse over an item.
  504. WM_CONTEXTMENU Notify message.
  505. This message is sent when the user right clicks over an item
  506. and then clicks "What's this?"
  507. --*/
  508. /////////////////////////////////////////////////////////////////////////////
  509. LRESULT
  510. CBosSmtpConfigDlg::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  511. {
  512. DEBUG_FUNCTION_NAME(_T("CBosSmtpConfigDlg::OnHelpRequest"));
  513. switch (uMsg)
  514. {
  515. case WM_HELP:
  516. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  517. break;
  518. case WM_CONTEXTMENU:
  519. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  520. break;
  521. }
  522. return TRUE;
  523. }
  524. /////////////////////////////////////////////////////////////////////////////