chiark / gitweb /
Import gnupg2_2.1.18-8~deb9u1.debian.tar.bz2
[gnupg2.git] / patches / 0060-dirmngr-Do-not-assume-that-etc-hosts-exists.patch
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.
4
5 * dirmngr/dns-stuff.c (libdns_init): Do not bail out.
6 --
7
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.
11
12 Fixes-commit: 88f1505f0613894d5544290a170119eb538921e5
13 Signed-off-by: Werner Koch <wk@gnupg.org>
14 (cherry picked from commit 5d873f288e86edfb684f4dd57ac36466b06494a4)
15 ---
16  dirmngr/dns-stuff.c | 16 ++++++++++++----
17  1 file changed, 12 insertions(+), 4 deletions(-)
18
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)
24        goto leave;
25      }
26  
27 -
28    {
29  #if HAVE_W32_SYSTEM
30 -    char *hosts_path = xtryasprintf ("%s\System32\drivers\etc\hosts",
31 +    char *hosts_path = xtryasprintf ("%s\\System32\\drivers\\etc\\hosts",
32                                       getenv ("SystemRoot"));
33      if (! hosts_path)
34        {
35 @@ -551,15 +550,24 @@ libdns_init (void)
36  
37      derr = dns_hosts_loadpath (ld.hosts, hosts_path);
38      xfree (hosts_path);
39 +    if (derr)
40 +      {
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.  */
47 +      }
48  #else
49      derr = dns_hosts_loadpath (ld.hosts, "/etc/hosts");
50 -#endif
51      if (derr)
52        {
53          err = libdns_error_to_gpg_error (derr);
54          log_error ("failed to load hosts file: %s\n", gpg_strerror (err));
55 -        goto leave;
56 +        err = 0; /* Do not bail out - having no /etc/hosts is legal.  */
57        }
58 +#endif
59    }
60  
61    /* dns_hints_local for stub mode, dns_hints_root for recursive.  */