]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[rt36039]
authorMark Andrews <marka@isc.org>
Wed, 30 Jul 2014 13:26:37 +0000 (23:26 +1000)
committerMark Andrews <marka@isc.org>
Wed, 30 Jul 2014 13:35:07 +0000 (23:35 +1000)
3902.   bug]            liblwres wasn't handling link-local addresses in
                        nameserver clauses in resolv.conf. [RT #36039]

(cherry picked from commit 70be3889746884692aa49939833d624ddd432bf0)

20 files changed:
CHANGES
bin/dig/dighost.c
config.h.in
configure
configure.in
lib/Atffile
lib/lwres/Atffile [new file with mode: 0644]
lib/lwres/Makefile.in
lib/lwres/compat.c [moved from lib/lwres/strtoul.c with 89% similarity]
lib/lwres/getaddrinfo.c
lib/lwres/include/lwres/Makefile.in
lib/lwres/include/lwres/compat.h [moved from lib/lwres/include/lwres/stdlib.h with 84% similarity]
lib/lwres/include/lwres/lwres.h
lib/lwres/include/lwres/platform.h.in
lib/lwres/lwconfig.c
lib/lwres/print.c
lib/lwres/tests/Atffile [new file with mode: 0644]
lib/lwres/tests/Makefile.in [new file with mode: 0644]
lib/lwres/tests/config_test.c [new file with mode: 0644]
lib/lwres/tests/testdata/link-local.conf [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 49181303bbdb10356feba55955b93e373fea4928..45eb262b7d519f55460e8f65a9441bc4f49e2476 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+3902.  bug]            liblwres wasn't handling link-local addresses in
+                       nameserver clauses in resolv.conf. [RT #36039]
+
 3901.  [protocol]      Added support for CAA record type (RFC 6844).
                        [RT #36625]
 
index 412bb79e87d1246125ebfadf81dfde9707f5b38d..06a8dfddbae477be3af9f62659a69176708f7521 100644 (file)
@@ -613,7 +613,8 @@ addr2af(int lwresaddrtype)
 static void
 copy_server_list(lwres_conf_t *confdata, dig_serverlist_t *dest) {
        dig_server_t *newsrv;
-       char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
+       char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") +
+                sizeof("%4000000000")];
        int af;
        int i;
 
@@ -628,6 +629,12 @@ copy_server_list(lwres_conf_t *confdata, dig_serverlist_t *dest) {
 
                lwres_net_ntop(af, confdata->nameservers[i].address,
                                   tmp, sizeof(tmp));
+               if (af == AF_INET6 && confdata->nameservers[i].zone != 0) {
+                       char buf[sizeof("%4000000000")];
+                       snprintf(buf, sizeof(buf), "%%%u",
+                                confdata->nameservers[i].zone);
+                       strlcat(tmp, buf, sizeof(tmp));
+               }
                newsrv = make_server(tmp, tmp);
                ISC_LINK_INIT(newsrv, link);
                ISC_LIST_ENQUEUE(*dest, newsrv, link);
index 06ea8bf3f8279e954c9de4f0c6c2a169dfd555a9..936c7596f5ec982c9c85ff2085db5ee7dc45a567 100644 (file)
@@ -229,6 +229,9 @@ int sigwait(const unsigned int *set, int *sig);
 /* Define to 1 if you have the <gssapi_krb5.h> header file. */
 #undef HAVE_GSSAPI_KRB5_H
 
+/* Define to 1 if you have the `if_nametoindex' function. */
+#undef HAVE_IF_NAMETOINDEX
+
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
index 47c5729c52fa18ea2e31b55e05d95f12207338c9..9255f12dfbfcc6fab479d503a617eb47c428e73f 100755 (executable)
--- a/configure
+++ b/configure
@@ -728,6 +728,7 @@ ISC_PLATFORM_NEEDVSNPRINTF
 LWRES_PLATFORM_NEEDSPRINTF
 ISC_PLATFORM_NEEDSPRINTF
 ISC_PLATFORM_NEEDSTRLCAT
+LWRES_PLATFORM_NEEDSTRLCPY
 ISC_PLATFORM_NEEDSTRLCPY
 GENRANDOMLIB
 LWRES_PLATFORM_NEEDSTRTOUL
 ac_fn_c_check_func "$LINENO" "strlcpy" "ac_cv_func_strlcpy"
 if test "x$ac_cv_func_strlcpy" = xyes; then :
   ISC_PLATFORM_NEEDSTRLCPY="#undef ISC_PLATFORM_NEEDSTRLCPY"
+         LWRES_PLATFORM_NEEDSTRLCPY="#undef LWRES_PLATFORM_NEEDSTRLCPY"
 else
   ISC_PLATFORM_NEEDSTRLCPY="#define ISC_PLATFORM_NEEDSTRLCPY 1"
+         LWRES_PLATFORM_NEEDSTRLCPY="#define LWRES_PLATFORM_NEEDSTRLCPY 1"
 fi
 
 
 
+
 ac_fn_c_check_func "$LINENO" "strlcat" "ac_cv_func_strlcat"
 if test "x$ac_cv_func_strlcat" = xyes; then :
   ISC_PLATFORM_NEEDSTRLCAT="#undef ISC_PLATFORM_NEEDSTRLCAT"
@@ -17613,6 +17617,8 @@ esac
 case $ac_cv_have_if_nametoindex in
 yes)
        ISC_PLATFORM_HAVEIFNAMETOINDEX="#define ISC_PLATFORM_HAVEIFNAMETOINDEX 1"
+       $as_echo "#define HAVE_IF_NAMETOINDEX 1" >>confdefs.h
+
        ;;
 *)
        ISC_PLATFORM_HAVEIFNAMETOINDEX="#undef ISC_PLATFORM_HAVEIFNAMETOINDEX"
@@ -20085,7 +20091,7 @@ ac_config_commands="$ac_config_commands chmod"
 # elsewhere if there's a good reason for doing so.
 #
 
-ac_config_files="$ac_config_files make/Makefile make/mkdep Makefile bin/Makefile bin/check/Makefile bin/confgen/Makefile bin/confgen/unix/Makefile bin/dig/Makefile bin/dnssec/Makefile bin/named/Makefile bin/named/unix/Makefile bin/nsupdate/Makefile bin/pkcs11/Makefile bin/rndc/Makefile bin/tests/Makefile bin/tests/atomic/Makefile bin/tests/db/Makefile bin/tests/dst/Makefile bin/tests/dst/Kdh.+002+18602.key bin/tests/dst/Kdh.+002+18602.private bin/tests/dst/Kdh.+002+48957.key bin/tests/dst/Kdh.+002+48957.private bin/tests/dst/Ktest.+001+00002.key bin/tests/dst/Ktest.+001+54622.key bin/tests/dst/Ktest.+001+54622.private bin/tests/dst/Ktest.+003+23616.key bin/tests/dst/Ktest.+003+23616.private bin/tests/dst/Ktest.+003+49667.key bin/tests/dst/dst_2_data bin/tests/dst/t2_data_1 bin/tests/dst/t2_data_2 bin/tests/dst/t2_dsasig bin/tests/dst/t2_rsasig bin/tests/hashes/Makefile bin/tests/headerdep_test.sh bin/tests/master/Makefile bin/tests/mem/Makefile bin/tests/names/Makefile bin/tests/net/Makefile bin/tests/rbt/Makefile bin/tests/resolver/Makefile bin/tests/sockaddr/Makefile bin/tests/system/Makefile bin/tests/system/conf.sh bin/tests/system/dlz/prereq.sh bin/tests/system/dlzexternal/Makefile bin/tests/system/dlzexternal/ns1/named.conf bin/tests/system/filter-aaaa/Makefile bin/tests/system/lwresd/Makefile bin/tests/system/rpz/Makefile bin/tests/system/tkey/Makefile bin/tests/system/tsiggss/Makefile bin/tests/tasks/Makefile bin/tests/timers/Makefile bin/tests/virtual-time/Makefile bin/tests/virtual-time/conf.sh bin/tools/Makefile contrib/check-secure-delegation.pl contrib/zone-edit.sh doc/Makefile doc/arm/Makefile doc/doxygen/Doxyfile doc/doxygen/Makefile doc/doxygen/doxygen-input-filter doc/misc/Makefile doc/xsl/Makefile doc/xsl/isc-docbook-chunk.xsl doc/xsl/isc-docbook-html.xsl doc/xsl/isc-docbook-latex.xsl doc/xsl/isc-manpage.xsl isc-config.sh lib/Makefile lib/bind9/Makefile lib/bind9/include/Makefile lib/bind9/include/bind9/Makefile lib/dns/Makefile lib/dns/include/Makefile lib/dns/include/dns/Makefile lib/dns/include/dst/Makefile lib/dns/tests/Makefile lib/export/Makefile lib/export/dns/Makefile lib/export/dns/include/Makefile lib/export/dns/include/dns/Makefile lib/export/dns/include/dst/Makefile lib/export/irs/Makefile lib/export/irs/include/Makefile lib/export/irs/include/irs/Makefile lib/export/isc/$thread_dir/Makefile lib/export/isc/$thread_dir/include/Makefile lib/export/isc/$thread_dir/include/isc/Makefile lib/export/isc/Makefile lib/export/isc/include/Makefile lib/export/isc/include/isc/Makefile lib/export/isc/nls/Makefile lib/export/isc/unix/Makefile lib/export/isc/unix/include/Makefile lib/export/isc/unix/include/isc/Makefile lib/export/isccfg/Makefile lib/export/isccfg/include/Makefile lib/export/isccfg/include/isccfg/Makefile lib/export/samples/Makefile lib/export/samples/Makefile-postinstall lib/irs/Makefile lib/irs/include/Makefile lib/irs/include/irs/Makefile lib/irs/include/irs/netdb.h lib/irs/include/irs/platform.h lib/isc/$arch/Makefile lib/isc/$arch/include/Makefile lib/isc/$arch/include/isc/Makefile lib/isc/$thread_dir/Makefile lib/isc/$thread_dir/include/Makefile lib/isc/$thread_dir/include/isc/Makefile lib/isc/Makefile lib/isc/include/Makefile lib/isc/include/isc/Makefile lib/isc/include/isc/platform.h lib/isc/tests/Makefile lib/isc/nls/Makefile lib/isc/unix/Makefile lib/isc/unix/include/Makefile lib/isc/unix/include/isc/Makefile lib/isccc/Makefile lib/isccc/include/Makefile lib/isccc/include/isccc/Makefile lib/isccfg/Makefile lib/isccfg/include/Makefile lib/isccfg/include/isccfg/Makefile lib/lwres/Makefile lib/lwres/include/Makefile lib/lwres/include/lwres/Makefile lib/lwres/include/lwres/netdb.h lib/lwres/include/lwres/platform.h lib/lwres/man/Makefile lib/lwres/unix/Makefile lib/lwres/unix/include/Makefile lib/lwres/unix/include/lwres/Makefile lib/tests/Makefile lib/tests/include/Makefile lib/tests/include/tests/Makefile unit/Makefile unit/unittest.sh"
+ac_config_files="$ac_config_files make/Makefile make/mkdep Makefile bin/Makefile bin/check/Makefile bin/confgen/Makefile bin/confgen/unix/Makefile bin/dig/Makefile bin/dnssec/Makefile bin/named/Makefile bin/named/unix/Makefile bin/nsupdate/Makefile bin/pkcs11/Makefile bin/rndc/Makefile bin/tests/Makefile bin/tests/atomic/Makefile bin/tests/db/Makefile bin/tests/dst/Makefile bin/tests/dst/Kdh.+002+18602.key bin/tests/dst/Kdh.+002+18602.private bin/tests/dst/Kdh.+002+48957.key bin/tests/dst/Kdh.+002+48957.private bin/tests/dst/Ktest.+001+00002.key bin/tests/dst/Ktest.+001+54622.key bin/tests/dst/Ktest.+001+54622.private bin/tests/dst/Ktest.+003+23616.key bin/tests/dst/Ktest.+003+23616.private bin/tests/dst/Ktest.+003+49667.key bin/tests/dst/dst_2_data bin/tests/dst/t2_data_1 bin/tests/dst/t2_data_2 bin/tests/dst/t2_dsasig bin/tests/dst/t2_rsasig bin/tests/hashes/Makefile bin/tests/headerdep_test.sh bin/tests/master/Makefile bin/tests/mem/Makefile bin/tests/names/Makefile bin/tests/net/Makefile bin/tests/rbt/Makefile bin/tests/resolver/Makefile bin/tests/sockaddr/Makefile bin/tests/system/Makefile bin/tests/system/conf.sh bin/tests/system/dlz/prereq.sh bin/tests/system/dlzexternal/Makefile bin/tests/system/dlzexternal/ns1/named.conf bin/tests/system/filter-aaaa/Makefile bin/tests/system/lwresd/Makefile bin/tests/system/rpz/Makefile bin/tests/system/tkey/Makefile bin/tests/system/tsiggss/Makefile bin/tests/tasks/Makefile bin/tests/timers/Makefile bin/tests/virtual-time/Makefile bin/tests/virtual-time/conf.sh bin/tools/Makefile contrib/check-secure-delegation.pl contrib/zone-edit.sh doc/Makefile doc/arm/Makefile doc/doxygen/Doxyfile doc/doxygen/Makefile doc/doxygen/doxygen-input-filter doc/misc/Makefile doc/xsl/Makefile doc/xsl/isc-docbook-chunk.xsl doc/xsl/isc-docbook-html.xsl doc/xsl/isc-docbook-latex.xsl doc/xsl/isc-manpage.xsl isc-config.sh lib/Makefile lib/bind9/Makefile lib/bind9/include/Makefile lib/bind9/include/bind9/Makefile lib/dns/Makefile lib/dns/include/Makefile lib/dns/include/dns/Makefile lib/dns/include/dst/Makefile lib/dns/tests/Makefile lib/export/Makefile lib/export/dns/Makefile lib/export/dns/include/Makefile lib/export/dns/include/dns/Makefile lib/export/dns/include/dst/Makefile lib/export/irs/Makefile lib/export/irs/include/Makefile lib/export/irs/include/irs/Makefile lib/export/isc/$thread_dir/Makefile lib/export/isc/$thread_dir/include/Makefile lib/export/isc/$thread_dir/include/isc/Makefile lib/export/isc/Makefile lib/export/isc/include/Makefile lib/export/isc/include/isc/Makefile lib/export/isc/nls/Makefile lib/export/isc/unix/Makefile lib/export/isc/unix/include/Makefile lib/export/isc/unix/include/isc/Makefile lib/export/isccfg/Makefile lib/export/isccfg/include/Makefile lib/export/isccfg/include/isccfg/Makefile lib/export/samples/Makefile lib/export/samples/Makefile-postinstall lib/irs/Makefile lib/irs/include/Makefile lib/irs/include/irs/Makefile lib/irs/include/irs/netdb.h lib/irs/include/irs/platform.h lib/isc/$arch/Makefile lib/isc/$arch/include/Makefile lib/isc/$arch/include/isc/Makefile lib/isc/$thread_dir/Makefile lib/isc/$thread_dir/include/Makefile lib/isc/$thread_dir/include/isc/Makefile lib/isc/Makefile lib/isc/include/Makefile lib/isc/include/isc/Makefile lib/isc/include/isc/platform.h lib/isc/tests/Makefile lib/isc/nls/Makefile lib/isc/unix/Makefile lib/isc/unix/include/Makefile lib/isc/unix/include/isc/Makefile lib/isccc/Makefile lib/isccc/include/Makefile lib/isccc/include/isccc/Makefile lib/isccfg/Makefile lib/isccfg/include/Makefile lib/isccfg/include/isccfg/Makefile lib/lwres/Makefile lib/lwres/include/Makefile lib/lwres/include/lwres/Makefile lib/lwres/include/lwres/netdb.h lib/lwres/include/lwres/platform.h lib/lwres/man/Makefile lib/lwres/tests/Makefile lib/lwres/unix/Makefile lib/lwres/unix/include/Makefile lib/lwres/unix/include/lwres/Makefile lib/tests/Makefile lib/tests/include/Makefile lib/tests/include/tests/Makefile unit/Makefile unit/unittest.sh"
 
 
 #
@@ -21214,6 +21220,7 @@ do
     "lib/lwres/include/lwres/netdb.h") CONFIG_FILES="$CONFIG_FILES lib/lwres/include/lwres/netdb.h" ;;
     "lib/lwres/include/lwres/platform.h") CONFIG_FILES="$CONFIG_FILES lib/lwres/include/lwres/platform.h" ;;
     "lib/lwres/man/Makefile") CONFIG_FILES="$CONFIG_FILES lib/lwres/man/Makefile" ;;
