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.

358 lines
10 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. ftpinst.hxx
  5. Abstract:
  6. This module defines the FTP_IIS_SERVICE type
  7. Author:
  8. Johnson Apacible (johnsona) 04-Sep-1996
  9. --*/
  10. #ifndef _FTPINST_HXX_
  11. #define _FTPINST_HXX_
  12. #include "iistypes.hxx"
  13. #include "stats.hxx"
  14. #include "type.hxx"
  15. typedef LPUSER_DATA PICLIENT_CONNECTION;
  16. typedef BOOL (*PFN_CLIENT_CONNECTION_ENUM)( PICLIENT_CONNECTION pcc,
  17. LPVOID pContext);
  18. // specifies the size of cache block for padding ==> to avoid false sharing
  19. # define MAX_CACHE_BLOCK_SIZE ( 64)
  20. class FTP_IIS_SERVICE : public IIS_SERVICE {
  21. public:
  22. FTP_IIS_SERVICE(
  23. IN LPCTSTR lpszServiceName,
  24. IN LPCSTR lpszModuleName,
  25. IN LPCSTR lpszRegParamKey,
  26. IN DWORD dwServiceId,
  27. IN ULONGLONG SvcLocId,
  28. IN BOOL MultipleInstanceSupport,
  29. IN DWORD cbAcceptExRecvBuffer,
  30. IN ATQ_CONNECT_CALLBACK pfnConnect,
  31. IN ATQ_COMPLETION pfnConnectEx,
  32. IN ATQ_COMPLETION pfnIoCompletion
  33. )
  34. :IIS_SERVICE(
  35. lpszServiceName,
  36. lpszModuleName,
  37. lpszRegParamKey,
  38. dwServiceId,
  39. SvcLocId,
  40. MultipleInstanceSupport,
  41. cbAcceptExRecvBuffer,
  42. pfnConnect,
  43. pfnConnectEx,
  44. pfnIoCompletion
  45. )
  46. {
  47. InitializeListHead( & m_InstanceList );
  48. INITIALIZE_CRITICAL_SECTION( &m_csInstanceLock);
  49. };
  50. ~FTP_IIS_SERVICE()
  51. {
  52. DeleteCriticalSection( &m_csInstanceLock);
  53. }
  54. VOID LockInstanceList( VOID) { EnterCriticalSection( &m_csInstanceLock); }
  55. VOID UnLockInstanceList( VOID) { LeaveCriticalSection( &m_csInstanceLock); }
  56. virtual DWORD GetServiceConfigInfoSize(IN DWORD dwLevel);
  57. virtual BOOL AddInstanceInfo( IN DWORD dwInstance, IN BOOL fMigrateRoots );
  58. virtual DWORD DisconnectUsersByInstance( IN IIS_SERVER_INSTANCE * pInstance );
  59. BOOL AggregateStatistics(
  60. IN PCHAR pDestination,
  61. IN PCHAR pSource
  62. );
  63. BOOL
  64. GetGlobalStatistics(
  65. IN DWORD dwLevel,
  66. OUT PCHAR *pBuffer
  67. );
  68. LIST_ENTRY m_InstanceList;
  69. CRITICAL_SECTION m_csInstanceLock;
  70. };
  71. typedef FTP_IIS_SERVICE *PFTP_IIS_SERVICE;
  72. //
  73. // This is the FTP version of the instance. Will contain all the
  74. // FTP specific operations.
  75. //
  76. typedef enum _ISOLATION_MODE
  77. {
  78. NoIsolation = 0,
  79. StandAloneIsolation,
  80. EnterpriseIsolation,
  81. IsolationModeOverflow
  82. } ISOLATION_MODE;
  83. class FTP_SERVER_INSTANCE : public IIS_SERVER_INSTANCE {
  84. public:
  85. FTP_SERVER_INSTANCE(
  86. IN PFTP_IIS_SERVICE pService,
  87. IN DWORD dwInstanceId,
  88. IN USHORT sPort,
  89. IN LPCSTR lpszRegParamKey,
  90. IN LPWSTR lpwszAnonPasswordSecretName,
  91. IN LPWSTR lpwszRootPasswordSecretName,
  92. IN BOOL fMigrateVroots
  93. ) ;
  94. ~FTP_SERVER_INSTANCE();
  95. //
  96. // Instance start & stop
  97. //
  98. virtual DWORD StartInstance();
  99. virtual DWORD StopInstance();
  100. //
  101. // VIRTUALS for service specific params/RPC admin
  102. //
  103. virtual BOOL SetServiceConfig(IN PCHAR pConfig );
  104. virtual BOOL GetServiceConfig(IN OUT PCHAR pConfig,IN DWORD dwLevel);
  105. virtual BOOL GetStatistics( IN DWORD dwLevel, OUT PCHAR *pBuffer);
  106. virtual BOOL ClearStatistics( VOID );
  107. virtual BOOL DisconnectUser( IN DWORD dwIdUser );
  108. virtual BOOL EnumerateUsers( OUT PCHAR* pBuffer, OUT PDWORD nRead );
  109. virtual VOID MDChangeNotify( MD_CHANGE_OBJECT * pco );
  110. BOOL FreeAllocCachedClientConn(VOID);
  111. PICLIENT_CONNECTION AllocClientConnFromAllocCache(VOID);
  112. VOID FreeClientConnToAllocCache(IN PICLIENT_CONNECTION pClient);
  113. //
  114. // Initialize the configuration data from registry information
  115. //
  116. // Arguments
  117. // hkeyReg key to the registry entry for parameters
  118. // FieldsToRead bitmapped flags indicating which data to be read.
  119. //
  120. // Returns:
  121. // NO_ERROR on success
  122. // Win32 error code otherwise
  123. //
  124. DWORD InitFromRegistry( IN FIELD_CONTROL FieldsToRead);
  125. DWORD
  126. ReadAuthentInfo(
  127. IN BOOL ReadAll = TRUE,
  128. IN DWORD SingleItemToRead = 0
  129. );
  130. DWORD
  131. GetConfigInformation( OUT LPFTP_CONFIG_INFO pConfigInfo);
  132. DWORD
  133. SetConfigInformation( IN LPFTP_CONFIG_INFO pConfigInfo);
  134. BOOL IsValid( VOID) const { return ( m_fValid); }
  135. VOID LockConfig( VOID) { EnterCriticalSection( &m_csLock); }
  136. VOID UnLockConfig( VOID) { LeaveCriticalSection( &m_csLock); }
  137. VOID LockConnectionsList()
  138. { EnterCriticalSection(&m_csConnectionsList); }
  139. VOID UnlockConnectionsList()
  140. { LeaveCriticalSection(&m_csConnectionsList); }
  141. DWORD GetCurrentConnectionsCount( VOID) const
  142. { return m_cCurrentConnections; }
  143. DWORD GetMaxCurrentConnectionsCount( VOID) const
  144. { return m_cMaxCurrentConnections; }
  145. DWORD SetLocalHostName(IN LPCSTR pszHost);
  146. LPCSTR QueryLocalHostName(VOID) const { return (m_pszLocalHostName); }
  147. DWORD QueryUserFlags(VOID) const { return (m_dwUserFlags); }
  148. BOOL QueryLowercaseFiles(VOID) const { return (m_fLowercaseFiles); }
  149. BOOL AllowAnonymous(VOID) const { return (m_fAllowAnonymous); }
  150. BOOL AllowGuestAccess(VOID) const { return (m_fAllowGuestAccess); }
  151. BOOL IsAllowedUser(IN BOOL fAnonymous)
  152. {
  153. return ((fAnonymous && m_fAllowAnonymous) ||
  154. (!fAnonymous && !m_fAllowAnonymous) ||
  155. (!fAnonymous && !m_fAnonymousOnly));
  156. }
  157. BOOL IsEnablePortAttack(VOID) const { return (m_fEnablePortAttack); }
  158. BOOL IsEnablePasvTheft(VOID) const { return (m_fEnablePasvTheft); };
  159. DWORD NumListenBacklog(VOID) const { return (m_ListenBacklog); }
  160. // Following functions return pointers to strings which should be used
  161. // within locked sections of config
  162. // Marked by LockConfig() and UnLockConfig()
  163. LPCSTR QueryMaxClientsMsg(VOID) const
  164. { return (LPCSTR)m_MaxClientsMessage.QueryStr(); }
  165. LPCSTR QueryGreetingMsg(VOID) const
  166. { return (LPCSTR)m_GreetingMessage.QueryStr(); }
  167. LPCSTR QueryBannerMsg(VOID) const
  168. { return (LPCSTR)m_BannerMessage.QueryStr(); }
  169. LPCSTR QueryExitMsg(VOID) const
  170. { return (LPCSTR)m_ExitMessage.QueryStr(); }
  171. BOOL EnumerateConnection( IN PFN_CLIENT_CONNECTION_ENUM pfnConnEnum,
  172. IN LPVOID pContext,
  173. IN DWORD dwConnectionId);
  174. VOID DisconnectAllConnections( VOID);
  175. PICLIENT_CONNECTION
  176. AllocNewConnection();
  177. VOID RemoveConnection( IN OUT PICLIENT_CONNECTION pcc);
  178. BOOL WriteParamsToRegistry( LPFTP_CONFIG_INFO pConfig );
  179. VOID Print( VOID) const;
  180. METADATA_REF_HANDLER* QueryMetaDataRefHandler() { return &m_rfAccessCheck; }
  181. PTCP_AUTHENT_INFO QueryAuthentInfo() { return &m_TcpAuthentInfo; }
  182. BOOL AllowReplaceOnRename( VOID ) const {
  183. return m_fAllowReplaceOnRename;
  184. }
  185. LPFTP_SERVER_STATISTICS QueryStatsObj( VOID ) { return m_pFTPStats; }
  186. ISOLATION_MODE QueryIsolationMode( VOID ) const {
  187. return m_UserIsolationMode;
  188. }
  189. private:
  190. //
  191. // Connections related data
  192. //
  193. // m_cMaxConnections: max connections permitted by config
  194. // m_cCurrentConnections: count of currently connected users
  195. // m_cMaxCurrentConnections: max connections seen in this session
  196. // Always m_cCurrentConnections
  197. // <= m_cMaxCurrentConnections
  198. // <= m_cMaxConnections;
  199. //
  200. // DWORD m_cMaxConnections;
  201. // replaced by TSVC_INFO::QueryMaxConnections()
  202. DWORD m_cCurrentConnections;
  203. DWORD m_cMaxCurrentConnections;
  204. BOOL m_fAllowAnonymous;
  205. BOOL m_fAllowGuestAccess;
  206. BOOL m_fAnnotateDirectories; // annotate dirs when dir changes
  207. BOOL m_fAnonymousOnly;
  208. BOOL m_fEnablePortAttack;
  209. BOOL m_fEnablePasvTheft;
  210. // if m_LowercaseFiles is TRUE, then dir listings from non-case-preserving
  211. // filesystems will be mapped to lowercase.
  212. BOOL m_fLowercaseFiles;
  213. BOOL m_fMsdosDirOutput; // send msdos style dir listings
  214. BOOL m_fFourDigitYear; // send 4 digit year dir listings
  215. STR m_ExitMessage;
  216. STR m_MaxClientsMessage;
  217. TCP_AUTHENT_INFO m_TcpAuthentInfo;
  218. //
  219. // Greeting Message can be a multiline message.
  220. // We maintain two copies of the message
  221. // 1) double null terminated seq. of strings with one line per string
  222. // 2) single null terminated string with \n characters interspersed.
  223. //
  224. // Representation 1 is used for sending data to clients
  225. // Representation 2 is used for RPC admin facility
  226. // We maintain the string as MULTI_SZ in the registry
  227. //
  228. MULTISZ m_GreetingMessage;
  229. LPTSTR m_pszGreetingMessageWithLineFeed;
  230. //
  231. // Same as for the greeting message, the banner could be multiline too.
  232. // Same handling.
  233. //
  234. MULTISZ m_BannerMessage;
  235. LPTSTR m_pszBannerMessageWithLineFeed;
  236. BOOL m_fEnableLicensing;
  237. DWORD m_ListenBacklog;
  238. CHAR * m_pszLocalHostName; // this machine name running ftp service
  239. DWORD m_dwUserFlags; // user flags established at start of conn
  240. //
  241. // For FTP server configuration information
  242. //
  243. //
  244. // TODO: merge configuration and instance object together
  245. //
  246. // LPFTP_SERVER_CONFIG m_pFtpServerConfig;
  247. HKEY m_hkeyParams;
  248. //
  249. // Other data related to configuration load and store
  250. //
  251. BOOL m_fValid;
  252. CRITICAL_SECTION m_csLock; // used for updating this object
  253. CHAR m_rgchCacheBlock[MAX_CACHE_BLOCK_SIZE]; // to avoid false sharing
  254. // we should avoid cache block conflict
  255. // Following set of data constitute the dynamic data for connections
  256. // ==> it will be good if they are closeby, within one cache block.
  257. CRITICAL_SECTION m_csConnectionsList;
  258. LIST_ENTRY m_ActiveConnectionsList; // list of all active connections
  259. LIST_ENTRY m_FreeConnectionsList; // free list for connection objects
  260. METADATA_REF_HANDLER m_rfAccessCheck;
  261. LPFTP_SERVER_STATISTICS m_pFTPStats;
  262. BOOL m_fAllowReplaceOnRename;
  263. ISOLATION_MODE m_UserIsolationMode;
  264. BOOL m_fLogInUtf8;
  265. };
  266. typedef FTP_SERVER_INSTANCE *PFTP_SERVER_INSTANCE;
  267. #endif // _FTPINST_HXX_