--------------------- PatchSet 2874 Date: 2001/08/26 09:02:01 Author: serassio Branch: cygwin Tag: (none) Log: Reworked new hosts file handling Members: src/cf.data.pre:1.10.2.10->1.10.2.11 src/defines.h:1.3.22.13->1.3.22.14 src/globals.h:1.5.12.11->1.5.12.12 src/tools.c:1.7.2.18->1.7.2.19 src/win32.c:1.1.50.12->1.1.50.13 Index: squid/src/cf.data.pre =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cf.data.pre,v retrieving revision 1.10.2.10 retrieving revision 1.10.2.11 diff -u -r1.10.2.10 -r1.10.2.11 --- squid/src/cf.data.pre 25 Aug 2001 10:36:57 -0000 1.10.2.10 +++ squid/src/cf.data.pre 26 Aug 2001 09:02:01 -0000 1.10.2.11 @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.10.2.10 2001/08/25 10:36:57 serassio Exp $ +# $Id: cf.data.pre,v 1.10.2.11 2001/08/26 09:02:01 serassio Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1102,7 +1102,7 @@ NAME: hosts_file TYPE: string -DEFAULT: $SYSNETDB/hosts +DEFAULT: $SYSNETDBHOSTS LOC: Config.etcHostsPath DOC_START Location of the host-local IP name-address associations @@ -1113,16 +1113,16 @@ (%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 + - 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 set to special value - "$SYSNETDB/hosts", it will be searched in the default Operating + 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 Index: squid/src/defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/defines.h,v retrieving revision 1.3.22.13 retrieving revision 1.3.22.14 diff -u -r1.3.22.13 -r1.3.22.14 --- squid/src/defines.h 25 Aug 2001 08:18:21 -0000 1.3.22.13 +++ squid/src/defines.h 26 Aug 2001 09:02:01 -0000 1.3.22.14 @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.3.22.13 2001/08/25 08:18:21 serassio Exp $ + * $Id: defines.h,v 1.3.22.14 2001/08/26 09:02:01 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -293,15 +293,12 @@ #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 +#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 Index: squid/src/globals.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/globals.h,v retrieving revision 1.5.12.11 retrieving revision 1.5.12.12 diff -u -r1.5.12.11 -r1.5.12.12 --- squid/src/globals.h 25 Aug 2001 08:18:21 -0000 1.5.12.11 +++ squid/src/globals.h 26 Aug 2001 09:02:01 -0000 1.5.12.12 @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.5.12.11 2001/08/25 08:18:21 serassio Exp $ + * $Id: globals.h,v 1.5.12.12 2001/08/26 09:02:01 serassio Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -154,7 +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 */ +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 =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.7.2.18 retrieving revision 1.7.2.19 diff -u -r1.7.2.18 -r1.7.2.19 --- squid/src/tools.c 25 Aug 2001 08:18:21 -0000 1.7.2.18 +++ squid/src/tools.c 26 Aug 2001 09:02:01 -0000 1.7.2.19 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.7.2.18 2001/08/25 08:18:21 serassio Exp $ + * $Id: tools.c,v 1.7.2.19 2001/08/26 09:02:01 serassio Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -1007,28 +1007,31 @@ FILE *fp; char buf[1024]; char buf2[512]; - char hosts_file[FILENAME_MAX]; + char *hosts_file = NULL; char *nt = buf; char *lt = buf; char *addr = buf; char *host = NULL; + + safe_free(hosts_file); if (NULL == Config.etcHostsPath) return; if (0 == strcmp(Config.etcHostsPath, "none")) return; - 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); + 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 - strcpy(hosts_file, Config.etcHostsPath); - debug(1, 5) ("etc_hosts: host files is '%s'\n", hosts_file); + 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", hosts_file, xstrerror()); + safe_free(hosts_file); return; } #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) @@ -1071,4 +1074,5 @@ fqdncacheAddEntryFromHosts(addr, hosts); wordlistDestroy(&hosts); } + safe_free(hosts_file); } Index: squid/src/win32.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/win32.c,v retrieving revision 1.1.50.12 retrieving revision 1.1.50.13 diff -u -r1.1.50.12 -r1.1.50.13 --- squid/src/win32.c 25 Aug 2001 08:18:21 -0000 1.1.50.12 +++ squid/src/win32.c 26 Aug 2001 09:02:01 -0000 1.1.50.13 @@ -28,7 +28,7 @@ #include static unsigned int GetOSVersion(); -static void Set_sys_network_db_path(); +static void Set_sys_network_db_hosts(); #define DATABASEPATH "DataBasePath" @@ -39,44 +39,46 @@ /* ====================================================================== */ static void -Set_sys_network_db_path() +Set_sys_network_db_hosts() { HKEY hndKey; - char buf[1024]; + char *RegValue = NULL; 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) { + 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: - 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); + 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: - strcpy(buf,"%WINDIR%"); + RegValue = xmalloc(sizeof(_WIN95_NETWORK_DB_HOSTS) + sizeof(_WIN_HOSTS_FILENAME) + 1); + strcpy(RegValue, _WIN95_NETWORK_DB_HOSTS); 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); + 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 @@ -146,7 +148,7 @@ return 1; if (atexit(WIN32_Exit) != 0) return 1; - Set_sys_network_db_path(); + Set_sys_network_db_hosts(); return 0; } #endif