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.

548 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. server.cxx
  7. This file contains the definition of SERVER_PARAMETERS_DIALOG.
  8. History:
  9. NarenG 12/15/92 Created.
  10. */
  11. #define INCL_WINDOWS_GDI
  12. #define INCL_WINDOWS
  13. #define INCL_DOSERRORS
  14. #define INCL_NETERRORS
  15. #define INCL_NETSHARE
  16. #define INCL_NETSERVER
  17. #define INCL_NETCONS
  18. #define INCL_NETLIB
  19. #include <lmui.hxx>
  20. #define INCL_BLT_WINDOW
  21. #define INCL_BLT_DIALOG
  22. #define INCL_BLT_CONTROL
  23. #define INCL_BLT_MISC
  24. #define INCL_BLT_CLIENT
  25. #define INCL_BLT_MSGPOPUP
  26. #define INCL_BLT_SPIN_GROUP
  27. #define INCL_BLT_GROUP
  28. #include <blt.hxx>
  29. extern "C"
  30. {
  31. #include <afpmgr.h>
  32. #include <macfile.h>
  33. }
  34. #include <string.hxx>
  35. #include <uitrace.hxx>
  36. #include <dbgstr.hxx>
  37. #include <netname.hxx>
  38. #include "util.hxx"
  39. #include "srvname.hxx"
  40. #include "server.hxx"
  41. /*******************************************************************
  42. NAME: SERVER_PARAMETERS_DIALOG::SERVER_PARAMETERS_DIALOG
  43. SYNOPSIS: Constructor for SERVER_PARAMETERS_DIALOG class
  44. ENTRY: hwndParent - handle of parent window
  45. EXIT:
  46. RETURNS:
  47. NOTES:
  48. HISTORY:
  49. NarenG 12/15/92 Created
  50. ********************************************************************/
  51. SERVER_PARAMETERS_DIALOG::SERVER_PARAMETERS_DIALOG(
  52. HWND hwndParent,
  53. AFP_SERVER_HANDLE hServer,
  54. const TCHAR * pszServerName )
  55. : DIALOG_WINDOW( MAKEINTRESOURCE( IDD_SERVER_PARAMETERS_DIALOG ),
  56. hwndParent ),
  57. _sltServerName( this, IDSP_SLT_SERVERNAME, ELLIPSIS_RIGHT ),
  58. _mleTextMsg( this, IDSP_MLE_LOGINMSG, AFP_MESSAGE_LEN ),
  59. _chkAllowPasswordSaves( this,IDSP_CHK_PASSWORD_SAVES ),
  60. _chkAllowGuestLogons( this, IDSP_CHK_GUESTLOGONS ),
  61. _chkAllowClearTextPasswords( this,IDSP_CHK_CLEARTEXT ),
  62. _mgrpSessionLimit( this, IDSP_RB_UNLIMITED, 2, IDSP_RB_UNLIMITED),
  63. _spsleSessions( this, IDSP_SLE_SESSIONS, 1, 1, AFP_MAXSESSIONS-1,
  64. TRUE, IDSP_SLE_SESSIONS_GROUP ),
  65. _spgrpSessions(this,IDSP_SB_SESSIONS_GROUP, IDSP_SB_SESSIONS_UP,
  66. IDSP_SB_SESSIONS_DOWN),
  67. _pbChange( this, IDSP_PB_CHANGE ),
  68. _dwParmNum( 0 ),
  69. _hServer( hServer )
  70. {
  71. UNREFERENCED( pszServerName );
  72. //
  73. // Make sure everything constructed OK
  74. //
  75. if ( QueryError() != NERR_Success )
  76. return;
  77. APIERR err;
  78. if ( ((err = _mgrpSessionLimit.QueryError()) != NERR_Success )
  79. || ((err = _spgrpSessions.AddAssociation(&_spsleSessions))!=NERR_Success)
  80. || ((err = _mgrpSessionLimit.AddAssociation( IDSP_RB_SESSIONS,
  81. &_spgrpSessions ))
  82. != NERR_Success )
  83. || ((err = _pbChange.QueryError()) != NERR_Success )
  84. || ((err = _chkAllowPasswordSaves.QueryError()) != NERR_Success )
  85. || ((err = _chkAllowGuestLogons.QueryError()) != NERR_Success )
  86. || ((err = _chkAllowClearTextPasswords.QueryError()) != NERR_Success )
  87. || ((err = _mleTextMsg.QueryError()) != NERR_Success )
  88. || ((err = _sltServerName.QueryError()) != NERR_Success )
  89. )
  90. {
  91. ReportError( err );
  92. return;
  93. }
  94. //
  95. // Just to be cool...
  96. //
  97. AUTO_CURSOR Cursor;
  98. err = BASE_ELLIPSIS::Init();
  99. if( err != NO_ERROR )
  100. {
  101. ReportError( err );
  102. return;
  103. }
  104. //
  105. // Set the caption to "SFM Server Attributes of Server".
  106. //
  107. err = ::SetCaption( this, IDS_CAPTION_ATTRIBUTES, pszServerName );
  108. if( err != NERR_Success )
  109. {
  110. ReportError( err );
  111. return;
  112. }
  113. //
  114. // Get the server information.
  115. //
  116. PAFP_SERVER_INFO pAfpServerInfo;
  117. err = ::AfpAdminServerGetInfo( _hServer, (LPBYTE*)&pAfpServerInfo );
  118. if ( err != NO_ERROR )
  119. {
  120. ReportError( AFPERR_TO_STRINGID( err ) );
  121. return;
  122. }
  123. //
  124. // Set the information
  125. //
  126. _sltServerName.SetText( pAfpServerInfo->afpsrv_name );
  127. _chkAllowPasswordSaves.SetCheck(
  128. (INT)(pAfpServerInfo->afpsrv_options &
  129. AFP_SRVROPT_ALLOWSAVEDPASSWORD ));
  130. _chkAllowGuestLogons.SetCheck(
  131. (INT)(pAfpServerInfo->afpsrv_options &
  132. AFP_SRVROPT_GUESTLOGONALLOWED ));
  133. _chkAllowClearTextPasswords.SetCheck(
  134. (INT)(!(pAfpServerInfo->afpsrv_options &
  135. AFP_SRVROPT_CLEARTEXTLOGONALLOWED )));
  136. SetSessionLimit( pAfpServerInfo->afpsrv_max_sessions );
  137. _mleTextMsg.SetText( pAfpServerInfo->afpsrv_login_msg );
  138. //
  139. // Direct the message edit control not to add end-of-line
  140. // character from wordwrapped text lines.
  141. //
  142. _mleTextMsg.SetFmtLines(FALSE);
  143. ::AfpAdminBufferFree( pAfpServerInfo );
  144. _pbChange.ClaimFocus();
  145. }
  146. /*******************************************************************
  147. NAME: SERVER_PARAMETERS_DIALOG :: ~SERVER_PARAMETERS_DIALOG
  148. SYNOPSIS: SERVER_PARAMETERS_DIALOG class destructor.
  149. EXIT: The object is destroyed.
  150. HISTORY:
  151. NarenG 02-Oct-1993 Stole from Server Manager and folded
  152. BASE_RES_DIALOG and FILES_DIALOG into one.
  153. ********************************************************************/
  154. SERVER_PARAMETERS_DIALOG :: ~SERVER_PARAMETERS_DIALOG()
  155. {
  156. BASE_ELLIPSIS::Term();
  157. } // SERVER_PARAMETERS_DIALOG :: ~SERVER_PARAMETERS_DIALOG
  158. /*******************************************************************
  159. NAME: SERVER_PARAMETERS_DIALOG :: OnCommand
  160. SYNOPSIS: This method is called whenever a WM_COMMAND message
  161. is sent to the dialog procedure.
  162. ENTRY: cid - The control ID from the
  163. generating control.
  164. EXIT: The command has been handled.
  165. RETURNS: BOOL - TRUE if we handled the command.
  166. FALSE if we did not handle
  167. the command.
  168. HISTORY:
  169. NarenG 02-Oct-1993 Stole from Server Manager and folded
  170. BASE_RES_DIALOG and FILES_DIALOG into one.
  171. ********************************************************************/
  172. BOOL SERVER_PARAMETERS_DIALOG :: OnCommand( const CONTROL_EVENT & event )
  173. {
  174. DWORD err;
  175. if( event.QueryCid() == _pbChange.QueryCid() )
  176. {
  177. //
  178. // Just to be cool...
  179. //
  180. AUTO_CURSOR Cursor;
  181. //
  182. // Bring up the change server name dialog
  183. //
  184. NLS_STR nlsServerName;
  185. BOOL fOK;
  186. if ( ( err = nlsServerName.QueryError() ) != NERR_Success )
  187. {
  188. ::MsgPopup( this, err );
  189. return FALSE;
  190. }
  191. _sltServerName.QueryText( &nlsServerName ) ;
  192. CHANGE_SERVER_NAME_DLG *pDlg = new CHANGE_SERVER_NAME_DLG(
  193. QueryHwnd(),
  194. &nlsServerName );
  195. if ( ( pDlg == NULL )
  196. || ((err = pDlg->QueryError()) != NERR_Success )
  197. || ((err = pDlg->Process( &fOK )) != NERR_Success ) )
  198. {
  199. err = err ? err : ERROR_NOT_ENOUGH_MEMORY;
  200. }
  201. delete pDlg;
  202. pDlg = NULL;
  203. if ( err != NO_ERROR )
  204. {
  205. ::MsgPopup( this, err );
  206. return FALSE;
  207. }
  208. else
  209. {
  210. if ( fOK )
  211. {
  212. _sltServerName.SetText( nlsServerName );
  213. _dwParmNum |= AFP_SERVER_PARMNUM_NAME;
  214. ::MsgPopup( this, IDS_SERVERNAME_CHANGE, MPSEV_WARNING, MP_OK );
  215. }
  216. }
  217. }
  218. return DIALOG_WINDOW::OnCommand( event );
  219. }
  220. /*******************************************************************
  221. NAME: SERVER_PARAMETERS_DIALOG::OnOK
  222. SYNOPSIS: Validate all the information and create the volume.
  223. ENTRY:
  224. EXIT:
  225. RETURNS:
  226. NOTES:
  227. HISTORY:
  228. NarenG 12/15/92 Created
  229. ********************************************************************/
  230. BOOL SERVER_PARAMETERS_DIALOG :: OnOK( VOID )
  231. {
  232. APIERR err;
  233. //
  234. // Just to be cool...
  235. //
  236. AUTO_CURSOR Cursor;
  237. AFP_SERVER_INFO AfpServerInfo;
  238. NLS_STR nlsServerName;
  239. if ( ( err = nlsServerName.QueryError() ) != NERR_Success )
  240. {
  241. ::MsgPopup( this, err );
  242. Dismiss(FALSE) ;
  243. return(FALSE);
  244. }
  245. //
  246. // Set the server name
  247. //
  248. _sltServerName.QueryText( &nlsServerName );
  249. AfpServerInfo.afpsrv_name = (LPWSTR)(nlsServerName.QueryPch());
  250. //
  251. // Get the logon message
  252. //
  253. UINT cb = _mleTextMsg.QueryTextSize();
  254. NLS_STR nlsMsgText( cb );
  255. //
  256. // Was there any text ?
  257. //
  258. if ( cb <= sizeof(TCHAR) ) // always has a terminating NULL
  259. {
  260. AfpServerInfo.afpsrv_login_msg = NULL;
  261. }
  262. else
  263. {
  264. if ( (( err = nlsMsgText.QueryError() ) != NERR_Success ) ||
  265. (( err = _mleTextMsg.QueryText(&nlsMsgText))!= NERR_Success ))
  266. {
  267. ::MsgPopup( this, err );
  268. Dismiss(FALSE) ;
  269. return(TRUE);
  270. }
  271. if ( nlsMsgText.QueryTextLength() > AFP_MESSAGE_LEN )
  272. {
  273. ::MsgPopup( this, IDS_MESSAGE_TOO_LONG );
  274. _mleTextMsg.ClaimFocus();
  275. _mleTextMsg.SelectString();
  276. return(FALSE);
  277. }
  278. AfpServerInfo.afpsrv_login_msg = (LPWSTR)(nlsMsgText.QueryPch());
  279. }
  280. //
  281. // Set the server options if the user changed it
  282. //
  283. AfpServerInfo.afpsrv_options = _chkAllowPasswordSaves.QueryCheck()
  284. ? AFP_SRVROPT_ALLOWSAVEDPASSWORD
  285. : 0;
  286. AfpServerInfo.afpsrv_options |= _chkAllowGuestLogons.QueryCheck()
  287. ? AFP_SRVROPT_GUESTLOGONALLOWED
  288. : 0;
  289. AfpServerInfo.afpsrv_options |= _chkAllowClearTextPasswords.QueryCheck()
  290. ? 0 : AFP_SRVROPT_CLEARTEXTLOGONALLOWED;
  291. AfpServerInfo.afpsrv_max_sessions = QuerySessionLimit();
  292. //
  293. // Set this information
  294. //
  295. _dwParmNum |= ( AFP_SERVER_PARMNUM_LOGINMSG |
  296. AFP_SERVER_PARMNUM_OPTIONS |
  297. AFP_SERVER_PARMNUM_MAX_SESSIONS );
  298. err = ::AfpAdminServerSetInfo( _hServer,
  299. (LPBYTE)&AfpServerInfo,
  300. _dwParmNum );
  301. if ( err == NO_ERROR )
  302. {
  303. Dismiss( TRUE );
  304. }
  305. else
  306. {
  307. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  308. }
  309. return TRUE;
  310. }
  311. /*******************************************************************
  312. NAME: SERVER_PARAMETERS_DIALOG::QuerySessionLimit
  313. SYNOPSIS: Get the user limit from the magic group
  314. ENTRY:
  315. EXIT:
  316. RETURNS: The user limit stored in the user limit magic group
  317. NOTES:
  318. HISTORY:
  319. NarenG 12/15/92 Created
  320. ********************************************************************/
  321. DWORD SERVER_PARAMETERS_DIALOG::QuerySessionLimit( VOID ) const
  322. {
  323. switch ( _mgrpSessionLimit.QuerySelection() )
  324. {
  325. case IDSP_RB_UNLIMITED:
  326. return( AFP_MAXSESSIONS );
  327. case IDSP_RB_SESSIONS:
  328. return( _spsleSessions.QueryValue() );
  329. default:
  330. //
  331. // Should never get here but in case we do, return unlimited
  332. //
  333. return( AFP_MAXSESSIONS );
  334. }
  335. }
  336. /*******************************************************************
  337. NAME: SERVER_PARAMETERS_DIALOG::SetSessionLimit
  338. SYNOPSIS: Sets the user limit on the magic group
  339. ENTRY: dwSessionLimit - maximum number of users allowed
  340. EXIT:
  341. RETURNS:
  342. NOTES:
  343. HISTORY:
  344. NarenG 12/15/92 Created
  345. ********************************************************************/
  346. VOID SERVER_PARAMETERS_DIALOG::SetSessionLimit( DWORD dwSessionLimit )
  347. {
  348. if ( dwSessionLimit == AFP_MAXSESSIONS )
  349. {
  350. //
  351. // Set selection to the Unlimited button
  352. //
  353. _mgrpSessionLimit.SetSelection( IDSP_RB_UNLIMITED );
  354. }
  355. else
  356. {
  357. //
  358. // Set the sessions button to the value
  359. //
  360. _mgrpSessionLimit.SetSelection( IDSP_RB_SESSIONS );
  361. _spsleSessions.SetValue( dwSessionLimit );
  362. _spsleSessions.Update();
  363. }
  364. }
  365. /*******************************************************************
  366. NAME: SERVER_PARAMETERS_DIALOG::QueryHelpContext
  367. SYNOPSIS: Query the help context of the dialog
  368. ENTRY:
  369. EXIT:
  370. RETURNS: Return the help context of the dialog
  371. NOTES:
  372. HISTORY:
  373. NarenG 12/15/92 Created
  374. ********************************************************************/
  375. ULONG SERVER_PARAMETERS_DIALOG::QueryHelpContext( VOID )
  376. {
  377. return HC_SERVER_PARAMETERS_DIALOG;
  378. }