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@gnupg.org>
This commit is contained in:
Werner Koch 2016-12-17 21:54:45 +01:00
parent c3c60843ea
commit e77b924fec
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
3 changed files with 67 additions and 2 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);