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.

2385 lines
62 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. * sharecrt.cxx
  7. * Contains dialogs for creating shares
  8. *
  9. * FILE HISTORY:
  10. * Yi-HsinS 1/6/92 Created, separated from sharefmx.cxx
  11. * and added SHARE_CREATE_BASE
  12. * Yi-HsinS 3/12/92 Added CREATE_SHARE_GROUP
  13. * Yi-HsinS 4/2/92 Added MayRun
  14. * Yi-HsinS 8/6/92 Reorganized to match Winball
  15. * YiHsinS 4/2/93 Disable viewing/changing permission on special
  16. * shares ( [A-Z]$, IPC$, ADMIN$ )
  17. *
  18. */
  19. #include <ntincl.hxx>
  20. #define INCL_WINDOWS_GDI
  21. #define INCL_WINDOWS
  22. #define INCL_DOSERRORS
  23. #define INCL_NETERRORS
  24. #define INCL_NETSERVER
  25. #define INCL_NETUSE
  26. #define INCL_NETSHARE
  27. #define INCL_NETCONS
  28. #define INCL_NETLIB
  29. #define INCL_ICANON
  30. #include <lmui.hxx>
  31. extern "C"
  32. {
  33. #include <sharedlg.h>
  34. #include <helpnums.h>
  35. #include <mnet.h>
  36. }
  37. #define INCL_BLT_DIALOG
  38. #define INCL_BLT_CONTROL
  39. #define INCL_BLT_MSGPOPUP
  40. #define INCL_BLT_SPIN_GROUP
  41. #include <blt.hxx>
  42. #include <string.hxx>
  43. #include <uitrace.hxx>
  44. #include <dbgstr.hxx>
  45. #include <lmoshare.hxx>
  46. #include <lmoesh.hxx>
  47. #include <lmoeconn.hxx>
  48. #include <lmosrv.hxx>
  49. #include <strchlit.hxx> // for string and character constants
  50. #include "sharecrt.hxx"
  51. #include "sharestp.hxx"
  52. #include <errmap.hxx>
  53. /*******************************************************************
  54. NAME: DetermineUserLimit
  55. SYNOPSIS: A utility function to determine the maximum number of
  56. users allowed on a share.
  57. ENTRY: psvr - the server object where the share will be placed
  58. RETURNS: The maximum number of users for shares on that server
  59. NOTES: The maximum number of users is determined as follows:
  60. if (not an NT machine) then
  61. LANMAN_USERS_MAX
  62. else
  63. whatever the server returned to us. If they return
  64. unlimited, 0xffffffff, then use NT_USERS_MAX to avoid
  65. maxing out the spin control
  66. HISTORY:
  67. BruceFo 9/12/95 Created
  68. ********************************************************************/
  69. ULONG DetermineUserLimit(SERVER_WITH_PASSWORD_PROMPT* psvr)
  70. {
  71. if (NULL == psvr)
  72. {
  73. return NT_USERS_MAX;
  74. }
  75. if (psvr->IsNT())
  76. {
  77. ULONG users = psvr->QueryMaxUsers();
  78. return (users > NT_USERS_MAX) ? NT_USERS_MAX : users;
  79. }
  80. else
  81. {
  82. return LANMAN_USERS_MAX;
  83. }
  84. }
  85. /*******************************************************************
  86. NAME: ADD_SHARE_DIALOG_BASE::ADD_SHARE_DIALOG_BASE
  87. SYNOPSIS: Constructor
  88. ENTRY: pszDlgResource - resource name of the dialog
  89. hwndParent - hwnd of the parent window
  90. ulHelpContextBase - the base help context
  91. EXIT:
  92. RETURNS:
  93. NOTES:
  94. HISTORY:
  95. Yi-HsinS 8/3/92 Created
  96. ********************************************************************/
  97. ADD_SHARE_DIALOG_BASE::ADD_SHARE_DIALOG_BASE( const TCHAR *pszDlgResource,
  98. HWND hwndParent,
  99. ULONG ulHelpContextBase )
  100. : SHARE_DIALOG_BASE( pszDlgResource, hwndParent, ulHelpContextBase ),
  101. _sleShare( this, SLE_SHARE, SHARE_NAME_LENGTH )
  102. {
  103. if ( QueryError() != NERR_Success )
  104. return;
  105. }
  106. /*******************************************************************
  107. NAME: ADD_SHARE_DIALOG_BASE::~ADD_SHARE_DIALOG_BASE
  108. SYNOPSIS: Destructor
  109. ENTRY:
  110. EXIT:
  111. RETURNS:
  112. NOTES:
  113. HISTORY:
  114. Yi-HsinS 8/3/92 Created
  115. ********************************************************************/
  116. ADD_SHARE_DIALOG_BASE::~ADD_SHARE_DIALOG_BASE()
  117. {
  118. }
  119. /*******************************************************************
  120. NAME: ADD_SHARE_DIALOG_BASE::QueryPathErrorMsg
  121. SYNOPSIS: Default error message when the path entered
  122. by the user is invalid. Depending on whether
  123. the dialog is used in the server manager or
  124. file manager, different error message for the
  125. invalid path will be displayed.
  126. ENTRY:
  127. EXIT:
  128. RETURNS:
  129. NOTES: This error message is the message used when the
  130. dialog exist in the server manager.
  131. HISTORY:
  132. Yi-HsinS 8/3/92 Created
  133. ********************************************************************/
  134. APIERR ADD_SHARE_DIALOG_BASE::QueryPathErrorMsg( VOID )
  135. {
  136. return IERR_SHARE_INVALID_LOCAL_PATH;
  137. }
  138. /*******************************************************************
  139. NAME: ADD_SHARE_DIALOG_BASE::OnAddShare
  140. SYNOPSIS: Gather information and create a new share
  141. ENTRY: psvr - the server on which to create the share
  142. pnlsNewShareName - optional parameter to store
  143. the name of the newly created share if all went well
  144. EXIT:
  145. RETURNS: TRUE if the share has been created successfully,
  146. and FALSE otherwise.
  147. NOTES:
  148. HISTORY:
  149. Yi-HsinS 8/25/91 Created
  150. Yi-HsinS 11/25/91 Made slestrpSharePath accepts local
  151. full path name
  152. Yi-HsinS 1/22/92 Check for sharing ADMIN$ or IPC$
  153. ********************************************************************/
  154. BOOL ADD_SHARE_DIALOG_BASE::OnAddShare( SERVER_WITH_PASSWORD_PROMPT *psvr,
  155. NLS_STR *pnlsNewShareName )
  156. {
  157. APIERR err = NERR_Success;
  158. BOOL fAddedShare = FALSE;
  159. SLE *psle = QuerySLEPath(); // Store the control window
  160. // to set focus on if error
  161. UIASSERT( psvr != NULL );
  162. do { // Not a loop, just for breaking out to the end if error occurs
  163. //
  164. // Get the path and computer
  165. //
  166. NLS_STR nlsPath;
  167. NLS_STR nlsServer;
  168. if ( ((err = nlsPath.QueryError() ) != NERR_Success )
  169. || ((err = nlsServer.QueryError()) != NERR_Success )
  170. || ((err = GetAndValidateComputerPath( psvr, &nlsServer, &nlsPath ))
  171. != NERR_Success )
  172. )
  173. {
  174. break;
  175. }
  176. //
  177. // Get the share name
  178. //
  179. NLS_STR nlsShare;
  180. if ( ((err = nlsShare.QueryError()) != NERR_Success )
  181. || ((err = QueryShare( &nlsShare )) != NERR_Success)
  182. || ( nlsShare.QueryTextLength() == 0 )
  183. )
  184. {
  185. psle = QuerySLEShare();
  186. err = err ? err : (APIERR) IERR_SHARE_INVALID_SHARE;
  187. break;
  188. }
  189. //
  190. // Validate the share name
  191. //
  192. if ( ::I_MNetNameValidate( NULL, nlsShare,
  193. NAMETYPE_SHARE, 0L) != NERR_Success )
  194. {
  195. err = (APIERR) IERR_SHARE_INVALID_SHARE;
  196. psle = QuerySLEShare();
  197. break;
  198. }
  199. //
  200. // Check if the name of the share is accessible from DOS machine
  201. //
  202. ULONG nType;
  203. if ( ::I_MNetPathType(NULL, nlsShare, &nType, INPT_FLAGS_OLDPATHS )
  204. != NERR_Success )
  205. {
  206. if ( ::MsgPopup( this, IERR_SHARE_NOT_ACCESSIBLE_FROM_DOS,
  207. MPSEV_INFO, MP_YESNO, nlsShare, MP_NO ) == IDNO )
  208. {
  209. psle = QuerySLEShare();
  210. break;
  211. }
  212. }
  213. //
  214. // Get the comment
  215. //
  216. NLS_STR nlsComment;
  217. if ( ((err = nlsComment.QueryError() ) != NERR_Success )
  218. || ((err = QueryComment( &nlsComment )) != NERR_Success )
  219. )
  220. {
  221. psle = QuerySLEComment();
  222. break;
  223. }
  224. //
  225. // Check whether it is a special share name -- ADMIN$ or IPC$
  226. // If creating the special share, the path and comment
  227. // has to be empty.
  228. //
  229. BOOL fAdminShare = (::stricmpf( nlsShare, ADMIN_SHARE) == 0);
  230. BOOL fIPCShare = (::stricmpf( nlsShare, IPC_SHARE) == 0);
  231. BOOL fPathEmpty = nlsPath.QueryTextLength() == 0;
  232. if ( fAdminShare || fIPCShare )
  233. {
  234. if ( !fPathEmpty )
  235. {
  236. err = (APIERR) IERR_SPECIAL_SHARE_INVALID_PATH;
  237. }
  238. else if ( nlsComment.QueryTextLength() != 0)
  239. {
  240. err = (APIERR) IERR_SPECIAL_SHARE_INVALID_COMMENT;
  241. psle = QuerySLEComment();
  242. }
  243. if ( err != NERR_Success )
  244. break;
  245. }
  246. //
  247. // Get the right error message when the path is invalid
  248. //
  249. if ( fPathEmpty && !fAdminShare && !fIPCShare )
  250. {
  251. err = QueryPathErrorMsg();
  252. break;
  253. }
  254. UINT uiResourceType = ( fIPCShare? STYPE_IPC : STYPE_DISKTREE);
  255. SHARE_2 sh2( nlsShare, nlsServer);
  256. if ( ((err = sh2.QueryError()) != NERR_Success )
  257. || ((err = sh2.CreateNew()) != NERR_Success )
  258. || ((err = sh2.SetResourceType( uiResourceType )) != NERR_Success)
  259. || ((err = sh2.SetPath( nlsPath )) != NERR_Success)
  260. )
  261. {
  262. break;
  263. }
  264. //
  265. // Set the comment
  266. //
  267. if ( (err = sh2.SetComment( nlsComment )) != NERR_Success )
  268. {
  269. if ( err == ERROR_INVALID_PARAMETER )
  270. err = IERR_SHARE_INVALID_COMMENT;
  271. psle = QuerySLEComment();
  272. break;
  273. }
  274. //
  275. // Get and set user limit
  276. //
  277. UINT uiUserLimit = (UINT) QueryUserLimit();
  278. BOOL fNT = psvr->IsNT();
  279. if ( (( !fNT ) && ( uiUserLimit != SHI_USES_UNLIMITED )
  280. && ( uiUserLimit > LANMAN_USERS_MAX ))
  281. || (( err = sh2.SetMaxUses( uiUserLimit ) ) != NERR_Success)
  282. )
  283. {
  284. err = err ? err : IERR_SHARE_INVALID_USERLIMIT;
  285. psle = QuerySpinSLEUsers();
  286. break;
  287. }
  288. //
  289. // Set the permissions/password if the server is a LM share-level server
  290. //
  291. if ( !fNT && psvr->IsShareLevel() )
  292. {
  293. // Error already checked when dismissing
  294. // SHARE_LEVEL_PERMISSIONS _DIALOG. So, we don't need
  295. // to set focus when error!
  296. // We upper case the password => same as netcmd
  297. // since password are used in Share level servers which are
  298. // always down-level servers.
  299. ALIAS_STR nlsPassword( QueryStoredPassword() );
  300. nlsPassword._strupr();
  301. if ( ((err = sh2.SetPermissions( QueryStoredPermissions() ))
  302. != NERR_Success)
  303. || ((err = sh2.SetPassword( nlsPassword ))
  304. != NERR_Success)
  305. )
  306. {
  307. break;
  308. }
  309. }
  310. //
  311. // Write out the share
  312. //
  313. if (( err = sh2.WriteNew()) == NERR_Success )
  314. {
  315. fAddedShare = TRUE;
  316. if ( pnlsNewShareName )
  317. err = pnlsNewShareName->CopyFrom( sh2.QueryName() );
  318. // If the server is an NT server, set the permissions.
  319. if ( ( fNT )
  320. && ( err == NERR_Success )
  321. && ( QueryStoredSecDesc() != NULL)
  322. )
  323. {
  324. err = ApplySharePermissions( sh2.QueryServer(),
  325. sh2.QueryName(),
  326. QueryStoredSecDesc() );
  327. // The permissions on special shares [A-Z]$, IPC$, ADMIN$
  328. // cannot be set.
  329. if ( err == ERROR_INVALID_PARAMETER )
  330. err = IERR_SPECIAL_SHARE_CANNOT_SET_PERMISSIONS;
  331. }
  332. }
  333. } while (FALSE);
  334. if ( err != NERR_Success )
  335. {
  336. // Map some errors
  337. switch ( err )
  338. {
  339. case ERROR_NOT_READY:
  340. err = IERR_SHARE_DRIVE_NOT_READY;
  341. break;
  342. case NERR_DuplicateShare:
  343. psle = QuerySLEShare();
  344. break;
  345. case NERR_BadTransactConfig:
  346. Dismiss( FALSE );
  347. break;
  348. default:
  349. break;
  350. }
  351. if ( err != NERR_Success )
  352. {
  353. ::MsgPopup( this,
  354. err,
  355. err == IERR_SPECIAL_SHARE_CANNOT_SET_PERMISSIONS
  356. ? MPSEV_WARNING
  357. : MPSEV_ERROR );
  358. }
  359. }
  360. //
  361. // Set focus to the appropriate control that contains invalid information
  362. //
  363. if ( !fAddedShare )
  364. {
  365. psle->SelectString();
  366. psle->ClaimFocus();
  367. }
  368. return fAddedShare;
  369. }
  370. /*******************************************************************
  371. NAME: ADD_SHARE_DIALOG_BASE::GetAndValidateComputerPath
  372. SYNOPSIS: Helper method to get the path of the share
  373. and the computer on which to create the share
  374. ENTRY: psvr - the server on which to create the share
  375. EXIT: pnlsComputer - pointer to the computer name
  376. pnlsPath - pointer to the path
  377. RETURNS:
  378. NOTES: This is a default virtual method used only when
  379. the dialogs derived from this class are used in the
  380. server manager.
  381. HISTORY:
  382. Yi-HsinS 8/3/92 Created
  383. ********************************************************************/
  384. APIERR ADD_SHARE_DIALOG_BASE::GetAndValidateComputerPath(
  385. SERVER_WITH_PASSWORD_PROMPT *psvr,
  386. NLS_STR *pnlsComputer,
  387. NLS_STR *pnlsPath )
  388. {
  389. UIASSERT( psvr != NULL );
  390. APIERR err;
  391. do { // NOT a loop
  392. *pnlsComputer = psvr->QueryName();
  393. if ( ((err = pnlsComputer->QueryError()) != NERR_Success )
  394. || ((err = QueryPath( pnlsPath )) != NERR_Success )
  395. )
  396. {
  397. break;
  398. }
  399. if ( pnlsPath->QueryTextLength() == 0 )
  400. {
  401. break;
  402. }
  403. //
  404. // Path should only be absolute path
  405. //
  406. NET_NAME netName( *pnlsPath, TYPE_PATH_ABS );
  407. if (( err = netName.QueryError()) != NERR_Success )
  408. {
  409. if ( err == ERROR_INVALID_NAME )
  410. err = (APIERR) IERR_SHARE_INVALID_LOCAL_PATH;
  411. break;
  412. }
  413. //
  414. // Validated successfully, so check to see if it's in the
  415. // form "x:". If so, append a "\" into the path.
  416. //
  417. if ( pnlsPath->QueryTextLength() == 2)
  418. pnlsPath->AppendChar( PATH_SEPARATOR );
  419. } while ( FALSE );
  420. return err;
  421. }
  422. /*******************************************************************
  423. NAME: FILEMGR_NEW_SHARE_DIALOG::FILEMGR_NEW_SHARE_DIALOG
  424. SYNOPSIS: Constructor
  425. ENTRY: hwndParent - hwnd of the parent window
  426. pszSelectedDir - the selected directory in the file manager
  427. ulHelpContextBase - the base help context
  428. fShowDefault - TRUE if we want to display the default share
  429. name, FALSE otherwise.
  430. EXIT:
  431. RETURNS:
  432. NOTES:
  433. HISTORY:
  434. Yi-HsinS 8/25/91 Created
  435. ********************************************************************/
  436. FILEMGR_NEW_SHARE_DIALOG::FILEMGR_NEW_SHARE_DIALOG( HWND hwndParent,
  437. const TCHAR *pszSelectedDir,
  438. ULONG ulHelpContextBase,
  439. BOOL fShowDefault,
  440. NLS_STR *pnlsNewShareName )
  441. : ADD_SHARE_DIALOG_BASE( MAKEINTRESOURCE(IDD_SHARECREATEDLG),
  442. hwndParent,
  443. ulHelpContextBase ),
  444. _newShareGrp( this, QuerySLEShare(), QuerySLEPath()),
  445. _pnlsNewShareName( pnlsNewShareName ),
  446. _psvr( NULL )
  447. {
  448. if ( QueryError() != NERR_Success )
  449. return;
  450. APIERR err;
  451. if ( ((err = _newShareGrp.QueryError()) != NERR_Success )
  452. || ((err = SetDefaults( pszSelectedDir, fShowDefault)) != NERR_Success )
  453. )
  454. {
  455. ReportError( err );
  456. return;
  457. }
  458. QuerySLEShare()->SelectString();
  459. QuerySLEShare()->ClaimFocus();
  460. }
  461. /*******************************************************************
  462. NAME: FILEMGR_NEW_SHARE_DIALOG::~FILEMGR_NEW_SHARE_DIALOG
  463. SYNOPSIS: Destructor
  464. ENTRY:
  465. EXIT:
  466. RETURNS:
  467. NOTES:
  468. HISTORY:
  469. Yi-HsinS 8/25/91 Created
  470. ********************************************************************/
  471. FILEMGR_NEW_SHARE_DIALOG::~FILEMGR_NEW_SHARE_DIALOG()
  472. {
  473. delete _psvr;
  474. _psvr = NULL;
  475. }
  476. /*******************************************************************
  477. NAME: FILEMGR_NEW_SHARE_DIALOG::QueryPathErrorMsg
  478. SYNOPSIS: Query the error message when the user
  479. entered an invalid path in the new share dialog
  480. used in the file manager.
  481. ENTRY:
  482. EXIT:
  483. RETURNS: Returns the error message for invalid path
  484. NOTES:
  485. HISTORY:
  486. Yi-HsinS 8/25/91 Created
  487. ********************************************************************/
  488. APIERR FILEMGR_NEW_SHARE_DIALOG::QueryPathErrorMsg( VOID )
  489. {
  490. return IERR_SHARE_INVALID_SHAREPATH;
  491. }
  492. /*******************************************************************
  493. NAME: FILEMGR_NEW_SHARE_DIALOG::QueryServer2
  494. SYNOPSIS: Get the SERVER_2 object by determining which server
  495. the path is on.
  496. ENTRY:
  497. EXIT: *ppsvr - pointer to the server object
  498. RETURNS:
  499. NOTES:
  500. HISTORY:
  501. Yi-HsinS 8/25/91 Created
  502. ********************************************************************/
  503. APIERR FILEMGR_NEW_SHARE_DIALOG::QueryServer2(
  504. SERVER_WITH_PASSWORD_PROMPT **ppsvr )
  505. {
  506. APIERR err;
  507. NLS_STR nlsPath;
  508. NLS_STR nlsComputer;
  509. do { // Not a loop
  510. if ( ((err = nlsPath.QueryError()) != NERR_Success )
  511. || ((err = nlsComputer.QueryError()) != NERR_Success )
  512. || ((err = QueryPath( &nlsPath )) != NERR_Success )
  513. )
  514. {
  515. break;
  516. }
  517. //
  518. // When the path is empty, ( probably because of ADMIN$/IPC$ )
  519. // assume the server is the local computer.
  520. //
  521. if ( nlsPath.QueryTextLength() == 0 )
  522. {
  523. nlsComputer = EMPTY_STRING;
  524. err = nlsComputer.QueryError();
  525. break;
  526. }
  527. //
  528. // Let the type be unknown so that SHARE_NET_NAME will set the
  529. // type accordingly. This is only valid when the path is not empty.
  530. //
  531. SHARE_NET_NAME netName( nlsPath, TYPE_UNKNOWN );
  532. if ( ( err = netName.QueryError()) != NERR_Success )
  533. {
  534. if ( err == ERROR_INVALID_NAME )
  535. err = (APIERR) IERR_SHARE_INVALID_SHAREPATH;
  536. SetFocusOnPath();
  537. break;
  538. }
  539. //
  540. // Get the Computer Name
  541. //
  542. if ((err = netName.QueryComputerName( &nlsComputer )) != NERR_Success )
  543. {
  544. break;
  545. }
  546. if ( netName.IsLocal( &err ) && ( err == NERR_Success ))
  547. {
  548. nlsComputer = EMPTY_STRING;
  549. err = nlsComputer.QueryError();
  550. }
  551. } while ( FALSE );
  552. //
  553. // Check to see the computer is the same the one stored before
  554. // If so, we don't need a new server object.
  555. // Else, delete the old server object and get a new one.
  556. //
  557. if ( ( err == NERR_Success )
  558. && ( ( _psvr == NULL )
  559. || ::I_MNetComputerNameCompare( nlsComputer, _psvr->QueryName() )
  560. )
  561. )
  562. {
  563. if ( _psvr != NULL )
  564. delete _psvr;
  565. //
  566. // We need to clear the security desc when the user switched to
  567. // a different computer.
  568. //
  569. if ( (err = ClearStoredInfo()) == NERR_Success )
  570. {
  571. _psvr = new SERVER_WITH_PASSWORD_PROMPT( nlsComputer,
  572. QueryHwnd(),
  573. QueryHelpContextBase() );
  574. if ( ( _psvr == NULL )
  575. || ((err = _psvr->QueryError()) != NERR_Success )
  576. || ((err = _psvr->GetInfo()) != NERR_Success )
  577. )
  578. {
  579. err = err? err : ERROR_NOT_ENOUGH_MEMORY;
  580. delete _psvr;
  581. _psvr = NULL;
  582. }
  583. }
  584. }
  585. *ppsvr = _psvr;
  586. return err;
  587. }
  588. /*******************************************************************
  589. NAME: FILEMGR_NEW_SHARE_DIALOG::SetDefaults
  590. SYNOPSIS: Set the default share and path in the SLEs
  591. ENTRY: pszSelectedDir - name of the selected directory
  592. EXIT:
  593. RETURNS:
  594. NOTES: We'll only set the default share name if the name has
  595. not been used before, i.e. when fShowDefault is TRUE
  596. HISTORY:
  597. Yi-HsinS 8/3/92 Created
  598. ********************************************************************/
  599. APIERR FILEMGR_NEW_SHARE_DIALOG::SetDefaults( const TCHAR *pszSelectedDir,
  600. BOOL fShowDefault )
  601. {
  602. APIERR err = NERR_Success;
  603. ALIAS_STR nlsSelectedDir( pszSelectedDir );
  604. if ( nlsSelectedDir.QueryTextLength() == 0 )
  605. {
  606. QueryPBCancel()->MakeDefault();
  607. return err;
  608. }
  609. //
  610. // Get Information on the selected directory
  611. //
  612. SHARE_NET_NAME netName( pszSelectedDir, TYPE_UNKNOWN );
  613. if ((err = netName.QueryError()) == NERR_Success )
  614. {
  615. BOOL fLocal = netName.IsLocal( &err );
  616. if ( err == NERR_Success )
  617. {
  618. NLS_STR nlsSharePath; // of the form "\\server\share\path"
  619. // or "x:\path"
  620. NLS_STR nlsShareName; // EMPTY_STRING is default
  621. NLS_STR nlsComputer;
  622. if ( (( err = nlsSharePath.QueryError()) == NERR_Success )
  623. && (( err = nlsShareName.QueryError()) == NERR_Success )
  624. && (( err = nlsComputer.QueryError()) == NERR_Success )
  625. )
  626. {
  627. //
  628. // Set the default value of SLEs
  629. // If the path is on a local computer, display the
  630. // absolute path. If it's not on a local computer,
  631. // display the UNC path
  632. //
  633. if ( fLocal )
  634. err = netName.QueryLocalPath( &nlsSharePath );
  635. else
  636. err = netName.QueryUNCPath( &nlsSharePath );
  637. err = err? err : netName.QueryComputerName( &nlsComputer );
  638. if ( fShowDefault )
  639. err = err? err : netName.QueryLastComponent( &nlsShareName);
  640. if ( err == NERR_Success )
  641. {
  642. UINT nShareLen = nlsShareName.QueryTextLength();
  643. if ( nShareLen == 0 )
  644. {
  645. QueryPBCancel()->MakeDefault();
  646. QueryPBPermissions()->Enable( FALSE );
  647. }
  648. else
  649. {
  650. QueryPBOK()->MakeDefault();
  651. QueryPBPermissions()->Enable( TRUE );
  652. if ( nShareLen > SHARE_NAME_LENGTH )
  653. {
  654. ISTR istr( nlsShareName );
  655. istr += SHARE_NAME_LENGTH;
  656. nlsShareName.DelSubStr( istr );
  657. }
  658. }
  659. SetPath ( nlsSharePath );
  660. SetShare( nlsShareName );
  661. }
  662. }
  663. }
  664. }
  665. return err;
  666. }
  667. /*******************************************************************
  668. NAME: FILEMGR_NEW_SHARE_DIALOG::GetAndValidateComputerPath
  669. SYNOPSIS: Helper method to get the path of the share
  670. and the computer on which to create the share
  671. ENTRY: psvr - the server on which to create the share
  672. EXIT: pnlsComputer - pointer to the computer name
  673. pnlsPath - pointer to the path
  674. RETURNS:
  675. NOTES: This is the virtual method used when the dialog belongs
  676. to the file manager.
  677. HISTORY:
  678. Yi-HsinS 8/3/92 Created
  679. ********************************************************************/
  680. APIERR FILEMGR_NEW_SHARE_DIALOG::GetAndValidateComputerPath(
  681. SERVER_WITH_PASSWORD_PROMPT *psvr,
  682. NLS_STR *pnlsComputer,
  683. NLS_STR *pnlsPath )
  684. {
  685. APIERR err;
  686. do { // NOT a loop
  687. *pnlsComputer = psvr->QueryName();
  688. if ( ((err = pnlsComputer->QueryError()) != NERR_Success )
  689. || ((err = QueryPath( pnlsPath )) != NERR_Success )
  690. )
  691. {
  692. break;
  693. }
  694. if ( pnlsPath->QueryTextLength() == 0 )
  695. {
  696. break;
  697. }
  698. //
  699. // Let the type be unknown so that SHARE_NET_NAME will set the
  700. // type accordingly. This is only valid when the path is not empty.
  701. //
  702. SHARE_NET_NAME netName( *pnlsPath, TYPE_UNKNOWN );
  703. if ( ( err = netName.QueryError()) != NERR_Success )
  704. {
  705. if ( err == ERROR_INVALID_NAME )
  706. err = (APIERR) IERR_SHARE_INVALID_SHAREPATH;
  707. break;
  708. }
  709. //
  710. // Get the path that is local to the computer.
  711. //
  712. if ((err = netName.QueryLocalPath( pnlsPath )) != NERR_Success )
  713. {
  714. break;
  715. }
  716. } while ( FALSE );
  717. return err;
  718. }
  719. /*******************************************************************
  720. NAME: FILEMGR_NEW_SHARE_DIALOG::OnOK
  721. SYNOPSIS: Create the share if the user clicks on the OK button
  722. ENTRY:
  723. EXIT:
  724. RETURNS:
  725. NOTES:
  726. HISTORY:
  727. Yi-HsinS 1/8/92 Created
  728. ********************************************************************/
  729. BOOL FILEMGR_NEW_SHARE_DIALOG::OnOK( VOID )
  730. {
  731. AUTO_CURSOR autocur;
  732. SERVER_WITH_PASSWORD_PROMPT *psvr = NULL;
  733. APIERR err = QueryServer2( &psvr );
  734. if ( err == NERR_Success )
  735. {
  736. if ( OnAddShare( psvr, _pnlsNewShareName ) )
  737. Dismiss( TRUE );
  738. }
  739. else
  740. {
  741. // Don't popup the error if the user clicks cancel button in the
  742. // password dialog.
  743. if ( err != IERR_USER_CLICKED_CANCEL )
  744. ::MsgPopup( this, err );
  745. }
  746. return TRUE;
  747. }
  748. /*******************************************************************
  749. NAME: FILEMGR_NEW_SHARE_DIALOG::QueryHelpContext
  750. SYNOPSIS: Get the help context of the dialog
  751. ENTRY:
  752. EXIT:
  753. RETURNS: Return the help context
  754. NOTES:
  755. HISTORY:
  756. Yi-HsinS 1/8/92 Created
  757. ********************************************************************/
  758. ULONG FILEMGR_NEW_SHARE_DIALOG::QueryHelpContext( VOID )
  759. {
  760. return QueryHelpContextBase() + HC_FILEMGRNEWSHARE;
  761. }
  762. /*******************************************************************
  763. NAME: FILEMGR_NEW_SHARE_GROUP::FILEMGR_NEW_SHARE_GROUP
  764. SYNOPSIS: Constructor
  765. ENTRY: pdlg - pointer to the dialog
  766. psleShare - pointer to the Share SLE
  767. pslePath - pointer to teh Path SLE
  768. EXIT:
  769. RETURNS:
  770. NOTES:
  771. HISTORY:
  772. Yi-HsinS 3/12/92 Created
  773. ********************************************************************/
  774. FILEMGR_NEW_SHARE_GROUP::FILEMGR_NEW_SHARE_GROUP(
  775. ADD_SHARE_DIALOG_BASE *pdlg,
  776. SLE *psleShare, SLE *pslePath )
  777. : _psleShare( psleShare ),
  778. _pslePath( pslePath ),
  779. _pdlg( pdlg )
  780. {
  781. UIASSERT( psleShare );
  782. UIASSERT( pslePath );
  783. UIASSERT( pdlg );
  784. _psleShare->SetGroup( this );
  785. _pslePath->SetGroup( this );
  786. }
  787. /*******************************************************************
  788. NAME: FILEMGR_NEW_SHARE_GROUP::~FILEMGR_NEW_SHARE_GROUP
  789. SYNOPSIS: Destructor
  790. ENTRY:
  791. EXIT:
  792. RETURNS:
  793. NOTES:
  794. HISTORY:
  795. Yi-HsinS 3/12/92 Created
  796. ********************************************************************/
  797. FILEMGR_NEW_SHARE_GROUP::~FILEMGR_NEW_SHARE_GROUP()
  798. {
  799. _psleShare = NULL;
  800. _pslePath = NULL;
  801. _pdlg = NULL;
  802. }
  803. /*******************************************************************
  804. NAME: FILEMGR_NEW_SHARE_GROUP::OnUserAction
  805. SYNOPSIS: If the share name is not empty, make OK the default button.
  806. Else, make CANCEL the default button.
  807. ENTRY:
  808. EXIT:
  809. RETURNS:
  810. NOTES:
  811. HISTORY:
  812. Yi-HsinS 3/12/92 Created
  813. ********************************************************************/
  814. APIERR FILEMGR_NEW_SHARE_GROUP::OnUserAction( CONTROL_WINDOW *pcw,
  815. const CONTROL_EVENT &e )
  816. {
  817. if ( ( pcw == _pslePath )
  818. || ( pcw == _psleShare )
  819. )
  820. {
  821. if ( e.QueryCode() == EN_CHANGE )
  822. {
  823. BOOL fShareEmpty = ( _psleShare->QueryTextLength() == 0 );
  824. BOOL fPathEmpty = ( _pslePath->QueryTextLength() == 0 );
  825. BOOL fEnable = FALSE;
  826. // If both share and path are not empty
  827. if ( !fShareEmpty && !fPathEmpty )
  828. {
  829. fEnable = TRUE;
  830. }
  831. // If share is not empty and path is empty,
  832. // check if the share name is ADMIN$ or IPC$
  833. else if ( !fShareEmpty && fPathEmpty )
  834. {
  835. APIERR err;
  836. NLS_STR nlsShare;
  837. if ( ((err = nlsShare.QueryError()) != NERR_Success )
  838. || ((err = _psleShare->QueryText( &nlsShare ))
  839. != NERR_Success )
  840. )
  841. {
  842. ::MsgPopup( pcw->QueryOwnerHwnd(), err );
  843. return GROUP_NO_CHANGE;
  844. }
  845. ALIAS_STR nlsAdmin( ADMIN_SHARE );
  846. ALIAS_STR nlsIPC( IPC_SHARE );
  847. if ( ( nlsShare._stricmp( nlsAdmin ) == 0 )
  848. || ( nlsShare._stricmp( nlsIPC ) == 0 )
  849. )
  850. {
  851. fEnable = TRUE;
  852. }
  853. }
  854. _pdlg->QueryPBPermissions()->Enable( fEnable );
  855. if ( !fShareEmpty )
  856. _pdlg->QueryPBOK()->MakeDefault();
  857. else
  858. _pdlg->QueryPBCancel()->MakeDefault();
  859. }
  860. }
  861. else
  862. {
  863. UIASSERT( FALSE );
  864. }
  865. return GROUP_NO_CHANGE;
  866. }
  867. /*******************************************************************
  868. NAME: SVRMGR_NEW_SHARE_DIALOG::SVRMGR_NEW_SHARE_DIALOG
  869. SYNOPSIS: Constructor
  870. ENTRY: hwndParent - hwnd of the parent window
  871. pszComputer - the selected directory in the file manager
  872. ulHelpContextBase - the base help context
  873. EXIT:
  874. RETURNS:
  875. NOTES:
  876. HISTORY:
  877. Yi-HsinS 8/25/91 Created
  878. ********************************************************************/
  879. SVRMGR_NEW_SHARE_DIALOG::SVRMGR_NEW_SHARE_DIALOG( HWND hwndParent,
  880. SERVER_WITH_PASSWORD_PROMPT *psvr,
  881. ULONG ulHelpContextBase )
  882. : ADD_SHARE_DIALOG_BASE( MAKEINTRESOURCE(IDD_SHARECREATEDLG),
  883. hwndParent,
  884. ulHelpContextBase ),
  885. _shareGrp( this, QuerySLEShare() ),
  886. _psvr( psvr )
  887. {
  888. UIASSERT( psvr != NULL );
  889. if ( QueryError() != NERR_Success )
  890. return;
  891. APIERR err;
  892. if ( ((err = _shareGrp.QueryError()) != NERR_Success)
  893. || ((err = SetMaxUserLimit(DetermineUserLimit(_psvr))) != NERR_Success)
  894. )
  895. {
  896. ReportError( err );
  897. return;
  898. }
  899. QueryPBCancel()->MakeDefault();
  900. QueryPBPermissions()->Enable( FALSE );
  901. }
  902. /*******************************************************************
  903. NAME: SVRMGR_NEW_SHARE_DIALOG::~SVRMGR_NEW_SHARE_DIALOG
  904. SYNOPSIS: Destructor
  905. ENTRY:
  906. EXIT:
  907. RETURNS:
  908. NOTES:
  909. HISTORY:
  910. Yi-HsinS 8/25/91 Created
  911. ********************************************************************/
  912. SVRMGR_NEW_SHARE_DIALOG::~SVRMGR_NEW_SHARE_DIALOG()
  913. {
  914. _psvr = NULL;
  915. }
  916. /*******************************************************************
  917. NAME: SVRMGR_NEW_SHARE_DIALOG::QueryServer2
  918. SYNOPSIS: Get the server object
  919. ENTRY:
  920. EXIT: *ppsvr - pointer to the server object
  921. RETURNS:
  922. NOTES:
  923. HISTORY:
  924. Yi-HsinS 8/25/91 Created
  925. ********************************************************************/
  926. APIERR SVRMGR_NEW_SHARE_DIALOG::QueryServer2(
  927. SERVER_WITH_PASSWORD_PROMPT **ppsvr )
  928. {
  929. UIASSERT( _psvr != NULL );
  930. *ppsvr = _psvr;
  931. return NERR_Success;
  932. }
  933. /*******************************************************************
  934. NAME: SVRMGR_NEW_SHARE_DIALOG::OnOK
  935. SYNOPSIS: Create the share when the user clicks on the OK button
  936. ENTRY:
  937. EXIT:
  938. RETURNS:
  939. NOTES:
  940. HISTORY:
  941. Yi-HsinS 1/8/92 Created
  942. ********************************************************************/
  943. BOOL SVRMGR_NEW_SHARE_DIALOG::OnOK( VOID )
  944. {
  945. AUTO_CURSOR autocur;
  946. if ( OnAddShare( _psvr ) )
  947. Dismiss( TRUE );
  948. return TRUE;
  949. }
  950. /*******************************************************************
  951. NAME: SVRMGR_NEW_SHARE_DIALOG::QueryHelpContext
  952. SYNOPSIS: Get the help context of the dialog
  953. ENTRY:
  954. EXIT:
  955. RETURNS: Return the help context
  956. NOTES:
  957. HISTORY:
  958. Yi-HsinS 1/8/92 Created
  959. ********************************************************************/
  960. ULONG SVRMGR_NEW_SHARE_DIALOG::QueryHelpContext( VOID )
  961. {
  962. return QueryHelpContextBase() + HC_SVRMGRNEWSHARE;
  963. }
  964. /*******************************************************************
  965. NAME: SVRMGR_NEW_SHARE_GROUP::SVRMGR_NEW_SHARE_GROUP
  966. SYNOPSIS: Constructor
  967. ENTRY: pdlg - pointer to the server manager new share dialog
  968. psleShare - pointer to the Share SLE
  969. EXIT:
  970. RETURNS:
  971. NOTES:
  972. HISTORY:
  973. Yi-HsinS 3/12/92 Created
  974. ********************************************************************/
  975. SVRMGR_NEW_SHARE_GROUP::SVRMGR_NEW_SHARE_GROUP( SVRMGR_NEW_SHARE_DIALOG *pdlg,
  976. SLE *psleShare )
  977. : _psleShare( psleShare ),
  978. _pdlg( pdlg )
  979. {
  980. UIASSERT( psleShare );
  981. UIASSERT( pdlg );
  982. _psleShare->SetGroup( this );
  983. }
  984. /*******************************************************************
  985. NAME: SVRMGR_NEW_SHARE_GROUP::~SVRMGR_NEW_SHARE_GROUP
  986. SYNOPSIS: Destructor
  987. ENTRY:
  988. EXIT:
  989. RETURNS:
  990. NOTES:
  991. HISTORY:
  992. Yi-HsinS 3/12/92 Created
  993. ********************************************************************/
  994. SVRMGR_NEW_SHARE_GROUP::~SVRMGR_NEW_SHARE_GROUP()
  995. {
  996. _psleShare = NULL;
  997. _pdlg = NULL;
  998. }
  999. /*******************************************************************
  1000. NAME: SVRMGR_NEW_SHARE_GROUP::OnUserAction
  1001. SYNOPSIS: If share name SLE is empty, set the default button
  1002. to CANCEL, else set the default button to OK.
  1003. We will also disable the permissions button if
  1004. necessary.
  1005. ENTRY: pcw - the control window that the event was sent to
  1006. e - the event that occurred
  1007. EXIT:
  1008. RETURNS:
  1009. NOTES:
  1010. HISTORY:
  1011. Yi-HsinS 3/12/92 Created
  1012. ********************************************************************/
  1013. APIERR SVRMGR_NEW_SHARE_GROUP::OnUserAction( CONTROL_WINDOW *pcw,
  1014. const CONTROL_EVENT &e )
  1015. {
  1016. if ( pcw == _psleShare )
  1017. {
  1018. if ( e.QueryCode() == EN_CHANGE )
  1019. {
  1020. SERVER_WITH_PASSWORD_PROMPT *psvr;
  1021. APIERR err = _pdlg->QueryServer2( &psvr );
  1022. if ( err != NERR_Success )
  1023. {
  1024. ::MsgPopup( pcw->QueryOwnerHwnd(), err );
  1025. }
  1026. else
  1027. {
  1028. BOOL fShareEmpty = ( _psleShare->QueryTextLength() == 0 );
  1029. if ( !fShareEmpty )
  1030. {
  1031. _pdlg->QueryPBOK()->MakeDefault();
  1032. // Enable the permissions button if the server
  1033. // is an NT server or an LM share-level server.
  1034. // LM user-level servers should already have
  1035. // the permissions button grayed.
  1036. if ( psvr->IsNT() || psvr->IsShareLevel() )
  1037. _pdlg->QueryPBPermissions()->Enable( TRUE );
  1038. }
  1039. else
  1040. {
  1041. _pdlg->QueryPBCancel()->MakeDefault();
  1042. // Disable the permissions button if the server
  1043. // is an NT server or an LM share-level server
  1044. // LM user-level servers should already have
  1045. // the permissions button grayed.
  1046. if ( psvr->IsNT() || psvr->IsShareLevel() )
  1047. _pdlg->QueryPBPermissions()->Enable( FALSE );
  1048. }
  1049. }
  1050. }
  1051. }
  1052. return GROUP_NO_CHANGE;
  1053. }
  1054. /*******************************************************************
  1055. NAME: SVRMGR_SHARE_PROP_DIALOG::SVRMGR_SHARE_PROP_DIALOG
  1056. SYNOPSIS: Constructor
  1057. ENTRY: hwndParent - hwnd of the parent window
  1058. pszComputer - the computer that the share is on
  1059. pszShare - the name of the share
  1060. ulHelpContextBase - the base help context
  1061. EXIT:
  1062. RETURNS:
  1063. NOTES:
  1064. HISTORY:
  1065. Yi-HsinS 8/3/92 Created
  1066. ********************************************************************/
  1067. SVRMGR_SHARE_PROP_DIALOG::SVRMGR_SHARE_PROP_DIALOG( HWND hwndParent,
  1068. SERVER_WITH_PASSWORD_PROMPT *psvr,
  1069. const TCHAR *pszShare,
  1070. ULONG ulHelpContextBase )
  1071. : ADD_SHARE_DIALOG_BASE( MAKEINTRESOURCE(IDD_SVRMGRSHAREPROPDLG),
  1072. hwndParent,
  1073. ulHelpContextBase ),
  1074. _nlsStoredPath(), // the original path of the share
  1075. _psvr( psvr ),
  1076. _fDeleted( FALSE )
  1077. {
  1078. UIASSERT( psvr != NULL );
  1079. if ( QueryError() != NERR_Success )
  1080. return;
  1081. APIERR err;
  1082. if ( ((err = _nlsStoredPath.QueryError()) != NERR_Success )
  1083. || ((err = SetMaxUserLimit( DetermineUserLimit(_psvr) )) != NERR_Success)
  1084. || ((err = UpdateInfo( _psvr, pszShare )) != NERR_Success )
  1085. || ((err = QueryPath( &_nlsStoredPath )) != NERR_Success )
  1086. )
  1087. {
  1088. ReportError( err );
  1089. return;
  1090. }
  1091. if ( !_psvr->IsNT() && _psvr->IsUserLevel() )
  1092. QueryPBPermissions()->Enable( FALSE );
  1093. SetShare( pszShare );
  1094. SetFocusOnComment();
  1095. }
  1096. /*******************************************************************
  1097. NAME: SVRMGR_SHARE_PROP_DIALOG::~SVRMGR_SHARE_PROP_DIALOG
  1098. SYNOPSIS: Destructor
  1099. ENTRY:
  1100. EXIT:
  1101. RETURNS:
  1102. NOTES: We don't need to delete _psvr. We'll leave it to whoever
  1103. that creates it.
  1104. HISTORY:
  1105. Yi-HsinS 8/3/92 Created
  1106. ********************************************************************/
  1107. SVRMGR_SHARE_PROP_DIALOG::~SVRMGR_SHARE_PROP_DIALOG()
  1108. {
  1109. _psvr = NULL;
  1110. }
  1111. /*******************************************************************
  1112. NAME: SVRMGR_SHARE_PROP_DIALOG::QueryServer2
  1113. SYNOPSIS: Get the server object
  1114. ENTRY:
  1115. EXIT: *ppsvr - pointer to the server object
  1116. RETURNS:
  1117. NOTES:
  1118. HISTORY:
  1119. Yi-HsinS 8/3/92 Created
  1120. ********************************************************************/
  1121. APIERR SVRMGR_SHARE_PROP_DIALOG::QueryServer2(
  1122. SERVER_WITH_PASSWORD_PROMPT **ppsvr )
  1123. {
  1124. UIASSERT( _psvr != NULL );
  1125. *ppsvr = _psvr;
  1126. return NERR_Success;
  1127. }
  1128. /*******************************************************************
  1129. NAME: SVRMGR_SHARE_PROP_DIALOG::StopShareIfNecessary
  1130. SYNOPSIS: Check if the user has changed the path of the directory
  1131. If so, stop sharing the old share.
  1132. ENTRY: pszShare - the name of the share
  1133. pfDeleteShare - pointer to a flag indicating whether
  1134. the share has been deleted or not
  1135. pfCancel - pointer to a flag indicating whether
  1136. the user has cancelled changing the
  1137. properties of the share
  1138. EXIT:
  1139. RETURNS:
  1140. NOTES:
  1141. HISTORY:
  1142. Yi-HsinS 8/3/92 Created
  1143. ********************************************************************/
  1144. APIERR SVRMGR_SHARE_PROP_DIALOG::StopShareIfNecessary( const TCHAR *pszShare,
  1145. BOOL *pfDeleteShare,
  1146. BOOL *pfCancel )
  1147. {
  1148. UIASSERT( pfCancel != NULL );
  1149. *pfCancel = FALSE;
  1150. UIASSERT( pfDeleteShare != NULL );
  1151. *pfDeleteShare = FALSE;
  1152. //
  1153. // If the share has already been deleted,
  1154. // just return
  1155. //
  1156. if ( _fDeleted )
  1157. {
  1158. *pfDeleteShare = TRUE;
  1159. return NERR_Success;
  1160. }
  1161. APIERR err;
  1162. ALIAS_STR nlsShare( pszShare );
  1163. do { // Not a loop
  1164. //
  1165. // Get and validate the path
  1166. //
  1167. NLS_STR nlsPath;
  1168. if ( ((err = nlsPath.QueryError()) != NERR_Success )
  1169. || ((err = QueryPath( &nlsPath )) != NERR_Success )
  1170. )
  1171. {
  1172. break;
  1173. }
  1174. ALIAS_STR nlsAdmin( ADMIN_SHARE );
  1175. ALIAS_STR nlsIPC( IPC_SHARE );
  1176. if ( ( nlsPath.QueryTextLength() != 0 )
  1177. || ( nlsShare._stricmp( nlsIPC ) != 0 )
  1178. )
  1179. {
  1180. NET_NAME netName( nlsPath, TYPE_PATH_ABS );
  1181. if ((err = netName.QueryError()) != NERR_Success )
  1182. {
  1183. if ( err == ERROR_INVALID_NAME )
  1184. err = IERR_SHARE_INVALID_LOCAL_PATH;
  1185. SetFocusOnPath();
  1186. break;
  1187. }
  1188. }
  1189. //
  1190. // If the path is of the form "x:", append a "\"
  1191. //
  1192. if ( nlsPath.QueryTextLength() == 2 )
  1193. {
  1194. if ((err = nlsPath.AppendChar( PATH_SEPARATOR)) != NERR_Success)
  1195. break;
  1196. }
  1197. BOOL fPathSame;
  1198. if ( nlsPath._stricmp( _nlsStoredPath ) == 0 )
  1199. {
  1200. fPathSame = TRUE;
  1201. }
  1202. else
  1203. {
  1204. fPathSame = FALSE;
  1205. }
  1206. MSGID msgid;
  1207. NLS_STR *apnlsParams[ 5 ];
  1208. apnlsParams[0] = &_nlsStoredPath;
  1209. apnlsParams[1] = &nlsShare;
  1210. INT i = 2;
  1211. //
  1212. // If the share is ADMIN$ or IPC$, and the path has changed
  1213. // popup an error.
  1214. //
  1215. if ( ( nlsShare._stricmp( nlsAdmin ) == 0 )
  1216. || ( nlsShare._stricmp( nlsIPC) == 0 )
  1217. )
  1218. {
  1219. if ( !fPathSame )
  1220. {
  1221. if ( IDNO == ::MsgPopup( this,
  1222. IERR_SPECIAL_SHARE_CANNOT_CHANGE_PATH,
  1223. MPSEV_WARNING, MP_YESNO, MP_YES ) )
  1224. {
  1225. *pfCancel = TRUE;
  1226. SetPath( _nlsStoredPath );
  1227. break;
  1228. }
  1229. else
  1230. {
  1231. break;
  1232. }
  1233. }
  1234. else
  1235. {
  1236. break;
  1237. }
  1238. }
  1239. //
  1240. // If the path has changed, popup an warning asking the
  1241. // user if he really wants to change the path.
  1242. //
  1243. if ( !fPathSame )
  1244. {
  1245. msgid = IDS_CHANGE_PATH_WARNING;
  1246. apnlsParams[ i++ ] = &nlsPath;
  1247. apnlsParams[ i++ ] = &nlsShare;
  1248. apnlsParams[ i ] = NULL;
  1249. if ( IDNO == ::MsgPopup( this, msgid, MPSEV_WARNING,
  1250. HC_DEFAULT_HELP, MP_YESNO,
  1251. apnlsParams, MP_NO ))
  1252. {
  1253. *pfCancel = TRUE;
  1254. SetPath( _nlsStoredPath );
  1255. break;
  1256. }
  1257. }
  1258. else
  1259. {
  1260. break;
  1261. }
  1262. //
  1263. // If there are users connected to the share, popup the
  1264. // warning dialog listing all users currently connected to the share.
  1265. //
  1266. SHARE_2 sh2( nlsShare, _psvr->QueryName(), FALSE );
  1267. if ( (( err = sh2.QueryError()) == NERR_Success )
  1268. && (( err = sh2.GetInfo()) == NERR_Success )
  1269. && ( sh2.QueryCurrentUses() > 0 )
  1270. )
  1271. {
  1272. BOOL fOK = TRUE;
  1273. // There are users currently connected to the share to be deleted,
  1274. // hence, popup a warning.
  1275. CURRENT_USERS_WARNING_DIALOG *pdlg =
  1276. new CURRENT_USERS_WARNING_DIALOG( QueryRobustHwnd(),
  1277. _psvr->QueryName(),
  1278. nlsShare,
  1279. QueryHelpContextBase() );
  1280. if ( ( pdlg == NULL )
  1281. || ((err = pdlg->QueryError()) != NERR_Success )
  1282. || ((err = pdlg->Process( &fOK )) != NERR_Success )
  1283. )
  1284. {
  1285. err = err? err : (APIERR) ERROR_NOT_ENOUGH_MEMORY;
  1286. }
  1287. delete pdlg;
  1288. // User clicked CANCEL for the pdlg
  1289. if ( !err && !fOK )
  1290. {
  1291. *pfCancel = TRUE;
  1292. break;
  1293. }
  1294. }
  1295. if ( err != NERR_Success )
  1296. break;
  1297. //
  1298. // If all is well so far, read the share permissions. When the
  1299. // share is deleted and recreated, the permissions will be
  1300. // reinstantiated as if the user had pressed "Permissions" in
  1301. // the New Share dialog. Otherwise the permissions will be lost
  1302. // when the share is "renamed".
  1303. //
  1304. if ( (err = UpdatePermissionsInfo( _psvr,
  1305. &sh2,
  1306. pszShare )) != NERR_Success )
  1307. {
  1308. DBGEOL( "SRVMGR_SHARE_PROP_DIALOG::StopShareIfNecessary: error loading permissions" );
  1309. break;
  1310. }
  1311. //
  1312. // We also must set this flag to ensure that permissions will be
  1313. // written on the new share
  1314. //
  1315. SetSecDescModified();
  1316. //
  1317. // Delete the share if everything went fine.
  1318. //
  1319. if ( (err = sh2.Delete()) == NERR_Success )
  1320. *pfDeleteShare = TRUE;
  1321. // falls through if error occurs
  1322. } while ( FALSE );
  1323. return err;
  1324. }
  1325. /*******************************************************************
  1326. NAME: SVRMGR_SHARE_PROP_DIALOG::OnOK
  1327. SYNOPSIS: Change the properties of the share when the user
  1328. clicks OK button
  1329. ENTRY:
  1330. EXIT:
  1331. RETURNS:
  1332. NOTES:
  1333. HISTORY:
  1334. Yi-HsinS 1/8/92 Created
  1335. ********************************************************************/
  1336. BOOL SVRMGR_SHARE_PROP_DIALOG::OnOK( VOID )
  1337. {
  1338. AUTO_CURSOR autocur;
  1339. BOOL fDeleteShare;
  1340. BOOL fCancel;
  1341. APIERR err;
  1342. NLS_STR nlsShare;
  1343. if ( ((err = nlsShare.QueryError()) == NERR_Success )
  1344. && ((err = QueryShare( &nlsShare )) == NERR_Success )
  1345. && ((err = StopShareIfNecessary( nlsShare, &fDeleteShare, &fCancel ))
  1346. == NERR_Success )
  1347. )
  1348. {
  1349. if ( !fCancel )
  1350. {
  1351. //
  1352. // If the share is deleted because the user change the path,
  1353. // create a new share with the same name.
  1354. //
  1355. if ( fDeleteShare )
  1356. {
  1357. _fDeleted = TRUE;
  1358. if ( OnAddShare( _psvr ) )
  1359. {
  1360. Dismiss( TRUE );
  1361. }
  1362. }
  1363. //
  1364. // Else change the properties of the existing share
  1365. //
  1366. else
  1367. {
  1368. err = OnChangeShareProperty( _psvr, nlsShare );
  1369. switch ( err )
  1370. {
  1371. case NERR_Success:
  1372. Dismiss( FALSE );
  1373. break;
  1374. case NERR_NetNameNotFound:
  1375. Dismiss( TRUE );
  1376. break;
  1377. case NERR_BadTransactConfig:
  1378. Dismiss( FALSE );
  1379. break;
  1380. case IERR_USER_CLICKED_CANCEL:
  1381. err = NERR_Success;
  1382. break;
  1383. }
  1384. }
  1385. }
  1386. else
  1387. {
  1388. if ( err == NERR_BadTransactConfig )
  1389. Dismiss( FALSE );
  1390. QuerySLEPath()->SelectString();
  1391. QuerySLEPath()->ClaimFocus();
  1392. }
  1393. }
  1394. if ( err != NERR_Success )
  1395. ::MsgPopup( this, err );
  1396. return TRUE;
  1397. }
  1398. /*******************************************************************
  1399. NAME: SVRMGR_SHARE_PROP_DIALOG::OnCancel
  1400. SYNOPSIS: Dismiss the dialog when the user clicks the CANCEL
  1401. button.
  1402. ENTRY:
  1403. EXIT:
  1404. RETURNS:
  1405. NOTES:
  1406. HISTORY:
  1407. Yi-HsinS 1/8/92 Created
  1408. ********************************************************************/
  1409. BOOL SVRMGR_SHARE_PROP_DIALOG::OnCancel( VOID )
  1410. {
  1411. Dismiss( _fDeleted );
  1412. return TRUE;
  1413. }
  1414. /*******************************************************************
  1415. NAME: SVRMGR_SHARE_PROP_DIALOG::QueryHelpContext
  1416. SYNOPSIS: Get the help context of the dialog
  1417. ENTRY:
  1418. EXIT:
  1419. RETURNS: Return the help context
  1420. NOTES:
  1421. HISTORY:
  1422. Yi-HsinS 1/8/92 Created
  1423. ********************************************************************/
  1424. ULONG SVRMGR_SHARE_PROP_DIALOG::QueryHelpContext( VOID )
  1425. {
  1426. return QueryHelpContextBase() + HC_SVRMGRSHAREPROP;
  1427. }
  1428. /*******************************************************************
  1429. NAME: FILEMGR_SHARE_PROP_DIALOG::FILEMGR_SHARE_PROP_DIALOG
  1430. SYNOPSIS: Constructor
  1431. ENTRY: hwndParent - hwnd of the parent window
  1432. pszSelectedDir - name of the selected directory.
  1433. ulHelpContextBase - the base help context
  1434. EXIT:
  1435. RETURNS:
  1436. NOTES:
  1437. HISTORY:
  1438. Yi-HsinS 8/25/91 Created
  1439. ********************************************************************/
  1440. FILEMGR_SHARE_PROP_DIALOG::FILEMGR_SHARE_PROP_DIALOG( HWND hwndParent,
  1441. const TCHAR *pszSelectedDir,
  1442. ULONG ulHelpContextBase )
  1443. : SHARE_DIALOG_BASE( MAKEINTRESOURCE(IDD_FILEMGRSHAREPROPDLG),
  1444. hwndParent,
  1445. ulHelpContextBase ),
  1446. _cbShare( this, CB_SHARE ),
  1447. _nlsLocalPath(),
  1448. _fShowDefault( TRUE ),
  1449. _fCreatedShare( FALSE ),
  1450. _psvr( NULL )
  1451. {
  1452. if ( QueryError() != NERR_Success )
  1453. return;
  1454. UIASSERT( pszSelectedDir != NULL );
  1455. APIERR err;
  1456. if ( ((err = _nlsLocalPath.QueryError()) != NERR_Success )
  1457. || ((err = Init( pszSelectedDir )) != NERR_Success )
  1458. )
  1459. {
  1460. ReportError( err );
  1461. return;
  1462. }
  1463. if ( !_psvr->IsNT() && _psvr->IsUserLevel() )
  1464. QueryPBPermissions()->Enable( FALSE );
  1465. }
  1466. /*******************************************************************
  1467. NAME: FILEMGR_SHARE_PROP_DIALOG::~FILEMGR_SHARE_PROP_DIALOG
  1468. SYNOPSIS: Destructor
  1469. ENTRY:
  1470. EXIT:
  1471. RETURNS:
  1472. NOTES:
  1473. HISTORY:
  1474. Yi-HsinS 8/25/91 Created
  1475. ********************************************************************/
  1476. FILEMGR_SHARE_PROP_DIALOG::~FILEMGR_SHARE_PROP_DIALOG()
  1477. {
  1478. delete _psvr;
  1479. _psvr = NULL;
  1480. }
  1481. /*******************************************************************
  1482. NAME: FILEMGR_SHARE_PROP_DIALOG::QueryServer2
  1483. SYNOPSIS: Get the server object
  1484. ENTRY:
  1485. EXIT: *ppsvr - pointer to server object
  1486. RETURNS:
  1487. NOTES:
  1488. HISTORY:
  1489. Yi-HsinS 8/25/91 Created
  1490. ********************************************************************/
  1491. APIERR FILEMGR_SHARE_PROP_DIALOG::QueryServer2(
  1492. SERVER_WITH_PASSWORD_PROMPT **ppsvr )
  1493. {
  1494. UIASSERT( _psvr != NULL );
  1495. *ppsvr = _psvr;
  1496. return NERR_Success;
  1497. }
  1498. /*******************************************************************
  1499. NAME: FILEMGR_SHARE_PROP_DIALOG::Init
  1500. SYNOPSIS: 2nd stage constructor
  1501. ENTRY: pszSelectedDir - name of the selected directory
  1502. EXIT:
  1503. RETURNS:
  1504. NOTES: Set up all internal variables and display the
  1505. correct information in the dialog
  1506. HISTORY:
  1507. Yi-HsinS 4/2/92 Created
  1508. ********************************************************************/
  1509. APIERR FILEMGR_SHARE_PROP_DIALOG::Init( const TCHAR *pszSelectedDir )
  1510. {
  1511. APIERR err;
  1512. NLS_STR nlsComputer;
  1513. NLS_STR nlsUNCPath;
  1514. SHARE_NET_NAME netName( pszSelectedDir, TYPE_PATH_ABS );
  1515. if ( ((err = nlsComputer.QueryError()) == NERR_Success )
  1516. && ((err = nlsUNCPath.QueryError()) == NERR_Success )
  1517. && ((err = netName.QueryError()) == NERR_Success )
  1518. && ((err = netName.QueryComputerName( &nlsComputer)) == NERR_Success)
  1519. && ((err = netName.QueryLocalPath( &_nlsLocalPath)) == NERR_Success)
  1520. )
  1521. {
  1522. if ( netName.IsLocal( &err ) && ( err == NERR_Success ))
  1523. {
  1524. nlsComputer = EMPTY_STRING;
  1525. if ( nlsComputer.QueryError() != NERR_Success )
  1526. return nlsComputer.QueryError();
  1527. }
  1528. _psvr = new SERVER_WITH_PASSWORD_PROMPT( nlsComputer,
  1529. QueryHwnd(),
  1530. QueryHelpContextBase() );
  1531. if ( ( _psvr != NULL )
  1532. && ((err = _psvr->QueryError()) == NERR_Success )
  1533. && ((err = _psvr->GetInfo()) == NERR_Success )
  1534. && ((err = SetMaxUserLimit( DetermineUserLimit(_psvr) )) == NERR_Success)
  1535. && ((err = Refresh()) == NERR_Success )
  1536. )
  1537. {
  1538. BOOL fLocal = netName.IsLocal( &err );
  1539. if (( err == NERR_Success ) && !fLocal )
  1540. {
  1541. if ((err = netName.QueryUNCPath( &nlsUNCPath )) == NERR_Success)
  1542. SetPath( nlsUNCPath );
  1543. }
  1544. else
  1545. {
  1546. SetPath( _nlsLocalPath );
  1547. }
  1548. _cbShare.ClaimFocus();
  1549. }
  1550. else
  1551. {
  1552. err = err? err : ERROR_NOT_ENOUGH_MEMORY;
  1553. delete _psvr;
  1554. _psvr = NULL;
  1555. }
  1556. }
  1557. return err;
  1558. }
  1559. /*******************************************************************
  1560. NAME: FILEMGR_SHARE_PROP_DIALOG::Refresh
  1561. SYNOPSIS: Refresh the combo box after the user created a new
  1562. share
  1563. ENTRY: pszNewShareName - Optional parameter indicating
  1564. what share to select after the refresh
  1565. EXIT:
  1566. RETURNS:
  1567. NOTES:
  1568. HISTORY:
  1569. Yi-HsinS 4/2/92 Created
  1570. ********************************************************************/
  1571. APIERR FILEMGR_SHARE_PROP_DIALOG::Refresh( const TCHAR *pszNewShareName )
  1572. {
  1573. AUTO_CURSOR autocur;
  1574. APIERR err;
  1575. SHARE2_ENUM sh2Enum( _psvr->QueryName() );
  1576. NET_NAME netName( _nlsLocalPath, TYPE_PATH_ABS );
  1577. NLS_STR nlsDefaultShare;
  1578. do {
  1579. if ( ((err = sh2Enum.QueryError()) != NERR_Success )
  1580. || ((err = netName.QueryError()) != NERR_Success )
  1581. || ((err = nlsDefaultShare.QueryError()) != NERR_Success )
  1582. || ((err = sh2Enum.GetInfo()) != NERR_Success )
  1583. || ((err = netName.QueryLastComponent( &nlsDefaultShare))
  1584. != NERR_Success)
  1585. )
  1586. {
  1587. break;
  1588. }
  1589. _cbShare.DeleteAllItems();
  1590. SHARE2_ENUM_ITER sh2EnumIter( sh2Enum );
  1591. const SHARE2_ENUM_OBJ *pshi2;
  1592. while ( (pshi2 = sh2EnumIter()) != NULL )
  1593. {
  1594. if ( ::stricmpf( pshi2->QueryPath(), _nlsLocalPath ) == 0 )
  1595. {
  1596. ALIAS_STR nlsTemp( pshi2->QueryName() );
  1597. if ( _cbShare.AddItem( nlsTemp ) < 0 )
  1598. {
  1599. err = ERROR_NOT_ENOUGH_MEMORY;
  1600. break;
  1601. }
  1602. }
  1603. if ( ::stricmpf( pshi2->QueryName(), nlsDefaultShare ) == 0 )
  1604. _fShowDefault = FALSE;
  1605. }
  1606. if ( err != NERR_Success )
  1607. break;
  1608. if ( _cbShare.QueryCount() == 0 )
  1609. {
  1610. err = IERR_SHARE_DIR_NOT_SHARED;
  1611. break;
  1612. }
  1613. INT nSel = 0;
  1614. if ( pszNewShareName )
  1615. nSel = _cbShare.FindItemExact( pszNewShareName );
  1616. _cbShare.SelectItem( nSel >= 0 ? nSel : 0 );
  1617. NLS_STR nlsShare;
  1618. if ( ((err = nlsShare.QueryError()) != NERR_Success )
  1619. || ((err = QueryShare( &nlsShare )) != NERR_Success )
  1620. || ((err = UpdateInfo( _psvr, nlsShare )) != NERR_Success )
  1621. )
  1622. {
  1623. break;
  1624. }
  1625. } while ( FALSE );
  1626. return err;
  1627. }
  1628. /*******************************************************************
  1629. NAME: FILEMGR_SHARE_PROP_DIALOG::OnCommand
  1630. SYNOPSIS: Check when the user changes the selection in the combobox
  1631. or when the user clicks on the new share button
  1632. ENTRY: event - the event that occurred
  1633. EXIT:
  1634. RETURNS:
  1635. NOTES:
  1636. HISTORY:
  1637. Yi-HsinS 1/8/92 Created
  1638. ********************************************************************/
  1639. BOOL FILEMGR_SHARE_PROP_DIALOG::OnCommand( const CONTROL_EVENT &event )
  1640. {
  1641. APIERR err = NERR_Success;
  1642. if ( ( event.QueryCid() == CB_SHARE )
  1643. && ( event.QueryCode() == CBN_SELCHANGE )
  1644. )
  1645. {
  1646. //
  1647. // When the user changes the selection in the listbox,
  1648. // get the share the user has selected and display its
  1649. // information in the dialog
  1650. //
  1651. NLS_STR nlsShare;
  1652. if ( ((err = nlsShare.QueryError()) != NERR_Success )
  1653. || ((err = QueryShare( &nlsShare )) != NERR_Success )
  1654. || ((err = UpdateInfo( _psvr, nlsShare )) != NERR_Success )
  1655. )
  1656. {
  1657. // Nothing to do
  1658. }
  1659. }
  1660. else if ( event.QueryCid() == BUTTON_NEWSHARE )
  1661. {
  1662. //
  1663. // The user clicked on the new share button, hence, show
  1664. // the new share dialog.
  1665. //
  1666. NLS_STR nlsPath;
  1667. NLS_STR nlsNewShareName;
  1668. if ( ((err = nlsPath.QueryError()) == NERR_Success )
  1669. && ((err = nlsNewShareName.QueryError()) == NERR_Success )
  1670. && ((err = QueryPath( &nlsPath)) == NERR_Success )
  1671. )
  1672. {
  1673. FILEMGR_NEW_SHARE_DIALOG *pdlg =
  1674. new FILEMGR_NEW_SHARE_DIALOG( QueryHwnd(),
  1675. nlsPath,
  1676. QueryHelpContextBase(),
  1677. _fShowDefault,
  1678. &nlsNewShareName );
  1679. BOOL fCreated;
  1680. if ( ( pdlg != NULL )
  1681. && ((err = pdlg->QueryError()) == NERR_Success )
  1682. && ((err = pdlg->Process( &fCreated )) == NERR_Success )
  1683. )
  1684. {
  1685. if ( fCreated )
  1686. {
  1687. err = Refresh( nlsNewShareName );
  1688. _fCreatedShare = TRUE;
  1689. }
  1690. }
  1691. else
  1692. {
  1693. err = err? err : ERROR_NOT_ENOUGH_MEMORY;
  1694. }
  1695. delete pdlg;
  1696. pdlg = NULL;
  1697. }
  1698. }
  1699. else
  1700. {
  1701. return SHARE_DIALOG_BASE::OnCommand( event );
  1702. }
  1703. if ( err != NERR_Success )
  1704. {
  1705. ::MsgPopup( this, err );
  1706. if ( err == IERR_SHARE_DIR_NOT_SHARED )
  1707. Dismiss( TRUE );
  1708. }
  1709. return TRUE;
  1710. }
  1711. /*******************************************************************
  1712. NAME: FILEMGR_SHARE_PROP_DIALOG::OnOK
  1713. SYNOPSIS: Change the property of the selected share
  1714. ENTRY:
  1715. EXIT:
  1716. RETURNS:
  1717. NOTES:
  1718. HISTORY:
  1719. Yi-HsinS 1/8/92 Created
  1720. ********************************************************************/
  1721. BOOL FILEMGR_SHARE_PROP_DIALOG::OnOK( VOID )
  1722. {
  1723. AUTO_CURSOR autocur;
  1724. NLS_STR nlsShare;
  1725. APIERR err;
  1726. if ( ((err = nlsShare.QueryError()) == NERR_Success )
  1727. && ((err = QueryShare( &nlsShare )) == NERR_Success )
  1728. )
  1729. {
  1730. err = OnChangeShareProperty( _psvr, nlsShare );
  1731. switch ( err )
  1732. {
  1733. case NERR_Success:
  1734. Dismiss( _fCreatedShare );
  1735. break;
  1736. case NERR_NetNameNotFound:
  1737. Dismiss( TRUE );
  1738. break;
  1739. case NERR_BadTransactConfig:
  1740. Dismiss( FALSE );
  1741. break;
  1742. case IERR_USER_CLICKED_CANCEL:
  1743. err = NERR_Success;
  1744. break;
  1745. }
  1746. }
  1747. if ( err != NERR_Success )
  1748. ::MsgPopup( this, err );
  1749. return TRUE;
  1750. }
  1751. /*******************************************************************
  1752. NAME: FILEMGR_SHARE_PROP_DIALOG::OnCancel
  1753. SYNOPSIS: Dismiss the dialog when the user clicks the Cancel
  1754. button
  1755. ENTRY:
  1756. EXIT:
  1757. RETURNS:
  1758. NOTES:
  1759. HISTORY:
  1760. Yi-HsinS 1/8/92 Created
  1761. ********************************************************************/
  1762. BOOL FILEMGR_SHARE_PROP_DIALOG::OnCancel( VOID )
  1763. {
  1764. Dismiss( _fCreatedShare );
  1765. return TRUE;
  1766. }
  1767. /*******************************************************************
  1768. NAME: FILEMGR_SHARE_PROP_DIALOG::QueryHelpContext
  1769. SYNOPSIS: Get the help context of the dialog
  1770. ENTRY:
  1771. EXIT:
  1772. RETURNS: Return the help context
  1773. NOTES:
  1774. HISTORY:
  1775. Yi-HsinS 8/25/91 Created
  1776. ********************************************************************/
  1777. ULONG FILEMGR_SHARE_PROP_DIALOG::QueryHelpContext( VOID )
  1778. {
  1779. return QueryHelpContextBase() + HC_FILEMGRSHAREPROP;
  1780. }