diff --git a/configure.ac b/configure.ac index 1c467bfff..663061031 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 1fc81b27a..eae674f5a 100644 --- a/dirmngr/dns-stuff.c +++ b/dirmngr/dns-stuff.c @@ -31,10 +31,12 @@ #include #include #ifdef HAVE_W32_SYSTEM +# define WIN32_LEAN_AND_MEAN # ifdef HAVE_WINSOCK2_H # include # endif # include +# include #else # if HAVE_SYSTEM_RESOLVER # include @@ -46,6 +48,7 @@ #include #include + /* 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 531513800..dd8e21e2e 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);