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.

569 lines
12 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. globals.cxx
  5. Abstract:
  6. This module contains global variable definitions shared by the
  7. various W3 Service components.
  8. Author:
  9. KeithMo 07-Mar-1993 Created.
  10. --*/
  11. #include "w3p.hxx"
  12. #include <time.h>
  13. #include <timer.h>
  14. //
  15. // Locks
  16. //
  17. CRITICAL_SECTION csGlobalLock;
  18. //
  19. // User database related data.
  20. //
  21. DWORD cConnectedUsers = 0; // Current connections.
  22. //
  23. // Connection information related data.
  24. //
  25. LIST_ENTRY listConnections;
  26. //
  27. // Miscellaneous data.
  28. //
  29. LARGE_INTEGER AllocationGranularity; // Page allocation granularity.
  30. HANDLE g_hSysAccToken = NULL;
  31. TCHAR * g_pszW3TempDirName = NULL; // Name of temporary directory.
  32. static BOOL l_bTempDirAlloced = FALSE;
  33. //
  34. // Server type string
  35. //
  36. CHAR g_szServerType[ sizeof(MSW3_VERSION_STR_MAX)];
  37. DWORD g_cbServerType = 0;
  38. CHAR szServerVersion[sizeof(MAKE_VERSION_STRING(MSW3_VERSION_STR_MAX))];
  39. DWORD cbServerVersionString = 0;
  40. STR* g_pstrMovedMessage;
  41. //
  42. // Whether or not to send HTTP 1.1
  43. //
  44. DWORD g_ReplyWith11;
  45. //
  46. // Whether or not to use TransmitFileAndRecv
  47. //
  48. DWORD g_fUseAndRecv;
  49. //
  50. // PUT/DELETE event timeout.
  51. //
  52. DWORD g_dwPutEventTimeout;
  53. CHAR g_szPutTimeoutString[17];
  54. DWORD g_dwPutTimeoutStrlen;
  55. //
  56. // Platform type
  57. //
  58. PLATFORM_TYPE W3PlatformType = PtNtServer;
  59. BOOL g_fIsWindows95 = FALSE;
  60. //
  61. // Statistics.
  62. // used to write statistics counter values to when instance is unknown
  63. //
  64. LPW3_SERVER_STATISTICS g_pW3Stats;
  65. extern BOOL fAnySecureFilters;
  66. //
  67. // Generate the string storage space
  68. //
  69. # include "strconst.h"
  70. # define CStrM( FriendlyName, ActualString) \
  71. const char PSZ_ ## FriendlyName[] = ActualString;
  72. ConstantStringsForThisModule()
  73. # undef CStrM
  74. //
  75. // Header Date time cache
  76. //
  77. PW3_DATETIME_CACHE g_pDateTimeCache = NULL;
  78. //
  79. // Downlevel Client Support (no HOST header support)
  80. //
  81. BOOL g_fDLCSupport;
  82. TCHAR* g_pszDLCMenu;
  83. DWORD g_cbDLCMenu;
  84. TCHAR* g_pszDLCHostName;
  85. DWORD g_cbDLCHostName;
  86. TCHAR* g_pszDLCCookieMenuDocument;
  87. DWORD g_cbDLCCookieMenuDocument;
  88. TCHAR* g_pszDLCMungeMenuDocument;
  89. DWORD g_cbDLCMungeMenuDocument;
  90. TCHAR* g_pszDLCCookieName;
  91. DWORD g_cbDLCCookieName;
  92. //
  93. // Notification object used to watch for changes in CAPI stores
  94. //
  95. STORE_CHANGE_NOTIFIER *g_pStoreChangeNotifier;
  96. //
  97. // CPU accounting/limits globals
  98. //
  99. DWORD g_dwNumProcessors = 1;
  100. //
  101. // Maximum client request buffer size
  102. //
  103. DWORD g_cbMaxClientRequestBuffer = W3_DEFAULT_MAX_CLIENT_REQUEST_BUFFER;
  104. //
  105. // Should we get stack back traces when appropriate?
  106. //
  107. BOOL g_fGetBackTraces = FALSE;
  108. //
  109. // WAM Event Log
  110. //
  111. EVENT_LOG *g_pWamEventLog = NULL;
  112. //
  113. // Public functions.
  114. //
  115. APIERR
  116. InitializeGlobals(
  117. VOID
  118. )
  119. /*++
  120. Routine Description:
  121. Initializes global shared variables. Some values are
  122. initialized with constants, others are read from the
  123. configuration registry.
  124. Arguments:
  125. None.
  126. Return Value:
  127. Win32
  128. --*/
  129. {
  130. DWORD err;
  131. HKEY hkey;
  132. //
  133. // Initialize the server version string based on the platform type
  134. //
  135. W3PlatformType = IISGetPlatformType();
  136. switch ( W3PlatformType ) {
  137. case PtNtWorkstation:
  138. strcpy(szServerVersion,MAKE_VERSION_STRING(MSW3_VERSION_STR_NTW));
  139. strcpy(g_szServerType, MSW3_VERSION_STR_NTW);
  140. break;
  141. case PtWindows95:
  142. case PtWindows9x:
  143. strcpy(szServerVersion,MAKE_VERSION_STRING(MSW3_VERSION_STR_W95));
  144. strcpy(g_szServerType, MSW3_VERSION_STR_W95);
  145. g_fIsWindows95 = TRUE;
  146. break;
  147. default:
  148. //
  149. // Either server or unhandled platform type!
  150. //
  151. DBG_ASSERT(InetIsNtServer(W3PlatformType));
  152. strcpy(szServerVersion,MAKE_VERSION_STRING(MSW3_VERSION_STR_IIS));
  153. strcpy(g_szServerType, MSW3_VERSION_STR_IIS);
  154. }
  155. g_cbServerType = strlen( g_szServerType);
  156. cbServerVersionString = strlen(szServerVersion);
  157. //
  158. // Create global locks.
  159. //
  160. INITIALIZE_CRITICAL_SECTION( &csGlobalLock );
  161. //
  162. // Initialize the connection list
  163. //
  164. InitializeListHead( &listConnections );
  165. err = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  166. W3_PARAMETERS_KEY,
  167. 0,
  168. KEY_READ,
  169. &hkey );
  170. if ( !err )
  171. {
  172. BOOL Success = ReadRegString( hkey,
  173. &g_pszW3TempDirName,
  174. W3_TEMP_DIR_NAME,
  175. "" );
  176. if ( !Success || !g_pszW3TempDirName || !*g_pszW3TempDirName )
  177. {
  178. DWORD dwTempDirNameLength;
  179. if ( l_bTempDirAlloced && g_pszW3TempDirName )
  180. {
  181. TCP_FREE( g_pszW3TempDirName );
  182. g_pszW3TempDirName = NULL;
  183. }
  184. l_bTempDirAlloced = FALSE;
  185. dwTempDirNameLength = GetTempPath( 0,
  186. NULL
  187. );
  188. if ( dwTempDirNameLength == 0)
  189. {
  190. g_pszW3TempDirName = ".\\";
  191. } else
  192. {
  193. DWORD dwTemp = dwTempDirNameLength + 1;
  194. g_pszW3TempDirName = (TCHAR *) TCP_ALLOC(dwTemp * sizeof(TCHAR));
  195. if (g_pszW3TempDirName == NULL)
  196. {
  197. g_pszW3TempDirName = ".\\";
  198. } else
  199. {
  200. l_bTempDirAlloced = TRUE;
  201. dwTempDirNameLength = GetTempPath( dwTemp,
  202. g_pszW3TempDirName
  203. );
  204. if ( dwTempDirNameLength == 0 ||
  205. dwTempDirNameLength > dwTemp)
  206. {
  207. TCP_FREE( g_pszW3TempDirName );
  208. g_pszW3TempDirName = ".\\";
  209. l_bTempDirAlloced = FALSE;
  210. }
  211. }
  212. }
  213. }
  214. #ifdef _NO_TRACING_
  215. #if DBG
  216. DWORD Debug = ReadRegistryDword( hkey,
  217. W3_DEBUG_FLAGS,
  218. DEFAULT_DEBUG_FLAGS
  219. );
  220. SET_DEBUG_FLAGS (Debug);
  221. #endif // DBG
  222. #endif
  223. g_ReplyWith11 = ReadRegistryDword(hkey,
  224. W3_VERSION_11,
  225. DEFAULT_SEND_11
  226. );
  227. g_dwPutEventTimeout = ReadRegistryDword(hkey,
  228. W3_PUT_TIMEOUT,
  229. DEFAULT_PUT_TIMEOUT
  230. );
  231. _itoa(g_dwPutEventTimeout, g_szPutTimeoutString, 10);
  232. g_dwPutTimeoutStrlen = strlen(g_szPutTimeoutString);
  233. //
  234. // See if we should use TransmitFileAndRecv
  235. //
  236. g_fUseAndRecv = ReadRegistryDword(hkey,
  237. W3_USE_ANDRECV,
  238. DEFAULT_USE_ANDRECV
  239. );
  240. //
  241. // Read globals for down level client support
  242. //
  243. g_fDLCSupport = !!ReadRegistryDword( hkey,
  244. W3_DLC_SUPPORT,
  245. 0 );
  246. if ( !ReadRegString( hkey,
  247. &g_pszDLCMenu,
  248. W3_DLC_MENU_STRING,
  249. "" ) )
  250. {
  251. return GetLastError();
  252. }
  253. g_cbDLCMenu = strlen( g_pszDLCMenu );
  254. if ( !ReadRegString( hkey,
  255. &g_pszDLCHostName,
  256. W3_DLC_HOSTNAME_STRING,
  257. "" ) )
  258. {
  259. return GetLastError();
  260. }
  261. g_cbDLCHostName = strlen( g_pszDLCHostName );
  262. if ( !ReadRegString( hkey,
  263. &g_pszDLCCookieMenuDocument,
  264. W3_DLC_COOKIE_MENU_DOCUMENT_STRING,
  265. "" ) )
  266. {
  267. return GetLastError();
  268. }
  269. g_cbDLCCookieMenuDocument = strlen( g_pszDLCCookieMenuDocument );
  270. if ( !ReadRegString( hkey,
  271. &g_pszDLCMungeMenuDocument,
  272. W3_DLC_MUNGE_MENU_DOCUMENT_STRING,
  273. "" ) )
  274. {
  275. return GetLastError();
  276. }
  277. g_cbDLCMungeMenuDocument = strlen( g_pszDLCMungeMenuDocument );
  278. if ( !ReadRegString( hkey,
  279. &g_pszDLCCookieName,
  280. W3_DLC_COOKIE_NAME_STRING,
  281. DLC_DEFAULT_COOKIE_NAME ) )
  282. {
  283. return GetLastError();
  284. }
  285. g_cbDLCCookieName = strlen( g_pszDLCCookieName );
  286. g_cbMaxClientRequestBuffer = ReadRegistryDword(
  287. hkey,
  288. W3_MAX_CLIENT_REQUEST_BUFFER_STRING,
  289. W3_DEFAULT_MAX_CLIENT_REQUEST_BUFFER );
  290. g_fGetBackTraces = ReadRegistryDword( hkey,
  291. W3_GET_BACKTRACES,
  292. g_fGetBackTraces );
  293. TCP_REQUIRE( !RegCloseKey( hkey ));
  294. }
  295. g_pstrMovedMessage = NULL;
  296. //
  297. // Create statistics object
  298. //
  299. g_pW3Stats = new W3_SERVER_STATISTICS();
  300. if ( g_pW3Stats == NULL )
  301. {
  302. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  303. return( ERROR_NOT_ENOUGH_MEMORY );
  304. }
  305. //
  306. // Get access token for system account
  307. //
  308. if ( !OpenProcessToken (
  309. GetCurrentProcess(),
  310. TOKEN_ALL_ACCESS,
  311. &g_hSysAccToken
  312. ) )
  313. {
  314. g_hSysAccToken = NULL;
  315. }
  316. //
  317. // Initialize the datetime cache
  318. //
  319. g_pDateTimeCache = new W3_DATETIME_CACHE;
  320. if ( g_pDateTimeCache == NULL )
  321. {
  322. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  323. return( ERROR_NOT_ENOUGH_MEMORY );
  324. }
  325. //
  326. // Create the CAPI store notification object
  327. //
  328. g_pStoreChangeNotifier = new STORE_CHANGE_NOTIFIER();
  329. if ( g_pStoreChangeNotifier == NULL )
  330. {
  331. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  332. return( ERROR_NOT_ENOUGH_MEMORY );
  333. }
  334. //
  335. // Get the CPU Accounting/Limits information
  336. //
  337. SYSTEM_INFO siInfo;
  338. GetSystemInfo(&siInfo);
  339. //
  340. // GetSystemInfo does not return any value, have to assume it succeeded.
  341. //
  342. g_dwNumProcessors = siInfo.dwNumberOfProcessors;
  343. //
  344. // Success!
  345. //
  346. return NO_ERROR;
  347. } // InitializeGlobals
  348. VOID
  349. TerminateGlobals(
  350. VOID
  351. )
  352. /*++
  353. Routine Description:
  354. Terminates global shared variables.
  355. Arguments:
  356. None.
  357. Return Value:
  358. None.
  359. --*/
  360. {
  361. if ( g_pDateTimeCache != NULL ) {
  362. delete g_pDateTimeCache;
  363. g_pDateTimeCache = NULL;
  364. }
  365. if( g_pW3Stats != NULL )
  366. {
  367. delete g_pW3Stats;
  368. g_pW3Stats = NULL;
  369. }
  370. if ( g_hSysAccToken )
  371. {
  372. CloseHandle( g_hSysAccToken );
  373. g_hSysAccToken = NULL;
  374. }
  375. if ( g_pszDLCMenu != NULL )
  376. {
  377. TCP_FREE( g_pszDLCMenu );
  378. g_pszDLCMenu = NULL;
  379. }
  380. if ( g_pszDLCHostName != NULL )
  381. {
  382. TCP_FREE( g_pszDLCHostName );
  383. g_pszDLCHostName = NULL;
  384. }
  385. if ( g_pszDLCCookieMenuDocument != NULL )
  386. {
  387. TCP_FREE( g_pszDLCCookieMenuDocument );
  388. g_pszDLCCookieMenuDocument = NULL;
  389. }
  390. if ( g_pszDLCMungeMenuDocument != NULL )
  391. {
  392. TCP_FREE( g_pszDLCMungeMenuDocument );
  393. g_pszDLCMungeMenuDocument = NULL;
  394. }
  395. if ( g_pszDLCCookieName != NULL )
  396. {
  397. TCP_FREE( g_pszDLCCookieName );
  398. g_pszDLCCookieName = NULL;
  399. }
  400. if ( g_pStoreChangeNotifier )
  401. {
  402. delete g_pStoreChangeNotifier;
  403. g_pStoreChangeNotifier = NULL;
  404. }
  405. if ( l_bTempDirAlloced && g_pszW3TempDirName )
  406. {
  407. TCP_FREE( g_pszW3TempDirName );
  408. g_pszW3TempDirName = NULL;
  409. l_bTempDirAlloced = FALSE;
  410. }
  411. TerminateFilters();
  412. W3_LIMIT_JOB_THREAD::TerminateLimitJobThread();
  413. W3_JOB_QUEUE::TerminateJobQueue();
  414. //
  415. // Dump heap residue.
  416. //
  417. TCP_DUMP_RESIDUE( );
  418. if( g_pWamEventLog ) {
  419. delete g_pWamEventLog;
  420. g_pWamEventLog = NULL;
  421. }
  422. //
  423. // Delete global locks.
  424. //
  425. DeleteCriticalSection( &csGlobalLock );
  426. } // TerminateGlobals