1 From: Werner Koch <wk@gnupg.org>
2 Date: Mon, 3 Apr 2017 19:10:50 +0200
3 Subject: dirmngr: Do not assume that /etc/hosts exists.
5 * dirmngr/dns-stuff.c (libdns_init): Do not bail out.
8 A standard Windows installation does not have a hosts file and thus we
9 can't bail out here. We should also not bail out on a Unix system
10 because /etc/hosts is just one method in nsswitch.conf.
12 Fixes-commit: 88f1505f0613894d5544290a170119eb538921e5
13 Signed-off-by: Werner Koch <wk@gnupg.org>
14 (cherry picked from commit 5d873f288e86edfb684f4dd57ac36466b06494a4)
16 dirmngr/dns-stuff.c | 16 ++++++++++++----
17 1 file changed, 12 insertions(+), 4 deletions(-)
19 diff --git a/dirmngr/dns-stuff.c b/dirmngr/dns-stuff.c
20 index c79a9c7..c2d5488 100644
21 --- a/dirmngr/dns-stuff.c
22 +++ b/dirmngr/dns-stuff.c
23 @@ -538,10 +538,9 @@ libdns_init (void)
30 - char *hosts_path = xtryasprintf ("%s\System32\drivers\etc\hosts",
31 + char *hosts_path = xtryasprintf ("%s\\System32\\drivers\\etc\\hosts",
32 getenv ("SystemRoot"));
35 @@ -551,15 +550,24 @@ libdns_init (void)
37 derr = dns_hosts_loadpath (ld.hosts, hosts_path);
41 + err = libdns_error_to_gpg_error (derr);
42 + /* Most Windows systems don't have a hosts files. So do not
43 + * report in this case. */
44 + if (gpg_err_code (err) != GPG_ERR_ENOENT)
45 + log_error ("failed to load hosts file: %s\n", gpg_strerror (err));
46 + err = 0; /* Do not bail out. */
49 derr = dns_hosts_loadpath (ld.hosts, "/etc/hosts");
53 err = libdns_error_to_gpg_error (derr);
54 log_error ("failed to load hosts file: %s\n", gpg_strerror (err));
56 + err = 0; /* Do not bail out - having no /etc/hosts is legal. */
61 /* dns_hints_local for stub mode, dns_hints_root for recursive. */