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.

531 lines
13 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : DlgConfirmPassword.cpp //
  3. // //
  4. // DESCRIPTION : The CDlgConfirmPassword class implements the //
  5. // dialog for additon of new Group. //
  6. // //
  7. // AUTHOR : yossg //
  8. // //
  9. // HISTORY : //
  10. // Jul 27 2000 yossg Create //
  11. // //
  12. // Copyright (C) 2000 Microsoft Corporation All Rights Reserved //
  13. /////////////////////////////////////////////////////////////////////////////
  14. #include "StdAfx.h"
  15. #include "DlgConfirmPassword.h"
  16. #include "FxsValid.h"
  17. #include "dlgutils.h"
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CDlgConfirmPassword
  20. CDlgConfirmPassword::CDlgConfirmPassword()
  21. {
  22. m_fIsDialogInitiated = FALSE;
  23. m_fIsPasswordDirty = FALSE;
  24. m_fIsConfirmPasswordDirty = FALSE;
  25. m_fIsPasswordChangedAndConfirmed = FALSE;
  26. }
  27. CDlgConfirmPassword::~CDlgConfirmPassword()
  28. {
  29. }
  30. /*
  31. + CDlgConfirmPassword::OnInitDialog
  32. +
  33. * Purpose:
  34. * Initiate all dialog controls.
  35. *
  36. * Arguments:
  37. * [in] uMsg : Value identifying the event.
  38. * [in] lParam : Message-specific value.
  39. * [in] wParam : Message-specific value.
  40. * [in] bHandled : bool value.
  41. *
  42. - Return:
  43. - 0 or 1
  44. */
  45. LRESULT
  46. CDlgConfirmPassword::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  47. {
  48. DEBUG_FUNCTION_NAME( _T("CDlgConfirmPassword::OnInitDialog"));
  49. HRESULT hRc = S_OK;
  50. //
  51. // Attach controls
  52. //
  53. m_UserNameBox.Attach(GetDlgItem(IDC_SMTP_USERNAME_EDIT));
  54. m_PasswordBox.Attach(GetDlgItem(IDC_SMTP_PASSWORD_EDIT));
  55. m_ConfirmPasswordBox.Attach(GetDlgItem(IDC_CONFIRM_PASSWORD_EDIT));
  56. //
  57. // Limit text length
  58. //
  59. m_UserNameBox.SetLimitText(FXS_MAX_USERNAME_LENGTH);
  60. m_PasswordBox.SetLimitText(FXS_MAX_PASSWORD_LENGTH);
  61. m_ConfirmPasswordBox.SetLimitText(FXS_MAX_PASSWORD_LENGTH);
  62. //
  63. // Init textboxes
  64. //
  65. m_UserNameBox.SetWindowText( m_bstrUserName);
  66. m_PasswordBox.SetWindowText( TEXT("******"));
  67. m_ConfirmPasswordBox.SetWindowText( TEXT("******"));
  68. m_fIsDialogInitiated = TRUE;
  69. EnableOK(FALSE);
  70. return 1; // Let the system set the focus
  71. }
  72. /*
  73. + CDlgConfirmPassword::OnOK
  74. +
  75. * Purpose:
  76. * Initiate all dialog controls.
  77. *
  78. * Arguments:
  79. * [in] uMsg : Value identifying the event.
  80. * [in] lParam : Message-specific value.
  81. * [in] wParam : Message-specific value.
  82. * [in] bHandled : bool value.
  83. *
  84. - Return:
  85. - 0 or 1
  86. */
  87. LRESULT
  88. CDlgConfirmPassword::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  89. {
  90. DEBUG_FUNCTION_NAME( _T("CDlgConfirmPassword::OnOK"));
  91. HRESULT hRc = S_OK;
  92. CComBSTR bstrUserName;
  93. CComBSTR bstrPassword;
  94. BOOL fSkipMessage = FALSE;
  95. int CtrlFocus = 0;
  96. m_fIsPasswordChangedAndConfirmed = FALSE;
  97. ATLASSERT (m_UserNameBox.GetWindowTextLength() >0 );//avoided by disabling OK button
  98. if ( !m_UserNameBox.GetWindowText(&bstrUserName))
  99. {
  100. CtrlFocus = IDC_SMTP_USERNAME_EDIT;
  101. DebugPrintEx(
  102. DEBUG_ERR,
  103. TEXT("Failed to GetWindowText(&bstrUserName)"));
  104. hRc = E_OUTOFMEMORY;
  105. goto Error;
  106. }
  107. //
  108. // Any credential change should involve password update and confirmation
  109. // We are supporting only two scenarioes: 1) Password update and 2) full credentilals change.
  110. //
  111. if ( !(m_fIsPasswordDirty && m_fIsConfirmPasswordDirty) )
  112. {
  113. if (!m_fIsPasswordDirty)
  114. {
  115. CtrlFocus = IDC_SMTP_PASSWORD_EDIT;
  116. }
  117. else // !m_fIsConfirmPasswordDirty
  118. {
  119. CtrlFocus = IDC_CONFIRM_PASSWORD_EDIT;
  120. }
  121. DebugPrintEx(
  122. DEBUG_WRN,
  123. TEXT("!(m_fIsPasswordDirty && m_fIsConfirmPasswordDirty)"));
  124. DlgMsgBox(this, IDS_INVALID_PASSWORD, MB_OK|MB_ICONEXCLAMATION);
  125. hRc = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  126. fSkipMessage = TRUE;
  127. goto Error;
  128. }
  129. else
  130. {
  131. //
  132. // Only is the password changed, we collect the new text from the control.
  133. // Otherwise, we leave the string as NULL so that the server won't set it.
  134. //
  135. if ( !m_PasswordBox.GetWindowText(&bstrPassword))
  136. {
  137. CtrlFocus = IDC_SMTP_PASSWORD_EDIT;
  138. DebugPrintEx(
  139. DEBUG_ERR,
  140. TEXT("Failed to GetWindowText(&bstrPassword)"));
  141. hRc = E_OUTOFMEMORY;
  142. goto Error;
  143. }
  144. //
  145. // To avoid any non controled password insertion we ask for
  146. // password confirmation
  147. //
  148. CComBSTR bstrConfirmedPassword;
  149. if ( !m_ConfirmPasswordBox.GetWindowText(&bstrConfirmedPassword))
  150. {
  151. CtrlFocus = IDC_SMTP_PASSWORD_EDIT;
  152. DebugPrintEx(
  153. DEBUG_ERR,
  154. TEXT("Failed to GetWindowText(&bstrPassword)"));
  155. hRc = E_OUTOFMEMORY;
  156. goto Error;
  157. }
  158. //
  159. // Password Compare
  160. //
  161. if ( 0 != wcscmp( bstrConfirmedPassword , bstrPassword ) )
  162. {
  163. DebugPrintEx(
  164. DEBUG_MSG,
  165. _T("The passwords that were entered are not the same."));
  166. DlgMsgBox(this, IDS_PASSWORD_NOT_MATCH, MB_OK|MB_ICONEXCLAMATION);
  167. goto Exit;
  168. }
  169. m_fIsPasswordChangedAndConfirmed = TRUE;
  170. }
  171. //
  172. // Step 2: Input Validation
  173. //
  174. if (!IsValidData(bstrUserName, bstrPassword, &CtrlFocus))
  175. {
  176. hRc = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  177. //in this case detailed message box was given by the called functions
  178. fSkipMessage = TRUE;
  179. goto Error;
  180. }
  181. //
  182. // Step 3: set the bstrs to the member
  183. //
  184. m_bstrUserName = bstrUserName;
  185. if (!m_bstrUserName)
  186. {
  187. DebugPrintEx(
  188. DEBUG_ERR,
  189. TEXT("Out of memory: Failed to allocate m_bstrUserName"));
  190. hRc = E_OUTOFMEMORY;
  191. goto Error;
  192. }
  193. if (m_fIsPasswordChangedAndConfirmed)
  194. {
  195. m_bstrPassword = bstrPassword;
  196. if (!m_bstrPassword)
  197. {
  198. DebugPrintEx(
  199. DEBUG_ERR,
  200. TEXT("Out of memory: Failed to allocate m_bstrPassword"));
  201. hRc = E_OUTOFMEMORY;
  202. goto Error;
  203. }
  204. }
  205. //
  206. // Step 4: Close the dialog
  207. //
  208. ATLASSERT(S_OK == hRc );
  209. EndDialog(wID);
  210. goto Exit;
  211. Error:
  212. ATLASSERT(S_OK != hRc);
  213. if (!fSkipMessage)
  214. {
  215. if (E_OUTOFMEMORY == hRc)
  216. {
  217. DlgMsgBox(this, IDS_MEMORY);
  218. }
  219. else
  220. {
  221. DlgMsgBox(this, IDS_FAIL2UPDATE_SMTP_CONFIG);
  222. }
  223. }
  224. ::SetFocus(GetDlgItem(CtrlFocus));
  225. Exit:
  226. return FAILED(hRc) ? 0 : 1;
  227. }
  228. /*
  229. - CDlgConfirmPassword::OnPasswordChanged
  230. -
  231. * Purpose:
  232. * Catch changes to the password edit box.
  233. *
  234. * Arguments:
  235. *
  236. * Return:
  237. * 1
  238. */
  239. LRESULT CDlgConfirmPassword::OnPasswordChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  240. {
  241. UNREFERENCED_PARAMETER (wNotifyCode);
  242. UNREFERENCED_PARAMETER (hWndCtl);
  243. UNREFERENCED_PARAMETER (bHandled);
  244. DEBUG_FUNCTION_NAME( _T("CDlgConfirmPassword::OnPasswordChanged"));
  245. if (!m_fIsDialogInitiated) // Event receieved in a too early stage
  246. {
  247. return 0;
  248. }
  249. switch (wID)
  250. {
  251. case IDC_SMTP_PASSWORD_EDIT:
  252. m_fIsPasswordDirty = TRUE;
  253. break;
  254. case IDC_CONFIRM_PASSWORD_EDIT:
  255. m_fIsConfirmPasswordDirty = TRUE;
  256. break;
  257. default:
  258. ATLASSERT(FALSE);
  259. }
  260. UINT uEnableOK = ( m_UserNameBox.GetWindowTextLength() );
  261. EnableOK(!!uEnableOK);
  262. return 1;
  263. }
  264. /*
  265. - CDlgConfirmPassword::OnTextChanged
  266. -
  267. * Purpose:
  268. * Check the validity of text inside a textbox.
  269. *
  270. * Arguments:
  271. *
  272. * Return:
  273. * 1
  274. */
  275. LRESULT
  276. CDlgConfirmPassword::OnTextChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  277. {
  278. DEBUG_FUNCTION_NAME( _T("CDlgConfirmPassword::OnTextChanged"));
  279. UINT fEnableOK;
  280. if (!m_fIsDialogInitiated) //event receieved in too early stage
  281. {
  282. return 0;
  283. }
  284. fEnableOK = ( m_UserNameBox.GetWindowTextLength() );
  285. EnableOK(!!fEnableOK);
  286. return 0;
  287. }
  288. /*
  289. - CDlgConfirmPassword::EnableOK
  290. -
  291. * Purpose:
  292. * Enable (disable) apply button.
  293. *
  294. * Arguments:
  295. * [in] fEnable - the value to enable the button
  296. *
  297. * Return:
  298. * void
  299. */
  300. VOID
  301. CDlgConfirmPassword::EnableOK(BOOL fEnable)
  302. {
  303. HWND hwndOK = GetDlgItem(IDOK);
  304. ::EnableWindow(hwndOK, fEnable);
  305. }
  306. /*
  307. - CDlgConfirmPassword::OnCancel
  308. -
  309. * Purpose:
  310. * End dialog OnCancel.
  311. *
  312. * Arguments:
  313. *
  314. * Return:
  315. * 0
  316. */
  317. LRESULT
  318. CDlgConfirmPassword::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  319. {
  320. DEBUG_FUNCTION_NAME( _T("CDlgConfirmPassword::OnCancel"));
  321. EndDialog(wID);
  322. return 0;
  323. }
  324. /*
  325. - CDlgConfirmPassword::InitCredentialsDlg
  326. -
  327. * Purpose:
  328. * Initiates the configuration from data retereived by RPC,
  329. *
  330. * Arguments:
  331. *
  332. * Return:
  333. * OLE error code
  334. */
  335. HRESULT CDlgConfirmPassword::InitCredentialsDlg(BSTR bstrUserName)
  336. {
  337. DEBUG_FUNCTION_NAME( _T("CDlgConfirmPassword::InitCredentialsDlg"));
  338. HRESULT hRc = S_OK;
  339. m_bstrUserName = bstrUserName;
  340. if (!m_bstrUserName )
  341. {
  342. DebugPrintEx(DEBUG_ERR,
  343. _T("Out of memory - Failed to Init m_bstrUserName. (ec: %0X8)"), hRc);
  344. //MsgBox by Caller Function
  345. hRc = E_OUTOFMEMORY;
  346. goto Exit;
  347. }
  348. ATLASSERT(S_OK == hRc);
  349. Exit:
  350. return hRc;
  351. }
  352. /*
  353. - CDlgConfirmPassword::IsValidData
  354. -
  355. * Purpose:
  356. * To validate all data types before save data.
  357. * This level should be responsible that detailed
  358. * error description will be shown to user.
  359. *
  360. * Arguments:
  361. * [in] BSTRs and DWORDs
  362. * [out] iFocus
  363. *
  364. * Return:
  365. * BOOOLEAN
  366. */
  367. BOOL CDlgConfirmPassword::IsValidData(BSTR bstrUserName, BSTR bstrPassword, int * pCtrlFocus)
  368. {
  369. DEBUG_FUNCTION_NAME( _T("CDlgConfirmPassword::IsValidData"));
  370. UINT uRetIDS = 0;
  371. ATLASSERT(pCtrlFocus);
  372. //
  373. // User Name
  374. //
  375. if (!IsNotEmptyString(bstrUserName))
  376. {
  377. DebugPrintEx( DEBUG_ERR,
  378. _T("Username string empty or spaces only."));
  379. uRetIDS = IDS_USERNAME_EMPTY;
  380. *pCtrlFocus = IDC_SMTP_USERNAME_EDIT;
  381. goto Error;
  382. }
  383. //
  384. // Password
  385. //
  386. //Currently do noting. empty string is valid also.
  387. ATLASSERT(0 == uRetIDS);
  388. goto Exit;
  389. Error:
  390. ATLASSERT(0 != uRetIDS);
  391. DlgMsgBox(this, uRetIDS);
  392. return FALSE;
  393. Exit:
  394. return TRUE;
  395. }
  396. //////////////////////////////////////////////////////////////////////////////
  397. /*++
  398. CDlgConfirmPassword::OnHelpRequest
  399. This is called in response to the WM_HELP Notify
  400. message and to the WM_CONTEXTMENU Notify message.
  401. WM_HELP Notify message.
  402. This message is sent when the user presses F1 or <Shift>-F1
  403. over an item or when the user clicks on the ? icon and then
  404. presses the mouse over an item.
  405. WM_CONTEXTMENU Notify message.
  406. This message is sent when the user right clicks over an item
  407. and then clicks "What's this?"
  408. --*/
  409. /////////////////////////////////////////////////////////////////////////////
  410. LRESULT
  411. CDlgConfirmPassword::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  412. {
  413. DEBUG_FUNCTION_NAME(_T("CDlgSMTPConfig::OnHelpRequest"));
  414. switch (uMsg)
  415. {
  416. case WM_HELP:
  417. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  418. break;
  419. case WM_CONTEXTMENU:
  420. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  421. break;
  422. }
  423. return TRUE;
  424. }
  425. /////////////////////////////////////////////////////////////////////////////