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.

581 lines
16 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1993 **/
  4. /**********************************************************************/
  5. /*
  6. ftpsmx.cxx
  7. This contains the main module for the FTP Server Manager
  8. Extension. It contains "SMLoadMenuW",...
  9. FILE HISTORY:
  10. YiHsinS 25-Mar-1993 Templated from smxdebug.c
  11. */
  12. #define INCL_NET
  13. #define INCL_NETLIB
  14. #define INCL_NETWKSTA
  15. #define INCL_WINDOWS
  16. #define INCL_NETERRORS
  17. #define INCL_DOSERRORS
  18. #include <lmui.hxx>
  19. #if defined(DEBUG)
  20. static const CHAR szFileName[] = __FILE__;
  21. #define _FILENAME_DEFINED_ONCE szFileName
  22. #endif
  23. #include <uiassert.hxx>
  24. #include <uitrace.hxx>
  25. #define INCL_BLT_WINDOW
  26. #define INCL_BLT_DIALOG
  27. #define INCL_BLT_CONTROL
  28. #define INCL_BLT_MSGPOPUP
  29. #include <blt.hxx>
  30. #include <dbgstr.hxx>
  31. extern "C"
  32. {
  33. #include <smx.h> // Server Manager extension defs
  34. #include <ftpmgr.h>
  35. }
  36. extern "C"
  37. {
  38. //
  39. // Dll load/unload entry point
  40. //
  41. BOOL FAR PASCAL FtpSmxDllInitialize( HINSTANCE hInstance,
  42. DWORD nReason,
  43. LPVOID pReserved );
  44. }
  45. #include <lmowks.hxx> // WKSTA_10
  46. #include <ftpmgr.hxx> // FTP_SVCMGR_DIALOG
  47. //
  48. // Constants
  49. //
  50. #define FTP_EXT_VERSION 0 // Version number for the extension interface
  51. //
  52. // Globals.
  53. //
  54. HINSTANCE _hInstance;
  55. HWND _hwndMessage;
  56. DWORD _dwVersion;
  57. DWORD _dwDelta;
  58. /*******************************************************************
  59. NAME: InitializeDll
  60. SYNOPSIS: Perform DLL initialiazation functions on a
  61. once-per-process basis.
  62. ENTRY: hInstance - Program instance of the caller.
  63. EXIT: The DLL has been initialized.
  64. RETURNS: BOOL - TRUE = Initialization OK.
  65. FALSE = Initialization failed.
  66. HISTORY:
  67. YiHsinS 25-Mar-1993 Created
  68. ********************************************************************/
  69. BOOL InitializeDll( HINSTANCE hInstance )
  70. {
  71. //
  72. // Save the instance handle.
  73. //
  74. _hInstance = hInstance;
  75. APIERR err = BLT::Init( _hInstance,
  76. IDRSRC_FTPMGR_BASE, IDRSRC_FTPMGR_LAST,
  77. IDS_UI_FTPMGR_BASE, IDS_UI_FTPMGR_LAST );
  78. if ( err == NERR_Success )
  79. {
  80. err = BLT::RegisterHelpFile( _hInstance,
  81. IDS_FTPSMX_HELPFILENAME,
  82. HC_UI_FTPMGR_BASE, HC_UI_FTPMGR_LAST );
  83. }
  84. if ( err != NERR_Success )
  85. BLT::Term( _hInstance );
  86. return ( err == NERR_Success );
  87. } // InitializeDll
  88. /*******************************************************************
  89. NAME: TerminateDll
  90. SYNOPSIS: Perform DLL termination functions on a
  91. once-per-process basis.
  92. EXIT: All necessary BLT terminators have been invoked.
  93. HISTORY:
  94. YiHsinS 25-Mar-1993 Created
  95. ********************************************************************/
  96. VOID TerminateDll( VOID )
  97. {
  98. //
  99. // Kill the NetUI goodies.
  100. //
  101. BLT::DeregisterHelpFile( _hInstance, 0 );
  102. BLT::Term( _hInstance );
  103. //
  104. // Just in case we try to do anything goofy.
  105. //
  106. _hInstance = NULL;
  107. } // TerminateDll
  108. /*******************************************************************
  109. NAME: RunFtpSvcMgr
  110. SYNOPSIS: Invoke the user session dialog of the FTP Server
  111. Manager Extension
  112. ENTRY: hWnd - Window handle of parent window.
  113. pszServer - The name of the server to set focus to
  114. RETURNS: APIERR
  115. HISTORY:
  116. YiHsinS 25-Mar-1993 Created
  117. ********************************************************************/
  118. VOID RunFtpSvcMgr( HWND hWnd, const TCHAR *pszServer )
  119. {
  120. AUTO_CURSOR autocur;
  121. //
  122. // Get the help file name
  123. //
  124. RESOURCE_STR nlsHelpFileName( IDS_FTPSMX_HELPFILENAME );
  125. APIERR err = nlsHelpFileName.QueryError();
  126. //
  127. // Invoke the user session dialog
  128. //
  129. if ( err == NERR_Success )
  130. {
  131. FTP_SVCMGR_DIALOG * pDlg = new FTP_SVCMGR_DIALOG( hWnd,
  132. pszServer );
  133. err = ( pDlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  134. : pDlg->QueryError();
  135. if ( err == NERR_Success )
  136. err = pDlg->Process();
  137. delete pDlg;
  138. pDlg = NULL;
  139. }
  140. if( err != NERR_Success )
  141. {
  142. // Try to see why we get the rpc server unavailable error.
  143. // Mainly, we want to distinguish between the case where
  144. // the server is not found v.s. the ftp service is
  145. // unavailable.
  146. if ( err == RPC_S_SERVER_UNAVAILABLE )
  147. {
  148. WKSTA_10 wksta10( pszServer );
  149. APIERR errTemp = wksta10.QueryError();
  150. if ( errTemp == NERR_Success )
  151. {
  152. errTemp = wksta10.GetInfo();
  153. if ( errTemp != NERR_Success )
  154. {
  155. // An error occurred while trying to do NetWorkstaGetInfo
  156. // at level 10 ( no privilege needed). Hence, the problem
  157. // might be bad path... We thus report the error
  158. // from NetWkstaGetInfo ( level 10 ).
  159. err = errTemp;
  160. }
  161. }
  162. }
  163. //
  164. // At this point, either the remote computer exist
  165. // or wksta10 object failed to construct. Hence, report that the
  166. // FTP Service is unavailable.
  167. //
  168. if ( err == RPC_S_SERVER_UNAVAILABLE )
  169. {
  170. ::MsgPopup( hWnd, IERR_FTP_SERVICE_UNAVAILABLE_ON_COMPUTER,
  171. MPSEV_ERROR, MP_OK, pszServer );
  172. }
  173. else
  174. {
  175. ::MsgPopup( hWnd, err );
  176. }
  177. }
  178. } // RunFtpSvcMgr
  179. /*******************************************************************
  180. NAME: FtpSmxDllInitialize
  181. SYNOPSIS: This DLL entry point is called when processes & threads
  182. are initialized and terminated, or upon calls to
  183. LoadLibrary() and FreeLibrary().
  184. ENTRY: hInstance - A handle to the DLL.
  185. nReason - Indicates why the DLL entry
  186. point is being called.
  187. pReserved - Reserved.
  188. RETURNS: BOOL - TRUE = DLL init was successful.
  189. FALSE = DLL init failed.
  190. NOTES: The return value is only relevant during processing of
  191. DLL_PROCESS_ATTACH notifications.
  192. HISTORY:
  193. YiHsinS 25-Mar-1993 Created
  194. ********************************************************************/
  195. BOOL FAR PASCAL FtpSmxDllInitialize( HINSTANCE hInstance,
  196. DWORD nReason,
  197. LPVOID pReserved )
  198. {
  199. UNREFERENCED( pReserved );
  200. BOOL fResult = TRUE;
  201. switch( nReason )
  202. {
  203. case DLL_PROCESS_ATTACH:
  204. //
  205. // This notification indicates that the DLL is attaching to
  206. // the address space of the current process. This is either
  207. // the result of the process starting up, or after a call to
  208. // LoadLibrary(). The DLL should us this as a hook to
  209. // initialize any instance data or to allocate a TLS index.
  210. //
  211. // This call is made in the context of the thread that
  212. // caused the process address space to change.
  213. //
  214. fResult = InitializeDll( hInstance );
  215. break;
  216. case DLL_PROCESS_DETACH:
  217. //
  218. // This notification indicates that the calling process is
  219. // detaching the DLL from its address space. This is either
  220. // due to a clean process exit or from a FreeLibrary() call.
  221. // The DLL should use this opportunity to return any TLS
  222. // indexes allocated and to free any thread local data.
  223. //
  224. // Note that this notification is posted only once per
  225. // process. Individual threads do not invoke the
  226. // DLL_THREAD_DETACH notification.
  227. //
  228. TerminateDll();
  229. break;
  230. case DLL_THREAD_ATTACH:
  231. //
  232. // This notfication indicates that a new thread is being
  233. // created in the current process. All DLLs attached to
  234. // the process at the time the thread starts will be
  235. // notified. The DLL should use this opportunity to
  236. // initialize a TLS slot for the thread.
  237. //
  238. // Note that the thread that posts the DLL_PROCESS_ATTACH
  239. // notification will not post a DLL_THREAD_ATTACH.
  240. //
  241. // Note also that after a DLL is loaded with LoadLibrary,
  242. // only threads created after the DLL is loaded will
  243. // post this notification.
  244. //
  245. break;
  246. case DLL_THREAD_DETACH:
  247. //
  248. // This notification indicates that a thread is exiting
  249. // cleanly. The DLL should use this opportunity to
  250. // free any data stored in TLS indices.
  251. //
  252. break;
  253. default:
  254. //
  255. // Who knows? Just ignore it.
  256. //
  257. break;
  258. }
  259. return fResult;
  260. } // FtpSmxDllInitialize
  261. /*******************************************************************
  262. NAME: SMELoadMenuW
  263. SYNOPSIS: This DLL entrypoint notifies the extension that it
  264. is getting loaded by the application.
  265. ENTRY: hwndMessage - The "owning" window.
  266. psmsload - Points to an SMS_LOADMENU
  267. structure containing load
  268. parameters.
  269. RETURNS: DWORD - Actually an APIERR, should be
  270. 0 if successful.
  271. HISTORY:
  272. YiHsinS 25-Mar-1993 Created
  273. ********************************************************************/
  274. DWORD PASCAL SMELoadMenuW( HWND hwndMessage,
  275. PSMS_LOADMENU psmsload )
  276. {
  277. if ( psmsload == NULL )
  278. return ERROR_INVALID_PARAMETER;
  279. _hwndMessage = hwndMessage;
  280. _dwDelta = psmsload->dwMenuDelta;
  281. _dwVersion = FTP_EXT_VERSION;
  282. if( psmsload->dwVersion > _dwVersion )
  283. {
  284. psmsload->dwVersion = _dwVersion;
  285. }
  286. else if( psmsload->dwVersion < _dwVersion )
  287. {
  288. _dwVersion = psmsload->dwVersion;
  289. }
  290. psmsload->dwServerType = 0; // Don't need special menu for View
  291. APIERR err = NERR_Success;
  292. if ( ( ::LoadString( _hInstance, IDS_FTPSMX_MENUNAME,
  293. psmsload->szMenuName, MENU_TEXT_LEN ) == 0 )
  294. || ( ::LoadString( _hInstance, IDS_FTPSMX_HELPFILENAME,
  295. psmsload->szHelpFileName, MAX_PATH-1 ) == 0 )
  296. || ( (psmsload->hMenu = ::LoadMenu( _hInstance,
  297. MAKEINTRESOURCE( ID_FTPSMX_MENU ))) == NULL )
  298. )
  299. {
  300. err = GetLastError();
  301. }
  302. return err;
  303. } // SMELoadMenuW
  304. /*******************************************************************
  305. NAME: SMEGetExtendedErrorStringW
  306. SYNOPSIS: If SMELoadW returns ERROR_EXTENDED_ERROR, then this
  307. entrypoint should be called to retrieve the error
  308. text associated with the failure condition.
  309. RETURNS: LPTSTR - The extended error text.
  310. HISTORY:
  311. YiHsinS 25-Mar-1993 Created
  312. ********************************************************************/
  313. LPTSTR PASCAL SMEGetExtendedErrorStringW( VOID )
  314. {
  315. // This extension will never return ERROR_EXTENDED_ERROR when
  316. // SMELoad fails.
  317. return NULL;
  318. } // SMEGetExtendedErrorStringW
  319. /*******************************************************************
  320. NAME: SMEMenuAction
  321. SYNOPSIS: Notifies the extension DLL that one of its menu
  322. items has been selected.
  323. ENTRY: dwEventId - The menu ID being activated (should be 1-99).
  324. HISTORY:
  325. YiHsinS 25-Mar-1993 Created
  326. ********************************************************************/
  327. VOID PASCAL SMEMenuAction( HWND hwndParent, DWORD dwEventId )
  328. {
  329. APIERR err = NERR_Success;
  330. //
  331. // Get the number of servers selected
  332. //
  333. SMS_GETSELCOUNT smsget;
  334. if ( (::SendMessage(_hwndMessage, SM_GETSELCOUNT, 0, (LPARAM)&smsget) == 0)
  335. || (smsget.dwItems == 0 )
  336. )
  337. {
  338. // No servers are selected
  339. err = IDS_NO_SERVERS_SELECTED;
  340. }
  341. else
  342. {
  343. //
  344. // Get the name of the selected server
  345. // ( There should only be one since server manager is single select
  346. // only ).
  347. //
  348. SMS_GETSERVERSEL smssel;
  349. if ( !SendMessage( _hwndMessage, SM_GETSERVERSEL, 0, (LPARAM)&smssel ))
  350. {
  351. err = IDS_CANNOT_GET_SERVER_SELECTION;
  352. }
  353. else
  354. {
  355. switch( dwEventId )
  356. {
  357. case IDM_FTP_SERVICE:
  358. RunFtpSvcMgr( hwndParent, smssel.szServerName );
  359. break;
  360. default:
  361. //
  362. // Who knows? Just ignore it.
  363. //
  364. break;
  365. }
  366. }
  367. }
  368. if ( err != NERR_Success )
  369. {
  370. ::MsgPopup( hwndParent, err );
  371. }
  372. } // SMEMenuAction
  373. /*******************************************************************
  374. NAME: SMEUnloadMenu
  375. SYNOPSIS: Notifies the extension DLL that it is getting unloaded.
  376. HISTORY:
  377. YiHsinS 25-Mar-1993 Created
  378. ********************************************************************/
  379. VOID PASCAL SMEUnloadMenu( VOID )
  380. {
  381. //
  382. // Nothing to do
  383. //
  384. } // SMEUnloadMenu
  385. /*******************************************************************
  386. NAME: SMEInitializeMenu
  387. SYNOPSIS: Notifies the extension DLL that the main menu is
  388. getting activated. The extension should use this
  389. opportunity to perform any menu manipulations.
  390. HISTORY:
  391. YiHsinS 25-Mar-1993 Created
  392. ********************************************************************/
  393. VOID PASCAL SMEInitializeMenu( VOID )
  394. {
  395. //
  396. // Nothing to do
  397. //
  398. } // SMEInitializeMenu
  399. /*******************************************************************
  400. NAME: SMERefresh
  401. SYNOPSIS: Notifies the extension DLL that the user has requested
  402. a refresh. The extension should use this opportunity
  403. to update any cached data.
  404. HISTORY:
  405. YiHsinS 25-Mar-1993 Created
  406. ********************************************************************/
  407. VOID PASCAL SMERefresh( HWND hwndParent )
  408. {
  409. //
  410. // Don't need to do refresh since this extension does
  411. // not recognize additional servers.
  412. //
  413. } // SMERefresh
  414. /*******************************************************************
  415. NAME: SMEValidateW
  416. SYNOPSIS: Tries to recognize the given server.
  417. ENTRY: psmsvalidate - Points to an SMS_VALIDATE
  418. structure.
  419. RETURNS: BOOL - TRUE if recognized,
  420. FALSE otherwise.
  421. HISTORY:
  422. YiHsinS 25-Mar-1993 Created
  423. ********************************************************************/
  424. BOOL PASCAL SMEValidateW( PSMS_VALIDATE psmsvalidate )
  425. {
  426. UNREFERENCED( psmsvalidate );
  427. //
  428. // This extension does not recognize additional servers
  429. //
  430. return FALSE;
  431. } // SMEValidateW