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.

550 lines
12 KiB

  1. /*++
  2. Copyright (c) 1994-2001 Microsoft Corporation
  3. Module Name :
  4. facc.cpp
  5. Abstract:
  6. FTP Accounts Property Page
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Sergei Antonov (sergeia)
  10. Project:
  11. Internet Services Manager
  12. Revision History:
  13. --*/
  14. #include "stdafx.h"
  15. #include "common.h"
  16. #include "inetprop.h"
  17. #include "InetMgrApp.h"
  18. #include "supdlgs.h"
  19. #include "shts.h"
  20. #include "ftpsht.h"
  21. #include "facc.h"
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26. IMPLEMENT_DYNCREATE(CFtpAccountsPage, CInetPropertyPage)
  27. CFtpAccountsPage::CFtpAccountsPage(
  28. IN CInetPropertySheet * pSheet
  29. )
  30. : CInetPropertyPage(CFtpAccountsPage::IDD, pSheet),
  31. m_fUserNameChanged(FALSE),
  32. m_fPasswordSync(FALSE),
  33. m_fPasswordSyncChanged(FALSE),
  34. m_fPasswordSyncMsgShown(TRUE)
  35. {
  36. #ifdef _DEBUG
  37. afxMemDF |= checkAlwaysMemDF;
  38. #endif // _DEBUG
  39. }
  40. CFtpAccountsPage::~CFtpAccountsPage()
  41. {
  42. }
  43. void
  44. CFtpAccountsPage::DoDataExchange(
  45. IN CDataExchange * pDX
  46. )
  47. {
  48. CInetPropertyPage::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CFtpAccountsPage)
  50. DDX_Check(pDX, IDC_CHECK_ALLOW_ANONYMOUS, m_fAllowAnonymous);
  51. DDX_Check(pDX, IDC_CHECK_ONLY_ANYMOUS, m_fOnlyAnonymous);
  52. DDX_Check(pDX, IDC_CHECK_ENABLE_PW_SYNCHRONIZATION, m_fPasswordSync);
  53. DDX_Control(pDX, IDC_EDIT_PASSWORD, m_edit_Password);
  54. DDX_Control(pDX, IDC_EDIT_USERNAME, m_edit_UserName);
  55. DDX_Control(pDX, IDC_STATIC_PW, m_static_Password);
  56. DDX_Control(pDX, IDC_STATIC_USERNAME, m_static_UserName);
  57. DDX_Control(pDX, IDC_STATIC_ACCOUNT_PROMPT, m_static_AccountPrompt);
  58. DDX_Control(pDX, IDC_BUTTON_CHECK_PASSWORD, m_button_CheckPassword);
  59. DDX_Control(pDX, IDC_BUTTON_BROWSE_USER, m_button_Browse);
  60. DDX_Control(pDX, IDC_CHECK_ENABLE_PW_SYNCHRONIZATION, m_chk_PasswordSync);
  61. DDX_Control(pDX, IDC_CHECK_ALLOW_ANONYMOUS, m_chk_AllowAnymous);
  62. DDX_Control(pDX, IDC_CHECK_ONLY_ANYMOUS, m_chk_OnlyAnonymous);
  63. //}}AFX_DATA_MAP
  64. //
  65. // Set password/username only during load stage,
  66. // or if saving when allowing anonymous logons
  67. //
  68. if (!pDX->m_bSaveAndValidate || m_fAllowAnonymous)
  69. {
  70. DDX_Text(pDX, IDC_EDIT_USERNAME, m_strUserName);
  71. DDV_MinMaxChars(pDX, m_strUserName, 1, UNLEN);
  72. //
  73. // Some people have a tendency to add "\\" before
  74. // the computer name in user accounts. Fix this here.
  75. //
  76. m_strUserName.TrimLeft();
  77. while (*m_strUserName == '\\')
  78. {
  79. m_strUserName = m_strUserName.Mid(2);
  80. }
  81. //
  82. // Display the remote password sync message if
  83. // password sync is on, the account is not local,
  84. // password sync has changed or username has changed
  85. // and the message hasn't already be shown.
  86. //
  87. if (pDX->m_bSaveAndValidate)
  88. {
  89. if (GetSheet()->QueryMajorVersion() < 6)
  90. {
  91. if (m_fPasswordSync
  92. && !IsLocalAccount(m_strUserName)
  93. && (m_fPasswordSyncChanged || m_fUserNameChanged)
  94. && !m_fPasswordSyncMsgShown
  95. )
  96. {
  97. //
  98. // Don't show it again
  99. //
  100. m_fPasswordSyncMsgShown = TRUE;
  101. if (!NoYesMessageBox(IDS_WRN_PWSYNC))
  102. {
  103. pDX->Fail();
  104. }
  105. }
  106. }
  107. }
  108. //DDX_Password(pDX, IDC_EDIT_PASSWORD, m_strPassword, g_lpszDummyPassword);
  109. DDX_Password_SecuredString(pDX, IDC_EDIT_PASSWORD, m_strPassword, g_lpszDummyPassword);
  110. if (!m_fPasswordSync)
  111. {
  112. //DDV_MaxCharsBalloon(pDX, m_strPassword, PWLEN);
  113. DDV_MaxCharsBalloon_SecuredString(pDX, m_strPassword, PWLEN);
  114. }
  115. }
  116. }
  117. //
  118. // Message Map
  119. //
  120. BEGIN_MESSAGE_MAP(CFtpAccountsPage, CInetPropertyPage)
  121. //{{AFX_MSG_MAP(CFtpAccountsPage)
  122. ON_BN_CLICKED(IDC_BUTTON_CHECK_PASSWORD, OnButtonCheckPassword)
  123. ON_BN_CLICKED(IDC_CHECK_ENABLE_PW_SYNCHRONIZATION, OnCheckEnablePwSynchronization)
  124. ON_EN_CHANGE(IDC_EDIT_USERNAME, OnChangeEditUsername)
  125. //}}AFX_MSG_MAP
  126. ON_EN_CHANGE(IDC_EDIT_PASSWORD, OnItemChanged)
  127. ON_BN_CLICKED(IDC_CHECK_ALLOW_ANONYMOUS, OnCheckAllowAnonymous)
  128. ON_BN_CLICKED(IDC_CHECK_ONLY_ANYMOUS, OnCheckAllowOnlyAnonymous)
  129. ON_BN_CLICKED(IDC_BUTTON_BROWSE_USER, OnButtonBrowseUser)
  130. END_MESSAGE_MAP()
  131. void
  132. CFtpAccountsPage::SetControlStates(
  133. IN BOOL fAllowAnonymous
  134. )
  135. /*++
  136. Routine Description:
  137. Set the states of the dialog control depending on its current
  138. values.
  139. Arguments:
  140. BOOL fAllowAnonymous : If TRUE, 'allow anonymous' is on.
  141. Return Value:
  142. None
  143. --*/
  144. {
  145. m_static_Password.EnableWindow(fAllowAnonymous && !m_fPasswordSync && HasAdminAccess());
  146. m_edit_Password.EnableWindow(fAllowAnonymous && !m_fPasswordSync && HasAdminAccess());
  147. m_button_CheckPassword.EnableWindow(fAllowAnonymous && !m_fPasswordSync && HasAdminAccess());
  148. m_static_AccountPrompt.EnableWindow(fAllowAnonymous);
  149. m_static_UserName.EnableWindow(fAllowAnonymous && HasAdminAccess());
  150. m_edit_UserName.EnableWindow(fAllowAnonymous && HasAdminAccess());
  151. m_button_Browse.EnableWindow(fAllowAnonymous && HasAdminAccess());
  152. m_chk_PasswordSync.EnableWindow(fAllowAnonymous && HasAdminAccess());
  153. m_chk_OnlyAnonymous.EnableWindow(fAllowAnonymous);
  154. }
  155. //
  156. // Message Handlers
  157. //
  158. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  159. BOOL
  160. CFtpAccountsPage::OnInitDialog()
  161. {
  162. CInetPropertyPage::OnInitDialog();
  163. CWaitCursor wait;
  164. if (GetSheet()->QueryMajorVersion() >= 6)
  165. {
  166. GetDlgItem(IDC_CHECK_ENABLE_PW_SYNCHRONIZATION)->EnableWindow(FALSE);
  167. GetDlgItem(IDC_CHECK_ENABLE_PW_SYNCHRONIZATION)->ShowWindow(SW_HIDE);
  168. }
  169. else
  170. {
  171. m_fPasswordSyncMsgShown = FALSE;
  172. }
  173. BOOL bADIsolated = ((CFtpSheet *)GetSheet())->HasADUserIsolation();
  174. ::EnableWindow(CONTROL_HWND(IDC_CHECK_ALLOW_ANONYMOUS), !bADIsolated);
  175. SetControlStates(m_fAllowAnonymous);
  176. return TRUE;
  177. }
  178. /* virtual */
  179. HRESULT
  180. CFtpAccountsPage::FetchLoadedValues()
  181. /*++
  182. Routine Description:
  183. Move configuration data from sheet to dialog controls
  184. Arguments:
  185. None
  186. Return Value:
  187. HRESULT
  188. --*/
  189. {
  190. CError err;
  191. BEGIN_META_INST_READ(CFtpSheet)
  192. FETCH_INST_DATA_FROM_SHEET(m_strUserName);
  193. FETCH_INST_DATA_FROM_SHEET_PASSWORD(m_strPassword);
  194. if (!((CFtpSheet *)GetSheet())->HasADUserIsolation())
  195. {
  196. FETCH_INST_DATA_FROM_SHEET(m_fAllowAnonymous);
  197. }
  198. else
  199. {
  200. m_fAllowAnonymous = FALSE;
  201. }
  202. FETCH_INST_DATA_FROM_SHEET(m_fOnlyAnonymous);
  203. if (GetSheet()->QueryMajorVersion() < 6)
  204. {
  205. FETCH_INST_DATA_FROM_SHEET(m_fPasswordSync);
  206. }
  207. END_META_INST_READ(err)
  208. return err;
  209. }
  210. /* virtual */
  211. HRESULT
  212. CFtpAccountsPage::SaveInfo()
  213. /*++
  214. Routine Description:
  215. Save the information on this property page
  216. Arguments:
  217. None
  218. Return Value:
  219. Error return code
  220. --*/
  221. {
  222. ASSERT(IsDirty());
  223. CError err;
  224. BeginWaitCursor();
  225. BEGIN_META_INST_WRITE(CFtpSheet)
  226. STORE_INST_DATA_ON_SHEET(m_strUserName)
  227. if (!((CFtpSheet *)GetSheet())->HasADUserIsolation())
  228. {
  229. STORE_INST_DATA_ON_SHEET(m_fOnlyAnonymous)
  230. STORE_INST_DATA_ON_SHEET(m_fAllowAnonymous)
  231. }
  232. if (GetSheet()->QueryMajorVersion() < 6)
  233. {
  234. STORE_INST_DATA_ON_SHEET(m_fPasswordSync)
  235. if (m_fPasswordSync)
  236. {
  237. //
  238. // Delete password
  239. //
  240. // CODEWORK: Shouldn't need to know ID number.
  241. // Implement m_fDelete flag in CMP template maybe?
  242. //
  243. FLAG_INST_DATA_FOR_DELETION(MD_ANONYMOUS_PWD);
  244. }
  245. else
  246. {
  247. STORE_INST_DATA_ON_SHEET(m_strPassword);
  248. }
  249. }
  250. else
  251. {
  252. STORE_INST_DATA_ON_SHEET(m_strPassword);
  253. }
  254. END_META_INST_WRITE(err)
  255. EndWaitCursor();
  256. return err;
  257. }
  258. void
  259. CFtpAccountsPage::OnItemChanged()
  260. /*++
  261. Routine Description:
  262. Register a change in control value on this page. Mark the page as dirty.
  263. All change messages map to this function
  264. Arguments:
  265. None
  266. Return Value:
  267. None
  268. --*/
  269. {
  270. SetModified(TRUE);
  271. SetControlStates(m_chk_AllowAnymous.GetCheck() > 0);
  272. }
  273. void
  274. CFtpAccountsPage::OnCheckAllowAnonymous()
  275. /*++
  276. Routine Description:
  277. Respond to 'allow anonymous' checkbox being pressed
  278. Arguments:
  279. None
  280. Return Value:
  281. None
  282. --*/
  283. {
  284. if (m_chk_AllowAnymous.GetCheck() == 0)
  285. {
  286. //
  287. // Show security warning
  288. //
  289. CClearTxtDlg dlg;
  290. if (dlg.DoModal() != IDOK)
  291. {
  292. m_chk_AllowAnymous.SetCheck(1);
  293. return;
  294. }
  295. }
  296. SetControlStates(m_chk_AllowAnymous.GetCheck() > 0);
  297. OnItemChanged();
  298. }
  299. void
  300. CFtpAccountsPage::OnCheckAllowOnlyAnonymous()
  301. /*++
  302. Routine Description:
  303. Respond to 'allow only anonymous' checkbox being pressed
  304. Arguments:
  305. None
  306. Return Value:
  307. None
  308. --*/
  309. {
  310. if (m_chk_OnlyAnonymous.GetCheck() == 0)
  311. {
  312. //
  313. // Show security warning
  314. //
  315. CClearTxtDlg dlg;
  316. if (dlg.DoModal() != IDOK)
  317. {
  318. m_chk_OnlyAnonymous.SetCheck(1);
  319. return;
  320. }
  321. }
  322. OnItemChanged();
  323. }
  324. void
  325. CFtpAccountsPage::OnButtonBrowseUser()
  326. /*++
  327. Routine Description:
  328. User browser button has been pressed. Browse for IUSR account name
  329. Arguments:
  330. None
  331. Return Value:
  332. None
  333. --*/
  334. {
  335. CString str;
  336. if (GetIUsrAccount(str))
  337. {
  338. //
  339. // If the name is non-local (determined by having
  340. // a slash in the name, password sync is disabled,
  341. // and a password should be entered.
  342. //
  343. m_edit_UserName.SetWindowText(str);
  344. if (GetSheet()->QueryMajorVersion() >= 6 || !(m_fPasswordSync = IsLocalAccount(str)))
  345. {
  346. m_edit_Password.SetWindowText(_T(""));
  347. m_edit_Password.SetFocus();
  348. }
  349. if (GetSheet()->QueryMajorVersion() < 6)
  350. {
  351. m_chk_PasswordSync.SetCheck(m_fPasswordSync);
  352. }
  353. OnItemChanged();
  354. }
  355. }
  356. void
  357. CFtpAccountsPage::OnButtonCheckPassword()
  358. /*++
  359. Routine Description:
  360. Check password button has been pressed.
  361. Arguments:
  362. None
  363. Return Value:
  364. None
  365. --*/
  366. {
  367. if (!UpdateData(TRUE))
  368. {
  369. return;
  370. }
  371. CString csTempPassword;
  372. m_strPassword.CopyTo(csTempPassword);
  373. CError err(CComAuthInfo::VerifyUserPassword(m_strUserName, csTempPassword));
  374. if (!err.MessageBoxOnFailure(m_hWnd))
  375. {
  376. DoHelpMessageBox(m_hWnd,IDS_PASSWORD_OK, MB_APPLMODAL | MB_OK | MB_ICONINFORMATION, 0);
  377. }
  378. }
  379. void
  380. CFtpAccountsPage::OnCheckEnablePwSynchronization()
  381. /*++
  382. Routine Description:
  383. Handler for 'enable password synchronization' checkbox press
  384. Arguments:
  385. None
  386. Return Value:
  387. None
  388. --*/
  389. {
  390. m_fPasswordSyncChanged = TRUE;
  391. m_fPasswordSync = !m_fPasswordSync;
  392. OnItemChanged();
  393. SetControlStates(m_chk_AllowAnymous.GetCheck() > 0);
  394. if (!m_fPasswordSync )
  395. {
  396. m_edit_Password.SetSel(0,-1);
  397. m_edit_Password.SetFocus();
  398. }
  399. }
  400. void
  401. CFtpAccountsPage::OnChangeEditUsername()
  402. /*++
  403. Routine description:
  404. Handler for 'username' edit box change messages
  405. Arguments:
  406. None
  407. Return Value:
  408. None
  409. --*/
  410. {
  411. m_fUserNameChanged = TRUE;
  412. OnItemChanged();
  413. }