Index: squid/src/cf.data.pre diff -u squid/src/cf.data.pre:1.32 squid/src/cf.data.pre:1.10.2.10 --- squid/src/cf.data.pre:1.32 Wed Aug 22 14:15:46 2001 +++ squid/src/cf.data.pre Sat Aug 25 03:36:57 2001 @@ -1102,15 +1102,18 @@ NAME: hosts_file TYPE: string -DEFAULT: /etc/hosts +DEFAULT: $SYSNETDB/hosts 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/or Windows default The file contains newline-separated definitions, in the form ip_address_in_dotted_form name [name ...] names are @@ -1118,9 +1121,12 @@ 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. + set to 'none', it won't be checked. If set to special value + "$SYSNETDB/hosts", 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 Index: squid/src/defines.h diff -u squid/src/defines.h:1.13 squid/src/defines.h:1.3.22.13 --- squid/src/defines.h:1.13 Thu Aug 16 00:39:03 2001 +++ squid/src/defines.h Sat Aug 25 01:18:21 2001 @@ -293,13 +293,21 @@ #define O_BINARY 0 #endif +#define DEFAULT_SYS_NETWORK_DB_PATH "/etc" +#if defined(_SQUID_MSWIN) +#define DEFAULT_HOSTS_FILENAME "\\hosts" +#else +#define DEFAULT_HOSTS_FILENAME "/hosts" +#endif + /* CygWin & Windows NT Port */ #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) #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_path; /* 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,28 @@ FILE *fp; char buf[1024]; char buf2[512]; + char hosts_file[FILENAME_MAX]; char *nt = buf; char *lt = buf; char *addr = buf; char *host = NULL; -#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) - char *systemroot = NULL; -#endif if (NULL == Config.etcHostsPath) return; if (0 == strcmp(Config.etcHostsPath, "none")) return; - fp = fopen(Config.etcHostsPath, "r"); + if (0 == strcmp(Config.etcHostsPath, "$SYSNETDB/hosts")) { + if (sys_network_db_path == NULL) + sys_network_db_path = xstrdup(DEFAULT_SYS_NETWORK_DB_PATH); + strcpy(hosts_file, sys_network_db_path); + strcat(hosts_file, DEFAULT_HOSTS_FILENAME); + } + else + strcpy(hosts_file, Config.etcHostsPath); + debug(1, 5) ("etc_hosts: host files is '%s'\n", hosts_file); + fp = fopen(hosts_file, "r"); if (fp == NULL) { debug(1, 1) ("parseEtcHosts: %s: %s\n", - Config.etcHostsPath, xstrerror()); + hosts_file, xstrerror()); return; } #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) Index: squid/src/win32.c diff -u squid/src/win32.c:1.3 squid/src/win32.c:1.1.50.12 --- squid/src/win32.c:1.3 Thu Aug 16 00:39:03 2001 +++ squid/src/win32.c Sat Aug 25 01:18:21 2001 @@ -28,11 +28,57 @@ #include static unsigned int GetOSVersion(); +static void Set_sys_network_db_path(); +#define DATABASEPATH "DataBasePath" + +static char TCP_REGKEY[256] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"; + /* ====================================================================== */ /* LOCAL FUNCTIONS */ /* ====================================================================== */ +static void +Set_sys_network_db_path() +{ + HKEY hndKey; + char buf[1024]; + DWORD Size = 0; +#ifdef _SQUID_CYGWIN_ + FILE * fp; + /* Checks if exist /etc/hosts on Cygwin */ + strcpy(buf, DEFAULT_SYS_NETWORK_DB_PATH); + strcat(buf, DEFAULT_HOSTS_FILENAME); + if ((fp = fopen(buf, "r")) != NULL) { + fclose (fp); + return; + } +#endif + switch (WIN32_OS_version) { + case _WIN_OS_WINNT: + case _WIN_OS_WIN2K: + case _WIN_OS_WINXP: + safe_free(sys_network_db_path); + /* 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); + RegQueryValueEx(hndKey, DATABASEPATH, NULL, &Type, buf, &Size); + RegCloseKey(hndKey); + } + break; + case _WIN_OS_WIN95: + case _WIN_OS_WIN98: + case _WIN_OS_WINME: + strcpy(buf,"%WINDIR%"); + break; + } + Size = ExpandEnvironmentStrings(buf, NULL, 1) + 1; + safe_free(sys_network_db_path); + sys_network_db_path = xmalloc(Size); + ExpandEnvironmentStrings(buf, sys_network_db_path, Size); +} + static unsigned int GetOSVersion() { @@ -48,30 +94,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 +146,8 @@ return 1; if (atexit(WIN32_Exit) != 0) return 1; + Set_sys_network_db_path(); return 0; } #endif +