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.

395 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. * sharefmx.cxx
  7. * Contains dialogs called by FMExtensionProc/WinFile/Svrmgr for creating,
  8. * deleting and managing shares.
  9. *
  10. * FILE HISTORY:
  11. * Yi-HsinS 8/25/91 Created
  12. * Yi-HsinS 11/25/91 Made sleShareDir in Create Share dialog
  13. * accepts local full path name.
  14. * Yi-HsinS 12/5/91 Uses NET_NAME
  15. * Yi-HsinS 12/15/91 Uses SHARE_NET_NAME
  16. * Yi-HsinS 12/31/91 Unicode work
  17. * Yi-HsinS 1/8/92 Move dialogs to sharestp.cxx,
  18. * sharecrt.cxx
  19. * Yi-HsinS 8/10/92 Added ShareManage and got rid of
  20. * WNetShareManagementW...
  21. *
  22. */
  23. #define INCL_WINDOWS_GDI
  24. #define INCL_WINDOWS
  25. #define INCL_DOSERRORS
  26. #define INCL_NETERRORS
  27. #define INCL_NETSHARE
  28. #define INCL_NETUSE
  29. #define INCL_NETSERVER
  30. #define INCL_NETCONS
  31. #define INCL_NETLIB
  32. #include <lmui.hxx>
  33. extern "C"
  34. {
  35. #include <mpr.h>
  36. #include <helpnums.h>
  37. #include <sharedlg.h>
  38. }
  39. #include <wfext.h>
  40. #define INCL_BLT_DIALOG
  41. #define INCL_BLT_CONTROL
  42. #define INCL_BLT_MSGPOPUP
  43. #define INCL_BLT_SPIN_GROUP
  44. #include <blt.hxx>
  45. #include <string.hxx>
  46. #include <uitrace.hxx>
  47. #include <lmoshare.hxx>
  48. #include <lmoesh.hxx>
  49. #include <lmoeconn.hxx>
  50. #include <lmosrv.hxx>
  51. #include <wnetdev.hxx>
  52. #include <fmx.hxx>
  53. #include <strchlit.hxx> // for string and character constants
  54. #include "sharestp.hxx"
  55. #include "sharecrt.hxx"
  56. #include "sharemgt.hxx"
  57. #include "sharefmx.hxx"
  58. /*******************************************************************
  59. NAME: ShareCreate
  60. SYNOPSIS: Get the item selected in FM and call the create share dialog
  61. ENTRY: hwnd - hwnd of the parent window
  62. EXIT:
  63. RETURNS:
  64. NOTES:
  65. HISTORY:
  66. Yi-HsinS 8/25/91 Created
  67. ********************************************************************/
  68. APIERR ShareCreate( HWND hwnd )
  69. {
  70. APIERR err = NERR_Success;
  71. if ( err = ::InitShellUI() )
  72. return err;
  73. ULONG ulOldHelpContextBase = POPUP::SetHelpContextBase( HC_UI_SHELL_BASE );
  74. //
  75. // Get the first selected item in the file manager
  76. //
  77. NLS_STR nlsSelItem;
  78. FMX fmx( hwnd );
  79. SERVER_WITH_PASSWORD_PROMPT *psvr = NULL;
  80. if ( ((err = nlsSelItem.QueryError()) == NERR_Success )
  81. && ((err = ::GetSelItem( hwnd, &nlsSelItem ) ) == NERR_Success )
  82. )
  83. {
  84. BOOL fShared = FALSE;
  85. //
  86. // If a file/directory is selected, check to see if the directory
  87. // (the directory the file is in if a file is selected)
  88. // is shared or not. If we select a file/directory on a LM2.1
  89. // share level server, a dialog will prompt for password to the
  90. // ADMIN$ share if we don't already have a connection to it.
  91. //
  92. if ( nlsSelItem.QueryTextLength() != 0 )
  93. {
  94. AUTO_CURSOR autocur;
  95. NET_NAME netname( nlsSelItem, TYPE_PATH_ABS );
  96. NLS_STR nlsLocalPath;
  97. NLS_STR nlsServer;
  98. if ( ((err = netname.QueryError()) == NERR_Success )
  99. && ((err = nlsLocalPath.QueryError()) == NERR_Success )
  100. && ((err = nlsServer.QueryError()) == NERR_Success )
  101. )
  102. {
  103. BOOL fLocal = netname.IsLocal( &err );
  104. //
  105. // Use better error code for non-LM device
  106. //
  107. if ( err == NERR_InvalidDevice )
  108. err = IERR_NOT_SUPPORTED_ON_NON_LM_DRIVE;
  109. if ( ( err == NERR_Success )
  110. && ( fLocal
  111. || ((err = netname.QueryComputerName(&nlsServer))
  112. == NERR_Success)
  113. )
  114. )
  115. {
  116. psvr = new SERVER_WITH_PASSWORD_PROMPT( nlsServer,
  117. hwnd,
  118. HC_UI_SHELL_BASE );
  119. if ( ( psvr != NULL )
  120. && ((err = psvr->QueryError()) == NERR_Success )
  121. && ((err = psvr->GetInfo()) == NERR_Success )
  122. && ((err = netname.QueryLocalPath(&nlsLocalPath))
  123. ==NERR_Success)
  124. )
  125. {
  126. //
  127. // Check to see if the directory is shared
  128. //
  129. SHARE2_ENUM sh2Enum( nlsServer );
  130. if ( ((err = sh2Enum.QueryError()) == NERR_Success )
  131. && ((err = sh2Enum.GetInfo()) == NERR_Success )
  132. )
  133. {
  134. SHARE_NAME_WITH_PATH_ENUM_ITER shPathEnum(sh2Enum,
  135. nlsLocalPath);
  136. if ((err = shPathEnum.QueryError()) == NERR_Success)
  137. {
  138. const TCHAR *pszShare;
  139. while ((pszShare = shPathEnum()) != NULL )
  140. {
  141. fShared = TRUE;
  142. break;
  143. }
  144. }
  145. }
  146. }
  147. else
  148. {
  149. if ( psvr == NULL )
  150. err = ERROR_NOT_ENOUGH_MEMORY;
  151. }
  152. }
  153. }
  154. }
  155. if ( err == NERR_Success )
  156. {
  157. //
  158. // If the directory is shared, popup the share properties
  159. // dialog. If not, popup the new share dialog.
  160. //
  161. SHARE_DIALOG_BASE *pdlg;
  162. if ( !fShared )
  163. pdlg = new FILEMGR_NEW_SHARE_DIALOG( hwnd,
  164. nlsSelItem,
  165. HC_UI_SHELL_BASE );
  166. else
  167. pdlg = new FILEMGR_SHARE_PROP_DIALOG( hwnd,
  168. nlsSelItem,
  169. HC_UI_SHELL_BASE );
  170. err = (APIERR) ( pdlg == NULL? ERROR_NOT_ENOUGH_MEMORY
  171. : pdlg->QueryError());
  172. if ( err == NERR_Success)
  173. {
  174. BOOL fSucceeded;
  175. err = pdlg->Process( &fSucceeded );
  176. //
  177. // Refresh the file manager if successfully created a share
  178. //
  179. if (( err == NERR_Success ) && fSucceeded )
  180. {
  181. delete psvr;
  182. psvr = NULL;
  183. fmx.Refresh();
  184. }
  185. }
  186. delete pdlg;
  187. }
  188. }
  189. delete psvr;
  190. psvr = NULL;
  191. if ( err != NERR_Success )
  192. {
  193. if ( err == ERROR_INVALID_LEVEL )
  194. err = ERROR_NOT_SUPPORTED;
  195. else if (err == IERR_USER_CLICKED_CANCEL)
  196. err = NERR_Success;
  197. if ( err != NERR_Success )
  198. ::MsgPopup( hwnd, err );
  199. }
  200. POPUP::SetHelpContextBase( ulOldHelpContextBase );
  201. return NERR_Success;
  202. }
  203. /*******************************************************************
  204. NAME: ShareStop
  205. SYNOPSIS: Get the item selected in FM and call the stop share dialog
  206. ENTRY: hwnd - hwnd of the parent window
  207. EXIT:
  208. RETURNS:
  209. NOTES:
  210. HISTORY:
  211. Yi-HsinS 8/25/91 Created
  212. ********************************************************************/
  213. APIERR ShareStop( HWND hwnd )
  214. {
  215. APIERR err = NERR_Success;
  216. if ( err = ::InitShellUI() )
  217. return err;
  218. ULONG ulOldHelpContextBase = POPUP::SetHelpContextBase( HC_UI_SHELL_BASE );
  219. //
  220. // Get the first selected item in the file manager
  221. //
  222. NLS_STR nlsSelItem;
  223. FMX fmx( hwnd );
  224. if ( ((err = nlsSelItem.QueryError()) == NERR_Success )
  225. && ((err = ::GetSelItem( hwnd, &nlsSelItem ) ) == NERR_Success )
  226. )
  227. {
  228. //
  229. // Check to see if the selected item is on a LM drive,
  230. // if not, pop an error.
  231. //
  232. NET_NAME netname( nlsSelItem, TYPE_PATH_ABS );
  233. if ((err = netname.QueryError()) == NERR_Success )
  234. {
  235. BOOL fLocal = netname.IsLocal( &err );
  236. //
  237. // Use better error code for non-LM device
  238. //
  239. if ( err == NERR_InvalidDevice )
  240. err = IERR_NOT_SUPPORTED_ON_NON_LM_DRIVE;
  241. }
  242. if ( err == NERR_Success )
  243. {
  244. //
  245. // Show the stop sharing dialog
  246. //
  247. STOP_SHARING_DIALOG *pdlg = new STOP_SHARING_DIALOG( hwnd,
  248. nlsSelItem,
  249. HC_UI_SHELL_BASE );
  250. err = (APIERR) ( pdlg == NULL? ERROR_NOT_ENOUGH_MEMORY
  251. : pdlg->QueryError() );
  252. BOOL fSucceeded;
  253. if ( err == NERR_Success )
  254. err = pdlg->Process( &fSucceeded );
  255. delete pdlg;
  256. //
  257. // Refresh the file manager if successfully stopped sharing a share
  258. //
  259. if (( err == NERR_Success ) && fSucceeded )
  260. fmx.Refresh();
  261. }
  262. }
  263. if ( err != NERR_Success )
  264. {
  265. if (err == IERR_USER_CLICKED_CANCEL)
  266. err = NERR_Success;
  267. else
  268. ::MsgPopup( hwnd, err );
  269. }
  270. POPUP::SetHelpContextBase( ulOldHelpContextBase );
  271. return NERR_Success;
  272. }
  273. /*******************************************************************
  274. NAME: ShareManage
  275. SYNOPSIS: Entry point for the share management dialog to be called
  276. from the server manager.
  277. ENTRY: hwnd - hwnd of the parent window
  278. pszServer - The server to focus on
  279. EXIT:
  280. RETURNS:
  281. NOTES:
  282. HISTORY:
  283. Yi-HsinS 8/8/92 Created
  284. ********************************************************************/
  285. VOID ShareManage( HWND hwnd, const TCHAR *pszServer )
  286. {
  287. APIERR err = NERR_Success;
  288. ULONG ulOldHelpContextBase = POPUP::SetHelpContextBase( HC_UI_SRVMGR_BASE);
  289. if ( ( err = ::InitShellUI() )
  290. || ( pszServer == NULL )
  291. )
  292. {
  293. err = err? err : ERROR_INVALID_PARAMETER ;
  294. }
  295. else
  296. {
  297. SHARE_MANAGEMENT_DIALOG *pdlg =
  298. new SHARE_MANAGEMENT_DIALOG( hwnd, pszServer, HC_UI_SRVMGR_BASE );
  299. err = (APIERR) ( pdlg == NULL? ERROR_NOT_ENOUGH_MEMORY
  300. : pdlg->QueryError() );
  301. if ( err == NERR_Success )
  302. {
  303. err = pdlg->Process();
  304. }
  305. delete pdlg;
  306. }
  307. if ( err != NERR_Success )
  308. {
  309. if ( err == ERROR_INVALID_LEVEL )
  310. err = ERROR_NOT_SUPPORTED;
  311. else if (err == IERR_USER_CLICKED_CANCEL)
  312. err = NERR_Success;
  313. if ( err != NERR_Success )
  314. ::MsgPopup( hwnd, err );
  315. }
  316. POPUP::SetHelpContextBase( ulOldHelpContextBase );
  317. }