Re: [PATCH] - New WIN32 hosts file code

From: Robert Collins <robert.collins@dont-contact.us>
Date: 26 Aug 2001 12:33:02 +1000

On 25 Aug 2001 21:05:40 +0200, Guido Serassio wrote:
> Hi,
>
> This is the new code for hosts file handling on Windows platforms, plus a
> new enhancement on GetOSVersion().
>
> I introduced a new default value for hosts_file option on squid.conf:
> $SYSNETDB/hosts.
>
> When hosts_file has this value, the host file is automatically searched on
> the default OS location:
>
> - 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

In cf.data.pre, this should read the same as your description here.

> The code was tested successfully on Cygwin and Linux Alpha.
>
> I think that can go on HEAD, but comments are welcome.
>
> Guido

+++ 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) <----- isn't that _SQUID_MSWIN_ ?
+#define DEFAULT_HOSTS_FILENAME "\\hosts"
+#else
+#define DEFAULT_HOSTS_FILENAME "/hosts"
+#endif
+
/* CygWin &

also

 if (0 == strcmp(Config.etcHostsPath, "$SYSNETDB/hosts")) {

is dangerous - someone may try
$SYSNETDB/squidonlyhosts or somesuch. We know that $SYSNETDB has to be
the beginning ogf the patch, so strncasecmp(Config.etcHostsPath,
"$SYSNETDB",9) would be better, followed up by a xstrdup of the rest of
the path. either that, or in cf.data.pre, mention the whole string as
being the special value - ie $SYSNETDBHOSTS

and

      strcpy(hosts_file, Config.etcHostsPath);

isn't safe programming, you don't know how long Config.etcHostsPath is -
use strncpy anywhere you are not guaranteed that the string will be
shorter than your buffer.. there are a couple of other occurences too.

In the debug statements, I think you should show both the configured
path and the translated path - ie ("etc_hosts: host file is configured
as '%s', resolved to '%s'\n", Config.etcHostsPath, hosts_file) -
otherwise folk will look in their config, and not see what is being
logged.

Other than that looks good to me.

Rob

>
>
>
> -
> =======================================================
> Serassio Guido
> Via Albenga, 11/4 10134 - Torino - ITALY
> Tel. : +39.011.610749
> E-mail: serassio@interfree.it
> serassio@libero.it
> WWW: http://www.serassio.it
Received on Sat Aug 25 2001 - 20:32:56 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:15 MST