Index: squid/src/cf.data.pre diff -u squid/src/cf.data.pre:1.32 squid/src/cf.data.pre:1.10.2.11 --- squid/src/cf.data.pre:1.32 Wed Aug 22 14:15:46 2001 +++ squid/src/cf.data.pre Sun Aug 26 02:02:01 2001 @@ -1102,25 +1102,31 @@ NAME: hosts_file TYPE: string -DEFAULT: /etc/hosts +DEFAULT: $SYSNETDBHOSTS LOC: Config.etcHostsPath DOC_START Location of the host-local IP name-address associations - database. Most Operating Systems have such a file: under - Un*X it's by default in /etc/hosts MS-Windows NT/2000 places - that in %SystemRoot%(by default - c:\winnt)\system32\drivers\etc\hosts, while Windows 9x/ME - places that in %windir%(usually c:\windows)\hosts + database. Most Operating Systems have such a file on different + default locations: + - Un*X: /etc/hosts + - Windows NT/2000: %SystemRoot%\system32\drivers\etc\hosts + (%SystemRoot% value install default is c:\winnt) + - Windows 9x/Me: %windir%\hosts + (%windir% value is usually c:\windows) + - Cygwin: /etc/hosts and, if not found here, Windows default The file contains newline-separated definitions, in the form ip_address_in_dotted_form name [name ...] names are - whitespace-separated. lines beginnng with an hash (#) + whitespace-separated. Lines beginnng with an hash (#) character are comments. - The file is checked at startup and upon configuration. If - set to 'none', it won't be checked. If append_domain is - used, that domain will be added to domain-local (i.e. not - containing any dot character) host definitions. + The file is checked at startup and upon configuration. + If set to 'none', it won't be checked. If set to special value + "$SYSNETDBHOSTS", it will be searched in the default Operating + System location specified above. + If append_domain is used, that domain will be added to + domain-local (i.e. not containing any dot character) host + definitions. DOC_END NAME: diskd_program Index: squid/src/defines.h diff -u squid/src/defines.h:1.13 squid/src/defines.h:1.3.22.14 --- squid/src/defines.h:1.13 Thu Aug 16 00:39:03 2001 +++ squid/src/defines.h Sun Aug 26 02:02:01 2001 @@ -293,13 +293,18 @@ #define O_BINARY 0 #endif +#define DEFAULT_SYS_NETWORK_DB_HOSTS "/etc/hosts" + /* CygWin & Windows NT Port */ #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) +#define _WIN_HOSTS_FILENAME "\\hosts" +#define _WIN95_NETWORK_DB_HOSTS "%WINDIR%" #define _WIN_OS_UNKNOWN 0 #define _WIN_OS_WIN32S 1 #define _WIN_OS_WIN95 2 #define _WIN_OS_WIN98 3 -#define _WIN_OS_WINNT 4 -#define _WIN_OS_WIN2K 5 -#define _WIN_OS_WINXP 6 +#define _WIN_OS_WINME 4 +#define _WIN_OS_WINNT 5 +#define _WIN_OS_WIN2K 6 +#define _WIN_OS_WINXP 7 #endif diff -u squid/src/dns_internal.c:1.11 squid/src/dns_internal.c:1.5.26.14 --- squid/src/dns_internal.c:1.11 Thu Aug 16 00:39:03 2001 +++ squid/src/dns_internal.c Sun Aug 19 09:27:15 2001 @@ -289,6 +289,7 @@ break; case _WIN_OS_WIN95: case _WIN_OS_WIN98: + case _WIN_OS_WINME: /* get nameservers from the Windows 9X registry */ if (RegOpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", Index: squid/src/globals.h diff -u squid/src/globals.h:1.11 squid/src/globals.h:1.5.12.11 --- squid/src/globals.h:1.11 Thu Aug 16 00:39:03 2001 +++ squid/src/globals.h Sat Aug 25 01:18:21 2001 @@ -154,6 +154,7 @@ extern RemovalPolicy *mem_policy; extern hash_table *proxy_auth_username_cache; /* NULL */ extern int incoming_sockets_accepted; +extern char *sys_network_db_hosts; /* NULL */ #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) extern unsigned int WIN32_OS_version; /* 0 */ extern char *WIN32_OS_string; Index: squid/src/tools.c diff -u squid/src/tools.c:1.15 squid/src/tools.c:1.7.2.18 --- squid/src/tools.c:1.15 Thu Aug 16 00:39:03 2001 +++ squid/src/tools.c Sat Aug 25 01:18:21 2001 @@ -964,21 +1007,31 @@ FILE *fp; char buf[1024]; char buf2[512]; + char *hosts_file = NULL; char *nt = buf; char *lt = buf; char *addr = buf; char *host = NULL; -#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) - char *systemroot = NULL; -#endif + + safe_free(hosts_file); if (NULL == Config.etcHostsPath) return; if (0 == strcmp(Config.etcHostsPath, "none")) return; - fp = fopen(Config.etcHostsPath, "r"); + if (0 == strcmp(Config.etcHostsPath, "$SYSNETDBHOSTS")) { + if (sys_network_db_hosts == NULL) + sys_network_db_hosts = xstrdup(DEFAULT_SYS_NETWORK_DB_HOSTS); + hosts_file = xstrdup(sys_network_db_hosts); + } + else + hosts_file = xstrdup(Config.etcHostsPath); + debug(1, 5) ("etc_hosts: host files is configured as '%s', resolved to '%s'\n", + Config.etcHostsPath, hosts_file); + fp = fopen(hosts_file, "r"); if (fp == NULL) { debug(1, 1) ("parseEtcHosts: %s: %s\n", - Config.etcHostsPath, xstrerror()); + hosts_file, xstrerror()); + safe_free(hosts_file); return; } #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) @@ -1021,4 +1074,5 @@ fqdncacheAddEntryFromHosts(addr, hosts); wordlistDestroy(&hosts); } + safe_free(hosts_file); } Index: squid/src/win32.c diff -u squid/src/win32.c:1.3 squid/src/win32.c:1.1.50.13 --- squid/src/win32.c:1.3 Thu Aug 16 00:39:03 2001 +++ squid/src/win32.c Sun Aug 26 02:02:01 2001 @@ -28,11 +28,59 @@ #include static unsigned int GetOSVersion(); +static void Set_sys_network_db_hosts(); +#define DATABASEPATH "DataBasePath" + +static char TCP_REGKEY[256] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"; + /* ====================================================================== */ /* LOCAL FUNCTIONS */ /* ====================================================================== */ +static void +Set_sys_network_db_hosts() +{ + HKEY hndKey; + char *RegValue = NULL; + DWORD Size = 0; +#ifdef _SQUID_CYGWIN_ + FILE * fp; + /* Checks if exist /etc/hosts on Cygwin */ + if ((fp = fopen(DEFAULT_SYS_NETWORK_DB_HOSTS, "r")) != NULL) { + fclose (fp); + return; + } +#endif + safe_free(RegValue); + switch (WIN32_OS_version) { + case _WIN_OS_WINNT: + case _WIN_OS_WIN2K: + case _WIN_OS_WINXP: + /* get hosts file location from Windows Registry */ + if (RegOpenKey(HKEY_LOCAL_MACHINE, TCP_REGKEY, &hndKey) == ERROR_SUCCESS) { + DWORD Type = 0; + RegQueryValueEx(hndKey, DATABASEPATH, NULL, &Type, NULL, &Size); + RegValue = xmalloc(Size + sizeof(_WIN_HOSTS_FILENAME) + 1); + RegQueryValueEx(hndKey, DATABASEPATH, NULL, &Type, RegValue, &Size); + RegCloseKey(hndKey); + } + break; + case _WIN_OS_WIN95: + case _WIN_OS_WIN98: + case _WIN_OS_WINME: + RegValue = xmalloc(sizeof(_WIN95_NETWORK_DB_HOSTS) + sizeof(_WIN_HOSTS_FILENAME) + 1); + strcpy(RegValue, _WIN95_NETWORK_DB_HOSTS); + break; + } + strcat(RegValue, _WIN_HOSTS_FILENAME); + Size = ExpandEnvironmentStrings(RegValue, NULL, 1) + 1; + safe_free(sys_network_db_hosts); + sys_network_db_hosts = xmalloc(Size); + ExpandEnvironmentStrings(RegValue, sys_network_db_hosts, Size); + safe_free(RegValue); +} + static unsigned int GetOSVersion() { @@ -48,30 +96,37 @@ WIN32_OS_string = xstrdup("Windows NT"); return _WIN_OS_WINNT; } + if ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 0)) { + WIN32_OS_string = xstrdup("Windows 2000"); + return _WIN_OS_WIN2K; + } if ((osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion == 1)) { WIN32_OS_string = xstrdup("Windows XP"); return _WIN_OS_WINXP; } - WIN32_OS_string = xstrdup("Windows 2000"); - return _WIN_OS_WIN2K; break; case VER_PLATFORM_WIN32_WINDOWS: - if ((osvi.dwMajorVersion > 4) || - ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0))) { + if ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 0)) { + WIN32_OS_string = xstrdup("Windows 95"); + return _WIN_OS_WIN95; + } + if ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 10)) { WIN32_OS_string = xstrdup("Windows 98"); return _WIN_OS_WIN98; } - WIN32_OS_string = xstrdup("Windows 95"); - return _WIN_OS_WIN95; + if ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 90)) { + WIN32_OS_string = xstrdup("Windows Me"); + return _WIN_OS_WINME; + } break; case VER_PLATFORM_WIN32s: WIN32_OS_string = xstrdup("Windows 3.1 with WIN32S"); return _WIN_OS_WIN32S; break; default: - return _WIN_OS_UNKNOWN; + break; } - WIN32_OS_string = xstrdup("Unknown"); + WIN32_OS_string = xstrdup("Unknown Windows system"); return _WIN_OS_UNKNOWN; } @@ -93,6 +148,8 @@ return 1; if (atexit(WIN32_Exit) != 0) return 1; + Set_sys_network_db_hosts(); return 0; } #endif +