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.

571 lines
15 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. tsvcinfo.hxx
  5. Abstract:
  6. Declares the Internet Publishing services information object.
  7. It was called as TSVC_INFO object. Later on this may be renamed as
  8. IPSVC_INFO object.
  9. This class provides the member function for all common functions
  10. exported from Internet Services DLL used by server dlls for
  11. internet services.
  12. Author:
  13. Murali R. Krishnan ( MuraliK ) 15-Nov-1994
  14. Project:
  15. Internet Services Common DLL
  16. Revision History:
  17. MuraliK 08-March-1995 Added TS_XPORT_CONNECTIONS object
  18. MuraliK 28-July-1995 Derived IPSVC_INFO from ISVC_INFO
  19. --*/
  20. # ifndef _TSVCINFO_HXX_
  21. # define _TSVCINFO_HXX_
  22. /************************************************************
  23. * Include Headers
  24. ************************************************************/
  25. # include "isvcinfo.hxx"
  26. # include "TsCache.hxx"
  27. # include "mimemap.hxx"
  28. # include "ipaccess.hxx"
  29. # include "xportcon.hxx" // define TS_XPORT_CONNECTIONS
  30. extern "C" {
  31. # include <winsock.h> // required for SOCKADDR_IN
  32. # include "atq.h"
  33. };
  34. /************************************************************
  35. * Private Constants
  36. ************************************************************/
  37. #define NULL_SERVICE_STATUS_HANDLE ( (SERVICE_STATUS_HANDLE ) NULL)
  38. #define SERVICE_START_WAIT_HINT ( 10000) // milliseconds
  39. #define SERVICE_STOP_WAIT_HINT ( 10000) // milliseconds
  40. #define DEF_ACCEPTEX_RECV_BUFFER_SIZE (2000) // 2000 bytes
  41. /************************************************************
  42. * Type Definitions
  43. ************************************************************/
  44. //
  45. // These functions get called back with the pointer to tsvcInfo object
  46. // as the context parameter.
  47. //
  48. typedef DWORD ( *PFN_SERVICE_SPECIFIC_INITIALIZE) ( LPVOID pContext);
  49. typedef DWORD ( *PFN_SERVICE_SPECIFIC_CLEANUP) ( LPVOID pContext);
  50. typedef VOID ( *PFN_SERVICE_CTRL_HANDLER) ( DWORD OpCode);
  51. class TSVC_INFO : public ISVC_INFO {
  52. public:
  53. //
  54. // Initialization/Tear down related methods
  55. //
  56. dllexp
  57. TSVC_INFO(
  58. IN LPCTSTR lpszServiceName,
  59. IN CHAR * lpszModuleName,
  60. IN CHAR * lpszRegParamKey,
  61. IN WCHAR * lpwszAnonPasswordSecretName,
  62. IN WCHAR * lpwszRootPasswordSecretName,
  63. IN DWORD dwServiceId,
  64. IN PFN_SERVICE_SPECIFIC_INITIALIZE pfnInitialize,
  65. IN PFN_SERVICE_SPECIFIC_CLEANUP pfnCleanup
  66. );
  67. dllexp ~TSVC_INFO( VOID);
  68. //
  69. // VIRTUAL methods
  70. //
  71. dllexp virtual BOOL IsValid(VOID) const
  72. { return ( m_fValid && ISVC_INFO::IsValid() ); }
  73. dllexp
  74. virtual BOOL
  75. ReadParamsFromRegistry( IN FIELD_CONTROL fc);
  76. dllexp
  77. virtual BOOL SetConfiguration( IN PVOID pConfig);
  78. dllexp
  79. virtual BOOL GetConfiguration( IN OUT PVOID pConfig);
  80. dllexp
  81. virtual DWORD
  82. QueryCurrentServiceState( VOID) const
  83. { return ( m_svcStatus.dwCurrentState); }
  84. //
  85. // Parameter access methods. Note that string or non-trivial admin data
  86. // items must have the read lock taken.
  87. //
  88. dllexp WCHAR * QueryAnonPasswordSecretName( VOID ) const
  89. { return m_pchAnonPasswordSecretName; }
  90. dllexp WCHAR * QueryVirtualRootsSecretName( VOID ) const
  91. { return m_pchVirtualRootsSecretName; }
  92. dllexp CHAR * QueryRoot( VOID ) const
  93. { return "/"; }
  94. dllexp DWORD QueryAuthentication( VOID ) const
  95. { return m_dwAuthentication; }
  96. dllexp short QueryPort( VOID ) const
  97. { return m_sPort; }
  98. dllexp BOOL QueryLogAnonymous( VOID ) const
  99. { return m_fLogAnonymous; }
  100. dllexp BOOL QueryLogNonAnonymous( VOID ) const
  101. { return m_fLogNonAnonymous; }
  102. dllexp const CHAR * QueryAnonUserName( VOID ) const
  103. { TCP_ASSERT( m_cReadLocks ); return m_pchAnonUserName; }
  104. dllexp const CHAR * QueryAnonUserPwd( VOID ) const
  105. { TCP_ASSERT( m_cReadLocks ); return m_achAnonUserPwd; }
  106. dllexp LPCTSTR QueryDefaultLogonDomain(VOID) const
  107. { TCP_ASSERT( m_cReadLocks ); return m_pchDefaultLogonDomain; }
  108. dllexp DWORD QueryLogonMethod( VOID ) const
  109. { return m_dwLogonMethod; }
  110. dllexp DWORD QueryLogFileType( VOID ) const
  111. { return m_dwLogFileType; }
  112. dllexp CHAR * QueryLogFileDirectory( VOID )
  113. { TCP_ASSERT( m_cReadLocks ); return m_pchLogFileDirectory; }
  114. dllexp CHAR * QueryLogFileName( VOID )
  115. { TCP_ASSERT( m_cReadLocks ); return m_pchLogFileName; }
  116. //
  117. // IP Security related methods
  118. //
  119. dllexp BOOL
  120. IPAccessCheck(
  121. IN LPSOCKADDR_IN psockAddr,
  122. OUT BOOL * pfGranted
  123. )
  124. {
  125. return ( (m_fNoIPAccessChecks) ? ((*pfGranted = TRUE), TRUE) :
  126. IPAccessCheckEx( psockAddr, pfGranted)
  127. );
  128. }
  129. dllexp BOOL
  130. IPAccessCheckEx(
  131. IN LPSOCKADDR_IN psockAddr,
  132. OUT BOOL * pfGranted
  133. );
  134. dllexp BOOL
  135. SetIPSecurity(
  136. IN HKEY hkey,
  137. IN INETA_CONFIG_INFO * pConfig
  138. );
  139. //
  140. // Service control related methods
  141. //
  142. dllexp DWORD
  143. QueryServiceSpecificExitCode( VOID) const
  144. { return ( m_svcStatus.dwServiceSpecificExitCode); }
  145. dllexp VOID
  146. SetServiceSpecificExitCode( DWORD err)
  147. { m_svcStatus.dwServiceSpecificExitCode = err; }
  148. dllexp DWORD
  149. DelayCurrentServiceCtrlOperation( IN DWORD dwWaitHint)
  150. {
  151. return
  152. UpdateServiceStatus(m_svcStatus.dwCurrentState,
  153. m_svcStatus.dwWin32ExitCode,
  154. m_svcStatus.dwCheckPoint,
  155. dwWaitHint);
  156. }
  157. dllexp DWORD
  158. UpdateServiceStatus(IN DWORD State,
  159. IN DWORD Win32ExitCode,
  160. IN DWORD CheckPoint,
  161. IN DWORD WaitHint );
  162. dllexp VOID
  163. ServiceCtrlHandler( IN DWORD dwOpCode);
  164. dllexp DWORD
  165. StartServiceOperation(
  166. IN PFN_SERVICE_CTRL_HANDLER pfnCtrlHandler
  167. );
  168. //
  169. // Miscellaneous methods
  170. //
  171. dllexp TSVC_CACHE & GetTsvcCache( VOID) { return ( m_tsCache); }
  172. dllexp PMIME_MAP QueryMimeMap( VOID) const { return ( m_pMimeMap); }
  173. //
  174. // Transport independent connections related functions.
  175. //
  176. // InitializeConnections( VOID)
  177. // CleanupConnections( VOID)
  178. //
  179. // Both these functions will be made private to TSVC_INFO and
  180. // will be invoked as part of the initialization of service
  181. // StartServiceOperation() once all the services
  182. // ( ftp and web move to use GUID based connections)
  183. // Till then these functions should be called as part of user
  184. // supplied initialization functions.
  185. //
  186. dllexp
  187. BOOL InitializeConnections( IN PFN_CONNECT_CALLBACK pfnConnect,
  188. IN ATQ_COMPLETION pfnConnectEx,
  189. IN ATQ_COMPLETION pfnIOCompletion,
  190. IN USHORT AdditionalPort = 0,
  191. IN DWORD cbReceiveBuffSize
  192. = DEF_ACCEPTEX_RECV_BUFFER_SIZE,
  193. IN const CHAR * pszServiceDBName = NULL);
  194. dllexp BOOL CleanupConnections( VOID);
  195. dllexp TS_XPORT_CONNECTIONS * QueryTsConnections( VOID)
  196. { return &m_tsConnections; }
  197. //
  198. // Functions for initializing and cleaning up sockets and
  199. // InterProcessCommunication RPC listeners.
  200. //
  201. // These also can move into automatic initialization in
  202. // StartServiceOperation(). But that has to wait till other
  203. // services ( which are tcpsvcs.dll clients) are configured
  204. // to work perfectly.
  205. //
  206. dllexp DWORD InitializeSockets( VOID);
  207. dllexp DWORD CleanupSockets( VOID);
  208. # if DBG
  209. virtual VOID Print( VOID) const;
  210. # endif // DBG
  211. private:
  212. BOOL m_fValid;
  213. DWORD m_fSocketsInitialized : 1;
  214. SERVICE_STATUS m_svcStatus;
  215. SERVICE_STATUS_HANDLE m_hsvcStatus;
  216. HANDLE m_hShutdownEvent;
  217. TSVC_CACHE m_tsCache;
  218. PMIME_MAP m_pMimeMap; // read-only pointer to mimemap
  219. //
  220. // Call back functions for service specific data/function
  221. //
  222. PFN_SERVICE_SPECIFIC_INITIALIZE m_pfnInitialize;
  223. PFN_SERVICE_SPECIFIC_CLEANUP m_pfnCleanup;
  224. //
  225. // Used for IP based Security
  226. //
  227. IPAccessList m_ipaDenyList;
  228. IPAccessList m_ipaGrantList;
  229. BOOL m_fNoIPAccessChecks;
  230. //
  231. // Server common administrable parameters
  232. //
  233. DWORD m_dwAuthentication; // Types Accepted/Required
  234. SHORT m_sPort; // Socket port (host order)
  235. BOOL m_fLogAnonymous;
  236. BOOL m_fLogNonAnonymous;
  237. CHAR * m_pchAnonUserName;
  238. CHAR m_achAnonUserPwd[PWLEN + 1];
  239. DWORD m_dwLogFileType;
  240. CHAR * m_pchLogFileDirectory;
  241. CHAR * m_pchLogFileName;
  242. //
  243. // Contains the anonymous user name
  244. //
  245. WCHAR * m_pchAnonPasswordSecretName;
  246. //
  247. // Contains the passwords for the virtual roots
  248. //
  249. WCHAR * m_pchVirtualRootsSecretName;
  250. //
  251. // logon method ( interactive or batch )
  252. //
  253. DWORD m_dwLogonMethod;
  254. //
  255. // logon default domain
  256. //
  257. CHAR * m_pchDefaultLogonDomain;
  258. //
  259. // For transport independent connections
  260. //
  261. TS_XPORT_CONNECTIONS m_tsConnections;
  262. //
  263. // Per server Initialization methods to be called once for
  264. // each server
  265. //
  266. BOOL InitializeIPSecurity( VOID);
  267. // Temporary stubbing
  268. BOOL InitializeNTSecurity( VOID) const { return ( TRUE); }
  269. //
  270. // Per server Termination methods to be called when each
  271. // server is shutdown
  272. //
  273. VOID TerminateCommonParams( VOID);
  274. VOID TerminateIPSecurity( VOID);
  275. VOID TerminateNTSecurity( VOID) const { return; } // temporary
  276. DWORD ReportServiceStatus( VOID);
  277. VOID InterrogateService( VOID );
  278. VOID StopService( VOID );
  279. VOID PauseService( VOID );
  280. VOID ContinueService( VOID );
  281. VOID ShutdownService( VOID );
  282. }; // class TSVC_INFO
  283. typedef TSVC_INFO FAR * LPTSVC_INFO;
  284. //
  285. // FROM 7/28/95 the object TSVC_INFO is renamed as IPSVC_INFO.
  286. // We will update elsewhere after beta on Aug 15, 1995
  287. // - MuraliK
  288. //
  289. typedef TSVC_INFO IPSVC_INFO;
  290. typedef IPSVC_INFO FAR * PIPSVC_INFO;
  291. /************************************************************
  292. * Macros
  293. ************************************************************/
  294. //
  295. //
  296. // Use the following macro once in outer scope of the file
  297. // where we construct the global TsvcInfo object.
  298. //
  299. // Every client of TsvcInfo should define the following macro
  300. // passing as parameter their global pointer to TsvcInfo object
  301. // This is required to generate certain stub functions, since
  302. // the service controller call-back functions do not return
  303. // the context information.
  304. //
  305. // Also we define
  306. // the global g_pTsvcInfo variable
  307. // a static variable gs_pfnSch,
  308. // which is a pointer to the local service control handler function.
  309. //
  310. # define _INTERNAL_DEFINE_TSVCINFO_INTERFACE( pTsvcInfo) \
  311. \
  312. LPTSVC_INFO g_pTsvcInfo; \
  313. \
  314. static VOID ServiceCtrlHandler( DWORD OpCode) \
  315. { \
  316. ASSERT( pTsvcInfo != NULL); \
  317. \
  318. ( pTsvcInfo)->ServiceCtrlHandler( OpCode); \
  319. \
  320. } \
  321. \
  322. static PFN_SERVICE_CTRL_HANDLER gs_pfnSch = ServiceCtrlHandler;
  323. //
  324. // Since all the services should use the global variable called g_pTsvcInfo
  325. // this is a convenience macro for defining the interface for services
  326. // structure
  327. // Also required since a lot of macros depend upon the variable g_pTsvcInfo
  328. //
  329. # define DEFINE_TSVC_INFO_INTERFACE() \
  330. _INTERNAL_DEFINE_TSVCINFO_INTERFACE( g_pTsvcInfo);
  331. //
  332. // Use the macro SERVICE_CTRL_HANDLER() to pass the parameter for
  333. // service control handler when we initialize the TsvcInfo object
  334. // ( in constructor for global TsvcInfo object)
  335. //
  336. # define SERVICE_CTRL_HANDLER() ( gs_pfnSch)
  337. # include "tssec.hxx" // for security related functions
  338. //
  339. // Virtual roots stuff
  340. //
  341. BOOL
  342. TsReadVirtualRoots(
  343. IN const TSVC_CACHE & TSvcCache,
  344. IN HKEY hKey,
  345. IN LPTSVC_INFO psi
  346. );
  347. BOOL
  348. TsSetVirtualRootsW(
  349. IN const TSVC_CACHE & TSvcCache,
  350. HKEY hkey,
  351. IN INETA_CONFIG_INFO * pConfig
  352. );
  353. //
  354. // Mime related functions
  355. //
  356. BOOL
  357. InitializeMimeMap( VOID);
  358. BOOL
  359. CleanupMimeMap( VOID);
  360. dllexp
  361. BOOL
  362. SelectMimeMappingForFileExt(
  363. IN const LPTSVC_INFO pTsvcInfo,
  364. IN const TCHAR * pchFilePath,
  365. OUT STR * pstrMimeType, // optional
  366. OUT STR * pstrIconFile = NULL); // optional
  367. //
  368. // Opens, Reads and caches the contents of the specified file
  369. //
  370. class CACHE_FILE_INFO
  371. {
  372. public:
  373. CACHE_FILE_INFO()
  374. { pbData = NULL; }
  375. BYTE * pbData;
  376. DWORD dwCacheFlags;
  377. };
  378. typedef CACHE_FILE_INFO * PCACHE_FILE_INFO;
  379. dllexp
  380. BOOL
  381. CheckOutCachedFile(
  382. IN const CHAR * pchFile,
  383. IN TSVC_CACHE * pTsvcCache,
  384. IN HANDLE hToken,
  385. OUT BYTE * * ppbData,
  386. OUT DWORD * pcbData,
  387. #ifdef JAPAN
  388. OUT PCACHE_FILE_INFO pCacheFileInfo,
  389. IN int nCharset
  390. #else
  391. OUT PCACHE_FILE_INFO pCacheFileInfo
  392. #endif
  393. );
  394. dllexp
  395. BOOL
  396. CheckInCachedFile(
  397. IN TSVC_CACHE * pTsvcCache,
  398. IN PCACHE_FILE_INFO pCacheFileInfo
  399. );
  400. //
  401. // Object cache manager related stuff
  402. //
  403. BOOL
  404. InitializeCacheScavenger(
  405. VOID
  406. );
  407. VOID
  408. TerminateCacheScavenger(
  409. VOID
  410. );
  411. # endif // _TSVCINFO_HXX_
  412. /************************ End of File ***********************/
  413. 
  414.