From 6d6e66c5a89aa4617b65796f274e52fa7fd24904 Mon Sep 17 00:00:00 2001 From: Jim Hague Date: Wed, 13 Sep 2017 12:49:39 +0100 Subject: [PATCH 1/5] Add libyaml to dependencies for Travis. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d46dd307..6b3fc7b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ addons: packages: - libunbound-dev - libidn11-dev + - libyaml-dev - check - libevent-dev - libev-dev From c74e8353a8838cdc0535352f1b505797089c07d2 Mon Sep 17 00:00:00 2001 From: Jim Hague Date: Wed, 13 Sep 2017 12:50:18 +0100 Subject: [PATCH 2/5] Move to clang-friendly way of marking unused function parameters as used. --- src/convert.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/convert.c b/src/convert.c index a5692b77..c9244781 100644 --- a/src/convert.c +++ b/src/convert.c @@ -1821,8 +1821,8 @@ getdns_yaml2dict(const char *str, getdns_dict **dict) return GETDNS_RETURN_GENERIC_ERROR; } #else /* USE_YAML_CONFIG */ - str = str; - dict = dict; + (void) str; + (void) dict; return GETDNS_RETURN_NOT_IMPLEMENTED; #endif /* USE_YAML_CONFIG */ } @@ -1845,8 +1845,8 @@ getdns_yaml2list(const char *str, getdns_list **list) return GETDNS_RETURN_GENERIC_ERROR; } #else /* USE_YAML_CONFIG */ - str = str; - list = list; + (void) str; + (void) list; return GETDNS_RETURN_NOT_IMPLEMENTED; #endif /* USE_YAML_CONFIG */ } @@ -1869,8 +1869,8 @@ getdns_yaml2bindata(const char *str, getdns_bindata **bindata) return GETDNS_RETURN_GENERIC_ERROR; } #else /* USE_YAML_CONFIG */ - str = str; - bindata = bindata; + (void) str; + (void) bindata; return GETDNS_RETURN_NOT_IMPLEMENTED; #endif /* USE_YAML_CONFIG */ } @@ -1893,8 +1893,8 @@ getdns_yaml2int(const char *str, uint32_t *value) return GETDNS_RETURN_GENERIC_ERROR; } #else /* USE_YAML_CONFIG */ - str = str; - value = value; + (void) str; + (void) value; return GETDNS_RETURN_NOT_IMPLEMENTED; #endif /* USE_YAML_CONFIG */ } From eabad34af95728ae410a728fd05f52f031bd6fc4 Mon Sep 17 00:00:00 2001 From: Jim Hague Date: Wed, 13 Sep 2017 12:51:16 +0100 Subject: [PATCH 3/5] Add libyaml dependency to README, and note how to remove it. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b54c8f73..65af0d07 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ External dependencies are linked outside the getdns API build tree (we rely on c * [libunbound from NLnet Labs](https://unbound.net/) version 1.4.16 or later. * [libidn from the FSF](https://www.gnu.org/software/libidn/) version 1. (Note that the libidn version means the conversions between A-labels and U-labels may permit conversion of formally invalid labels under IDNA2008.) * [libssl and libcrypto from the OpenSSL Project](https://www.openssl.org/) version 0.9.7 or later. (Note: version 1.0.1 or later is required for TLS support, version 1.0.2 or later is required for TLS hostname authentication) +* [libyaml](http://pyyaml.org/wiki/LibYAML) version 0.1.6 or later. * Doxygen is used to generate documentation; while this is not technically necessary for the build it makes things a lot more pleasant. For example, to build on a recent version of Ubuntu, you would need the following packages: @@ -99,6 +100,7 @@ Note: If you only want to build stubby, then use the `--with-stubby` option when * getdns can be configured for stub resolution mode only with the `--enable-stub-only` option to configure. This removes the dependency on `libunbound`. * Currently getdns only offers two helper functions to deal with IDN: `getdns_convert_ulabel_to_alabel` and `getdns_convert_alabel_to_ulabel`. If you do not need these functions, getdns can be configured to compile without them with the `--without-libidn` option to configure. +* getdns can be configured to not support YAML configuration with the `--disable-yaml-config` option to configure. This removes the dependency on `libyaml`. * When both `--enable-stub-only` and `--without-libidn` options are used, getdns has only one dependency left, which is OpenSSL. ## Extensions and Event loop dependencies From 9683a64f733dcb93f858aff6a029a3660f1388fb Mon Sep 17 00:00:00 2001 From: Jim Hague Date: Wed, 13 Sep 2017 15:01:13 +0100 Subject: [PATCH 4/5] Add test 255-yaml-config with basic test of getdns_yaml2dict. --- .../255-yaml-config.Makefile | 15 ++++ .../255-yaml-config.tpkg/255-yaml-config.c | 60 ++++++++++++++ .../255-yaml-config.tpkg/255-yaml-config.dsc | 16 ++++ .../255-yaml-config.tpkg/255-yaml-config.good | 80 +++++++++++++++++++ .../255-yaml-config.input | 47 +++++++++++ .../255-yaml-config.tpkg/255-yaml-config.pre | 14 ++++ .../255-yaml-config.tpkg/255-yaml-config.test | 7 ++ 7 files changed, 239 insertions(+) create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.Makefile create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.c create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.dsc create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.good create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.input create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.pre create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.test diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.Makefile b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.Makefile new file mode 100644 index 00000000..c297df6d --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.Makefile @@ -0,0 +1,15 @@ +builddir = @BUILDDIR@ +testname = @TPKG_NAME@ +LIBTOOL = $(builddir)/libtool + +CFLAGS=-I$(builddir)/src +LDLIBS=$(builddir)/src/libgetdns.la + +.SUFFIXES: .c .o .a .lo .h + +.c.lo: + $(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $< -o $@ + +$(testname): $(testname).lo + $(LIBTOOL) --tag=CC --mode=link $(CC) $(LDLIBS) $(LDFLAGS) -o $(testname) $(testname).lo + diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.c b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.c new file mode 100644 index 00000000..b2a5f15b --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include + +int main(int ac, char *av[]) +{ + FILE *f; + char *buf = NULL; + size_t len; + ssize_t bytes_read; + + f = fopen(av[1], "r"); + if (!f) { + fprintf(stderr, "Could not open %s", av[1]); + exit(EXIT_FAILURE); + } + + bytes_read = getdelim(&buf, &len, '\0', f); + fclose(f); + + if (bytes_read == -1) { + fprintf(stderr, "Could not read %s", av[1]); + exit(EXIT_FAILURE); + } + + buf = realloc(buf, bytes_read + 1); + if (!buf) { + fprintf(stderr, "Could not grow buffer"); + exit(EXIT_FAILURE); + } + buf[bytes_read] = '\0'; + + getdns_dict *dict = NULL; + getdns_return_t r; + + if (!(dict = getdns_dict_create())) { + fprintf(stderr, "Could not create dict"); + exit(EXIT_FAILURE); + } + + r = getdns_yaml2dict(buf, &dict); + if (r) { + fprintf(stderr, "Error setting dict data: %s", getdns_get_errorstr_by_id(r)); + getdns_dict_destroy(dict); + exit(EXIT_FAILURE); + } + + char *dict_str = getdns_pretty_print_dict(dict); + if (!dict_str) { + fprintf(stderr, "Could not convert dict to string"); + getdns_dict_destroy(dict); + exit(EXIT_FAILURE); + } + + printf("%s\n", dict_str); + free(dict_str); + getdns_dict_destroy(dict); + exit(EXIT_SUCCESS); +} diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.dsc b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.dsc new file mode 100644 index 00000000..e00f4468 --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.dsc @@ -0,0 +1,16 @@ +BaseName: 255-yaml-config +Version: 1.0 +Description: Test YAML configuration +CreationDate: Wed 13 Sep 2017 12:42:32 BST +Maintainer: Jim Hague +Category: +Component: +CmdDepends: +Depends: 200-stub-only-compile.tpkg +Help: +Pre: 255-yaml-config.pre +Post: +Test: 255-yaml-config.test +AuxFiles: +Passed: +Failure: diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.good b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.good new file mode 100644 index 00000000..aae0e318 --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.good @@ -0,0 +1,80 @@ +{ + "dnssec_return_status": 1000, + "upstream_recursive_servers": + [ + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": + }, + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": + } + ] +} diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.input b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.input new file mode 100644 index 00000000..68e4460f --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.input @@ -0,0 +1,47 @@ +upstream_recursive_servers: +# IPv4 addresses +# The Surfnet/Sinodun servers + - address_data: 145.100.185.15 + tls_auth_name: "dnsovertls.sinodun.com" + tls_pubkey_pinset: + - digest: "sha256" + value: 62lKu9HsDVbyiPenApnc4sfmSYTHOVfFgL3pyB+cBL4= + - address_data: 145.100.185.16 + tls_auth_name: "dnsovertls1.sinodun.com" + tls_pubkey_pinset: + - digest: "sha256" + value: cE2ecALeE5B+urJhDrJlVFmf38cJLAvqekONvjvpqUA= +# The getdnsapi.net server + - address_data: 185.49.141.37 + tls_auth_name: "getdnsapi.net" + tls_pubkey_pinset: + - digest: "sha256" + value: foxZRnIh9gZpWnl+zEiKa0EJ2rdCGroMWm02gaxSc9Q= +# The uncensored DNS servers (no SPKI available) + - address_data: 184.105.193.78 + tls_auth_name: "unicast.censurfridns.dk" +# IPv6 addresses +# The Surfnet/Sinodun servers + - address_data: 2001:610:1:40ba:145:100:185:15 + tls_auth_name: "dnsovertls.sinodun.com" + tls_pubkey_pinset: + - digest: "sha256" + value: 62lKu9HsDVbyiPenApnc4sfmSYTHOVfFgL3pyB+cBL4= + - address_data: 2001:610:1:40ba:145:100:185:16 + tls_auth_name: "dnsovertls1.sinodun.com" + tls_pubkey_pinset: + - digest: "sha256" + value: cE2ecALeE5B+urJhDrJlVFmf38cJLAvqekONvjvpqUA= +# The getdnsapi.net server + - address_data: 2a04:b900:0:100::38 + tls_auth_name: "getdnsapi.net" + tls_pubkey_pinset: + - digest: "sha256" + value: foxZRnIh9gZpWnl+zEiKa0EJ2rdCGroMWm02gaxSc9Q= +# The uncensored DNS server (no SPKI available) + - address_data: 2620:ff:c000:0:1::64:25 + tls_auth_name: "unicast.censurfridns.dk" + +# Require DNSSEC validation. For releases earlier than 1.2 a trust anchor must +# be configured configured manually. This can be done with unbound-anchor. +dnssec_return_status: GETDNS_EXTENSION_TRUE diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.pre b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.pre new file mode 100644 index 00000000..802443c2 --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.pre @@ -0,0 +1,14 @@ +# #-- 255-yaml-config.test --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master +# use .tpkg.var.test for in test variable passing +[ -f .tpkg.var.test ] && source .tpkg.var.test + +( + grep '^CC=' "${BUILDDIR}/build-stub-only/src/Makefile" + grep '^LDFLAGS=' "${BUILDDIR}/build-stub-only/src/Makefile" + + BUILDDIR4SED=`echo "${BUILDDIR}/build-stub-only" | sed 's/\//\\\\\//g'` + sed -e "s/@BUILDDIR@/${BUILDDIR4SED}/g" \ + -e "s/@TPKG_NAME@/${TPKG_NAME}/g" "${TPKG_NAME}.Makefile" +) > Makefile diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.test b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.test new file mode 100644 index 00000000..b3735fb4 --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.test @@ -0,0 +1,7 @@ +# #-- 255-yaml-config.test --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master +# use .tpkg.var.test for in test variable passing +[ -f .tpkg.var.test ] && source .tpkg.var.test + +make && "./${TPKG_NAME}" 255-yaml-config.input | tee out && diff out "${TPKG_NAME}.good" From 57c40b147d07960e4b390980bf1775fa6c29a6d1 Mon Sep 17 00:00:00 2001 From: Jim Hague Date: Wed, 13 Sep 2017 15:02:36 +0100 Subject: [PATCH 5/5] Fix capturing exit code of a test. tpkg was not capturing the exit code of the test, but the exit code of the write_result actions. --- src/test/tpkg/tpkg | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/tpkg/tpkg b/src/test/tpkg/tpkg index 713adcfb..043d2ece 100755 --- a/src/test/tpkg/tpkg +++ b/src/test/tpkg/tpkg @@ -858,9 +858,10 @@ echo "--------------- Test Output ------------------" | write_result result.$dsc pre out "[log] Executing test" - -( ${SHELL} $dsc_test ${TPKG_ARGS} 2>&1 ) | write_result result.$dsc_basename +( ${SHELL} $dsc_test ${TPKG_ARGS} 2>&1 ) > result.$dsc_basename.tmp test_result=$? +write_result result.$dsc_basename < result.$dsc_basename.tmp +rm -f result.$dsc_basename.tmp epoch # would like to run after post, but that is not possible :-( if [ $test_result -ne 0 ]; then err "[warning] Test executed with errors: $test_result."