[Pkg-gnupg-commit] [gnupg2] 147/180: dirmngr: Fix setup of libdns for W32.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Sat Dec 24 22:29:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit e77b924fec1082faae48cdd2ff8474874a22bdf7
Author: Werner Koch <wk at gnupg.org>
Date:   Sat Dec 17 21:54:45 2016 +0100

    dirmngr: Fix setup of libdns for W32.
    
    * configure.ac (DNSLIB) {W32]: Add -liphlpapi.
    * dirmngr/dns-stuff.c [W32]: Include iphlpapi.h and define
    WIN32_LEAN_AND_MEAN.
    (libdns_init) [W32]: Use GetNetworkParams to get the nameserver.
    * dirmngr/t-dns-stuff.c (init_sockets): New.
    (main): Call it.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 configure.ac          |  6 ++++++
 dirmngr/dns-stuff.c   | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 dirmngr/t-dns-stuff.c | 12 ++++++++++++
 3 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1c467bf..6630610 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1088,6 +1088,12 @@ if test "$build_dirmngr" = "yes"; then
     show_tor_support="${show_tor_support} (no system resolver)"
   fi
 
+  if test "$have_w32_system" = yes; then
+    if test "$use_libdns" = yes; then
+      DNSLIBS="$DNSLIBS -liphlpapi"
+    fi
+  fi
+
   LIBS=$_dns_save_libs
 fi
 
diff --git a/dirmngr/dns-stuff.c b/dirmngr/dns-stuff.c
index 1fc81b2..eae674f 100644
--- a/dirmngr/dns-stuff.c
+++ b/dirmngr/dns-stuff.c
@@ -31,10 +31,12 @@
 #include <config.h>
 #include <sys/types.h>
 #ifdef HAVE_W32_SYSTEM
+# define WIN32_LEAN_AND_MEAN
 # ifdef HAVE_WINSOCK2_H
 #  include <winsock2.h>
 # endif
 # include <windows.h>
+# include <iphlpapi.h>
 #else
 # if HAVE_SYSTEM_RESOLVER
 #  include <netinet/in.h>
@@ -46,6 +48,7 @@
 #include <string.h>
 #include <unistd.h>
 
+
 /* William Ahern's DNS library, included as a source copy.  */
 #ifdef USE_LIBDNS
 # include "dns.h"
@@ -229,6 +232,8 @@ free_dns_addrinfo (dns_addrinfo_t ai)
     }
 }
 
+
+#ifndef HAVE_W32_SYSTEM
 /* Return H_ERRNO mapped to a gpg-error code.  Will never return 0. */
 static gpg_error_t
 get_h_errno_as_gpg_error (void)
@@ -245,7 +250,7 @@ get_h_errno_as_gpg_error (void)
     }
   return gpg_error (ec);
 }
-
+#endif /*!HAVE_W32_SYSTEM*/
 
 static gpg_error_t
 map_eai_to_gpg_error (int ec)
@@ -323,7 +328,6 @@ libdns_init (void)
   gpg_error_t err;
   struct libdns_s ld;
   int derr;
-  const char *fname;
   char *cfgstr = NULL;
 
   if (libdns.resolv_conf)
@@ -378,6 +382,47 @@ libdns_init (void)
     }
   else
     {
+#ifdef HAVE_W32_SYSTEM
+      ULONG ninfo_len;
+      PFIXED_INFO ninfo;
+      PIP_ADDR_STRING pip;
+      int idx;
+
+      ninfo_len = 2048;
+      ninfo = xtrymalloc (ninfo_len);
+      if (!ninfo)
+        {
+          err = gpg_error_from_syserror ();
+          goto leave;
+        }
+
+      if (GetNetworkParams (ninfo, &ninfo_len))
+        {
+          log_error ("GetNetworkParms failed: %s\n", w32_strerror (-1));
+          err = gpg_error (GPG_ERR_GENERAL);
+          xfree (ninfo);
+          goto leave;
+        }
+
+      for (idx=0, pip = &(ninfo->DnsServerList);
+           pip && idx < DIM (ld.resolv_conf->nameserver);
+           pip = pip->Next)
+        {
+          log_debug ("ninfo->dnsserver[%d] '%s'\n", idx, pip->IpAddress.String);
+          err = libdns_error_to_gpg_error
+            (dns_resconf_pton (&ld.resolv_conf->nameserver[idx],
+                               pip->IpAddress.String));
+          if (err)
+            log_error ("failed to set nameserver[%d] '%s': %s\n",
+                       idx, pip->IpAddress.String, gpg_strerror (err));
+          else
+            idx++;
+        }
+      xfree (ninfo);
+
+#else /* Unix */
+      const char *fname;
+
       fname = "/etc/resolv.conf";
       err = libdns_error_to_gpg_error
         (dns_resconf_loadpath (ld.resolv_conf, fname));
@@ -395,6 +440,8 @@ libdns_init (void)
           log_error ("failed to load '%s': %s\n", fname, gpg_strerror (err));
           goto leave;
         }
+
+#endif /* Unix */
     }
 
   ld.hosts = dns_hosts_open (&derr);
diff --git a/dirmngr/t-dns-stuff.c b/dirmngr/t-dns-stuff.c
index 5315138..dd8e21e 100644
--- a/dirmngr/t-dns-stuff.c
+++ b/dirmngr/t-dns-stuff.c
@@ -33,6 +33,16 @@ static int verbose;
 static int debug;
 
 
+static void
+init_sockets (void)
+{
+#ifdef HAVE_W32_SYSTEM
+  WSADATA wsadat;
+
+  WSAStartup (0x202, &wsadat);
+#endif
+}
+
 
 int
 main (int argc, char **argv)
@@ -147,6 +157,8 @@ main (int argc, char **argv)
       exit (1);
     }
 
+  init_sockets ();
+
   if (opt_tor)
     {
       err = enable_dns_tormode (opt_new_circuit);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list