Source code of Windows XP (NT5)
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.

654 lines
16 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1997 **/
  4. /**********************************************************************/
  5. /*
  6. sfmcfg.cpp
  7. Implementation for the configuration property page.
  8. FILE HISTORY:
  9. 8/20/97 ericdav Code moved into file managemnet snapin
  10. */
  11. #include "stdafx.h"
  12. #include "sfmcfg.h"
  13. #include "sfmutil.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. //
  21. // CMacFilesConfiguration property page
  22. //
  23. /////////////////////////////////////////////////////////////////////////////
  24. IMPLEMENT_DYNCREATE(CMacFilesConfiguration, CPropertyPage)
  25. CMacFilesConfiguration::CMacFilesConfiguration()
  26. : CPropertyPage(CMacFilesConfiguration::IDD),
  27. m_bIsNT5(FALSE)
  28. {
  29. //{{AFX_DATA_INIT(CMacFilesConfiguration)
  30. //}}AFX_DATA_INIT
  31. }
  32. CMacFilesConfiguration::~CMacFilesConfiguration()
  33. {
  34. }
  35. void CMacFilesConfiguration::DoDataExchange(CDataExchange* pDX)
  36. {
  37. CPropertyPage::DoDataExchange(pDX);
  38. //{{AFX_DATA_MAP(CMacFilesConfiguration)
  39. DDX_Control(pDX, IDC_COMBO_AUTHENTICATION, m_comboAuthentication);
  40. DDX_Control(pDX, IDC_RADIO_SESSSION_LIMIT, m_radioSessionLimit);
  41. DDX_Control(pDX, IDC_EDIT_LOGON_MESSAGE, m_editLogonMessage);
  42. DDX_Control(pDX, IDC_RADIO_SESSION_UNLIMITED, m_radioSessionUnlimited);
  43. DDX_Control(pDX, IDC_CHECK_SAVE_PASSWORD, m_checkSavePassword);
  44. DDX_Control(pDX, IDC_EDIT_SESSION_LIMIT, m_editSessionLimit);
  45. DDX_Control(pDX, IDC_EDIT_SERVER_NAME, m_editServerName);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CMacFilesConfiguration, CPropertyPage)
  49. //{{AFX_MSG_MAP(CMacFilesConfiguration)
  50. ON_BN_CLICKED(IDC_RADIO_SESSION_UNLIMITED, OnRadioSessionUnlimited)
  51. ON_BN_CLICKED(IDC_RADIO_SESSSION_LIMIT, OnRadioSesssionLimit)
  52. ON_BN_CLICKED(IDC_CHECK_SAVE_PASSWORD, OnCheckSavePassword)
  53. ON_EN_CHANGE(IDC_EDIT_LOGON_MESSAGE, OnChangeEditLogonMessage)
  54. ON_EN_CHANGE(IDC_EDIT_SERVER_NAME, OnChangeEditServerName)
  55. ON_EN_CHANGE(IDC_EDIT_SESSION_LIMIT, OnChangeEditSessionLimit)
  56. // ON_EN_KILLFOCUS(IDC_EDIT_SESSION_LIMIT, OnKillfocusEditSessionLimit) bug#158617
  57. ON_WM_CREATE()
  58. ON_WM_DESTROY()
  59. ON_WM_HELPINFO()
  60. ON_WM_CONTEXTMENU()
  61. ON_CBN_SELCHANGE(IDC_COMBO_AUTHENTICATION, OnSelchangeComboAuthentication)
  62. //}}AFX_MSG_MAP
  63. END_MESSAGE_MAP()
  64. /////////////////////////////////////////////////////////////////////////////
  65. //
  66. // CMacFilesConfiguration message handlers
  67. //
  68. /////////////////////////////////////////////////////////////////////////////
  69. BOOL CMacFilesConfiguration::OnInitDialog()
  70. {
  71. CPropertyPage::OnInitDialog();
  72. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  73. PAFP_SERVER_INFO pAfpServerInfo;
  74. DWORD err;
  75. CString strTemp;
  76. if ( !g_SfmDLL.LoadFunctionPointers() )
  77. return S_OK;
  78. //
  79. // Setup our controls
  80. //
  81. m_editSessionLimit.LimitText(10);
  82. //
  83. // Get the info from the server
  84. //
  85. err = ((SERVERGETINFOPROC) g_SfmDLL[AFP_SERVER_GET_INFO])(m_pSheet->m_hAfpServer,
  86. (LPBYTE*) &pAfpServerInfo);
  87. if (err != NO_ERROR)
  88. {
  89. ::SFMMessageBox(err);
  90. //
  91. // Just to setup the radio buttons
  92. //
  93. SetSessionLimit(AFP_MAXSESSIONS);
  94. return TRUE;
  95. }
  96. err = m_pSheet->IsNT5Machine(m_pSheet->m_strMachine, &m_bIsNT5);
  97. if (err != NO_ERROR)
  98. {
  99. m_bIsNT5 = FALSE; // Assume NT4
  100. }
  101. //
  102. // Since we can't just specify which options we want to set,
  103. // we need to save off the original options and then just
  104. // change the ones we expose through this UI. We don't want
  105. // to disturb the others.
  106. //
  107. m_dwAfpOriginalOptions = pAfpServerInfo->afpsrv_options;
  108. //
  109. // Set the information
  110. //
  111. m_editServerName.SetLimitText(AFP_SERVERNAME_LEN);
  112. m_editServerName.SetWindowText(pAfpServerInfo->afpsrv_name);
  113. m_checkSavePassword.SetCheck(
  114. (INT)(pAfpServerInfo->afpsrv_options &
  115. AFP_SRVROPT_ALLOWSAVEDPASSWORD ));
  116. // fill in the combo box and select the correct item
  117. // combobox is not sorted so this is the order of the items
  118. strTemp.LoadString(IDS_AUTH_MS_ONLY);
  119. m_comboAuthentication.AddString(strTemp);
  120. strTemp.LoadString(IDS_AUTH_APPLE_CLEARTEXT);
  121. m_comboAuthentication.AddString(strTemp);
  122. if (m_bIsNT5)
  123. {
  124. strTemp.LoadString(IDS_AUTH_APPLE_ENCRYPTED);
  125. m_comboAuthentication.AddString(strTemp);
  126. strTemp.LoadString(IDS_AUTH_CLEARTEXT_OR_MS);
  127. m_comboAuthentication.AddString(strTemp);
  128. strTemp.LoadString(IDS_AUTH_ENCRYPTED_OR_MS);
  129. m_comboAuthentication.AddString(strTemp);
  130. }
  131. BOOL bCleartext = pAfpServerInfo->afpsrv_options & AFP_SRVROPT_CLEARTEXTLOGONALLOWED;
  132. // default NT4 value for MS AUM
  133. BOOL bMS = (bCleartext) ? FALSE : TRUE;
  134. if (m_bIsNT5)
  135. {
  136. bMS = pAfpServerInfo->afpsrv_options & AFP_SRVROPT_MICROSOFT_UAM;
  137. }
  138. BOOL bEncrypted = pAfpServerInfo->afpsrv_options & AFP_SRVROPT_NATIVEAPPLEUAM;
  139. if (bEncrypted && bMS)
  140. m_comboAuthentication.SetCurSel(4);
  141. else
  142. if (bCleartext && bMS)
  143. m_comboAuthentication.SetCurSel(3);
  144. else
  145. if (bEncrypted)
  146. m_comboAuthentication.SetCurSel(2);
  147. else
  148. if (bCleartext)
  149. m_comboAuthentication.SetCurSel(1);
  150. else
  151. m_comboAuthentication.SetCurSel(0);
  152. SetSessionLimit(pAfpServerInfo->afpsrv_max_sessions);
  153. //
  154. // Direct the message edit control not to add end-of-line
  155. // character from wordwrapped text lines.
  156. //
  157. m_editLogonMessage.SetLimitText(AFP_MESSAGE_LEN);
  158. m_editLogonMessage.FmtLines(FALSE);
  159. m_editLogonMessage.SetWindowText(pAfpServerInfo->afpsrv_login_msg);
  160. ((SFMBUFFERFREEPROC) g_SfmDLL[AFP_BUFFER_FREE])(pAfpServerInfo);
  161. SetModified(FALSE);
  162. return TRUE; // return TRUE unless you set the focus to a control
  163. // EXCEPTION: OCX Property Pages should return FALSE
  164. }
  165. BOOL CMacFilesConfiguration::OnKillActive()
  166. {
  167. // TODO: Add your specialized code here and/or call the base class
  168. return CPropertyPage::OnKillActive();
  169. }
  170. void CMacFilesConfiguration::OnOK()
  171. {
  172. // TODO: Add your specialized code here and/or call the base class
  173. CPropertyPage::OnOK();
  174. }
  175. BOOL CMacFilesConfiguration::OnSetActive()
  176. {
  177. // TODO: Add your specialized code here and/or call the base class
  178. return CPropertyPage::OnSetActive();
  179. }
  180. void CMacFilesConfiguration::OnRadioSessionUnlimited()
  181. {
  182. SetModified(TRUE);
  183. UpdateRadioButtons(TRUE);
  184. }
  185. void CMacFilesConfiguration::OnRadioSesssionLimit()
  186. {
  187. SetModified(TRUE);
  188. UpdateRadioButtons(FALSE);
  189. }
  190. void
  191. CMacFilesConfiguration::UpdateRadioButtons
  192. (
  193. BOOL bUnlimitedClicked
  194. )
  195. {
  196. if (bUnlimitedClicked)
  197. {
  198. m_radioSessionUnlimited.SetCheck(1);
  199. m_radioSessionLimit.SetCheck(0);
  200. m_editSessionLimit.EnableWindow(FALSE);
  201. }
  202. else
  203. {
  204. m_radioSessionUnlimited.SetCheck(0);
  205. m_radioSessionLimit.SetCheck(1);
  206. m_editSessionLimit.EnableWindow(TRUE);
  207. }
  208. }
  209. void
  210. CMacFilesConfiguration::SetSessionLimit
  211. (
  212. DWORD dwSessionLimit
  213. )
  214. {
  215. if ( dwSessionLimit == AFP_MAXSESSIONS )
  216. {
  217. //
  218. // Set selection to the Unlimited button
  219. //
  220. m_radioSessionUnlimited.SetCheck(1);
  221. dwSessionLimit = 1;
  222. UpdateRadioButtons(TRUE);
  223. }
  224. else
  225. {
  226. //
  227. // Set the sessions button to the value
  228. //
  229. m_radioSessionUnlimited.SetCheck(0);
  230. m_spinSessionLimit.SetPos( dwSessionLimit );
  231. UpdateRadioButtons(FALSE);
  232. }
  233. CString cstrSessionLimit;
  234. cstrSessionLimit.Format(_T("%u"), dwSessionLimit);
  235. m_editSessionLimit.SetWindowText(cstrSessionLimit);
  236. }
  237. DWORD
  238. CMacFilesConfiguration::QuerySessionLimit()
  239. {
  240. if (m_radioSessionUnlimited.GetCheck())
  241. {
  242. return AFP_MAXSESSIONS;
  243. }
  244. else
  245. {
  246. CString strSessionLimit;
  247. m_editSessionLimit.GetWindowText(strSessionLimit);
  248. strSessionLimit.TrimLeft();
  249. strSessionLimit.TrimRight();
  250. //
  251. // Strip off any leading zeros
  252. //
  253. int nCount = 0;
  254. while (strSessionLimit[nCount] == '0')
  255. {
  256. nCount++;
  257. }
  258. if (nCount)
  259. {
  260. //
  261. // Leading zeros, strip off and set the text
  262. //
  263. strSessionLimit = strSessionLimit.Right(strSessionLimit.GetLength() - nCount);
  264. }
  265. __int64 i64SessionLimit = _wtoi64(strSessionLimit);
  266. DWORD dwSessionLimit = AFP_MAXSESSIONS;
  267. if (i64SessionLimit <= AFP_MAXSESSIONS)
  268. dwSessionLimit = (DWORD)i64SessionLimit;
  269. if (dwSessionLimit == 0)
  270. dwSessionLimit = 1;
  271. // Now, dwSessionLimit is in the range [1, AFP_MAXSESSIONS]
  272. CString cstrSessionLimit;
  273. cstrSessionLimit.Format(_T("%u"), dwSessionLimit);
  274. m_editSessionLimit.SetWindowText(cstrSessionLimit);
  275. return dwSessionLimit;
  276. }
  277. }
  278. void CMacFilesConfiguration::OnSelchangeComboAuthentication()
  279. {
  280. SetModified(TRUE);
  281. }
  282. void CMacFilesConfiguration::OnCheckSavePassword()
  283. {
  284. SetModified(TRUE);
  285. }
  286. void CMacFilesConfiguration::OnChangeEditLogonMessage()
  287. {
  288. SetModified(TRUE);
  289. }
  290. void CMacFilesConfiguration::OnChangeEditServerName()
  291. {
  292. SetModified(TRUE);
  293. }
  294. void CMacFilesConfiguration::OnChangeEditSessionLimit()
  295. {
  296. SetModified(TRUE);
  297. }
  298. void CMacFilesConfiguration::OnKillfocusEditSessionLimit()
  299. {
  300. if (::IsWindow(m_editSessionLimit.GetSafeHwnd()))
  301. {
  302. //
  303. // Calling this forces the edit box to validate itself
  304. //
  305. QuerySessionLimit();
  306. }
  307. }
  308. BOOL CMacFilesConfiguration::OnApply()
  309. {
  310. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  311. AFP_SERVER_INFO AfpServerInfo;
  312. DWORD dwParmNum = 0;
  313. DWORD err;
  314. CString strServerName;
  315. CString strLogonMessage;
  316. if ( !g_SfmDLL.LoadFunctionPointers() )
  317. return S_OK;
  318. ::ZeroMemory(&AfpServerInfo, sizeof(AfpServerInfo));
  319. //
  320. // Get the server name
  321. //
  322. if (m_editServerName.GetModify())
  323. {
  324. m_editServerName.GetWindowText(strServerName);
  325. strServerName.TrimLeft();
  326. strServerName.TrimRight();
  327. if ( strServerName.IsEmpty() )
  328. {
  329. ::AfxMessageBox(IDS_NEED_SERVER_NAME);
  330. m_editServerName.SetFocus();
  331. return FALSE;
  332. }
  333. //
  334. // Validate the server name
  335. //
  336. if ( strServerName.Find(_T(':') ) != -1 )
  337. {
  338. ::AfxMessageBox( IDS_AFPERR_InvalidServerName );
  339. m_editServerName.SetFocus();
  340. m_editServerName.SetSel(0, -1);
  341. return FALSE;
  342. }
  343. //
  344. // Warn the user that the change won't take effect until
  345. // the service is restarted.
  346. //
  347. if (!m_bIsNT5)
  348. {
  349. ::AfxMessageBox(IDS_SERVERNAME_CHANGE, MB_ICONEXCLAMATION);
  350. }
  351. AfpServerInfo.afpsrv_name = (LPWSTR) ((LPCWSTR) strServerName);
  352. dwParmNum |= AFP_SERVER_PARMNUM_NAME;
  353. m_editServerName.SetModify(FALSE);
  354. }
  355. //
  356. // Get the logon message
  357. //
  358. if (m_editLogonMessage.GetModify())
  359. {
  360. m_editLogonMessage.GetWindowText(strLogonMessage);
  361. strLogonMessage.TrimLeft();
  362. strLogonMessage.TrimRight();
  363. //
  364. // Was there any text ?
  365. //
  366. if ( strLogonMessage.IsEmpty() ) // always has a terminating NULL
  367. {
  368. AfpServerInfo.afpsrv_login_msg = NULL;
  369. }
  370. else
  371. {
  372. if ( strLogonMessage.GetLength() > AFP_MESSAGE_LEN )
  373. {
  374. ::AfxMessageBox(IDS_MESSAGE_TOO_LONG);
  375. // Set focus to the edit box and select the text
  376. m_editLogonMessage.SetFocus();
  377. m_editLogonMessage.SetSel(0, -1);
  378. return(FALSE);
  379. }
  380. AfpServerInfo.afpsrv_login_msg = (LPWSTR) ((LPCWSTR) strLogonMessage);
  381. }
  382. dwParmNum |= AFP_SERVER_PARMNUM_LOGINMSG;
  383. m_editLogonMessage.SetModify(FALSE);
  384. }
  385. //
  386. // Restore the original options and then just update the ones we
  387. // are able to change
  388. //
  389. AfpServerInfo.afpsrv_options = m_dwAfpOriginalOptions;
  390. //
  391. // Set the server options to whatever the user set
  392. //
  393. if (m_checkSavePassword.GetCheck())
  394. {
  395. //
  396. // Set the option bit
  397. //
  398. AfpServerInfo.afpsrv_options |= AFP_SRVROPT_ALLOWSAVEDPASSWORD;
  399. }
  400. else
  401. {
  402. //
  403. // Clear the option bit
  404. //
  405. AfpServerInfo.afpsrv_options &= ~AFP_SRVROPT_ALLOWSAVEDPASSWORD;
  406. }
  407. // set the correct authentication options depending upon what is selected
  408. switch (m_comboAuthentication.GetCurSel())
  409. {
  410. case 0:
  411. // MS Auth only
  412. if (!m_bIsNT5)
  413. {
  414. AfpServerInfo.afpsrv_options &= ~AFP_SRVROPT_MICROSOFT_UAM;
  415. }
  416. else
  417. {
  418. AfpServerInfo.afpsrv_options |= AFP_SRVROPT_MICROSOFT_UAM;
  419. }
  420. AfpServerInfo.afpsrv_options &= ~AFP_SRVROPT_CLEARTEXTLOGONALLOWED;
  421. AfpServerInfo.afpsrv_options &= ~AFP_SRVROPT_NATIVEAPPLEUAM;
  422. break;
  423. case 1:
  424. // Apple cleartext
  425. AfpServerInfo.afpsrv_options |= AFP_SRVROPT_CLEARTEXTLOGONALLOWED;
  426. AfpServerInfo.afpsrv_options &= ~AFP_SRVROPT_MICROSOFT_UAM;
  427. AfpServerInfo.afpsrv_options &= ~AFP_SRVROPT_NATIVEAPPLEUAM;
  428. break;
  429. case 2:
  430. // Apple encrypted (only on NT5)
  431. AfpServerInfo.afpsrv_options &= ~AFP_SRVROPT_CLEARTEXTLOGONALLOWED;
  432. AfpServerInfo.afpsrv_options &= ~AFP_SRVROPT_MICROSOFT_UAM;
  433. AfpServerInfo.afpsrv_options |= AFP_SRVROPT_NATIVEAPPLEUAM;
  434. break;
  435. case 3:
  436. // Cleartext or MS (only on NT5)
  437. AfpServerInfo.afpsrv_options |= AFP_SRVROPT_CLEARTEXTLOGONALLOWED;
  438. AfpServerInfo.afpsrv_options |= AFP_SRVROPT_MICROSOFT_UAM;
  439. AfpServerInfo.afpsrv_options &= ~AFP_SRVROPT_NATIVEAPPLEUAM;
  440. break;
  441. case 4:
  442. // Apple Encrypted or MS (only on NT5)
  443. AfpServerInfo.afpsrv_options &= ~AFP_SRVROPT_CLEARTEXTLOGONALLOWED;
  444. AfpServerInfo.afpsrv_options |= AFP_SRVROPT_MICROSOFT_UAM;
  445. AfpServerInfo.afpsrv_options |= AFP_SRVROPT_NATIVEAPPLEUAM;
  446. break;
  447. default:
  448. ASSERT(FALSE);
  449. break;
  450. }
  451. // if we are enabling an authentication type that has apple encrypted
  452. // then we need to warn the user.
  453. if ( (AfpServerInfo.afpsrv_options & AFP_SRVROPT_NATIVEAPPLEUAM) &&
  454. !(m_dwAfpOriginalOptions & AFP_SRVROPT_NATIVEAPPLEUAM) )
  455. {
  456. if (AfxMessageBox(IDS_AUTH_WARNING, MB_OKCANCEL) == IDCANCEL)
  457. {
  458. m_comboAuthentication.SetFocus();
  459. return FALSE;
  460. }
  461. }
  462. //
  463. // Get the session limit
  464. //
  465. AfpServerInfo.afpsrv_max_sessions = QuerySessionLimit();
  466. //
  467. // Now tell the server about it
  468. //
  469. dwParmNum |= ( AFP_SERVER_PARMNUM_OPTIONS |
  470. AFP_SERVER_PARMNUM_MAX_SESSIONS );
  471. err = ((SERVERSETINFOPROC) g_SfmDLL[AFP_SERVER_SET_INFO])(m_pSheet->m_hAfpServer,
  472. (LPBYTE)&AfpServerInfo,
  473. dwParmNum );
  474. if ( err != NO_ERROR )
  475. {
  476. ::SFMMessageBox(err);
  477. return FALSE;
  478. }
  479. // update our options
  480. m_dwAfpOriginalOptions = AfpServerInfo.afpsrv_options;
  481. //
  482. // Clear the modified status for this page
  483. //
  484. SetModified(FALSE);
  485. return TRUE;
  486. }
  487. int CMacFilesConfiguration::OnCreate(LPCREATESTRUCT lpCreateStruct)
  488. {
  489. if (CPropertyPage::OnCreate(lpCreateStruct) == -1)
  490. return -1;
  491. HWND hParent = ::GetParent(m_hWnd);
  492. _ASSERTE(hParent);
  493. if (m_pSheet)
  494. {
  495. m_pSheet->AddRef();
  496. m_pSheet->SetSheetWindow(hParent);
  497. }
  498. return 0;
  499. }
  500. void CMacFilesConfiguration::OnDestroy()
  501. {
  502. CPropertyPage::OnDestroy();
  503. if (m_pSheet)
  504. {
  505. SetEvent(m_pSheet->m_hDestroySync);
  506. m_pSheet->SetSheetWindow(NULL);
  507. m_pSheet->Release();
  508. }
  509. }
  510. BOOL CMacFilesConfiguration::OnHelpInfo(HELPINFO* pHelpInfo)
  511. {
  512. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  513. if (pHelpInfo->iContextType == HELPINFO_WINDOW)
  514. {
  515. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  516. m_pSheet->m_strHelpFilePath,
  517. HELP_WM_HELP,
  518. g_aHelpIDs_CONFIGURE_SFM);
  519. }
  520. return TRUE;
  521. }
  522. void CMacFilesConfiguration::OnContextMenu(CWnd* pWnd, CPoint /*point*/)
  523. {
  524. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  525. if (this == pWnd)
  526. return;
  527. ::WinHelp (pWnd->m_hWnd,
  528. m_pSheet->m_strHelpFilePath,
  529. HELP_CONTEXTMENU,
  530. g_aHelpIDs_CONFIGURE_SFM);
  531. }