+    "lib/lwres/tests/Makefile") CONFIG_FILES="$CONFIG_FILES lib/lwres/tests/Makefile" ;;
     "lib/lwres/unix/Makefile") CONFIG_FILES="$CONFIG_FILES lib/lwres/unix/Makefile" ;;
     "lib/lwres/unix/include/Makefile") CONFIG_FILES="$CONFIG_FILES lib/lwres/unix/include/Makefile" ;;
     "lib/lwres/unix/include/lwres/Makefile") CONFIG_FILES="$CONFIG_FILES lib/lwres/unix/include/lwres/Makefile" ;;
index f4a2b9bde9a9fc49e6f024796d7590c69f34d751..5189fc31c5e8927d1e0787ea043ee5c63056361c 100644 (file)
@@ -2335,9 +2335,12 @@ AC_SUBST(LWRES_PLATFORM_NEEDSTRTOUL)
 AC_SUBST(GENRANDOMLIB)
 
 AC_CHECK_FUNC(strlcpy,
-       [ISC_PLATFORM_NEEDSTRLCPY="#undef ISC_PLATFORM_NEEDSTRLCPY"],
-       [ISC_PLATFORM_NEEDSTRLCPY="#define ISC_PLATFORM_NEEDSTRLCPY 1"])
+       [ISC_PLATFORM_NEEDSTRLCPY="#undef ISC_PLATFORM_NEEDSTRLCPY"
+         LWRES_PLATFORM_NEEDSTRLCPY="#undef LWRES_PLATFORM_NEEDSTRLCPY"],
+       [ISC_PLATFORM_NEEDSTRLCPY="#define ISC_PLATFORM_NEEDSTRLCPY 1"
+         LWRES_PLATFORM_NEEDSTRLCPY="#define LWRES_PLATFORM_NEEDSTRLCPY 1"])
 AC_SUBST(ISC_PLATFORM_NEEDSTRLCPY)
