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.

1370 lines
36 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1993 **/
  4. /**********************************************************************/
  5. /*
  6. ftpmgr.cxx
  7. The file contains the classes for the FTP user sessions dialog
  8. and the security dialog.
  9. FILE HISTORY:
  10. YiHsinS 17-Mar-1992 Created
  11. */
  12. #define INCL_NET
  13. #define INCL_NETLIB
  14. #define INCL_WINDOWS
  15. #define INCL_WINDOWS_GDI
  16. #define INCL_NETERRORS
  17. #define INCL_DOSERRORS
  18. #include <lmui.hxx>
  19. #if defined(DEBUG)
  20. static const CHAR szFileName[] = __FILE__;
  21. #define _FILENAME_DEFINED_ONCE szFileName
  22. #endif
  23. #define INCL_BLT_WINDOW
  24. #define INCL_BLT_DIALOG
  25. #define INCL_BLT_CONTROL
  26. #define INCL_BLT_CLIENT
  27. #define INCL_BLT_MSGPOPUP
  28. #define INCL_BLT_EVENT
  29. #define INCL_BLT_MISC
  30. #define INCL_BLT_CC
  31. #include <blt.hxx>
  32. #include <uiassert.hxx>
  33. #include <uitrace.hxx>
  34. #include <dbgstr.hxx>
  35. extern "C"
  36. {
  37. #include <winsock.h> // IN_ADDR, inet_ntoa
  38. #include <lmapibuf.h> // For NetApiBufferFree
  39. #include <ftpd.h> // For I_Ftp... APIs
  40. #include <mnet.h>
  41. #include <ftpmgr.h>
  42. }
  43. #include <lmoloc.hxx>
  44. #include <ftpmgr.hxx>
  45. /*******************************************************************
  46. NAME: FTP_USER_LBI::FTP_USER_LBI
  47. SYNOPSIS: Constructor. Each LBI represents a user connected
  48. to the FTP service on the given computer.
  49. ENTRY: pszUserName - The name of the user
  50. ulUserID - The internal ID used by the FTP
  51. service to represent this user
  52. fAnonymous - TRUE if the user logged on as anonymous
  53. FALSE otherwise.
  54. pszInternetAddress - The address of the host the user
  55. is connected from.
  56. pszConnectTimeString - The duration of time the user has
  57. been connected
  58. EXIT:
  59. RETURNS:
  60. NOTES:
  61. HISTORY:
  62. YiHsinS 25-Mar-1993 Created
  63. ********************************************************************/
  64. FTP_USER_LBI::FTP_USER_LBI( const TCHAR *pszUserName,
  65. ULONG ulUserID,
  66. BOOL fAnonymous,
  67. const TCHAR *pszInternetAddress,
  68. const TCHAR *pszConnectTimeString )
  69. : _nlsUserName ( pszUserName ),
  70. _ulUserID ( ulUserID ),
  71. _fAnonymous ( fAnonymous ),
  72. _nlsInternetAddress ( pszInternetAddress ),
  73. _nlsConnectTimeString( pszConnectTimeString )
  74. {
  75. if ( QueryError() )
  76. return;
  77. APIERR err = NERR_Success;
  78. //
  79. // If the user name is username@mailhost-style string,
  80. // print only the username portion ( everything left of @ )
  81. //
  82. ISTR istr( _nlsUserName );
  83. if ( _nlsUserName.strchr( &istr, TCH('@')))
  84. _nlsUserName.DelSubStr( istr );
  85. if ( ( err = _nlsUserName.QueryError() )
  86. || ( err = _nlsInternetAddress.QueryError() )
  87. || ( err = _nlsConnectTimeString.QueryError() )
  88. )
  89. {
  90. ReportError( err? err : ERROR_NOT_ENOUGH_MEMORY );
  91. return;
  92. }
  93. }
  94. /*******************************************************************
  95. NAME: FTP_USER_LBI::FTP_USER_LBI
  96. SYNOPSIS: Destructor
  97. ENTRY:
  98. EXIT:
  99. RETURNS:
  100. NOTES:
  101. HISTORY:
  102. YiHsinS 25-Mar-1993 Created
  103. ********************************************************************/
  104. FTP_USER_LBI::~FTP_USER_LBI()
  105. {
  106. // Nothing to do for now
  107. }
  108. /*******************************************************************
  109. NAME: FTP_USER_LBI::Paint
  110. SYNOPSIS: Redefine Paint() method of the LBI class.
  111. ENTRY: plb - the listbox this LBI belongs to
  112. hdc
  113. prect
  114. pGUILTT
  115. EXIT:
  116. RETURNS:
  117. NOTES:
  118. HISTORY:
  119. YiHsinS 25-Mar-1993 Created
  120. ********************************************************************/
  121. VOID FTP_USER_LBI::Paint( LISTBOX *plb, HDC hdc, const RECT *prect,
  122. GUILTT_INFO *pGUILTT ) const
  123. {
  124. FTP_USER_LISTBOX *plbUser = ( FTP_USER_LISTBOX *) plb;
  125. STR_DTE strdteUserName( _nlsUserName );
  126. STR_DTE strdteInternetAddress( _nlsInternetAddress );
  127. STR_DTE strdteConnectTime( _nlsConnectTimeString );
  128. DISPLAY_TABLE cdt( 4, plbUser->QueryColumnWidths() );
  129. cdt[0] = (DMID_DTE *) (IsAnonymousUser()? plbUser->QueryAnonymousBitmap()
  130. : plbUser->QueryUserBitmap());
  131. cdt[1] = &strdteUserName;
  132. cdt[2] = &strdteInternetAddress;
  133. cdt[3] = &strdteConnectTime;
  134. cdt.Paint( plb, hdc, prect, pGUILTT );
  135. }
  136. /*******************************************************************
  137. NAME: FTP_USER_LBI::Compare
  138. SYNOPSIS: Redefine Compare() method of the LBI class.
  139. We compare the user names of the two LBIs.
  140. ENTRY: plbi - Pointer to the LBI to compare with
  141. EXIT:
  142. RETURNS:
  143. NOTES:
  144. HISTORY:
  145. YiHsinS 25-Mar-1993 Created
  146. ********************************************************************/
  147. INT FTP_USER_LBI::Compare( const LBI *plbi ) const
  148. {
  149. return _nlsUserName._stricmp( *( ((FTP_USER_LBI *) plbi)->QueryUserName()));
  150. }
  151. /*******************************************************************
  152. NAME: FTP_USER_LBI::QueryLeadingChar
  153. SYNOPSIS: Returns the leading character of the user name
  154. ENTRY:
  155. EXIT:
  156. RETURNS:
  157. NOTES:
  158. HISTORY:
  159. YiHsinS 25-Mar-1993 Created
  160. ********************************************************************/
  161. WCHAR FTP_USER_LBI::QueryLeadingChar( VOID ) const
  162. {
  163. ISTR istr( _nlsUserName );
  164. return _nlsUserName.QueryChar( istr );
  165. }
  166. /*******************************************************************
  167. NAME: FTP_USER_LISTBOX::FTP_USER_LISTBOX
  168. SYNOPSIS: Constructor
  169. ENTRY: powOwner - pointer to the owner window
  170. cid - resource id of the listbox
  171. pszServer - the server name to point to
  172. EXIT:
  173. RETURNS:
  174. NOTES:
  175. HISTORY:
  176. YiHsinS 25-Mar-1993 Created
  177. ********************************************************************/
  178. FTP_USER_LISTBOX::FTP_USER_LISTBOX( OWNER_WINDOW *powOwner,
  179. CID cid,
  180. const TCHAR *pszServer )
  181. : BLT_LISTBOX( powOwner, cid ),
  182. _nlsServer ( pszServer ),
  183. _nlsUnknown( IDS_UI_UNKNOWN ),
  184. _pdmdteUser( NULL ),
  185. _pdmdteAnonymous( NULL ),
  186. _intlProf()
  187. {
  188. if ( QueryError() )
  189. return;
  190. APIERR err;
  191. if ( ( err = _nlsServer.QueryError())
  192. || ( err = _nlsUnknown.QueryError())
  193. || ( err = _intlProf.QueryError())
  194. || (( _pdmdteUser = new DMID_DTE( BMID_USER )) == NULL )
  195. || (( _pdmdteAnonymous = new DMID_DTE( BMID_ANONYMOUS)) == NULL )
  196. || ( err = _pdmdteUser->QueryError())
  197. || ( err = _pdmdteAnonymous->QueryError())
  198. || ( err = DISPLAY_TABLE::CalcColumnWidths( _adx, 4, powOwner, cid,TRUE))
  199. )
  200. {
  201. ReportError( err? err : ERROR_NOT_ENOUGH_MEMORY );
  202. return;
  203. }
  204. }
  205. /*******************************************************************
  206. NAME: FTP_USER_LISTBOX::~FTP_USER_LISTBOX
  207. SYNOPSIS: Destructor
  208. ENTRY:
  209. EXIT:
  210. RETURNS:
  211. NOTES:
  212. HISTORY:
  213. YiHsinS 25-Mar-1993 Created
  214. ********************************************************************/
  215. FTP_USER_LISTBOX::~FTP_USER_LISTBOX()
  216. {
  217. delete _pdmdteUser;
  218. delete _pdmdteAnonymous;
  219. _pdmdteUser = NULL;
  220. _pdmdteAnonymous = NULL;
  221. }
  222. /*******************************************************************
  223. NAME: FTP_USER_LISTBOX::Fill
  224. SYNOPSIS: This method enumerates the users connected to the
  225. FTP service and add them to the listbox.
  226. ENTRY:
  227. EXIT:
  228. RETURNS: APIERR
  229. NOTES:
  230. HISTORY:
  231. YiHsinS 25-Mar-1993 Created
  232. ********************************************************************/
  233. APIERR FTP_USER_LISTBOX::Fill( VOID )
  234. {
  235. //
  236. // Enumerate the users connected to the FTP service on the
  237. // given server.
  238. //
  239. DWORD nCount = 0;
  240. LPFTP_USER_INFO aUserInfo = NULL;
  241. APIERR err = ::I_FtpEnumerateUsers( (LPWSTR) _nlsServer.QueryPch(),
  242. &nCount,
  243. &aUserInfo );
  244. if ( err == NERR_Success )
  245. {
  246. NLS_STR nlsTimeString;
  247. NLS_STR nlsInternetAddress;
  248. if ( (( err = nlsTimeString.QueryError()) == NERR_Success )
  249. && (( err = nlsInternetAddress.QueryError()) == NERR_Success )
  250. )
  251. {
  252. //
  253. // Loop through all the users, create LBIs for each of them,
  254. // and add them to the listbox.
  255. //
  256. LPFTP_USER_INFO pUserInfo = aUserInfo;
  257. for ( INT i = 0; i < (INT) nCount; i++ )
  258. {
  259. err = QueryTimeString( pUserInfo->tConnect, &nlsTimeString );
  260. if ( err != NERR_Success )
  261. break;
  262. IN_ADDR inaddr;
  263. inaddr.s_addr = pUserInfo->inetHost;
  264. CHAR *pszInternetAddress = ::inet_ntoa( inaddr );
  265. if ( err = nlsInternetAddress.MapCopyFrom( pszInternetAddress) )
  266. break;
  267. const TCHAR * pszDisplayName = pUserInfo->pszUser;
  268. if( ( pszDisplayName == NULL ) || ( *pszDisplayName == '\0' ) )
  269. {
  270. pszDisplayName = _nlsUnknown;
  271. }
  272. FTP_USER_LBI *plbi = new FTP_USER_LBI( pszDisplayName,
  273. pUserInfo->idUser,
  274. pUserInfo->fAnonymous,
  275. nlsInternetAddress,
  276. nlsTimeString );
  277. if ( ( plbi == NULL )
  278. || ( err = plbi->QueryError() )
  279. || ( AddItem( plbi ) < 0 )
  280. )
  281. {
  282. delete plbi;
  283. plbi = NULL;
  284. err = err? err : ERROR_NOT_ENOUGH_MEMORY;
  285. break;
  286. }
  287. ++pUserInfo;
  288. }
  289. }
  290. }
  291. ::NetApiBufferFree( (LPVOID) aUserInfo );
  292. return err;
  293. }
  294. /*******************************************************************
  295. NAME: FTP_USER_LISTBOX::Refresh
  296. SYNOPSIS: This method refresh the contents of the listbox.
  297. ENTRY:
  298. EXIT:
  299. RETURNS: APIERR
  300. NOTES:
  301. HISTORY:
  302. YiHsinS 25-Mar-1993 Created
  303. ********************************************************************/
  304. APIERR FTP_USER_LISTBOX::Refresh( VOID )
  305. {
  306. SetRedraw( FALSE );
  307. //
  308. // Delete all the original items in the listbox
  309. //
  310. DeleteAllItems();
  311. //
  312. // Call Fill() to enumerate the users
  313. //
  314. APIERR err = Fill();
  315. Invalidate();
  316. SetRedraw( TRUE );
  317. return err;
  318. }
  319. /*******************************************************************
  320. NAME: FTP_USER_LISTBOX::QueryTimeString
  321. SYNOPSIS: This method turns the time duration to a displayable
  322. string that complies with the window settings.
  323. ENTRY: ulTime - The elapsed time
  324. EXIT: pnlsTime - Pointer to the time display string returned.
  325. RETURNS: APIERR
  326. NOTES:
  327. HISTORY:
  328. YiHsinS 25-Mar-1993 Created
  329. ********************************************************************/
  330. #define SECONDS_PER_DAY 86400
  331. #define SECONDS_PER_HOUR 3600
  332. #define SECONDS_PER_MINUTE 60
  333. APIERR FTP_USER_LISTBOX::QueryTimeString( ULONG ulTime, NLS_STR *pnlsTime )
  334. {
  335. INT nDay = (INT) ulTime / SECONDS_PER_DAY;
  336. ulTime %= SECONDS_PER_DAY;
  337. INT nHour = (INT) ulTime / SECONDS_PER_HOUR;
  338. ulTime %= SECONDS_PER_HOUR;
  339. INT nMinute = (INT) ulTime / SECONDS_PER_MINUTE;
  340. INT nSecond = (INT) ulTime % SECONDS_PER_MINUTE;
  341. return _intlProf.QueryDurationStr( nDay, nHour, nMinute, nSecond, pnlsTime);
  342. }
  343. /*******************************************************************
  344. NAME: FTP_SVCMGR_DIALOG::FTP_SVCMGR_DIALOG
  345. SYNOPSIS: Constructor. This is the user sessions dialog of
  346. FTP service manager.
  347. ENTRY: hwndOwner - Hwnd of the owner window
  348. pszServer - The name of the server to point to
  349. EXIT:
  350. RETURNS:
  351. NOTES:
  352. HISTORY:
  353. YiHsinS 25-Mar-1993 Created
  354. ********************************************************************/
  355. FTP_SVCMGR_DIALOG::FTP_SVCMGR_DIALOG( HWND hwndOwner,
  356. const TCHAR *pszServer )
  357. : DIALOG_WINDOW( MAKEINTRESOURCE( IDD_FTPSVCMGRDLG), hwndOwner ),
  358. _nlsServer( pszServer ),
  359. _lbUser ( this, LB_USERS, pszServer ),
  360. _pbuttonDisconnect ( this, BUTTON_DISCONNECT ),
  361. _pbuttonDisconnectAll( this, BUTTON_DISCONNECT_ALL )
  362. {
  363. if ( QueryError() != NERR_Success )
  364. return;
  365. //
  366. // Call Refresh() to fill the users in the listbox
  367. //
  368. APIERR err = NERR_Success;
  369. if ( ((err = _nlsServer.QueryError()) != NERR_Success )
  370. || ((err = Refresh()) != NERR_Success )
  371. )
  372. {
  373. ReportError( err );
  374. return;
  375. }
  376. //
  377. // Set the caption to include the server name if the given
  378. // server name is not an empty string.
  379. //
  380. if ( _nlsServer.QueryTextLength() > 0 )
  381. {
  382. RESOURCE_STR nlsCaption( IDS_FTP_USER_SESSIONS_ON_COMPUTER );
  383. ISTR istr ( _nlsServer );
  384. istr += 2; // Skip the two backslashes
  385. ALIAS_STR nlsSrvWithoutPrefix( _nlsServer.QueryPch( istr ) );
  386. if ( ((err = nlsCaption.QueryError()) != NERR_Success )
  387. || ((err = nlsCaption.InsertParams( 1, &nlsSrvWithoutPrefix))
  388. != NERR_Success)
  389. )
  390. {
  391. ReportError( err );
  392. return;
  393. }
  394. SetText( nlsCaption );
  395. }
  396. }
  397. /*******************************************************************
  398. NAME: FTP_SVCMGR_DIALOG::~FTP_SVCMGR_DIALOG
  399. SYNOPSIS: Destructor
  400. ENTRY:
  401. EXIT:
  402. RETURNS:
  403. NOTES:
  404. HISTORY:
  405. YiHsinS 25-Mar-1993 Created
  406. ********************************************************************/
  407. FTP_SVCMGR_DIALOG::~FTP_SVCMGR_DIALOG()
  408. {
  409. // Nothing to do for now
  410. }
  411. /*******************************************************************
  412. NAME: FTP_SVCMGR_DIALOG::Refresh
  413. SYNOPSIS: Refresh the contents of the user listbox
  414. ENTRY:
  415. EXIT:
  416. RETURNS: APIERR
  417. NOTES:
  418. HISTORY:
  419. YiHsinS 25-Mar-1993 Created
  420. ********************************************************************/
  421. APIERR FTP_SVCMGR_DIALOG::Refresh( VOID )
  422. {
  423. AUTO_CURSOR autocur;
  424. APIERR err = _lbUser.Refresh();
  425. if ( err == NERR_Success )
  426. {
  427. //
  428. // Enable/Disable the Disconnect/DisconnectAll button
  429. // depending on whether there are users in the listbox
  430. // after the refresh.
  431. //
  432. _pbuttonDisconnect.Enable( ( _lbUser.QueryCount() > 0 )
  433. && (_lbUser.QuerySelCount() > 0 ));
  434. _pbuttonDisconnectAll.Enable( _lbUser.QueryCount() > 0 );
  435. }
  436. _lbUser.ClaimFocus();
  437. return err;
  438. }
  439. /*******************************************************************
  440. NAME: FTP_SVCMGR_DIALOG::OnCommand
  441. SYNOPSIS: Process all commands for Security, Refresh,
  442. Disconnect, Disconnect All buttons.
  443. ENTRY: event - The event that occurred
  444. EXIT:
  445. RETURNS:
  446. NOTES:
  447. HISTORY:
  448. YiHsinS 25-Mar-1993 Created
  449. ********************************************************************/
  450. BOOL FTP_SVCMGR_DIALOG::OnCommand( const CONTROL_EVENT &event )
  451. {
  452. APIERR err = NERR_Success;
  453. switch ( event.QueryCid() )
  454. {
  455. case BUTTON_DISCONNECT:
  456. {
  457. INT *paSelItems = NULL;
  458. BOOL fAtLeastDeleteOneUser = FALSE;
  459. do { // not a loop
  460. INT nCount = _lbUser.QuerySelCount();
  461. if ( nCount == 0 )
  462. {
  463. // If no user is selected, just ignore the command.
  464. break;
  465. }
  466. else if ( nCount > 1 )
  467. {
  468. // If more than one user is selected in the listbox,
  469. // give a warning to the user to see if he/she
  470. // really wanted to disconnect the selected users.
  471. if ( ::MsgPopup( this,
  472. IDS_CONFIRM_DISCONNECT_SELECTED_USERS,
  473. MPSEV_WARNING, MP_YESNO, MP_NO ) != IDYES )
  474. {
  475. break;
  476. }
  477. }
  478. //
  479. // Get all the items selected in the listbox
  480. //
  481. paSelItems = (INT *) new BYTE[ sizeof(INT) * nCount ];
  482. if ( paSelItems == NULL )
  483. {
  484. err = ERROR_NOT_ENOUGH_MEMORY;
  485. break;
  486. }
  487. if ( err = _lbUser.QuerySelItems( paSelItems, nCount ))
  488. break;
  489. //
  490. // Pop up an warning containing the user name to be
  491. // disconnected if only one user is selected. Otherwise,
  492. // we would have already pop up the warning.
  493. //
  494. FTP_USER_LBI *pusrlbi = _lbUser.QueryItem( paSelItems[0] );
  495. if ( nCount == 1 )
  496. {
  497. if ( IDYES != ::MsgPopup( this,
  498. IDS_CONFIRM_DISCONNECT_ONE_USER,
  499. MPSEV_WARNING,
  500. MP_YESNO,
  501. *(pusrlbi->QueryUserName()),
  502. MP_NO ))
  503. {
  504. break;
  505. }
  506. }
  507. //
  508. // Disconnect the selected users one by one. If an error
  509. // occurred while disconnecting a user, we would break out
  510. // of the loop and the rest of the users will not be
  511. // disconnected.
  512. //
  513. AUTO_CURSOR autocur;
  514. for ( INT i = 0; i < nCount; i++ )
  515. {
  516. pusrlbi = _lbUser.QueryItem( paSelItems[i] );
  517. err = ::I_FtpDisconnectUser( (LPWSTR) _nlsServer.QueryPch(),
  518. pusrlbi->QueryUserID());
  519. if( err == NERR_UserNotFound )
  520. {
  521. //
  522. // The user is no longer connected. Since this
  523. // is what the admin wants anyway, we'll pretend
  524. // it succeeded.
  525. //
  526. err = NERR_Success;
  527. }
  528. if ( err != NERR_Success )
  529. break;
  530. fAtLeastDeleteOneUser = TRUE;
  531. }
  532. } while ( FALSE );
  533. if ( err )
  534. ::MsgPopup( this, err );
  535. //
  536. // If at least one user has be disconnected, refresh the listbox.
  537. //
  538. if ( fAtLeastDeleteOneUser )
  539. {
  540. if ( err = Refresh() )
  541. ::MsgPopup( this, err );
  542. }
  543. delete paSelItems;
  544. break;
  545. }
  546. case BUTTON_DISCONNECT_ALL:
  547. {
  548. //
  549. // Give a warning to the user to see if he really wants to
  550. // disconnect all users.
  551. //
  552. if ( IDYES == ::MsgPopup( this,
  553. IDS_CONFIRM_DISCONNECT_ALL_USERS,
  554. MPSEV_WARNING, MP_YESNO, MP_NO ))
  555. {
  556. //
  557. // Disconnect all Users and refresh the listbox
  558. //
  559. AUTO_CURSOR autocur;
  560. if ( (err = ::I_FtpDisconnectUser(
  561. (LPWSTR) _nlsServer.QueryPch(), 0)) == NERR_Success )
  562. {
  563. err = Refresh();
  564. }
  565. if ( err != NERR_Success )
  566. ::MsgPopup( this, err );
  567. }
  568. break;
  569. }
  570. case BUTTON_SECURITY:
  571. {
  572. //
  573. // Show the security dialog.
  574. //
  575. AUTO_CURSOR autocur;
  576. FTP_SECURITY_DIALOG *pdlg = new FTP_SECURITY_DIALOG( QueryHwnd(),
  577. _nlsServer );
  578. BOOL fOK = FALSE;
  579. if ( ( pdlg == NULL )
  580. || ( err = pdlg->QueryError() )
  581. || ( err = pdlg->Process( &fOK ) )
  582. )
  583. {
  584. err = err? err: ERROR_NOT_ENOUGH_MEMORY;
  585. }
  586. else if ( fOK )
  587. {
  588. // If the user clicks OK in the security dialog,
  589. // we need to refresh the listbox since the service
  590. // might blew some users away depending on the new
  591. // read/write access.
  592. err = Refresh();
  593. }
  594. if ( err != NERR_Success )
  595. ::MsgPopup( this, err );
  596. delete pdlg;
  597. pdlg = NULL;
  598. break;
  599. }
  600. case BUTTON_REFRESH:
  601. {
  602. if ( (err = Refresh()) != NERR_Success )
  603. ::MsgPopup( this, err );
  604. break;
  605. }
  606. case LB_USERS:
  607. //
  608. // Enable the Disconnect button only if the user has a selection
  609. // in the listbox.
  610. //
  611. _pbuttonDisconnect.Enable( ( _lbUser.QueryCount() > 0 )
  612. && (_lbUser.QuerySelCount() > 0 ));
  613. //
  614. // Falls through
  615. //
  616. default:
  617. return DIALOG_WINDOW::OnCommand( event );
  618. }
  619. return TRUE;
  620. }
  621. /*******************************************************************
  622. NAME: FTP_SVCMGR_DIALOG::QueryHelpContext
  623. SYNOPSIS: Get the help context for this dialog
  624. ENTRY:
  625. EXIT:
  626. RETURNS: ULONG - The help context for this dialog
  627. NOTES:
  628. HISTORY:
  629. YiHsinS 25-Mar-1993 Created
  630. ********************************************************************/
  631. ULONG FTP_SVCMGR_DIALOG::QueryHelpContext( VOID )
  632. {
  633. return HC_FTPSVCMGR_DIALOG;
  634. }
  635. /*******************************************************************
  636. NAME: FTP_SECURITY_DIALOG::FTP_SECURITY_DIALOG
  637. SYNOPSIS: Constructor
  638. ENTRY: hwndOwner - Hwnd of the owner window
  639. pszServer - The name of the server name to point to
  640. EXIT:
  641. RETURNS:
  642. NOTES:
  643. HISTORY:
  644. YiHsinS 25-Mar-1993 Created
  645. ********************************************************************/
  646. FTP_SECURITY_DIALOG::FTP_SECURITY_DIALOG( HWND hwndOwner,
  647. const TCHAR *pszServer )
  648. : DIALOG_WINDOW( MAKEINTRESOURCE( IDD_FTPSECDLG ), hwndOwner ),
  649. _nlsServer ( pszServer ),
  650. _fLocal ( TRUE ),
  651. _cbPartition ( this, CB_PARTITION ),
  652. _sltFileSysInfo ( this, SLT_FILESYSTEMTYPE ),
  653. _checkbReadAccess ( this, CHECKB_READ ),
  654. _checkbWriteAccess( this, CHECKB_WRITE ),
  655. _ulReadAccess ( 0 ),
  656. _ulWriteAccess ( 0 ),
  657. _nCurrentDiskIndex( 0 )
  658. {
  659. if ( QueryError() )
  660. return;
  661. //
  662. // Get security information on all drives
  663. //
  664. APIERR err;
  665. if ( ((err = _nlsServer.QueryError()) != NERR_Success )
  666. || ((err = ::I_FtpQueryVolumeSecurity( (LPWSTR) _nlsServer.QueryPch(),
  667. &_ulReadAccess, &_ulWriteAccess )) != NERR_Success )
  668. || ((err = AddDrives()) != NERR_Success )
  669. )
  670. {
  671. ReportError( err );
  672. return;
  673. }
  674. if ( _cbPartition.QueryCount() > 0 )
  675. {
  676. //
  677. // Select the first partition and show its information
  678. //
  679. _cbPartition.SelectItem( 0 );
  680. if ((err = ShowCurrentPartitionInfo()) != NERR_Success )
  681. {
  682. ReportError( err );
  683. return;
  684. }
  685. }
  686. else
  687. {
  688. // Popup an error if there are not partitions on the machine to
  689. // configure.
  690. ReportError( IDS_NO_PARTITION );
  691. return;
  692. }
  693. //
  694. // Set the caption to include the server name if the given server name
  695. // is not an empty string.
  696. //
  697. if ( _nlsServer.QueryTextLength() > 0 )
  698. {
  699. RESOURCE_STR nlsCaption( IDS_FTP_SERVER_SECURITY_ON_COMPUTER );
  700. ISTR istr ( _nlsServer );
  701. istr += 2; // Skip the two backslashes
  702. ALIAS_STR nlsSrvWithoutPrefix( _nlsServer.QueryPch( istr ) );
  703. if ( ((err = nlsCaption.QueryError()) != NERR_Success )
  704. || ((err = nlsCaption.InsertParams( 1, &nlsSrvWithoutPrefix))
  705. != NERR_Success)
  706. )
  707. {
  708. ReportError( err );
  709. return;
  710. }
  711. SetText( nlsCaption );
  712. }
  713. }
  714. /*******************************************************************
  715. NAME: FTP_SECURITY_DIALOG::~FTP_SECURITY_DIALOG
  716. SYNOPSIS: Destructor
  717. ENTRY:
  718. EXIT:
  719. RETURNS:
  720. NOTES:
  721. HISTORY:
  722. YiHsinS 25-Mar-1993 Created
  723. ********************************************************************/
  724. FTP_SECURITY_DIALOG::~FTP_SECURITY_DIALOG()
  725. {
  726. // Nothing to do for now
  727. }
  728. /*******************************************************************
  729. NAME: FTP_SECURITY_DIALOG::AddDrivers
  730. SYNOPSIS: Get all drivers on the selected server and add
  731. them to the partition combo
  732. ENTRY:
  733. EXIT:
  734. RETURNS: APIERR
  735. NOTES:
  736. HISTORY:
  737. YiHsinS 6-Apr-1993 Created
  738. ********************************************************************/
  739. APIERR FTP_SECURITY_DIALOG::AddDrives( VOID )
  740. {
  741. APIERR err = NERR_Success;
  742. _fLocal = TRUE;
  743. //
  744. // Check if the given server is the local computer
  745. //
  746. if ( _nlsServer.QueryTextLength() > 0 )
  747. {
  748. LOCATION loc; // local machine
  749. NLS_STR nlsLocalComputer;
  750. if ( ( (err = nlsLocalComputer.QueryError()) != NERR_Success )
  751. || ( (err = loc.QueryError()) != NERR_Success )
  752. || ( (err = loc.QueryDisplayName(&nlsLocalComputer)) != NERR_Success)
  753. )
  754. {
  755. return err;
  756. }
  757. ISTR istr( _nlsServer );
  758. istr += 2; // Skip the two backslashes
  759. if ( ::I_MNetComputerNameCompare( nlsLocalComputer,
  760. _nlsServer.QueryPch( istr)) != 0 )
  761. _fLocal = FALSE;
  762. }
  763. //
  764. // If the machine is local, use GetDriveType to get all the possible
  765. // drives.
  766. //
  767. if ( _fLocal )
  768. {
  769. //
  770. // Add local drive letters to the combobox
  771. //
  772. TCHAR szDevice[4]; // This will contain A:, B:, ...
  773. ::strcpyf( szDevice, SZ("?:\\"));
  774. for ( INT i = TCH('Z'); i >= TCH('A'); i-- )
  775. {
  776. szDevice[0] = (TCHAR)i;
  777. szDevice[2] = TCH('\\');
  778. ULONG ulRes= ::GetDriveType( szDevice );
  779. if ( ( ulRes == DRIVE_FIXED )
  780. || ( ulRes == DRIVE_REMOVABLE )
  781. || ( ulRes == DRIVE_CDROM )
  782. )
  783. {
  784. szDevice[2] = 0; // nuke the backslash at the end
  785. if ( _cbPartition.AddItem( szDevice ) < 0 )
  786. {
  787. err = ERROR_NOT_ENOUGH_MEMORY;
  788. break;
  789. }
  790. }
  791. }
  792. }
  793. //
  794. // If the machine is not the local one, use MNetServerDiskEnum
  795. // to get all the drives.
  796. //
  797. else
  798. {
  799. BYTE *pbBuffer = NULL;
  800. UINT nEntriesRead = 0;
  801. err = ::MNetServerDiskEnum( _nlsServer,
  802. 0,
  803. &pbBuffer,
  804. &nEntriesRead );
  805. if ( err == NERR_Success )
  806. {
  807. UIASSERT( pbBuffer != NULL );
  808. for ( UINT i = 0; i < nEntriesRead; i++ )
  809. {
  810. ALIAS_STR nls( (TCHAR *) pbBuffer );
  811. if ( _cbPartition.AddItem( nls ) < 0 )
  812. {
  813. err = ERROR_NOT_ENOUGH_MEMORY;
  814. break;
  815. }
  816. pbBuffer += nls.QueryTextSize();
  817. }
  818. }
  819. ::MNetApiBufferFree( &pbBuffer );
  820. }
  821. return err;
  822. }
  823. /*******************************************************************
  824. NAME: FTP_SECURITY_DIALOG::ShowCurrentPartitionInfo
  825. SYNOPSIS: Show the information ( i.e. file system information,
  826. read access, write access ) of the current selected
  827. partition
  828. ENTRY:
  829. EXIT:
  830. RETURNS: APIERR
  831. NOTES:
  832. HISTORY:
  833. YiHsinS 25-Mar-1993 Created
  834. ********************************************************************/
  835. APIERR FTP_SECURITY_DIALOG::ShowCurrentPartitionInfo( VOID )
  836. {
  837. APIERR err = NERR_Success;
  838. //
  839. // Get the selected drive
  840. //
  841. NLS_STR nlsSelectedDrive;
  842. NLS_STR nlsFileSysInfo;
  843. if ( ((err = nlsSelectedDrive.QueryError())==NERR_Success)
  844. && ((err = _cbPartition.QueryItemText(&nlsSelectedDrive))==NERR_Success)
  845. && ((err = nlsSelectedDrive.AppendChar( TCH('\\')))==NERR_Success)
  846. )
  847. {
  848. //
  849. // Update _nCurrentDiskIndex
  850. //
  851. ISTR istr( nlsSelectedDrive );
  852. _nCurrentDiskIndex = nlsSelectedDrive.QueryChar( istr ) - TCH('A');
  853. //
  854. // Show the security information
  855. //
  856. _checkbWriteAccess.Enable( TRUE );
  857. _checkbReadAccess.SetCheck( (INT) _ulReadAccess &
  858. ( 0x1 <<_nCurrentDiskIndex ));
  859. _checkbWriteAccess.SetCheck( (INT) _ulWriteAccess &
  860. ( 0x1 <<_nCurrentDiskIndex));
  861. if ( _fLocal )
  862. {
  863. //
  864. // Show the file system information
  865. //
  866. ULONG ulRes = ::GetDriveType( (LPWSTR) nlsSelectedDrive.QueryPch());
  867. if (( ulRes == DRIVE_REMOVABLE ) || ( ulRes == DRIVE_CDROM ))
  868. {
  869. err = nlsFileSysInfo.Load( ulRes == DRIVE_REMOVABLE
  870. ? IDS_DRIVE_REMOVABLE
  871. : IDS_DRIVE_CDROM );
  872. //
  873. // Disable Allow Write checkbox when the selection is a CDROM
  874. //
  875. if ( ulRes == DRIVE_CDROM )
  876. _checkbWriteAccess.Enable( FALSE );
  877. }
  878. else
  879. {
  880. err = GetFileSystemInfo( nlsSelectedDrive, &nlsFileSysInfo);
  881. // If we cannot get the file system info,
  882. // then just show them as unknown type.
  883. if ( err != NERR_Success )
  884. err = nlsFileSysInfo.Load( IDS_UI_UNKNOWN );
  885. }
  886. }
  887. else
  888. {
  889. err = nlsFileSysInfo.Load( IDS_UI_UNKNOWN );
  890. }
  891. }
  892. if ( err == NERR_Success )
  893. _sltFileSysInfo.SetText( nlsFileSysInfo );
  894. return err;
  895. }
  896. /*******************************************************************
  897. NAME: FTP_SECURITY_DIALOG::GetFileSystemInfo
  898. SYNOPSIS: Get the file system information for the given drive
  899. ENTRY: pszDrive - The drive to get information on
  900. EXIT: pnlsFileSysInfo - Pointer to a string describing the
  901. file system info of pszDrive
  902. RETURNS:
  903. NOTES:
  904. HISTORY:
  905. YiHsinS 25-Mar-1993 Created
  906. ********************************************************************/
  907. #define MAX_FILE_SYSTEM_INFO_LENGTH 20
  908. APIERR FTP_SECURITY_DIALOG::GetFileSystemInfo( const TCHAR *pszDrive,
  909. NLS_STR *pnlsFileSysInfo )
  910. {
  911. TCHAR szFileSysInfo[ MAX_FILE_SYSTEM_INFO_LENGTH ];
  912. APIERR err = NERR_Success;
  913. if ( ::GetVolumeInformation( (LPWSTR) pszDrive,
  914. NULL, 0, NULL, NULL, NULL,
  915. szFileSysInfo, MAX_FILE_SYSTEM_INFO_LENGTH) )
  916. {
  917. err = pnlsFileSysInfo->CopyFrom( szFileSysInfo );
  918. }
  919. else
  920. {
  921. err = ::GetLastError();
  922. }
  923. return err;
  924. }
  925. /*******************************************************************
  926. NAME: FTP_SECURITY_DIALOG::SaveDriveSecurity
  927. SYNOPSIS: Save the read/write access indicated by the current
  928. read/write checkbox to the drive indexed by _nCurrentDiskIndex
  929. ( 0 represents A:, 1 represents B:,...).
  930. ENTRY:
  931. EXIT:
  932. RETURNS:
  933. NOTES:
  934. HISTORY:
  935. YiHsinS 25-Mar-1993 Created
  936. ********************************************************************/
  937. VOID FTP_SECURITY_DIALOG::SaveDriveSecurity( VOID )
  938. {
  939. //
  940. // Save the read access depending on the read access checkbox
  941. //
  942. if ( _checkbReadAccess.QueryCheck() )
  943. _ulReadAccess |= ( 0x1 << _nCurrentDiskIndex );
  944. else
  945. _ulReadAccess &= ~( 0x1 << _nCurrentDiskIndex );
  946. //
  947. // Save the write access depending on the write access checkbox
  948. //
  949. if ( _checkbWriteAccess.QueryCheck() )
  950. _ulWriteAccess |= ( 0x1 << _nCurrentDiskIndex );
  951. else
  952. _ulWriteAccess &= ~( 0x1 << _nCurrentDiskIndex );
  953. }
  954. /*******************************************************************
  955. NAME: FTP_SECURITY_DIALOG::OnOK
  956. SYNOPSIS: Set the security (read/write access) back to the service
  957. ENTRY:
  958. EXIT:
  959. RETURNS:
  960. NOTES:
  961. HISTORY:
  962. YiHsinS 25-Mar-1993 Created
  963. ********************************************************************/
  964. BOOL FTP_SECURITY_DIALOG::OnOK( VOID )
  965. {
  966. //
  967. // Store the information of the last selected partition
  968. //
  969. SaveDriveSecurity();
  970. //
  971. // Set the Read mask and Write mask of the partitions
  972. //
  973. APIERR err = ::I_FtpSetVolumeSecurity( (LPWSTR) _nlsServer.QueryPch(),
  974. _ulReadAccess,
  975. _ulWriteAccess);
  976. if ( err != NERR_Success )
  977. ::MsgPopup( this, err );
  978. else
  979. Dismiss( TRUE );
  980. return TRUE;
  981. }
  982. /*******************************************************************
  983. NAME: FTP_SECURITY_DIALOG::OnCommand
  984. SYNOPSIS: When the user change selection in the partition combo,
  985. we must save the read/write access of the previous selected
  986. drive and show the info on the currently selected drive.
  987. ENTRY: event - The event that occurred
  988. EXIT:
  989. RETURNS:
  990. NOTES:
  991. HISTORY:
  992. YiHsinS 25-Mar-1993 Created
  993. ********************************************************************/
  994. BOOL FTP_SECURITY_DIALOG::OnCommand( const CONTROL_EVENT &event )
  995. {
  996. if ( ( event.QueryCid() == CB_PARTITION )
  997. && ( event.QueryCode() == CBN_SELCHANGE )
  998. )
  999. {
  1000. //
  1001. // Save read/write access of the previously selected partition
  1002. // NOTE: _nCurrentDiskIndex still points to the previously selected
  1003. // partition
  1004. //
  1005. SaveDriveSecurity();
  1006. //
  1007. // Show current selected disk info
  1008. //
  1009. APIERR err = ShowCurrentPartitionInfo();
  1010. if ( err != NERR_Success )
  1011. ::MsgPopup( this, err );
  1012. return TRUE;
  1013. }
  1014. return DIALOG_WINDOW::OnCommand( event );
  1015. }
  1016. /*******************************************************************
  1017. NAME: FTP_SECURITY_DIALOG::QueryHelpContext
  1018. SYNOPSIS: Get the help context for this dialog
  1019. ENTRY:
  1020. EXIT:
  1021. RETURNS: ULONG - The help context for this dialog
  1022. NOTES:
  1023. HISTORY:
  1024. YiHsinS 25-Mar-1993 Created
  1025. ********************************************************************/
  1026. ULONG FTP_SECURITY_DIALOG::QueryHelpContext( VOID )
  1027. {
  1028. return HC_FTPSECURITY_DIALOG;
  1029. }