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.

342 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. class FTP_SERVER_INSTANCE : public IIS_SERVER_INSTANCE {
  77. public:
  78. FTP_SERVER_INSTANCE(
  79. IN PFTP_IIS_SERVICE pService,
  80. IN DWORD dwInstanceId,
  81. IN USHORT sPort,
  82. IN LPCSTR lpszRegParamKey,
  83. IN LPWSTR lpwszAnonPasswordSecretName,
  84. IN LPWSTR lpwszRootPasswordSecretName,
  85. IN BOOL fMigrateVroots
  86. ) ;
  87. ~FTP_SERVER_INSTANCE();
  88. //
  89. // Instance start & stop
  90. //
  91. virtual DWORD StartInstance();
  92. virtual DWORD StopInstance();
  93. //
  94. // VIRTUALS for service specific params/RPC admin
  95. //
  96. virtual BOOL SetServiceConfig(IN PCHAR pConfig );
  97. virtual BOOL GetServiceConfig(IN OUT PCHAR pConfig,IN DWORD dwLevel);
  98. virtual BOOL GetStatistics( IN DWORD dwLevel, OUT PCHAR *pBuffer);
  99. virtual BOOL ClearStatistics( VOID );
  100. virtual BOOL DisconnectUser( IN DWORD dwIdUser );
  101. virtual BOOL EnumerateUsers( OUT PCHAR* pBuffer, OUT PDWORD nRead );
  102. virtual VOID MDChangeNotify( MD_CHANGE_OBJECT * pco );
  103. BOOL FreeAllocCachedClientConn(VOID);
  104. PICLIENT_CONNECTION AllocClientConnFromAllocCache(VOID);
  105. VOID FreeClientConnToAllocCache(IN PICLIENT_CONNECTION pClient);
  106. //
  107. // Initialize the configuration data from registry information
  108. //
  109. // Arguments
  110. // hkeyReg key to the registry entry for parameters
  111. // FieldsToRead bitmapped flags indicating which data to be read.
  112. //
  113. // Returns:
  114. // NO_ERROR on success
  115. // Win32 error code otherwise
  116. //
  117. DWORD InitFromRegistry( IN FIELD_CONTROL FieldsToRead);
  118. DWORD
  119. ReadAuthentInfo(
  120. IN BOOL ReadAll = TRUE,
  121. IN DWORD SingleItemToRead = 0
  122. );
  123. DWORD
  124. GetConfigInformation( OUT LPFTP_CONFIG_INFO pConfigInfo);
  125. DWORD
  126. SetConfigInformation( IN LPFTP_CONFIG_INFO pConfigInfo);
  127. BOOL IsValid( VOID) const { return ( m_fValid); }
  128. VOID LockConfig( VOID) { EnterCriticalSection( &m_csLock); }
  129. VOID UnLockConfig( VOID) { LeaveCriticalSection( &m_csLock); }
  130. VOID LockConnectionsList()
  131. { EnterCriticalSection(&m_csConnectionsList); }
  132. VOID UnlockConnectionsList()
  133. { LeaveCriticalSection(&m_csConnectionsList); }
  134. DWORD GetCurrentConnectionsCount( VOID) const
  135. { return m_cCurrentConnections; }
  136. DWORD GetMaxCurrentConnectionsCount( VOID) const
  137. { return m_cMaxCurrentConnections; }
  138. DWORD SetLocalHostName(IN LPCSTR pszHost);
  139. LPCSTR QueryLocalHostName(VOID) const { return (m_pszLocalHostName); }
  140. DWORD QueryUserFlags(VOID) const { return (m_dwUserFlags); }
  141. BOOL QueryLowercaseFiles(VOID) const { return (m_fLowercaseFiles); }
  142. BOOL AllowAnonymous(VOID) const { return (m_fAllowAnonymous); }
  143. BOOL AllowGuestAccess(VOID) const { return (m_fAllowGuestAccess); }
  144. BOOL IsAllowedUser(IN BOOL fAnonymous)
  145. {
  146. return ((fAnonymous && m_fAllowAnonymous) ||
  147. (!fAnonymous && !m_fAllowAnonymous) ||
  148. (!fAnonymous && !m_fAnonymousOnly));
  149. }
  150. BOOL IsEnablePortAttack(VOID) const { return (m_fEnablePortAttack); }
  151. BOOL IsEnablePasvTheft(VOID) const { return (m_fEnablePasvTheft); };
  152. DWORD NumListenBacklog(VOID) const { return (m_ListenBacklog); }
  153. // Following functions return pointers to strings which should be used
  154. // within locked sections of config
  155. // Marked by LockConfig() and UnLockConfig()
  156. LPCSTR QueryMaxClientsMsg(VOID) const
  157. { return (LPCSTR)m_MaxClientsMessage.QueryStr(); }
  158. LPCSTR QueryGreetingMsg(VOID) const
  159. { return (LPCSTR)m_GreetingMessage.QueryStr(); }
  160. LPCSTR QueryBannerMsg(VOID) const
  161. { return (LPCSTR)m_BannerMessage.QueryStr(); }
  162. LPCSTR QueryExitMsg(VOID) const
  163. { return (LPCSTR)m_ExitMessage.QueryStr(); }
  164. BOOL EnumerateConnection( IN PFN_CLIENT_CONNECTION_ENUM pfnConnEnum,
  165. IN LPVOID pContext,
  166. IN DWORD dwConnectionId);
  167. VOID DisconnectAllConnections( VOID);
  168. PICLIENT_CONNECTION
  169. AllocNewConnection();
  170. VOID RemoveConnection( IN OUT PICLIENT_CONNECTION pcc);
  171. BOOL WriteParamsToRegistry( LPFTP_CONFIG_INFO pConfig );
  172. VOID Print( VOID) const;
  173. METADATA_REF_HANDLER* QueryMetaDataRefHandler() { return &m_rfAccessCheck; }
  174. PTCP_AUTHENT_INFO QueryAuthentInfo() { return &m_TcpAuthentInfo; }
  175. BOOL AllowReplaceOnRename( VOID ) const {
  176. return m_fAllowReplaceOnRename;
  177. }
  178. LPFTP_SERVER_STATISTICS QueryStatsObj( VOID ) { return m_pFTPStats; }
  179. private:
  180. //
  181. // Connections related data
  182. //
  183. // m_cMaxConnections: max connections permitted by config
  184. // m_cCurrentConnections: count of currently connected users
  185. // m_cMaxCurrentConnections: max connections seen in this session
  186. // Always m_cCurrentConnections
  187. // <= m_cMaxCurrentConnections
  188. // <= m_cMaxConnections;
  189. //
  190. // DWORD m_cMaxConnections;
  191. // replaced by TSVC_INFO::QueryMaxConnections()
  192. DWORD m_cCurrentConnections;
  193. DWORD m_cMaxCurrentConnections;
  194. BOOL m_fAllowAnonymous;
  195. BOOL m_fAllowGuestAccess;
  196. BOOL m_fAnnotateDirectories; // annotate dirs when dir changes
  197. BOOL m_fAnonymousOnly;
  198. BOOL m_fEnablePortAttack;
  199. BOOL m_fEnablePasvTheft;
  200. // if m_LowercaseFiles is TRUE, then dir listings from non-case-preserving
  201. // filesystems will be mapped to lowercase.
  202. BOOL m_fLowercaseFiles;
  203. BOOL m_fMsdosDirOutput; // send msdos style dir listings
  204. BOOL m_fFourDigitYear; // send 4 digit year dir listings
  205. STR m_ExitMessage;
  206. STR m_MaxClientsMessage;
  207. TCP_AUTHENT_INFO m_TcpAuthentInfo;
  208. //
  209. // Greeting Message can be a multiline message.
  210. // We maintain two copies of the message
  211. // 1) double null terminated seq. of strings with one line per string
  212. // 2) single null terminated string with \n characters interspersed.
  213. //
  214. // Representation 1 is used for sending data to clients
  215. // Representation 2 is used for RPC admin facility
  216. // We maintain the string as MULTI_SZ in the registry
  217. //
  218. MULTISZ m_GreetingMessage;
  219. LPTSTR m_pszGreetingMessageWithLineFeed;
  220. //
  221. // Same as for the greeting message, the banner could be multiline too.
  222. // Same handling.
  223. //
  224. MULTISZ m_BannerMessage;
  225. LPTSTR m_pszBannerMessageWithLineFeed;
  226. BOOL m_fEnableLicensing;
  227. DWORD m_ListenBacklog;
  228. CHAR * m_pszLocalHostName; // this machine name running ftp service
  229. DWORD m_dwUserFlags; // user flags established at start of conn
  230. //
  231. // For FTP server configuration information
  232. //
  233. //
  234. // TODO: merge configuration and instance object together
  235. //
  236. // LPFTP_SERVER_CONFIG m_pFtpServerConfig;
  237. HKEY m_hkeyParams;
  238. //
  239. // Other data related to configuration load and store
  240. //
  241. BOOL m_fValid;
  242. CRITICAL_SECTION m_csLock; // used for updating this object
  243. CHAR m_rgchCacheBlock[MAX_CACHE_BLOCK_SIZE]; // to avoid false sharing
  244. // we should avoid cache block conflict
  245. // Following set of data constitute the dynamic data for connections
  246. // ==> it will be good if they are closeby, within one cache block.
  247. CRITICAL_SECTION m_csConnectionsList;
  248. LIST_ENTRY m_ActiveConnectionsList; // list of all active connections
  249. LIST_ENTRY m_FreeConnectionsList; // free list for connection objects
  250. METADATA_REF_HANDLER m_rfAccessCheck;
  251. LPFTP_SERVER_STATISTICS m_pFTPStats;
  252. BOOL m_fAllowReplaceOnRename;
  253. };
  254. typedef FTP_SERVER_INSTANCE *PFTP_SERVER_INSTANCE;
  255. #endif // _FTPINST_HXX_