Leaked source code of windows server 2003
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.

400 lines
8.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1994 **/
  4. /**********************************************************************/
  5. /*
  6. main.cxx
  7. Library initialization for infocomm.dll --
  8. Internet Information Services Common dll.
  9. FILE HISTORY:
  10. Johnl 06-Oct-1994 Created.
  11. MuraliK 15-Nov-1994
  12. Modified to include new service list initializations
  13. MuraliK 21-Feb-1995
  14. Added init and cleanup of debugging variables
  15. MuraliK 16-May-1995
  16. Added code to read debug flags.
  17. MuraliK 6-June-1995
  18. Initialized Atq Bandwidth Level, reading values from registry
  19. MuraliK 16-Oct-1995 Tailored it for infocom.dll
  20. */
  21. #include <tcpdllp.hxx>
  22. #include <atq.h>
  23. #include <info_srv.h>
  24. #include <inetsvcs.h>
  25. #include <lonsi.hxx>
  26. #include <mb.hxx>
  27. #include <irtlmisc.h>
  28. PISRPC g_pIsrpc = NULL;
  29. HINSTANCE g_hDll = NULL;
  30. LONG g_cInitializers = 0;
  31. CRITICAL_SECTION g_csDllInitLock;
  32. DECLARE_PLATFORM_TYPE();
  33. enum {
  34. INIT_NONE,
  35. INIT_DEBUG_PRINT,
  36. INIT_ENTRY_POINTS,
  37. INIT_SVC_LOC,
  38. INIT_IISRTL,
  39. INIT_ATQ,
  40. INIT_SECURITY,
  41. INIT_SVC_INFO,
  42. INIT_METABASE,
  43. INIT_TSUNAMI,
  44. INIT_SCAVENGER,
  45. INIT_SVC_RPC,
  46. INIT_RDNS,
  47. INIT_MIME_MAP,
  48. INIT_CONFIG_FROM_REG,
  49. INIT_LOGGING,
  50. INIT_ENDPOINT_UTILITIES
  51. } g_InitCommonDllState = INIT_NONE;
  52. //
  53. // externs
  54. //
  55. DWORD
  56. InitGlobalConfigFromReg(
  57. VOID
  58. );
  59. #ifdef _NO_TRACING_
  60. DWORD
  61. GetDebugFlagsFromReg(
  62. IN LPCTSTR pszRegEntry
  63. );
  64. #endif
  65. extern "C"
  66. BOOL WINAPI DllMain( HINSTANCE hDll, DWORD dwReason, LPVOID lpvReserved )
  67. {
  68. BOOL fReturn = TRUE;
  69. switch ( dwReason )
  70. {
  71. case DLL_PROCESS_ATTACH: {
  72. CREATE_DEBUG_PRINT_OBJECT( "infocomm.dll");
  73. LOAD_DEBUG_FLAGS_FROM_REG_STR(INET_INFO_PARAMETERS_KEY, 0);
  74. g_hDll = hDll;
  75. //
  76. // Initialize the platform type
  77. //
  78. (VOID)IISGetPlatformType( );
  79. DBG_REQUIRE( DisableThreadLibraryCalls( hDll ) );
  80. INITIALIZE_CRITICAL_SECTION( &g_csDllInitLock );
  81. break;
  82. }
  83. case DLL_PROCESS_DETACH:
  84. DELETE_DEBUG_PRINT_OBJECT();
  85. DeleteCriticalSection( &g_csDllInitLock );
  86. break;
  87. case DLL_THREAD_ATTACH:
  88. case DLL_THREAD_DETACH:
  89. default:
  90. break ;
  91. }
  92. return ( fReturn);
  93. } // main()
  94. BOOL
  95. CallInitFunctions(
  96. VOID
  97. )
  98. /*++
  99. Description:
  100. Call all the init functions.
  101. Return value:
  102. TRUE of all init's succeed.
  103. --*/
  104. {
  105. DWORD err = NO_ERROR;
  106. g_InitCommonDllState = INIT_NONE;
  107. #ifdef _NO_TRACING_
  108. if (!VALID_DEBUG_PRINT_OBJECT()) goto error;
  109. #endif
  110. g_InitCommonDllState = INIT_DEBUG_PRINT;
  111. if (!GetDynamicEntryPoints()) goto error;
  112. g_InitCommonDllState = INIT_ENTRY_POINTS;
  113. if (!pfnInitSvcLoc()) goto error;
  114. g_InitCommonDllState = INIT_SVC_LOC;
  115. if (!InitializeIISRTL()) goto error;
  116. g_InitCommonDllState = INIT_IISRTL;
  117. if (!AtqInitialize(0)) goto error;
  118. g_InitCommonDllState = INIT_ATQ;
  119. err = InitializeSecurity(g_hDll);
  120. if (err != NO_ERROR) goto error;
  121. g_InitCommonDllState = INIT_SECURITY;
  122. if (!IIS_SERVICE::InitializeServiceInfo()) goto error;
  123. g_InitCommonDllState = INIT_SVC_INFO;
  124. if (!IIS_SERVICE::InitializeMetabaseComObject()) goto error;
  125. g_InitCommonDllState = INIT_METABASE;
  126. if (!Tsunami_Initialize()) goto error;
  127. g_InitCommonDllState = INIT_TSUNAMI;
  128. if (!InitializeCacheScavenger()) goto error;
  129. g_InitCommonDllState = INIT_SCAVENGER;
  130. if (!IIS_SERVICE::InitializeServiceRpc(
  131. INET_INFO_SERVICE_NAME,
  132. inetinfo_ServerIfHandle
  133. )
  134. ) goto error;
  135. g_InitCommonDllState = INIT_SVC_RPC;
  136. if (!InitRDns()) goto error;
  137. g_InitCommonDllState = INIT_RDNS;
  138. if (!InitializeMimeMap(INET_INFO_PARAMETERS_KEY)) goto error;
  139. g_InitCommonDllState = INIT_MIME_MAP;
  140. err = InitGlobalConfigFromReg();
  141. if (err != NO_ERROR) goto error;
  142. g_InitCommonDllState = INIT_CONFIG_FROM_REG;
  143. err = LOGGING::Initialize();
  144. if (err != NO_ERROR) goto error;
  145. g_InitCommonDllState = INIT_LOGGING;
  146. if (!InitializeEndpointUtilities()) goto error;
  147. g_InitCommonDllState = INIT_ENDPOINT_UTILITIES;
  148. return TRUE;
  149. error:
  150. if (err != NO_ERROR) {
  151. SetLastError(err);
  152. }
  153. return FALSE;
  154. }
  155. VOID
  156. CallUninitFunctions(
  157. VOID
  158. )
  159. /*++
  160. Description:
  161. Call all the uninit functions.
  162. Return value:
  163. None.
  164. --*/
  165. {
  166. switch (g_InitCommonDllState) {
  167. case INIT_ENDPOINT_UTILITIES:
  168. TerminateEndpointUtilities();
  169. case INIT_LOGGING:
  170. LOGGING::Terminate();
  171. case INIT_CONFIG_FROM_REG:
  172. case INIT_MIME_MAP:
  173. CleanupMimeMap();
  174. case INIT_RDNS:
  175. TerminateRDns();
  176. case INIT_SVC_RPC:
  177. IIS_SERVICE::CleanupServiceRpc();
  178. case INIT_SCAVENGER:
  179. TerminateCacheScavenger();
  180. case INIT_TSUNAMI:
  181. Tsunami_Terminate();
  182. case INIT_METABASE:
  183. IIS_SERVICE::CleanupMetabaseComObject();
  184. case INIT_SVC_INFO:
  185. IIS_SERVICE::CleanupServiceInfo();
  186. case INIT_SECURITY:
  187. TerminateSecurity();
  188. case INIT_ATQ:
  189. if ( !AtqTerminate()) {
  190. DBGPRINTF(( DBG_CONTEXT,
  191. " ATQ Terminate Failed with Error %d\n", GetLastError()
  192. ));
  193. DBGPRINTF(( DBG_CONTEXT, " ATQ Terminate Failed\n"));
  194. }
  195. case INIT_SVC_LOC:
  196. pfnTerminateSvcLoc();
  197. case INIT_IISRTL:
  198. TerminateIISRTL();
  199. case INIT_ENTRY_POINTS:
  200. FreeDynamicLibraries();
  201. case INIT_DEBUG_PRINT:
  202. case INIT_NONE:
  203. /* no complaints Mr. Compiler */ break;
  204. }
  205. }
  206. BOOL
  207. InitCommonDlls(
  208. VOID
  209. )
  210. /*++
  211. Description:
  212. DLL Init and uninit functions that don't have to worry about the
  213. peb lock being taken during PROCESS_ATTACH/DETACH.
  214. --*/
  215. {
  216. BOOL fReturn = TRUE;
  217. RECT rect;
  218. DBGPRINTF(( DBG_CONTEXT,
  219. "[InitCommonDlls] Entered - Initialization count %d\n",
  220. g_cInitializers ));
  221. EnterCriticalSection( &g_csDllInitLock );
  222. //
  223. // Are we already initialized?
  224. //
  225. if ( g_cInitializers ) {
  226. g_cInitializers++;
  227. LeaveCriticalSection( &g_csDllInitLock );
  228. return TRUE;
  229. }
  230. INITIALIZE_PLATFORM_TYPE();
  231. if ( !CallInitFunctions() )
  232. {
  233. DWORD err;
  234. IIS_PRINTF((buff,"Initializing infocomm.dll module failed\n"));
  235. err = GetLastError();
  236. CallUninitFunctions();
  237. SetLastError(err);
  238. fReturn = FALSE;
  239. } else {
  240. //
  241. // Call a windows API that will cause windows server side thread to
  242. // be created for tcpsvcs.exe. This prevents a severe winsrv memory
  243. // leak when spawning processes and
  244. // gives a perf boost so the windows
  245. // console isn't brought up and torn down each time. :(
  246. //
  247. (VOID) AdjustWindowRectEx( &rect,
  248. 0,
  249. FALSE,
  250. 0 );
  251. // fReturn already init to TRUE
  252. }
  253. //
  254. // Only inc the init count if we initialized successfully
  255. //
  256. if ( fReturn ) {
  257. g_cInitializers++;
  258. }
  259. LeaveCriticalSection( &g_csDllInitLock );
  260. return fReturn;
  261. }
  262. BOOL
  263. TerminateCommonDlls(
  264. VOID
  265. )
  266. {
  267. MB mb( (IMDCOM*) IIS_SERVICE::QueryMDObject() );
  268. DBG_ASSERT( g_cInitializers > 0 );
  269. DBGPRINTF(( DBG_CONTEXT,
  270. "[TerminateCommonDlls] Init Count = %d\n",
  271. g_cInitializers ));
  272. EnterCriticalSection( &g_csDllInitLock );
  273. if ( --g_cInitializers )
  274. {
  275. LeaveCriticalSection( &g_csDllInitLock );
  276. return TRUE;
  277. }
  278. //
  279. // When we clean up, make sure the metabase has been saved,
  280. // so no recent modifications get lost.
  281. //
  282. DBGPRINTF(( DBG_CONTEXT,
  283. "[TerminateCommonDlls] Saving Metabase\n" ));
  284. mb.Save();
  285. DBGPRINTF(( DBG_CONTEXT,
  286. "[TerminateCommonDlls] Terminating dlls\n" ));
  287. CallUninitFunctions();
  288. LeaveCriticalSection( &g_csDllInitLock );
  289. return TRUE;
  290. }