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.

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