Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

505 lines
13 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1992 **/
  4. /**********************************************************************/
  5. /*
  6. * sharemgt.cxx
  7. * Contains the dialog for managing shares in the server manager
  8. * SHARE_MANAGEMENT_DIALOG
  9. *
  10. * FILE HISTORY:
  11. * Yi-HsinS 1/6/92 Created
  12. * Yi-HsinS 3/12/92 Fixed behaviour of default buttons
  13. * and added SEL_SRV_ONLY flag to
  14. * STANDALONE_SET_FOCUS_DIALOG.
  15. * Yi-HsinS 4/2/92 Added MayRun
  16. * Yi-HsinS 5/20/92 Added call to IsValid on when Add
  17. * Share button is pressed.
  18. * Yi-HsinS 8/6/92 Reorganize to match Winball
  19. * Yi-HsinS 11/20/92 Added support for sticky shares
  20. *
  21. */
  22. #define INCL_WINDOWS_GDI
  23. #define INCL_WINDOWS
  24. #define INCL_DOSERRORS
  25. #define INCL_NETERRORS
  26. #define INCL_NETSERVER
  27. #define INCL_NETWKSTA
  28. #define INCL_NETSHARE
  29. #define INCL_NETCONS
  30. #define INCL_NETLIB
  31. #define INCL_ICANON
  32. #include <lmui.hxx>
  33. extern "C"
  34. {
  35. #include <sharedlg.h>
  36. #include <helpnums.h>
  37. #include <mnet.h>
  38. }
  39. #define INCL_BLT_DIALOG
  40. #define INCL_BLT_CONTROL
  41. #define INCL_BLT_MSGPOPUP
  42. #define INCL_BLT_SPIN_GROUP
  43. #include <blt.hxx>
  44. #include <string.hxx>
  45. #include <uitrace.hxx>
  46. #include <lmoshare.hxx>
  47. #include <lmoesh.hxx>
  48. #include <lmoeconn.hxx>
  49. #include <lmosrv.hxx>
  50. #include <lmowks.hxx>
  51. #include <strchlit.hxx> // for string and character constants
  52. #include "sharemgt.hxx"
  53. /*******************************************************************
  54. NAME: SHARE_MANAGEMENT_DIALOG::SHARE_MANAGEMENT_DIALOG
  55. SYNOPSIS: Constructor
  56. ENTRY: hwndParent - hwnd of the parent window
  57. pszComputer - name of the selected computer
  58. ulHelpContextBase - the base help context
  59. EXIT:
  60. RETURNS:
  61. NOTES:
  62. HISTORY:
  63. Yi-HsinS 1/6/92 Created
  64. ********************************************************************/
  65. SHARE_MANAGEMENT_DIALOG::SHARE_MANAGEMENT_DIALOG( HWND hwndParent,
  66. const TCHAR *pszComputer,
  67. ULONG ulHelpContextBase )
  68. : VIEW_SHARE_DIALOG_BASE( MAKEINTRESOURCE(IDD_SHAREMANAGEMENTDLG),
  69. hwndParent,
  70. ulHelpContextBase,
  71. STYPE_DISK_SHARE | STYPE_IPC_SHARE ),
  72. _buttonStopSharing( this, BUTTON_STOPSHARING ),
  73. _buttonShareInfo ( this, BUTTON_SHAREINFO ),
  74. _buttonClose ( this, IDOK )
  75. {
  76. if ( QueryError() != NERR_Success )
  77. return;
  78. UIASSERT( pszComputer != NULL );
  79. APIERR err;
  80. if ((err = Init( pszComputer )) != NERR_Success )
  81. {
  82. ReportError( err );
  83. return;
  84. }
  85. }
  86. /*******************************************************************
  87. NAME: SHARING_MANAGEMENT_DIALOG::Init
  88. SYNOPSIS: Initialize all information displayed in the dialog
  89. ENTRY: pszComputer - the name of the computer we are focusing on
  90. EXIT:
  91. RETURNS:
  92. NOTES:
  93. HISTORY:
  94. Yi-HsinS 4/2/92 Created
  95. ********************************************************************/
  96. APIERR SHARE_MANAGEMENT_DIALOG::Init( const TCHAR *pszComputer )
  97. {
  98. AUTO_CURSOR autocur;
  99. //
  100. // Update the listbox and the title of the listbox
  101. //
  102. APIERR err = InitComputer( pszComputer );
  103. ResetControls();
  104. return err;
  105. }
  106. /*******************************************************************
  107. NAME: SHARE_MANAGEMENT_DIALOG::Refresh
  108. SYNOPSIS: Refresh the share listbox
  109. ENTRY:
  110. EXIT:
  111. RETURNS:
  112. NOTES:
  113. HISTORY:
  114. Yi-HsinS 1/7/92 Created
  115. ********************************************************************/
  116. APIERR SHARE_MANAGEMENT_DIALOG::Refresh( VOID )
  117. {
  118. APIERR err = VIEW_SHARE_DIALOG_BASE::Refresh();
  119. ResetControls();
  120. return err;
  121. }
  122. /*******************************************************************
  123. NAME: SHARE_MANAGEMENT_DIALOG::ResetControls
  124. SYNOPSIS: Enable/Disable/MakeDefault the push buttons according
  125. to whether there are items in the listbox
  126. ENTRY:
  127. EXIT:
  128. RETURNS:
  129. NOTES:
  130. HISTORY:
  131. Yi-HsinS 1/8/92 Created
  132. ********************************************************************/
  133. VOID SHARE_MANAGEMENT_DIALOG::ResetControls( VOID )
  134. {
  135. INT nCount = QueryLBShare()->QueryCount();
  136. //
  137. // If there are items in the listbox, select the first one
  138. // and set focus to the listbox.
  139. //
  140. if ( nCount > 0 )
  141. {
  142. QueryLBShare()->SelectItem( 0 );
  143. QueryLBShare()->ClaimFocus();
  144. // JonN 01/27/99: PREFIX bug 444908
  145. _buttonShareInfo.Enable( NULL != QueryLBShare()->QueryItem()
  146. && !QueryLBShare()->QueryItem()->IsSticky());
  147. }
  148. //
  149. // Else set focus to the Close button
  150. //
  151. else
  152. {
  153. _buttonClose.MakeDefault();
  154. _buttonClose.ClaimFocus();
  155. _buttonShareInfo.Enable( FALSE );
  156. }
  157. //
  158. // Disable the stop sharing buttons if there are no
  159. // items in the listbox
  160. //
  161. _buttonStopSharing.Enable( nCount > 0 );
  162. }
  163. /*******************************************************************
  164. NAME: SHARE_MANAGEMENT_DIALOG::OnCommand
  165. SYNOPSIS: Handle all push buttons commands
  166. ENTRY: event - the CONTROL_EVENT that occurred
  167. EXIT:
  168. RETURNS:
  169. NOTES:
  170. HISTORY:
  171. Yi-HsinS 1/8/92 Created
  172. ********************************************************************/
  173. BOOL SHARE_MANAGEMENT_DIALOG::OnCommand( const CONTROL_EVENT &event )
  174. {
  175. APIERR err = NERR_Success;
  176. switch ( event.QueryCid() )
  177. {
  178. case LB_SHARE:
  179. if ( event.QueryCode() == LBN_SELCHANGE )
  180. {
  181. if ( QueryLBShare()->QueryCount() > 0 )
  182. _buttonShareInfo.Enable( !QueryLBShare()->QueryItem()->IsSticky());
  183. }
  184. else
  185. {
  186. return VIEW_SHARE_DIALOG_BASE::OnCommand( event );
  187. }
  188. break;
  189. case BUTTON_STOPSHARING:
  190. err = OnStopSharing();
  191. break;
  192. case BUTTON_SHAREINFO:
  193. err = OnShareInfo();
  194. break;
  195. case BUTTON_ADDSHARE:
  196. err = OnAddShare();
  197. break;
  198. default:
  199. return VIEW_SHARE_DIALOG_BASE::OnCommand( event );
  200. }
  201. if ( err != NERR_Success )
  202. ::MsgPopup( this, err );
  203. return TRUE;
  204. }
  205. /*******************************************************************
  206. NAME: SHARE_MANAGEMENT_DIALOG::OnStopSharing
  207. SYNOPSIS: Called when the "Stop Sharing" button is pressed.
  208. Delete the selected share and pop up any warning
  209. message if there are users connected to the share.
  210. ENTRY:
  211. EXIT:
  212. RETURNS:
  213. NOTES:
  214. HISTORY:
  215. Yi-HsinS 1/8/92 Created
  216. ********************************************************************/
  217. APIERR SHARE_MANAGEMENT_DIALOG::OnStopSharing( VOID )
  218. {
  219. AUTO_CURSOR autocur;
  220. SHARE_LISTBOX *plbShare = QueryLBShare();
  221. SHARE_LBI *pshlbi = plbShare->QueryItem();
  222. //
  223. // Stop sharing the selected item in the listbox
  224. //
  225. BOOL fCancel = FALSE;
  226. APIERR err;
  227. if ( pshlbi && pshlbi->IsSticky() ) // JonN 01/27/99 PREFIX bug 444912
  228. {
  229. err = ::MNetShareDelSticky( QueryComputerName(),
  230. pshlbi->QueryShareName()->QueryPch(),
  231. 0 ); // Reserved
  232. }
  233. else
  234. {
  235. err = StopShare( *(pshlbi->QueryShareName()), &fCancel );
  236. }
  237. if ( err != NERR_Success )
  238. {
  239. ::MsgPopup( this, err );
  240. }
  241. //
  242. // If the user successfully deleted the share or if the error
  243. // from deleting the share is NERR_NetNameNotFound, refresh the
  244. // listbox to reflect the latest information.
  245. //
  246. APIERR err1 = NERR_Success;
  247. if ( (!fCancel && (err == NERR_Success )) // successfully deleted a share
  248. || ( err == NERR_NetNameNotFound )
  249. )
  250. {
  251. err1 = Refresh();
  252. }
  253. return err1;
  254. }
  255. /*******************************************************************
  256. NAME: SHARING_MANAGEMENT_DIALOG::OnAddShare
  257. SYNOPSIS: Called when the "New Share" button is pressed.
  258. ENTRY:
  259. EXIT:
  260. RETURNS:
  261. NOTES:
  262. HISTORY:
  263. Yi-HsinS 4/2/92 Created
  264. ********************************************************************/
  265. APIERR SHARE_MANAGEMENT_DIALOG::OnAddShare( VOID )
  266. {
  267. APIERR err = NERR_Success; // JonN 01/27/00 PREFIX bug 444911
  268. SVRMGR_NEW_SHARE_DIALOG *pdlg =
  269. new SVRMGR_NEW_SHARE_DIALOG( QueryRobustHwnd(),
  270. QueryServer2(),
  271. QueryHelpContextBase() );
  272. BOOL fSucceeded;
  273. if ( ( pdlg == NULL )
  274. || ((err = pdlg->QueryError()) != NERR_Success )
  275. || ((err = pdlg->Process( &fSucceeded )) != NERR_Success )
  276. )
  277. {
  278. err = err ? err : (APIERR) ERROR_NOT_ENOUGH_MEMORY;
  279. ::MsgPopup( this, err );
  280. }
  281. delete pdlg;
  282. pdlg = NULL;
  283. //
  284. // If the user succeeded in creating a new share,
  285. // refresh the share listbox.
  286. //
  287. return ( fSucceeded? Refresh() : NERR_Success );
  288. }
  289. /*******************************************************************
  290. NAME: SHARE_MANAGEMENT_DIALOG::OnShareInfo
  291. SYNOPSIS: Called when the "Properties" button is pressed.
  292. Will pop up a dialog showing the properties of the
  293. selected share.
  294. ENTRY:
  295. EXIT:
  296. RETURNS:
  297. NOTES:
  298. HISTORY:
  299. Yi-HsinS 1/8/92 Created
  300. ********************************************************************/
  301. APIERR SHARE_MANAGEMENT_DIALOG::OnShareInfo( VOID )
  302. {
  303. APIERR err = NERR_Success;
  304. SHARE_LISTBOX *plbShare = QueryLBShare();
  305. SHARE_LBI *pshlbi = plbShare->QueryItem();
  306. SVRMGR_SHARE_PROP_DIALOG *pdlg =
  307. new SVRMGR_SHARE_PROP_DIALOG( QueryRobustHwnd(),
  308. QueryServer2(),
  309. *(pshlbi->QueryShareName()),
  310. QueryHelpContextBase() );
  311. BOOL fChanged;
  312. if ( ( pdlg == NULL )
  313. || ((err = pdlg->QueryError()) != NERR_Success )
  314. || ((err = pdlg->Process( &fChanged )) != NERR_Success )
  315. )
  316. {
  317. err = err ? err : (APIERR) ERROR_NOT_ENOUGH_MEMORY;
  318. }
  319. delete pdlg;
  320. pdlg = NULL;
  321. //
  322. // If the user successfully change the path of the share or if
  323. // the error from getting the share properties is NERR_NetNameNotFound,
  324. // refresh the listbox to reflect the latest information.
  325. //
  326. if ( (( err == NERR_Success) && fChanged )
  327. || ( err == NERR_NetNameNotFound )
  328. )
  329. {
  330. APIERR err1 = Refresh();
  331. err = err? err : err1;
  332. }
  333. plbShare->ClaimFocus();
  334. return err;
  335. }
  336. /*******************************************************************
  337. NAME: SHARE_MANAGEMENT_DIALOG::OnShareLbDblClk
  338. SYNOPSIS: This is called when the user double clicks on a share
  339. in the listbox. Will pop up a dialog showing the
  340. properties of the selected share.
  341. ENTRY:
  342. EXIT:
  343. RETURNS:
  344. NOTES:
  345. HISTORY:
  346. Yi-HsinS 1/8/92 Created
  347. ********************************************************************/
  348. BOOL SHARE_MANAGEMENT_DIALOG::OnShareLbDblClk( VOID )
  349. {
  350. APIERR err = OnShareInfo();
  351. if ( err != NERR_Success )
  352. ::MsgPopup( this, err );
  353. return TRUE;
  354. }
  355. /*******************************************************************
  356. NAME: SHARE_MANAGEMENT_DIALOG::QueryHelpContext
  357. SYNOPSIS: Query the help context of the dialog
  358. ENTRY:
  359. EXIT:
  360. RETURNS: Return the help context of the dialog
  361. NOTES:
  362. HISTORY:
  363. Yi-HsinS 1/6/92 Created
  364. ********************************************************************/
  365. ULONG SHARE_MANAGEMENT_DIALOG::QueryHelpContext( VOID )
  366. {
  367. return QueryHelpContextBase() + HC_SVRMGRSHAREMANAGEMENT;
  368. }