+AC_SUBST(LWRES_PLATFORM_NEEDSTRLCPY)
 
 AC_CHECK_FUNC(strlcat,
        [ISC_PLATFORM_NEEDSTRLCAT="#undef ISC_PLATFORM_NEEDSTRLCAT"],
@@ -2693,6 +2696,7 @@ esac
 case $ac_cv_have_if_nametoindex in
 yes)
        ISC_PLATFORM_HAVEIFNAMETOINDEX="#define ISC_PLATFORM_HAVEIFNAMETOINDEX 1"
+       AC_DEFINE(HAVE_IF_NAMETOINDEX, 1)
        ;;
 *)
        ISC_PLATFORM_HAVEIFNAMETOINDEX="#undef ISC_PLATFORM_HAVEIFNAMETOINDEX"
@@ -3747,6 +3751,7 @@ AC_CONFIG_FILES([
        lib/lwres/include/lwres/netdb.h
        lib/lwres/include/lwres/platform.h
        lib/lwres/man/Makefile
+       lib/lwres/tests/Makefile
        lib/lwres/unix/Makefile
        lib/lwres/unix/include/Makefile
        lib/lwres/unix/include/lwres/Makefile
index 76a50ce4aec732078c59b7a0b5d875f042f8d6a3..47b9f7520ca767407f56275a06f4a2ad2084f109 100644 (file)
@@ -4,3 +4,4 @@ prop: test-suite = bind9
 
 tp: dns
 tp: isc
+tp: lwres
diff --git a/lib/lwres/Atffile b/lib/lwres/Atffile
new file mode 100644 (file)
index 0000000..1edb838
--- /dev/null
@@ -0,0 +1,5 @@
+Content-Type: application/X-atf-atffile; version="1"
+
+prop: test-suite = bind9
+
+tp: tests
index 0cf873b51560060169d6d5b497eb86ea2a8727c3..667bff94f7a7cae56371ae5ef5994f8176866831 100644 (file)
@@ -31,25 +31,25 @@ CDEFINES =
 CWARNINGS =
 
 # Alphabetically
-OBJS =         context.@O@ gai_strerror.@O@ getaddrinfo.@O@ gethost.@O@ \
+OBJS =         compat.@O@ context.@O@ \
+               gai_strerror.@O@ getaddrinfo.@O@ gethost.@O@ \
                getipnode.@O@ getnameinfo.@O@ getrrset.@O@ herror.@O@ \
                lwbuffer.@O@ lwconfig.@O@ lwpacket.@O@ lwresutil.@O@ \
                lwres_gabn.@O@ lwres_gnba.@O@ lwres_grbn.@O@ lwres_noop.@O@ \
-               lwinetaton.@O@ lwinetpton.@O@ lwinetntop.@O@ print.@O@ \
-               strtoul.@O@
+               lwinetaton.@O@ lwinetpton.@O@ lwinetntop.@O@ print.@O@
 
 # Alphabetically
-SRCS =         context.c gai_strerror.c getaddrinfo.c gethost.c \
+SRCS =         compat.c context.c gai_strerror.c getaddrinfo.c gethost.c \
                getipnode.c getnameinfo.c getrrset.c herror.c \
                lwbuffer.c lwconfig.c lwpacket.c lwresutil.c \
                lwres_gabn.c lwres_gnba.c lwres_grbn.c lwres_noop.c \
-               lwinetaton.c lwinetpton.c lwinetntop.c print.c \
-               strtoul.c
+               lwinetaton.c lwinetpton.c lwinetntop.c print.c
 
 LIBS =         @LIBS@
 
 SUBDIRS =      include man unix
 TARGETS =      timestamp
+TESTDIRS =     @UNITTESTS@
 
 @BIND9_MAKE_RULES@
 
similarity index 89%
rename from lib/lwres/strtoul.c
rename to lib/lwres/compat.c
index f66f5a7937b51a6aef3666c7c9a9f98cfffb3e9a..9edc5658b9e67cadc5d5a02b503f0d632b7818da 100644 (file)
@@ -57,7 +57,7 @@ static char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93";
 #include <ctype.h>
 #include <errno.h>
 
-#include <lwres/stdlib.h>
+#include <lwres/compat.h>
 
 #define DE_CONST(konst, var) \
        do { \
@@ -129,3 +129,28 @@ lwres_strtoul(const char *nptr, char **endptr, int base) {
                DE_CONST(any ? s - 1 : nptr, *endptr);
        return (acc);
 }
+
+size_t
+lwres_strlcpy(char *dst, const char *src, size_t size) {
+       char *d = dst;
+       const char *s = src;
+       size_t n = size;
+
+       /* Copy as many bytes as will fit */
+       if (n != 0U && --n != 0U) {
+               do {
+                       if ((*d++ = *s++) == 0)
+                               break;
+               } while (--n != 0U);
+       }
+
+       /* Not enough room in dst, add NUL and traverse rest of src */
+       if (n == 0U) {
+               if (size != 0U)
+                       *d = '\0';              /* NUL-terminate dst */
+               while (*s++)
+                       ;
+       }
+
+       return(s - src - 1);    /* count does not include NUL */
+}
index 43211fd07c2bc8e60e462b20ca60d9f06e7419e1..be1f09aafb4d067d5996b1d9d4b16dcbcc25c454 100644 (file)
 #include <config.h>
 
 #include <errno.h>
+#include <string.h>
 
-#include <isc/string.h>
-
+#include <lwres/compat.h>
 #include <lwres/lwres.h>
 #include <lwres/net.h>
 #include <lwres/netdb.h>
-#include <lwres/stdlib.h>
 
 #define SA(addr)       ((struct sockaddr *)(addr))
 #define SIN(addr)      ((struct sockaddr_in *)(addr))
index a32678cfcf1f66fc2e6b5373621e685ebeb52870..9ede380d3e78c9536810986a4957e16b61d1a4f7 100644 (file)
@@ -24,8 +24,8 @@ top_srcdir =  @top_srcdir@
 # machine generated.  The latter are handled specially in the
 # install target below.
 #
-HEADERS =      context.h int.h ipv6.h lang.h list.h lwbuffer.h lwpacket.h \
-               lwres.h result.h stdlib.h version.h
+HEADERS =      compat.h context.h int.h ipv6.h lang.h list.h \
+               lwbuffer.h lwpacket.h lwres.h result.h version.h
 
 SUBDIRS =
 TARGETS =
similarity index 84%
rename from lib/lwres/include/lwres/stdlib.h
rename to lib/lwres/include/lwres/compat.h
index 25a109ee30c70bc6eacc8bed02ba57a1c130b017..5f9b60f8c176321fef961b1e5df85675d2c270f7 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: stdlib.h,v 1.6 2007/06/19 23:47:23 tbox Exp $ */
+#ifndef LWRES_COMPAT_H
+#define LWRES_COMPAT_H 1
 
-#ifndef LWRES_STDLIB_H
-#define LWRES_STDLIB_H 1
-
-/*! \file lwres/stdlib.h */
+/*! \file lwres/compat.h */
 
 #include <stdlib.h>
 
 #define strtoul lwres_strtoul
 #endif
 
+#ifdef LWRES_PLATFORM_NEEDSTRLCPY
+#define strlcpy lwres_strlcpy
+#endif
+
 LWRES_LANG_BEGINDECLS
 
 unsigned long lwres_strtoul(const char *, char **, int);
+size_t lwres_strlcpy(char *dst, const char *src, size_t size);
 
 LWRES_LANG_ENDDECLS
 
index 6912448cf9ee86d9ef589b782925b013e0dad540..c63cbef4da217256d8264290a2f0d80ea08e4ae4 100644 (file)
@@ -121,6 +121,7 @@ struct lwres_addr {
        lwres_uint32_t                  family;
        lwres_uint16_t                  length;
        unsigned char                   address[LWRES_ADDR_MAXLEN];
+       lwres_uint32_t                  zone;
        LWRES_LINK(lwres_addr_t)        link;
 };
 
index bb4f6ee235e9e0fd3f4e839e058ed1d121322918..95ad40b6093a55858c7b4aea04f5985209414874 100644 (file)
  */
 @LWRES_PLATFORM_NEEDSTRTOUL@
 
+/*! \brief
+ * Define if this system needs strlcpy.
+ */
+@LWRES_PLATFORM_NEEDSTRLCPY@
+
 #ifndef LWRES_PLATFORM_USEDECLSPEC
 #define LIBLWRES_EXTERNAL_DATA
 #else
index 62630238e1211b084b7191ec6202fd7642b5ecd5..ec84113c40a0aee6d9fa64dd47da8d0597f77a92 100644 (file)
@@ -15,8 +15,6 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id$ */
-
 /*! \file */
 
 /**
@@ -63,6 +61,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <lwres/compat.h>
 #include <lwres/lwbuffer.h>
 #include <lwres/lwres.h>
 #include <lwres/net.h>
@@ -204,6 +203,7 @@ lwres_resetaddr(lwres_addr_t *addr) {
        memset(addr->address, 0, LWRES_ADDR_MAXLEN);
        addr->family = 0;
        addr->length = 0;
+       addr->zone = 0;
 }
 
 static char *
@@ -449,6 +449,18 @@ static lwres_result_t
 lwres_create_addr(const char *buffer, lwres_addr_t *addr, int convert_zero) {
        struct in_addr v4;
        struct in6_addr v6;
+       char buf[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") +
+                sizeof("%4294967295")];
+       char *percent;
+       size_t n;
+
+       n = strlcpy(buf, buffer, sizeof(buf));
+       if (n >= sizeof(buf))
+               return (LWRES_R_FAILURE);
+
+       percent = strchr(buf, '%');
+       if (percent != NULL)
+               *percent = 0;
 
        if (lwres_net_aton(buffer, &v4) == 1) {
                if (convert_zero) {
@@ -459,15 +471,35 @@ lwres_create_addr(const char *buffer, lwres_addr_t *addr, int convert_zero) {
                }
                addr->family = LWRES_ADDRTYPE_V4;
                addr->length = NS_INADDRSZ;
+               addr->zone = 0;
                memmove((void *)addr->address, &v4, NS_INADDRSZ);
 
-       } else if (lwres_net_pton(AF_INET6, buffer, &v6) == 1) {
+       } else if (lwres_net_pton(AF_INET6, buf, &v6) == 1) {
                addr->family = LWRES_ADDRTYPE_V6;
                addr->length = NS_IN6ADDRSZ;
                memmove((void *)addr->address, &v6, NS_IN6ADDRSZ);
-       } else {
+               if (percent != NULL) {
+                       unsigned long zone;
+                       char *ep;
+
+                       percent++;
+
+#ifdef HAVE_IF_NAMETOINDEX
+                       zone = if_nametoindex(percent);
+                       if (zone != 0) {
+                               addr->zone = zone;
+                               return (LWRES_R_SUCCESS);
+                       }
+#endif
+                       zone = strtoul(percent, &ep, 10);
+                       if (ep != percent && *ep == 0)
+                               addr->zone = zone;
+                       else
+                               return (LWRES_R_FAILURE);
+               } else
+                       addr->zone = 0;
+       } else
                return (LWRES_R_FAILURE); /* Unrecognised format. */
-       }
 
        return (LWRES_R_SUCCESS);
 }
@@ -630,6 +662,7 @@ lwres_conf_print(lwres_context_t *ctx, FILE *fp) {
        int i;
        int af;
        char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
+       char buf[sizeof("%4000000000")];
        const char *p;
        lwres_conf_t *confdata;
        lwres_addr_t tmpaddr;
@@ -647,7 +680,13 @@ lwres_conf_print(lwres_context_t *ctx, FILE *fp) {
                if (p != tmp)
                        return (LWRES_R_FAILURE);
 
-               fprintf(fp, "nameserver %s\n", tmp);
+               if (af == AF_INET6 && confdata->lwservers[i].zone != 0) {
+                       snprintf(buf, sizeof(buf), "%%%u",
+                               confdata->nameservers[i].zone);
+               } else
+                       buf[0] = 0;
+
+               fprintf(fp, "nameserver %s%s\n", tmp, buf);
        }
 
        for (i = 0; i < confdata->lwnext; i++) {
@@ -658,7 +697,13 @@ lwres_conf_print(lwres_context_t *ctx, FILE *fp) {
                if (p != tmp)
                        return (LWRES_R_FAILURE);
 
-               fprintf(fp, "lwserver %s\n", tmp);
+               if (af == AF_INET6 && confdata->lwservers[i].zone != 0) {
+                       snprintf(buf, sizeof(buf), "%%%u",
+                               confdata->nameservers[i].zone);
+               } else
+                       buf[0] = 0;
+
+               fprintf(fp, "lwserver %s%s\n", tmp, buf);
        }
 
        if (confdata->domainname != NULL) {
index 87f30323fe9a729fcd4aab0b64750a30208c4422..ebd54c8046fba7538287309ffc4b5750e39b9779 100644 (file)
@@ -25,7 +25,7 @@
 
 #define        LWRES__PRINT_SOURCE     /* Used to get the lwres_print_* prototypes. */
 
-#include <lwres/stdlib.h>
+#include <lwres/compat.h>
 
 #include "assert_p.h"
 #include "print_p.h"
diff --git a/lib/lwres/tests/Atffile b/lib/lwres/tests/Atffile
new file mode 100644 (file)
index 0000000..c3e044f
--- /dev/null
@@ -0,0 +1,5 @@
+Content-Type: application/X-atf-atffile; version="1"
+
+prop: test-suite = bind9
+
+tp-glob: *_test
diff --git a/lib/lwres/tests/Makefile.in b/lib/lwres/tests/Makefile.in
new file mode 100644 (file)
index 0000000..e0a3293
--- /dev/null
@@ -0,0 +1,54 @@
+# Copyright (C) 2011-2014  Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+# $Id$
+
+srcdir =       @srcdir@
+VPATH =                @srcdir@
+top_srcdir =   @top_srcdir@
+
+# Attempt to disable parallel processing.
+.NOTPARALLEL:
+.NO_PARALLEL:
+
+@BIND9_VERSION@
+
+@BIND9_MAKE_INCLUDES@
+
+CINCLUDES =    -I. -Iinclude -I../include ${LWRES_INCLUDES}
+CDEFINES =     -DTESTS="\"${top_builddir}/lib/lwres/tests/\""
+
+LWRESLIBS =    ../liblwres.@A@
+LWRESDEPLIBS = ../liblwres.@A@
+
+LIBS =         @LIBS@ @ATFLIBS@
+
+OBJS = 
+SRCS =         config_test.c
+
+SUBDIRS =
+TARGETS =      config_test@EXEEXT@
+
+@BIND9_MAKE_RULES@
+
+config_test@EXEEXT@: config_test.@O@ ${LWRESDEPLIBS}
+       ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
+                       config_test.@O@ ${LWRESLIBS} ${LIBS}
+
+unit::
+       sh ${top_srcdir}/unit/unittest.sh
+
+clean distclean::
+       rm -f ${TARGETS}
+       rm -f atf.out
diff --git a/lib/lwres/tests/config_test.c b/lib/lwres/tests/config_test.c
new file mode 100644 (file)
index 0000000..d3ea556
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <atf-c.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "../lwconfig.c"
+
+static void
+setup_test() {
+       /*
+        * atf-run changes us to a /tmp directory, so tests
+        * that access test data files must first chdir to the proper
+        * location.
+        */
+       ATF_CHECK(chdir(TESTS) != -1);
+}
+
+ATF_TC(parse_linklocal);
+ATF_TC_HEAD(parse_linklocal, tc) {
+       atf_tc_set_md_var(tc, "descr", "lwres_conf_parse link-local nameserver");
+}
+ATF_TC_BODY(parse_linklocal, tc) {
+       lwres_result_t result;
+       lwres_context_t *ctx = NULL;
+       unsigned char addr[16] = { 0xfe, 0x80, 0x00, 0x00,
+                                  0x00, 0x00, 0x00, 0x00,
+                                  0x00, 0x00, 0x00, 0x00,
+                                  0x00, 0x00, 0x00, 0x01 };
+
+       UNUSED(tc);
+
+       setup_test();
+
+       lwres_context_create(&ctx, NULL, NULL, NULL,
+                            LWRES_CONTEXT_USEIPV4 | LWRES_CONTEXT_USEIPV6);
+       ATF_CHECK_EQ(ctx->confdata.nsnext, 0);
+       ATF_CHECK_EQ(ctx->confdata.nameservers[0].zone, 0);
+
+       result = lwres_conf_parse(ctx, "testdata/link-local.conf");
+       ATF_CHECK_EQ(result, LWRES_R_SUCCESS);
+       ATF_CHECK_EQ(ctx->confdata.nsnext, 1);
+       ATF_CHECK_EQ(ctx->confdata.nameservers[0].zone, 1);
+       ATF_CHECK_EQ(memcmp(ctx->confdata.nameservers[0].address, addr, 16), 0);
+       lwres_context_destroy(&ctx);
+}
+
+/*
+ * Main
+ */
+ATF_TP_ADD_TCS(tp) {
+       ATF_TP_ADD_TC(tp, parse_linklocal);
+       return (atf_no_error());
+}
diff --git a/lib/lwres/tests/testdata/link-local.conf b/lib/lwres/tests/testdata/link-local.conf
new file mode 100644 (file)
index 0000000..8a37963
--- /dev/null
@@ -0,0 +1 @@
+nameserver fe80::1%1