From 0fc43d4a6216c32c97b31d0340dd12a10a8c4030 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Thu, 3 Sep 2009 10:07:13 +0000 Subject: [PATCH] Luca Bruno's patch. git-svn-id: file:///svn/unbound/trunk@1806 be551aaa-1e26-0410-a405-d3ace91eadb9 --- config.h.in | 3 ++ configure | 4 ++- configure.ac | 3 +- doc/CREDITS | 1 + doc/Changelog | 4 +++ doc/libunbound.3.in | 6 ++-- libunbound/libunbound.c | 71 +++++++++++++++++++++++++++++++++++++++-- 7 files changed, 86 insertions(+), 6 deletions(-) diff --git a/config.h.in b/config.h.in index 02962bac5..ca10de5ab 100644 --- a/config.h.in +++ b/config.h.in @@ -125,6 +125,9 @@ /* if the function 'ioctlsocket' is available */ #undef HAVE_IOCTLSOCKET +/* Define to 1 if you have the header file. */ +#undef HAVE_IPHLPAPI_H + /* Define to 1 if you have the `kill' function. */ #undef HAVE_KILL diff --git a/configure b/configure index cd17c6850..1479b3a30 100755 --- a/configure +++ b/configure @@ -13501,7 +13501,8 @@ CC="$lt_save_CC" -for ac_header in stdarg.h stdbool.h netinet/in.h sys/param.h sys/socket.h sys/uio.h sys/resource.h arpa/inet.h syslog.h netdb.h sys/wait.h pwd.h glob.h grp.h login_cap.h winsock2.h ws2tcpip.h + +for ac_header in stdarg.h stdbool.h netinet/in.h sys/param.h sys/socket.h sys/uio.h sys/resource.h arpa/inet.h syslog.h netdb.h sys/wait.h pwd.h glob.h grp.h login_cap.h winsock2.h ws2tcpip.h iphlpapi.h do as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 @@ -20903,6 +20904,7 @@ else WINDRES="$ac_cv_prog_WINDRES" fi + LIBS="$LIBS -liphlpapi" fi if test $ac_cv_func_getaddrinfo = no; then case " $LIBOBJS " in diff --git a/configure.ac b/configure.ac index 8728053c8..e070ea6a8 100644 --- a/configure.ac +++ b/configure.ac @@ -198,7 +198,7 @@ AC_CHECK_TOOL(STRIP, strip) ACX_LIBTOOL_C_ONLY # Checks for header files. -AC_CHECK_HEADERS([stdarg.h stdbool.h netinet/in.h sys/param.h sys/socket.h sys/uio.h sys/resource.h arpa/inet.h syslog.h netdb.h sys/wait.h pwd.h glob.h grp.h login_cap.h winsock2.h ws2tcpip.h],,, [AC_INCLUDES_DEFAULT]) +AC_CHECK_HEADERS([stdarg.h stdbool.h netinet/in.h sys/param.h sys/socket.h sys/uio.h sys/resource.h arpa/inet.h syslog.h netdb.h sys/wait.h pwd.h glob.h grp.h login_cap.h winsock2.h ws2tcpip.h iphlpapi.h ],,, [AC_INCLUDES_DEFAULT]) # check for types. # Using own tests for int64* because autoconf builtin only give 32bit. @@ -528,6 +528,7 @@ if test "$USE_WINSOCK" = 1; then UB_ON_WINDOWS=yes AC_SUBST(UB_ON_WINDOWS) AC_CHECK_TOOL(WINDRES, windres) + LIBS="$LIBS -liphlpapi" fi if test $ac_cv_func_getaddrinfo = no; then AC_LIBOBJ([fake-rfc2553]) diff --git a/doc/CREDITS b/doc/CREDITS index b01bc2a77..499b7ba15 100644 --- a/doc/CREDITS +++ b/doc/CREDITS @@ -16,3 +16,4 @@ Alexander Gall - multihomed, anycast testing of unbound resolver server. Zdenek Vasicek and Marek Vavrusa - python module. cz.nic - sponsoring 'summer of code' development by Zdenek and Marek. Brett Carr - windows beta testing. +Luca Bruno - patch for windows support in libunbound hosts and resolvconf(). diff --git a/doc/Changelog b/doc/Changelog index 5ec1ff2b2..f6eeb105c 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +3 September 2009: Wouter + - Got a patch from Luca Bruno for libunbound support on windows to + pick up the system resolvconf nameservers and hosts there. + 2 September 2009: Wouter - TRAFFIC keyword for testbound. Simplifies test generation. ${range lower val upper} to check probe timeout values. diff --git a/doc/libunbound.3.in b/doc/libunbound.3.in index 6ff734d8a..ddb7eeb37 100644 --- a/doc/libunbound.3.in +++ b/doc/libunbound.3.in @@ -201,14 +201,16 @@ Usually "/etc/resolv.conf". Uses those nameservers as caching proxies. If they do not support DNSSEC, validation may fail. Only nameservers are picked up, the searchdomain, ndots and other settings from \fIresolv.conf\fR(5) are ignored. -If fname NULL is passed, "/etc/resolv.conf" is used. +If fname NULL is passed, "/etc/resolv.conf" is used (if on Windows, +the system\-wide configured nameserver is picked instead). At this time it is only possible to set configuration before the first resolve is done. .TP .B ub_ctx_hosts Read list of hosts from the filename given. Usually "/etc/hosts". When queried for, these addresses are not marked -DNSSEC secure. If fname NULL is passed, "/etc/hosts" is used. +DNSSEC secure. If fname NULL is passed, "/etc/hosts" is used +(if on Windows, etc/hosts from WINDIR is picked instead). At this time it is only possible to set configuration before the first resolve is done. .TP diff --git a/libunbound/libunbound.c b/libunbound/libunbound.c index d4500e364..6df145bb1 100644 --- a/libunbound/libunbound.c +++ b/libunbound/libunbound.c @@ -60,6 +60,11 @@ #include "services/cache/infra.h" #include "services/cache/rrset.h" +#if defined(UB_ON_WINDOWS) && defined (HAVE_WINDOWS_H) +#include +#include +#endif /* UB_ON_WINDOWS */ + struct ub_ctx* ub_ctx_create() { @@ -788,8 +793,47 @@ ub_ctx_resolvconf(struct ub_ctx* ctx, char* fname) char buf[1024]; char* parse, *addr; int r; - if(fname == NULL) + + if(fname == NULL) { +#if !defined(UB_ON_WINDOWS) || !defined(HAVE_WINDOWS_H) fname = "/etc/resolv.conf"; +#else + FIXED_INFO *info; + ULONG buflen = sizeof(*info); + IP_ADDR_STRING *ptr; + + info = (FIXED_INFO *) malloc(sizeof (FIXED_INFO)); + if (info == NULL) + return UB_READFILE; + + if (GetNetworkParams(info, &buflen) == ERROR_BUFFER_OVERFLOW) { + free(info); + info = (FIXED_INFO *) malloc(buflen); + if (info == NULL) + return UB_READFILE; + } + + if (GetNetworkParams(info, &buflen) == NO_ERROR) { + int retval=0; + ptr = &(info->DnsServerList); + while (ptr) { + numserv++; + if((retval=ub_ctx_set_fwd(ctx, + ptr->IpAddress.String)!=0)) { + free(info); + return retval; + } + ptr = ptr->Next; + } + free(info); + if (numserv==0) + return UB_READFILE; + return UB_NOERROR; + } + free(info); + return UB_READFILE; +#endif /* WINDOWS */ + } in = fopen(fname, "r"); if(!in) { /* error in errno! perror(fname) */ @@ -840,8 +884,31 @@ ub_ctx_hosts(struct ub_ctx* ctx, char* fname) return UB_AFTERFINAL; } lock_basic_unlock(&ctx->cfglock); - if(fname == NULL) + if(fname == NULL) { +#if defined(UB_ON_WINDOWS) && defined(HAVE_WINDOWS_H) + /* + * If this is Windows NT/XP/2K it's in + * %WINDIR%\system32\drivers\etc\hosts. + * If this is Windows 95/98/Me it's in %WINDIR%\hosts. + */ + name = getenv("WINDIR"); + if (name != NULL) { + int retval=0; + snprintf(buf, sizeof(buf), "%s%s", name, + "\\system32\\drivers\\etc\\hosts"); + if((retval=ub_ctx_hosts(ctx, buf)) !=0 ) { + snprintf(buf, sizeof(buf), "%s%s", name, + "\\hosts"); + retval=ub_ctx_hosts(ctx, buf); + } + free(name); + return retval; + } + return UB_READFILE; +#else fname = "/etc/hosts"; +#endif /* WIN32 */ + } in = fopen(fname, "r"); if(!in) { /* error in errno! perror(fname) */ -- 2.47.3