dirmngr: Do not assume that /etc/hosts exists.

* dirmngr/dns-stuff.c (libdns_init): Do not bail out.
--

A standard Windows installation does not have a hosts file and thus we
can't bail out here.  We should also not bail out on a Unix system
because /etc/hosts is just one method in  nsswitch.conf.

Fixes-commit: 88f1505f06
Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2017-04-03 19:10:50 +02:00
parent c6b5611c23
commit 5d873f288e
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 12 additions and 4 deletions

View File

@ -538,10 +538,9 @@ libdns_init (void)
goto leave;
}
{
#if HAVE_W32_SYSTEM
char *hosts_path = xtryasprintf ("%s\System32\drivers\etc\hosts",
char *hosts_path = xtryasprintf ("%s\\System32\\drivers\\etc\\hosts",
getenv ("SystemRoot"));
if (! hosts_path)
{
@ -551,15 +550,24 @@ libdns_init (void)
derr = dns_hosts_loadpath (ld.hosts, hosts_path);
xfree (hosts_path);
if (derr)
{
err = libdns_error_to_gpg_error (derr);
/* Most Windows systems don't have a hosts files. So do not
* report in this case. */
if (gpg_err_code (err) != GPG_ERR_ENOENT)
log_error ("failed to load hosts file: %s\n", gpg_strerror (err));
err = 0; /* Do not bail out. */
}
#else
derr = dns_hosts_loadpath (ld.hosts, "/etc/hosts");
#endif
if (derr)
{
err = libdns_error_to_gpg_error (derr);
log_error ("failed to load hosts file: %s\n", gpg_strerror (err));
goto leave;
err = 0; /* Do not bail out - having no /etc/hosts is legal. */
}
#endif
}
/* dns_hints_local for stub mode, dns_hints_root for recursive. */