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.

320 lines
6.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1993 **/
  4. /**********************************************************************/
  5. /*
  6. globals.cxx
  7. This module contains global variable definitions shared by the
  8. various FTPD Service components.
  9. Functions exported by this module:
  10. InitializeGlobals
  11. TerminateGlobals
  12. ReadParamsFromRegistry
  13. WriteParamsToRegistry
  14. FILE HISTORY:
  15. KeithMo 07-Mar-1993 Created.
  16. MuraliK 11-April-1995 Created new global ftp server config object
  17. */
  18. #include "ftpdp.hxx"
  19. #include "acptctxt.hxx"
  20. #include <timer.h>
  21. //
  22. // Private constants.
  23. //
  24. #ifdef _NO_TRACING_
  25. #define DEFAULT_DEBUG_FLAGS 0
  26. #else
  27. #define DEFAULT_TRACE_FLAGS 0
  28. #endif
  29. #define DEFAULT_NO_EXTENDED_FILENAME 0
  30. //
  31. // Socket transfer buffer size.
  32. //
  33. DWORD g_SocketBufferSize;
  34. //
  35. // Statistics.
  36. //
  37. //
  38. // FTP Statistics structure.
  39. //
  40. LPFTP_SERVER_STATISTICS g_pFTPStats;
  41. //
  42. // Miscellaneous data.
  43. //
  44. //
  45. // The FTP Server sign-on string.
  46. //
  47. LPSTR g_FtpServiceNameString;
  48. //
  49. // key for the registry to read parameters
  50. //
  51. HKEY g_hkeyParams = NULL;
  52. //
  53. // List holding all the PASV accept context entries
  54. //
  55. LIST_ENTRY g_AcceptContextList;
  56. //
  57. // The number of threads currently blocked in Synchronous sockets
  58. // calls, like recv()
  59. //
  60. DWORD g_ThreadsBlockedInSyncCalls = 0;
  61. //
  62. // The maximum number of threads that will be allowed to block in
  63. // Synchronous sockets calls. Magic # that will be changed if the max # of
  64. // pool threads is less than 100.
  65. //
  66. DWORD g_MaxThreadsBlockedInSyncCalls = 100;
  67. //
  68. // The global variable lock.
  69. //
  70. CRITICAL_SECTION g_GlobalLock;
  71. #ifdef KEEP_COMMAND_STATS
  72. //
  73. // Lock protecting per-command statistics.
  74. //
  75. CRITICAL_SECTION g_CommandStatisticsLock;
  76. #endif // KEEP_COMMAND_STATS
  77. //
  78. // By default, extended characters are allowed for file/directory names
  79. // in the data transfer commands. Reg key can disable this.
  80. //
  81. DWORD g_fNoExtendedChars = FALSE;
  82. #if DBG
  83. //
  84. // Debug-specific data.
  85. //
  86. //
  87. // Debug output control flags.
  88. //
  89. #endif // DBG
  90. //
  91. // Public functions.
  92. //
  93. /*******************************************************************
  94. NAME: InitializeGlobals
  95. SYNOPSIS: Initializes global shared variables. Some values are
  96. initialized with constants, others are read from the
  97. configuration registry.
  98. RETURNS: APIERR - NO_ERROR if successful, otherwise a Win32
  99. error code.
  100. NOTES: This routine may only be called by a single thread
  101. of execution; it is not necessarily multi-thread safe.
  102. Also, this routine is called before the event logging
  103. routines have been initialized. Therefore, event
  104. logging is not available.
  105. HISTORY:
  106. KeithMo 07-Mar-1993 Created.
  107. MuraliK 05-April-1995 Added FTP server config object
  108. ********************************************************************/
  109. APIERR
  110. InitializeGlobals(
  111. VOID
  112. )
  113. {
  114. APIERR err = NO_ERROR;
  115. DWORD dwDebugFlags;
  116. ACCEPT_CONTEXT_ENTRY *pAcceptEntry = NULL;
  117. UINT_PTR dwMaxThreads = 0;
  118. //
  119. // Setup the service sign-on string.
  120. //
  121. g_FtpServiceNameString = "Microsoft FTP Service\0"; // must be double \0 terminated
  122. //
  123. // Set up PASV accept event variables
  124. //
  125. InitializeListHead( &g_AcceptContextList );
  126. if ( err = CreateInitialAcceptContext() )
  127. {
  128. return err;
  129. }
  130. //
  131. // Create global locks.
  132. //
  133. INITIALIZE_CRITICAL_SECTION( &g_GlobalLock );
  134. #ifdef KEEP_COMMAND_STATS
  135. INITIALIZE_CRITICAL_SECTION( &g_CommandStatisticsLock );
  136. #endif // KEEP_COMMAND_STATS
  137. //
  138. // Create an FTP server object and load values from registry.
  139. //
  140. //
  141. // Connect to the registry.
  142. //
  143. err = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  144. FTPD_PARAMETERS_KEY,
  145. 0,
  146. KEY_ALL_ACCESS,
  147. &g_hkeyParams );
  148. if( err != NO_ERROR )
  149. {
  150. DBGPRINTF(( DBG_CONTEXT,
  151. "cannot open registry key %s, error %lu\n",
  152. FTPD_PARAMETERS_KEY,
  153. err ));
  154. //
  155. // Load Default values
  156. //
  157. err = NO_ERROR;
  158. }
  159. //
  160. // Figure out how many pool threads we can create maximally - if less than built-in
  161. // number, adjust accordingly
  162. //
  163. dwMaxThreads = AtqGetInfo( AtqMaxThreadLimit );
  164. if ( dwMaxThreads/2 < (UINT_PTR)g_MaxThreadsBlockedInSyncCalls )
  165. {
  166. g_MaxThreadsBlockedInSyncCalls = (DWORD)(dwMaxThreads/2);
  167. }
  168. DBGPRINTF((DBG_CONTEXT,
  169. "Max # of threads allowed to be blocked in sync calls : %d\n",
  170. g_MaxThreadsBlockedInSyncCalls));
  171. # ifdef _NO_TRACING_
  172. # if DBG
  173. dwDebugFlags = ReadRegistryDword( g_hkeyParams,
  174. FTPD_DEBUG_FLAGS,
  175. DEFAULT_DEBUG_FLAGS );
  176. SET_DEBUG_FLAGS( dwDebugFlags);
  177. # endif // DBG
  178. # endif
  179. g_fNoExtendedChars = ReadRegistryDword( g_hkeyParams,
  180. FTPD_NO_EXTENDED_FILENAME,
  181. DEFAULT_NO_EXTENDED_FILENAME );
  182. g_pFTPStats = new FTP_SERVER_STATISTICS;
  183. if ( g_pFTPStats == NULL )
  184. {
  185. err = ERROR_NOT_ENOUGH_MEMORY;
  186. }
  187. return ( err);
  188. } // InitializeGlobals()
  189. /*******************************************************************
  190. NAME: TerminateGlobals
  191. SYNOPSIS: Terminate global shared variables.
  192. NOTES: This routine may only be called by a single thread
  193. of execution; it is not necessarily multi-thread safe.
  194. Also, this routine is called after the event logging
  195. routines have been terminated. Therefore, event
  196. logging is not available.
  197. HISTORY:
  198. KeithMo 07-Mar-1993 Created.
  199. ********************************************************************/
  200. VOID
  201. TerminateGlobals(
  202. VOID
  203. )
  204. {
  205. if ( g_hkeyParams != NULL) {
  206. RegCloseKey( g_hkeyParams);
  207. g_hkeyParams = NULL;
  208. }
  209. DeleteAcceptContexts();
  210. DeleteCriticalSection( &g_GlobalLock );
  211. #ifdef KEEP_COMMAND_STATS
  212. DeleteCriticalSection( &g_CommandStatisticsLock );
  213. #endif // KEEP_COMMAND_STATS
  214. } // TerminateGlobals
  215. /************************ End Of File ************************/