mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-02 12:01:32 +01:00
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:
parent
c3c60843ea
commit
e77b924fec
@ -1088,6 +1088,12 @@ if test "$build_dirmngr" = "yes"; then
|
|||||||
show_tor_support="${show_tor_support} (no system resolver)"
|
show_tor_support="${show_tor_support} (no system resolver)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test "$have_w32_system" = yes; then
|
||||||
|
if test "$use_libdns" = yes; then
|
||||||
|
DNSLIBS="$DNSLIBS -liphlpapi"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
LIBS=$_dns_save_libs
|
LIBS=$_dns_save_libs
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -31,10 +31,12 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#ifdef HAVE_W32_SYSTEM
|
#ifdef HAVE_W32_SYSTEM
|
||||||
|
# define WIN32_LEAN_AND_MEAN
|
||||||
# ifdef HAVE_WINSOCK2_H
|
# ifdef HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
# endif
|
# endif
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
|
# include <iphlpapi.h>
|
||||||
#else
|
#else
|
||||||
# if HAVE_SYSTEM_RESOLVER
|
# if HAVE_SYSTEM_RESOLVER
|
||||||
# include <netinet/in.h>
|
# include <netinet/in.h>
|
||||||
@ -46,6 +48,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
/* William Ahern's DNS library, included as a source copy. */
|
/* William Ahern's DNS library, included as a source copy. */
|
||||||
#ifdef USE_LIBDNS
|
#ifdef USE_LIBDNS
|
||||||
# include "dns.h"
|
# 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. */
|
/* Return H_ERRNO mapped to a gpg-error code. Will never return 0. */
|
||||||
static gpg_error_t
|
static gpg_error_t
|
||||||
get_h_errno_as_gpg_error (void)
|
get_h_errno_as_gpg_error (void)
|
||||||
@ -245,7 +250,7 @@ get_h_errno_as_gpg_error (void)
|
|||||||
}
|
}
|
||||||
return gpg_error (ec);
|
return gpg_error (ec);
|
||||||
}
|
}
|
||||||
|
#endif /*!HAVE_W32_SYSTEM*/
|
||||||
|
|
||||||
static gpg_error_t
|
static gpg_error_t
|
||||||
map_eai_to_gpg_error (int ec)
|
map_eai_to_gpg_error (int ec)
|
||||||
@ -323,7 +328,6 @@ libdns_init (void)
|
|||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
struct libdns_s ld;
|
struct libdns_s ld;
|
||||||
int derr;
|
int derr;
|
||||||
const char *fname;
|
|
||||||
char *cfgstr = NULL;
|
char *cfgstr = NULL;
|
||||||
|
|
||||||
if (libdns.resolv_conf)
|
if (libdns.resolv_conf)
|
||||||
@ -378,6 +382,47 @@ libdns_init (void)
|
|||||||
}
|
}
|
||||||
else
|
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";
|
fname = "/etc/resolv.conf";
|
||||||
err = libdns_error_to_gpg_error
|
err = libdns_error_to_gpg_error
|
||||||
(dns_resconf_loadpath (ld.resolv_conf, fname));
|
(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));
|
log_error ("failed to load '%s': %s\n", fname, gpg_strerror (err));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* Unix */
|
||||||
}
|
}
|
||||||
|
|
||||||
ld.hosts = dns_hosts_open (&derr);
|
ld.hosts = dns_hosts_open (&derr);
|
||||||
|
@ -33,6 +33,16 @@ static int verbose;
|
|||||||
static int debug;
|
static int debug;
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_sockets (void)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_W32_SYSTEM
|
||||||
|
WSADATA wsadat;
|
||||||
|
|
||||||
|
WSAStartup (0x202, &wsadat);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
@ -147,6 +157,8 @@ main (int argc, char **argv)
|
|||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init_sockets ();
|
||||||
|
|
||||||
if (opt_tor)
|
if (opt_tor)
|
||||||
{
|
{
|
||||||
err = enable_dns_tormode (opt_new_circuit);
|
err = enable_dns_tormode (opt_new_circuit);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user