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.

421 lines
10 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. dllentry.cxx
  5. Abstract:
  6. Entry point for WinInet Internet client DLL
  7. Contents:
  8. WinInetDllEntryPoint
  9. Author:
  10. Richard L Firth (rfirth) 10-Nov-1994
  11. Environment:
  12. Win32 (user-mode) DLL
  13. Revision History:
  14. 10-Nov-1994 rfirth
  15. Created
  16. --*/
  17. #include <wininetp.h>
  18. #include <process.h>
  19. #include <perfdiag.hxx>
  20. #include <shlwapi.h>
  21. #include <advpub.h>
  22. #include "autodial.h"
  23. //
  24. // Downlevel delay load support (we forward to shlwapi)
  25. //
  26. #include <delayimp.h>
  27. PfnDliHook __pfnDliFailureHook;
  28. #define FLAGS_SZ "Flags"
  29. #define FLAGS_DW PLUGIN_AUTH_FLAGS_CAN_HANDLE_UI | PLUGIN_AUTH_FLAGS_KEEP_ALIVE_NOT_REQUIRED
  30. #define IE_SECURITY_DIGEST_REG_KEY "Software\\Microsoft\\Internet Explorer\\Security\\Digest"
  31. #if defined(__cplusplus)
  32. extern "C" {
  33. #endif
  34. BOOL
  35. WINAPI
  36. DllMain(
  37. IN HINSTANCE DllHandle,
  38. IN DWORD Reason,
  39. IN LPVOID Reserved
  40. );
  41. #if defined(__cplusplus)
  42. }
  43. #endif
  44. //
  45. // global data
  46. //
  47. GLOBAL CRITICAL_SECTION GeneralInitCritSec = {0};
  48. //
  49. // functions
  50. //
  51. void SetupDelayloadErrorHandler()
  52. {
  53. __pfnDliFailureHook = (PfnDliHook)GetProcAddress(GetModuleHandleA("shlwapi.dll"), "DelayLoadFailureHook");
  54. }
  55. BOOL
  56. WINAPI
  57. DllMain(
  58. IN HINSTANCE DllHandle,
  59. IN DWORD Reason,
  60. IN LPVOID Reserved
  61. )
  62. /*++
  63. Routine Description:
  64. Performs global initialization and termination for all protocol modules.
  65. This function only handles process attach and detach which are required for
  66. global initialization and termination, respectively. We disable thread
  67. attach and detach. New threads calling Wininet APIs will get an
  68. INTERNET_THREAD_INFO structure created for them by the first API requiring
  69. this structure
  70. Arguments:
  71. DllHandle - handle of this DLL. Unused
  72. Reason - process attach/detach or thread attach/detach
  73. Reserved - if DLL_PROCESS_ATTACH, NULL means DLL is being dynamically
  74. loaded, else static. For DLL_PROCESS_DETACH, NULL means DLL
  75. is being freed as a consequence of call to FreeLibrary()
  76. else the DLL is being freed as part of process termination
  77. Return Value:
  78. BOOL
  79. Success - TRUE
  80. Failure - FALSE. Failed to initialize
  81. --*/
  82. {
  83. if (Reason != DLL_PROCESS_ATTACH) {
  84. DEBUG_ENTER((DBG_DLL,
  85. Bool,
  86. "DllMain",
  87. "%#x, %s, %#x",
  88. DllHandle,
  89. (Reason == DLL_PROCESS_ATTACH) ? "DLL_PROCESS_ATTACH"
  90. : (Reason == DLL_PROCESS_DETACH) ? "DLL_PROCESS_DETACH"
  91. : (Reason == DLL_THREAD_ATTACH) ? "DLL_THREAD_ATTACH"
  92. : (Reason == DLL_THREAD_DETACH) ? "DLL_THREAD_DETACH"
  93. : "?",
  94. Reserved
  95. ));
  96. }
  97. DWORD error;
  98. //
  99. // perform global dll initialization, if any.
  100. //
  101. switch (Reason) {
  102. case DLL_PROCESS_ATTACH:
  103. GlobalDllHandle = DllHandle;
  104. GlobalPlatformType = PlatformType(&GlobalPlatformVersion5);
  105. // Call SHFusionInitialize only on themed platforms:
  106. if (GlobalPlatformWhistler)
  107. SHFusionInitializeFromModule((HMODULE)DllHandle);
  108. SetupDelayloadErrorHandler();
  109. InitializeCriticalSection(&GeneralInitCritSec);
  110. INITIALIZE_DEBUG_REGKEY();
  111. INITIALIZE_DEBUG_MEMORY();
  112. INET_DEBUG_START();
  113. GlobalDllInitialize();
  114. if (!InternetCreateThreadInfo(TRUE)) {
  115. return FALSE;
  116. }
  117. DEBUG_ENTER((DBG_DLL,
  118. Bool,
  119. "DllMain",
  120. "%#x, %s, %#x",
  121. DllHandle,
  122. (Reason == DLL_PROCESS_ATTACH) ? "DLL_PROCESS_ATTACH"
  123. : (Reason == DLL_PROCESS_DETACH) ? "DLL_PROCESS_DETACH"
  124. : (Reason == DLL_THREAD_ATTACH) ? "DLL_THREAD_ATTACH"
  125. : (Reason == DLL_THREAD_DETACH) ? "DLL_THREAD_DETACH"
  126. : "?",
  127. Reserved
  128. ));
  129. DEBUG_LEAVE(TRUE);
  130. break;
  131. case DLL_PROCESS_DETACH:
  132. //
  133. // signal to all APIs (and any other function that might have an
  134. // interest) that the DLL is being shutdown
  135. //
  136. GlobalDynaUnload = (Reserved == NULL) ? TRUE : FALSE;
  137. InDllCleanup = TRUE;
  138. GlobalPleaseQuitWhatYouAreDoing = TRUE;
  139. DEBUG_PRINT(DLL,
  140. INFO,
  141. ("DLL Terminated\n"
  142. ));
  143. DEBUG_LEAVE(TRUE);
  144. if (GlobalDynaUnload) {
  145. if (GlobalDataInitialized) {
  146. GlobalDataTerminate();
  147. }
  148. GlobalDllTerminate();
  149. ExitAutodialModule();
  150. InternetTerminateThreadInfo();
  151. }
  152. CloseInternetSettingsKey();
  153. PERF_DUMP();
  154. PERF_END();
  155. //TERMINATE_DEBUG_MEMORY(FALSE);
  156. TERMINATE_DEBUG_MEMORY(TRUE);
  157. INET_DEBUG_FINISH();
  158. TERMINATE_DEBUG_REGKEY();
  159. //InternetDestroyThreadInfo();
  160. GlobalUserName.~CUserName();
  161. DeleteCriticalSection(&GeneralInitCritSec);
  162. // Call SHFusionUninitialize only on themed platforms:
  163. if (GlobalPlatformWhistler)
  164. SHFusionUninitialize();
  165. break;
  166. case DLL_THREAD_DETACH:
  167. //
  168. // kill the INTERNET_THREAD_INFO
  169. //
  170. DEBUG_LEAVE(TRUE);
  171. InternetDestroyThreadInfo();
  172. break;
  173. case DLL_THREAD_ATTACH:
  174. //
  175. // we do nothing for thread attach - if we need an INTERNET_THREAD_INFO
  176. // then it gets created by the function which realises we need one
  177. //
  178. AllowCAP();
  179. DEBUG_LEAVE(TRUE);
  180. break;
  181. }
  182. return TRUE;
  183. }
  184. //////////////////////////////////////////////////////////////////////////
  185. //
  186. // Autoregistration entry points
  187. //
  188. //////////////////////////////////////////////////////////////////////////
  189. HRESULT CallRegInstall(LPSTR szSection)
  190. {
  191. HRESULT hr = E_FAIL;
  192. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  193. if (hinstAdvPack)
  194. {
  195. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, achREGINSTALL);
  196. if (pfnri)
  197. {
  198. hr = pfnri(GlobalDllHandle, szSection, NULL);
  199. }
  200. FreeLibrary(hinstAdvPack);
  201. }
  202. return hr;
  203. }
  204. extern VOID MakeCacheLocationsConsistent();
  205. STDAPI
  206. DllInstall
  207. (
  208. IN BOOL bInstall, // Install or Uninstall
  209. IN LPCWSTR pwStr
  210. )
  211. {
  212. HRESULT hr = S_OK;
  213. if(bInstall && StrCmpIW( pwStr, L"HKCUHard") == 0)
  214. {
  215. AddHardeningPrivacyDefaults();
  216. return hr;
  217. }
  218. if(bInstall && StrCmpIW( pwStr, L"HKCUSoft") == 0)
  219. {
  220. RemoveHardeningPrivacyDefaults();
  221. return hr;
  222. }
  223. // Add entries to selfreg.inx and include the code below to support self-registration.
  224. #ifdef WININET_SELFREG
  225. BOOL bUseHKCU = FALSE;
  226. if (pwStr && (0 == StrCmpIW(pwStr, L"HKCU")))
  227. {
  228. bUseHKCU = TRUE;
  229. }
  230. if ( bInstall )
  231. {
  232. hr = CallRegInstall(bUseHKCU ? "Reg.HKCU" : "Reg.HKLM");
  233. }
  234. else
  235. {
  236. hr = CallRegInstall(bUseHKCU ? "Unreg.HKCU" : "UnReg.HKLM");
  237. }
  238. #endif
  239. if( bInstall && (!pwStr || !*pwStr || (StrCmpIW( pwStr, L"HKLM") == 0)))
  240. {
  241. // Write out to HKLM\Software\Microsoft\Internet Explorer\Security\Digest
  242. HKEY hKey;
  243. DWORD dwError, dwRegDisp, dwFlags;
  244. dwFlags = FLAGS_DW;
  245. dwError = REGCREATEKEYEX(HKEY_LOCAL_MACHINE,
  246. IE_SECURITY_DIGEST_REG_KEY, 0, NULL,
  247. 0, KEY_READ | KEY_WRITE, NULL, &hKey, &dwRegDisp);
  248. if (dwError == ERROR_SUCCESS)
  249. {
  250. dwError = RegSetValueEx(hKey, FLAGS_SZ, 0,
  251. REG_BINARY, (LPBYTE) &dwFlags, sizeof(DWORD));
  252. REGCLOSEKEY(hKey);
  253. }
  254. // also need to fix up the HKLM\SV\MS\IE\AdavancedOptions\Negotiate so that "Restore Defaults" will work
  255. // HKEY hKey;
  256. // DWORD dwError, dwRegDisp, dwFlags;
  257. GlobalPlatformType = PlatformType(&GlobalPlatformVersion5);
  258. if (GlobalPlatformWhistler)
  259. {
  260. dwFlags = 0x00000001;
  261. dwError = REGCREATEKEYEX(HKEY_LOCAL_MACHINE,
  262. "SOFTWARE\\Microsoft\\Internet Explorer\\AdvancedOptions\\CRYPTO\\NEGOTIATE", 0, NULL,
  263. 0, KEY_WRITE, NULL, &hKey, &dwRegDisp);
  264. if (dwError == ERROR_SUCCESS)
  265. {
  266. dwError = RegSetValueEx(hKey, "DefaultValue", 0,
  267. REG_DWORD, (LPBYTE) &dwFlags, sizeof(DWORD));
  268. REGCLOSEKEY(hKey);
  269. }
  270. }
  271. #ifndef UNIX
  272. DWORD dwNSVersion;
  273. if( GetActiveNetscapeVersion( &dwNSVersion) == FALSE)
  274. dwNSVersion = 0;
  275. SetNetscapeImportVersion( dwNSVersion);
  276. #endif // UNIX
  277. WritePrivateProfileString("compatibility", "NOTIFIER", "0x400000", "win.ini");
  278. WritePrivateProfileString(NULL, NULL, NULL, "win.ini");
  279. }
  280. else if(bInstall && StrCmpIW( pwStr, L"HKCU") == 0)
  281. {
  282. MakeCacheLocationsConsistent();
  283. #ifndef UNIX
  284. TCHAR szNSFilename[MAX_PATH];
  285. DWORD cNSFilenameSize = MAX_PATH;
  286. DWORD dwNSVersion;
  287. if( GetNetscapeImportVersion( &dwNSVersion) == TRUE
  288. && dwNSVersion != 0
  289. && FindNetscapeCookieFile( dwNSVersion, szNSFilename, &cNSFilenameSize) == TRUE)
  290. {
  291. ImportCookieFile( szNSFilename );
  292. }
  293. #endif // UNIX
  294. ie401::Import401History();
  295. ie401::Import401Content();
  296. }
  297. else if (!bInstall && (!pwStr || !*pwStr || (StrCmpIW(pwStr, L"HKLM") == 0)))
  298. {
  299. RegDeleteKey(HKEY_LOCAL_MACHINE, IE_SECURITY_DIGEST_REG_KEY);
  300. }
  301. //
  302. // set up privacy defaults
  303. //
  304. if(bInstall && StrCmpIW( pwStr, L"HKCU") == 0 && !IsInGUIModeSetup())
  305. {
  306. CheckPrivacyDefaults();
  307. }
  308. return hr;
  309. }