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.

580 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. volprop.cxx
  7. This file contains the definitions of VOLUME_PROPERTIES_DIALOG
  8. class.
  9. History:
  10. NarenG 11/18/92 Modified SHARE_DIALOG_BASE for
  11. AFPMGR
  12. */
  13. #define INCL_WINDOWS_GDI
  14. #define INCL_WINDOWS
  15. #define INCL_DOSERRORS
  16. #define INCL_NETERRORS
  17. #define INCL_NETSHARE
  18. #define INCL_NETSERVER
  19. #define INCL_NETCONS
  20. #define INCL_NETLIB
  21. #include <lmui.hxx>
  22. #define INCL_BLT_WINDOW
  23. #define INCL_BLT_DIALOG
  24. #define INCL_BLT_CONTROL
  25. #define INCL_BLT_MISC
  26. #define INCL_BLT_CLIENT
  27. #define INCL_BLT_MSGPOPUP
  28. #define INCL_BLT_SPIN_GROUP
  29. #define INCL_BLT_GROUP
  30. #include <blt.hxx>
  31. extern "C"
  32. {
  33. #include <afpmgr.h>
  34. #include <macfile.h>
  35. }
  36. #include <string.hxx>
  37. #include <uitrace.hxx>
  38. #include <dbgstr.hxx>
  39. #include <netname.hxx>
  40. #include "util.hxx"
  41. #include "perms.hxx"
  42. #include "volprop.hxx"
  43. /*******************************************************************
  44. NAME: VOLUME_PROPERTIES_DIALOG::VOLUME_PROPERTIES_DIALOG
  45. SYNOPSIS: Constructor for VOLUME_PROPERTIES_DIALOG class
  46. ENTRY: hwndParent - handle of parent window
  47. EXIT:
  48. RETURNS:
  49. NOTES:
  50. HISTORY:
  51. NarenG 11/18/92 Modified for AFPMGR
  52. ********************************************************************/
  53. VOLUME_PROPERTIES_DIALOG::VOLUME_PROPERTIES_DIALOG(
  54. HWND hwndParent,
  55. AFP_SERVER_HANDLE hServer,
  56. const TCHAR * pszVolumeName,
  57. const TCHAR * pszServerName,
  58. BOOL fCalledBySrvMgr )
  59. : DIALOG_WINDOW ( MAKEINTRESOURCE(IDD_VOLUME_PROPERTIES_DIALOG),hwndParent),
  60. _sltpVolumeName( this, IDVP_SLT_NAME, ELLIPSIS_RIGHT ),
  61. _sltpVolumePath( this, IDVP_SLT_PATH, ELLIPSIS_PATH ),
  62. _slePassword( this, IDVP_SLE_PASSWORD, AFP_VOLPASS_LEN ),
  63. _slePasswordConfirm( this, IDVP_SLE_CONFIRM_PASSWORD, AFP_VOLPASS_LEN ),
  64. _chkReadOnly( this, IDVP_CHK_READONLY ),
  65. _chkGuestAccess( this, IDVP_CHK_GUEST_ACCESS ),
  66. _mgrpUserLimit( this, IDVP_RB_UNLIMITED, 2, IDVP_RB_UNLIMITED),
  67. _spsleUsers( this, IDVP_SLE_USERS,1,1,AFP_VOLUME_UNLIMITED_USES-1,
  68. TRUE, IDVP_SLE_USERS_GROUP ),
  69. _spgrpUsers(this,IDVP_SB_USERS_GROUP,IDVP_SB_USERS_UP,IDVP_SB_USERS_DOWN),
  70. _pbPermissions( this, IDVP_PB_PERMISSIONS ),
  71. _pbOK( this, IDOK ),
  72. _pbCancel( this, IDCANCEL ),
  73. _nlsVolumePath(),
  74. _nlsVolumeName( pszVolumeName ),
  75. _nlsServerName( pszServerName ),
  76. _fCalledBySrvMgr( fCalledBySrvMgr ),
  77. _hServer( hServer )
  78. {
  79. //
  80. // Make sure everything constructed OK
  81. //
  82. if ( QueryError() != NERR_Success )
  83. return;
  84. APIERR err;
  85. if ( ((err = _sltpVolumeName.QueryError()) != NERR_Success )
  86. || ((err = _sltpVolumePath.QueryError()) != NERR_Success )
  87. || ((err = _nlsVolumePath.QueryError()) != NERR_Success )
  88. || ((err = _nlsVolumeName.QueryError()) != NERR_Success )
  89. || ((err = _nlsServerName.QueryError()) != NERR_Success )
  90. || ((err = _slePassword.QueryError()) != NERR_Success )
  91. || ((err = _slePasswordConfirm.QueryError()) != NERR_Success )
  92. || ((err = _mgrpUserLimit.QueryError()) != NERR_Success )
  93. || ((err = _spgrpUsers.AddAssociation( &_spsleUsers )) != NERR_Success )
  94. || ((err = _mgrpUserLimit.AddAssociation( IDVP_RB_USERS, &_spgrpUsers ))
  95. != NERR_Success )
  96. || ((err = _chkReadOnly.QueryError()) != NERR_Success )
  97. || ((err = _chkGuestAccess.QueryError()) != NERR_Success )
  98. )
  99. {
  100. ReportError( err );
  101. return;
  102. }
  103. //
  104. // This may take a while
  105. //
  106. AUTO_CURSOR Cursor;
  107. if ( fCalledBySrvMgr )
  108. {
  109. //
  110. // Set the caption to "Volume Properties on Server".
  111. //
  112. err = ::SetCaption(this, IDS_CAPTION_VOLUME_PROPERTIES, pszServerName);
  113. if( err != NERR_Success )
  114. {
  115. ReportError( err );
  116. return;
  117. }
  118. }
  119. //
  120. // Get the volume information
  121. //
  122. PAFP_VOLUME_INFO pAfpVolumeInfo;
  123. DWORD error = ::AfpAdminVolumeGetInfo( _hServer,
  124. (LPWSTR)pszVolumeName,
  125. (LPBYTE*)&pAfpVolumeInfo );
  126. if ( error != NO_ERROR )
  127. {
  128. ReportError( error );
  129. return;
  130. }
  131. //
  132. // Set the name
  133. //
  134. _sltpVolumeName.SetText( pszVolumeName );
  135. //
  136. // Set the path
  137. //
  138. if ((( err = _sltpVolumePath.SetText(pAfpVolumeInfo->afpvol_path))
  139. != NERR_Success ) ||
  140. (( err = _nlsVolumePath.CopyFrom( pAfpVolumeInfo->afpvol_path ) )
  141. != NERR_Success ))
  142. {
  143. ReportError( err );
  144. return;
  145. }
  146. //
  147. // Set the password SLE to AFP_NULL_PASSWORD if there is a password
  148. //
  149. if ( ( pAfpVolumeInfo->afpvol_password != NULL ) &&
  150. ( (pAfpVolumeInfo->afpvol_password)[0] != TEXT('\0') ))
  151. {
  152. _slePassword.SetText( (LPWSTR)AFP_NULL_PASSWORD );
  153. _slePasswordConfirm.SetText( (LPWSTR)AFP_NULL_PASSWORD );
  154. _slePassword.SelectString();
  155. }
  156. //
  157. // Set the security options
  158. //
  159. _chkReadOnly.SetCheck( (INT)( pAfpVolumeInfo->afpvol_props_mask &
  160. AFP_VOLUME_READONLY ));
  161. //
  162. // If this is a CDFS volume, then disable this checkbox
  163. // The way we find out if this is CDFS partition is by calling
  164. // AfpAdminDirectoryGetInfo. If it returns AFPERR_SecurityNotSupported
  165. // then we know that is is CDFS and is readonly
  166. //
  167. PAFP_DIRECTORY_INFO pDirInfo;
  168. err = AfpAdminDirectoryGetInfo( _hServer,
  169. pAfpVolumeInfo->afpvol_path,
  170. (LPBYTE*)&pDirInfo );
  171. if ( err == AFPERR_SecurityNotSupported || err == AFPERR_UnsupportedFS )
  172. {
  173. _chkReadOnly.Enable( FALSE );
  174. }
  175. else if ( err != NO_ERROR )
  176. {
  177. ReportError( err );
  178. return;
  179. }
  180. else
  181. {
  182. ::AfpAdminBufferFree( pDirInfo );
  183. }
  184. _chkGuestAccess.SetCheck( (INT)( pAfpVolumeInfo->afpvol_props_mask &
  185. AFP_VOLUME_GUESTACCESS ));
  186. //
  187. // Set the max uses limit
  188. //
  189. SetUserLimit( pAfpVolumeInfo->afpvol_max_uses ) ;
  190. //
  191. // Free the returned buffer
  192. //
  193. ::AfpAdminBufferFree( pAfpVolumeInfo );
  194. _slePassword.ClaimFocus();
  195. _fPasswordChanged = FALSE;
  196. }
  197. /*******************************************************************
  198. NAME: VOLUME_PROPERTIES_DIALOG::OnCommand
  199. SYNOPSIS: Handle the case where the user clicked the permission button
  200. ENTRY: event - the CONTROL_EVENT that occurred
  201. EXIT:
  202. RETURNS:
  203. NOTES:
  204. HISTORY:
  205. NarenG 11/18/92 Modified for AFPMGR
  206. ********************************************************************/
  207. BOOL VOLUME_PROPERTIES_DIALOG::OnCommand( const CONTROL_EVENT &event )
  208. {
  209. DWORD err;
  210. if ( event.QueryCid() == IDVP_PB_PERMISSIONS )
  211. {
  212. //
  213. // This may take a while
  214. //
  215. AUTO_CURSOR Cursor;
  216. //
  217. // Get the password if there is one.
  218. //
  219. DIRECTORY_PERMISSIONS_DLG *pdlg = new DIRECTORY_PERMISSIONS_DLG(
  220. QueryHwnd(),
  221. _hServer,
  222. _nlsServerName.QueryPch(),
  223. _fCalledBySrvMgr,
  224. _nlsVolumePath.QueryPch(),
  225. _nlsVolumePath.QueryPch() );
  226. if (( pdlg == NULL )
  227. || (( err = pdlg->QueryError()) != NERR_Success )
  228. || (( err = pdlg->Process()) != NERR_Success ))
  229. {
  230. err = err ? err: ERROR_NOT_ENOUGH_MEMORY;
  231. }
  232. delete pdlg;
  233. if ( err != NERR_Success )
  234. {
  235. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  236. }
  237. return TRUE;
  238. }
  239. if ( ( event.QueryCid() == IDVP_SLE_PASSWORD ) ||
  240. ( event.QueryCid() == IDVP_SLE_CONFIRM_PASSWORD ) )
  241. {
  242. if ( event.QueryCode() == EN_CHANGE )
  243. {
  244. _fPasswordChanged = TRUE;
  245. }
  246. }
  247. return DIALOG_WINDOW::OnCommand( event );
  248. }
  249. /*******************************************************************
  250. NAME: VOLUME_PROPERTIES_DIALOG::OnOK
  251. SYNOPSIS: Validate all the information and create the volume.
  252. ENTRY:
  253. EXIT:
  254. RETURNS:
  255. NOTES:
  256. HISTORY:
  257. NarenG 11/18/92 Modified for AFPMGR
  258. ********************************************************************/
  259. BOOL VOLUME_PROPERTIES_DIALOG::OnOK( VOID )
  260. {
  261. APIERR err;
  262. //
  263. // This may take a while
  264. //
  265. AUTO_CURSOR Cursor;
  266. DWORD dwParmNum = AFP_VOL_PARMNUM_MAXUSES | AFP_VOL_PARMNUM_PROPSMASK;
  267. NLS_STR nlsPassword;
  268. NLS_STR nlsPasswordConfirm;
  269. //
  270. // This is not a loop.
  271. //
  272. do {
  273. //
  274. // Get the password if there is one.
  275. //
  276. if ( ( err = nlsPassword.QueryError() ) != NERR_Success )
  277. break;
  278. if ( ( err = _slePassword.QueryText( &nlsPassword )) != NERR_Success )
  279. break;
  280. //
  281. // Get the password confirmation.
  282. //
  283. if ( ( err = nlsPasswordConfirm.QueryError() ) != NERR_Success )
  284. break;
  285. if ( ( err = _slePasswordConfirm.QueryText( &nlsPasswordConfirm ))
  286. != NERR_Success )
  287. break;
  288. } while ( FALSE );
  289. if ( err != NERR_Success )
  290. {
  291. ::MsgPopup( this, err );
  292. return TRUE;
  293. }
  294. //
  295. // Set up the volume structure
  296. //
  297. AFP_VOLUME_INFO AfpVolume;
  298. AfpVolume.afpvol_name = (LPWSTR)(_nlsVolumeName.QueryPch());
  299. //
  300. // Validate the password that was typed in
  301. //
  302. if ( nlsPassword.strcmp( nlsPasswordConfirm ) )
  303. {
  304. ::MsgPopup( this, IDS_PASSWORD_MISMATCH );
  305. SetFocusOnPasswordConfirm();
  306. return TRUE;
  307. }
  308. //
  309. // If the user changed the password then set it to the new one.
  310. //
  311. AfpVolume.afpvol_password = (LPWSTR)NULL;
  312. if ( _fPasswordChanged )
  313. {
  314. dwParmNum |= AFP_VOL_PARMNUM_PASSWORD;
  315. AfpVolume.afpvol_password = (LPWSTR)(nlsPassword.QueryPch());
  316. }
  317. //
  318. // Set the properties
  319. //
  320. AfpVolume.afpvol_props_mask = _chkReadOnly.QueryCheck()
  321. ? AFP_VOLUME_READONLY
  322. : 0;
  323. AfpVolume.afpvol_props_mask |= _chkGuestAccess.QueryCheck()
  324. ? AFP_VOLUME_GUESTACCESS
  325. : 0;
  326. AfpVolume.afpvol_max_uses = QueryUserLimit();
  327. //
  328. // Try to set the information
  329. //
  330. DWORD error = ::AfpAdminVolumeSetInfo( _hServer,
  331. (LPBYTE)&AfpVolume,
  332. dwParmNum );
  333. if ( error == NO_ERROR )
  334. {
  335. Dismiss( TRUE );
  336. }
  337. else
  338. {
  339. ::MsgPopup( this, AFPERR_TO_STRINGID( error ) );
  340. }
  341. return TRUE;
  342. }
  343. /*******************************************************************
  344. NAME: VOLUME_PROPERTIES_DIALOG::QueryUserLimit
  345. SYNOPSIS: Get the user limit from the magic group
  346. ENTRY:
  347. EXIT:
  348. RETURNS: The user limit stored in the user limit magic group
  349. NOTES:
  350. HISTORY:
  351. NarenG 11/18/92 Modified for AFPMGR
  352. ********************************************************************/
  353. DWORD VOLUME_PROPERTIES_DIALOG::QueryUserLimit( VOID ) const
  354. {
  355. switch ( _mgrpUserLimit.QuerySelection() )
  356. {
  357. case IDVP_RB_UNLIMITED:
  358. return( AFP_VOLUME_UNLIMITED_USES );
  359. case IDVP_RB_USERS:
  360. return( _spsleUsers.QueryValue() );
  361. default:
  362. //
  363. // Should never get here but in case we do, return unlimited
  364. //
  365. return( AFP_VOLUME_UNLIMITED_USES );
  366. }
  367. }
  368. /*******************************************************************
  369. NAME: VOLUME_PROPERTIES_DIALOG::SetUserLimit
  370. SYNOPSIS: Sets the user limit on the magic group
  371. ENTRY: dwUserLimit - maximum number of users allowed
  372. EXIT:
  373. RETURNS:
  374. NOTES:
  375. HISTORY:
  376. NarenG 11/18/92 Modified for AFPMGR
  377. ********************************************************************/
  378. VOID VOLUME_PROPERTIES_DIALOG::SetUserLimit( DWORD dwUserLimit )
  379. {
  380. if ( dwUserLimit == AFP_VOLUME_UNLIMITED_USES )
  381. {
  382. //
  383. // Set selection to the Unlimited button
  384. //
  385. _mgrpUserLimit.SetSelection( IDVP_RB_UNLIMITED );
  386. }
  387. else
  388. {
  389. //
  390. // Set the Users button to the value
  391. //
  392. _mgrpUserLimit.SetSelection( IDVP_RB_USERS );
  393. _spsleUsers.SetValue( dwUserLimit );
  394. _spsleUsers.Update();
  395. }
  396. }
  397. /*******************************************************************
  398. NAME: VOLUME_PROPERTIES_DIALOG::QueryHelpContext
  399. SYNOPSIS: Query the help context of the dialog
  400. ENTRY:
  401. EXIT:
  402. RETURNS: Return the help context of the dialog
  403. NOTES:
  404. HISTORY:
  405. NarenG 11/18/92 Modified for AFPMGR
  406. ********************************************************************/
  407. ULONG VOLUME_PROPERTIES_DIALOG::QueryHelpContext( VOID )
  408. {
  409. return HC_VOLUME_PROPERTIES_DIALOG;
  410. }