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.

236 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name :
  4. w3wp.cxx
  5. Abstract:
  6. Main module for IIS compatible worker process
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 23-Sept-1998
  9. Environment:
  10. Win32 - User Mode
  11. Project:
  12. IIS compatible worker process
  13. --*/
  14. /************************************************************
  15. * Include Headers
  16. ************************************************************/
  17. #include "precomp.hxx"
  18. #include "wpif.h"
  19. #include "ulw3.h"
  20. #include "../../../svcs/mdadmin/ntsec.h"
  21. DECLARE_DEBUG_PRINTS_OBJECT();
  22. DECLARE_DEBUG_VARIABLE();
  23. //
  24. // Configuration parameters registry key.
  25. //
  26. // BUGBUG
  27. #undef INET_INFO_KEY
  28. #undef INET_INFO_PARAMETERS_KEY
  29. #define INET_INFO_KEY \
  30. "System\\CurrentControlSet\\Services\\iisw3adm"
  31. #define INET_INFO_PARAMETERS_KEY \
  32. INET_INFO_KEY "\\Parameters"
  33. const CHAR g_pszWpRegLocation[] =
  34. INET_INFO_PARAMETERS_KEY "\\WP";
  35. class DEBUG_WRAPPER {
  36. public:
  37. DEBUG_WRAPPER( IN LPCSTR pszModule)
  38. {
  39. #if DBG
  40. CREATE_DEBUG_PRINT_OBJECT( pszModule);
  41. #else
  42. UNREFERENCED_PARAMETER(pszModule);
  43. #endif
  44. LOAD_DEBUG_FLAGS_FROM_REG_STR( g_pszWpRegLocation, DEBUG_ERROR );
  45. }
  46. ~DEBUG_WRAPPER(void)
  47. { DELETE_DEBUG_PRINT_OBJECT(); }
  48. };
  49. //
  50. // W3 DLL which does all the work
  51. //
  52. extern "C" INT
  53. __cdecl
  54. wmain(
  55. INT argc,
  56. PWSTR argv[]
  57. )
  58. {
  59. DEBUG_WRAPPER dbgWrapper( "w3wp" );
  60. HRESULT hr;
  61. HMODULE hModule = NULL;
  62. PFN_ULW3_ENTRY pEntry = NULL;
  63. ULONG rcRet = CLEAN_WORKER_PROCESS_EXIT_CODE;
  64. BOOL fCoInit = FALSE;
  65. //
  66. // We don't want the worker process to get stuck in a dialog box
  67. // if it goes awry.
  68. //
  69. SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX );
  70. IF_DEBUG( TRACE)
  71. {
  72. //
  73. // Print out our process affinity mask on debug builds.
  74. //
  75. BOOL fRet = TRUE;
  76. DWORD_PTR ProcessAffinityMask = 0;
  77. DWORD_PTR SystemAffinityMask = 0;
  78. fRet = GetProcessAffinityMask(
  79. GetCurrentProcess(),
  80. &ProcessAffinityMask,
  81. &SystemAffinityMask
  82. );
  83. DBGPRINTF(( DBG_CONTEXT, "Process affinity mask: %p\n", ProcessAffinityMask ));
  84. }
  85. //
  86. // Move this process to the WindowStation (with full access to all) in
  87. // which we would have been if running in inetinfo.exe (look at
  88. // iis\svcs\mdadmin\ntsec.cxx)
  89. //
  90. HWINSTA hWinSta = OpenWindowStationA(SZ_IIS_WINSTA, FALSE, WINSTA_ALL);
  91. if (hWinSta == NULL)
  92. {
  93. hr = HRESULT_FROM_WIN32(GetLastError());
  94. goto Finished;
  95. }
  96. //
  97. // Set this as this process's window station
  98. //
  99. if (!SetProcessWindowStation(hWinSta))
  100. {
  101. hr = HRESULT_FROM_WIN32(GetLastError());
  102. goto Finished;
  103. }
  104. //
  105. // Do some COM junk
  106. //
  107. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  108. if (FAILED(hr))
  109. {
  110. DBGPRINTF(( DBG_CONTEXT,
  111. "Error in CoInitializeEx(). hr = %x\n",
  112. hr ));
  113. rcRet = ERROR_WORKER_PROCESS_EXIT_CODE;
  114. goto Finished;
  115. }
  116. fCoInit = TRUE;
  117. hr = CoInitializeSecurity( NULL
  118. , -1
  119. , NULL
  120. , NULL
  121. , RPC_C_AUTHN_LEVEL_DEFAULT
  122. , RPC_C_IMP_LEVEL_IMPERSONATE
  123. , NULL
  124. , EOAC_NONE
  125. , NULL);
  126. if (FAILED(hr))
  127. {
  128. DBGPRINTF(( DBG_CONTEXT,
  129. "Error in CoInitializeSecurity(). hr = %x\n",
  130. hr ));
  131. rcRet = ERROR_WORKER_PROCESS_EXIT_CODE;
  132. goto Finished;
  133. }
  134. //
  135. // Load the ULW3 DLL which does all the work
  136. //
  137. hModule = LoadLibrary( ULW3_DLL_NAME );
  138. if ( hModule == NULL )
  139. {
  140. DBGPRINTF(( DBG_CONTEXT,
  141. "Error loading W3 service dll '%ws'. Error = %d\n",
  142. ULW3_DLL_NAME,
  143. GetLastError() ));
  144. rcRet = ERROR_WORKER_PROCESS_EXIT_CODE;
  145. goto Finished;
  146. }
  147. pEntry = (PFN_ULW3_ENTRY) GetProcAddress( hModule,
  148. ULW3_DLL_ENTRY );
  149. if ( pEntry == NULL )
  150. {
  151. DBGPRINTF(( DBG_CONTEXT,
  152. "Could not find entry point '%s'. Error = %d\n",
  153. ULW3_DLL_ENTRY,
  154. GetLastError() ));
  155. rcRet = ERROR_WORKER_PROCESS_EXIT_CODE;
  156. goto Finished;
  157. }
  158. hr = pEntry( argc,
  159. argv,
  160. FALSE ); // Compatibility Mode = FALSE
  161. if ( FAILED( hr ) )
  162. {
  163. DBGPRINTF(( DBG_CONTEXT,
  164. "Error executing W3WP. hr = %x\n",
  165. hr ));
  166. rcRet = ERROR_WORKER_PROCESS_EXIT_CODE;
  167. goto Finished;
  168. }
  169. Finished:
  170. DBG_ASSERT(SUCCEEDED(hr));
  171. //
  172. // Cleanup any lingering COM objects before unloading
  173. //
  174. if ( fCoInit )
  175. {
  176. CoUninitialize();
  177. }
  178. if ( hModule != NULL )
  179. {
  180. FreeLibrary( hModule );
  181. }
  182. return CLEAN_WORKER_PROCESS_EXIT_CODE;
  183. }