From 056d2e2b544d51013127ce4debef5e0b04550893 Mon Sep 17 00:00:00 2001 From: Petr Menšík Date: Jan 30 2022 20:10:13 +0000 Subject: [PATCH 1/4] Initial support for BIND 9.18 support Some changes needed to build with the most recent BIND9 release. It does not yet provide complete support for new release. Detects version of libdns just from libdns.so symlink. It requires --libdir= explicitly set for this part to work. --- diff --git a/configure.ac b/configure.ac index faac214..e5ab91d 100644 --- a/configure.ac +++ b/configure.ac @@ -53,6 +53,18 @@ AC_TRY_COMPILE([ [CFLAGS="$SAVED_CFLAGS" AC_MSG_RESULT([no])]) +# Check if build chain supports -std=gnu11 +AC_MSG_CHECKING([for -std=gnu11 compiler flag]) +SAVED_CFLAGS="$CFLAGS" +CFLAGS="-std=gnu11 -Werror" +AC_TRY_COMPILE([ + extern int fdef(void); +],[], +[AC_MSG_RESULT([yes]) + CFLAGS="$SAVED_CFLAGS -std=gnu11"], +[CFLAGS="$SAVED_CFLAGS" + AC_MSG_RESULT([no])]) + # Get CFLAGS from isc-config.sh AC_ARG_VAR([BIND9_CFLAGS], [C compiler flags for bind9, overriding isc-config.sh]) @@ -98,6 +110,7 @@ AC_RUN_IFELSE([AC_LANG_PROGRAM([ #include ],[ printf("%d\n", dns_libinterface) ])], [ LIBDNS_VERSION_MAJOR=`./conftest$ac_exeext` + AC_MSG_RESULT([$LIBDNS_VERSION_MAJOR]) AC_DEFINE_UNQUOTED([LIBDNS_VERSION_MAJOR], [$LIBDNS_VERSION_MAJOR], [Define libdns version])], [ AC_RUN_IFELSE([AC_LANG_PROGRAM([[ @@ -111,9 +124,24 @@ AC_RUN_IFELSE([AC_LANG_PROGRAM([ return !(scanned == 3 && major == 9); ]])], [ LIBDNS_VERSION_MAJOR=`./conftest$ac_exeext` + AC_MSG_RESULT([$LIBDNS_VERSION_MAJOR]) AC_DEFINE_UNQUOTED([LIBDNS_VERSION_MAJOR], [$LIBDNS_VERSION_MAJOR], [Define libdns version])], - [AC_MSG_ERROR([Can't obtain libdns version.])]) + [ + LIBDNS_PATH="${libdir}/libdns.so" + if test -L "$LIBDNS_PATH" ; then + LIBDNS_VERSION_MAJOR=$(ls -l "$LIBDNS_PATH" | sed -e 's/^.*->\s*libdns-9\.\([[0-9]]\+\)\.\([[0-9]]\+\).*\.so/\1 \2/' -e t -e d | xargs printf "%02d%02d") + else + AC_MSG_ERROR([Can't obtain libdns version1.]) + fi + if test -z "$LIBDNS_VERSION_MAJOR" || test "$LIBDNS_VERSION_MAJOR" -lt 1200; then + AC_MSG_ERROR([Can't obtain libdns version ($LIBDNS_VERSION_MAJOR).]) + else + AC_DEFINE_UNQUOTED([LIBDNS_VERSION_MAJOR], [$LIBDNS_VERSION_MAJOR], + [Define libdns version]) + AC_MSG_RESULT([$LIBDNS_VERSION_MAJOR]) + fi + ]) ], [AC_MSG_ERROR([Cross compiling is not supported.])] ) @@ -137,6 +165,10 @@ AC_CHECK_LIB([dns], [dns_db_setservestalettl], [AC_DEFINE([HAVE_DNS_SERVESTALE], 1, [Define if dns library provides dns_db_setservestalettl])] ) +AC_CHECK_LIB([dns], [dns_result_totext], + [AC_DEFINE([HAVE_DNS_RESULT_TOTEXT], 1, [Define if dns library provides dns_result_totext])] +) + dnl Older autoconf (2.59, for example) doesn't define docdir [[ ! -n "$docdir" ]] && docdir='${datadir}/doc/${PACKAGE_TARNAME}' AC_SUBST([docdir]) diff --git a/src/acl.c b/src/acl.c index ba89abc..c6b3782 100644 --- a/src/acl.c +++ b/src/acl.c @@ -281,7 +281,11 @@ acl_configure_zone_ssutable(const char *policy_str, dns_zone_t *zone) goto cleanup; } +#if LIBDNS_VERSION_MAJOR >= 1700 + dns_ssutable_create(mctx, &table); +#else CHECK(dns_ssutable_create(mctx, &table)); +#endif for (el = cfg_list_first(policy); el != NULL; el = cfg_list_next(el)) { const cfg_obj_t *stmt; @@ -303,9 +307,14 @@ acl_configure_zone_ssutable(const char *policy_str, dns_zone_t *zone) result = get_fixed_name(stmt, "name", &fname); if (result == ISC_R_NOTFOUND && match_type == dns_ssumatchtype_subdomain) { +#if LIBDNS_VERSION_MAJOR >= 1700 + dns_name_copy(dns_zone_getorigin(zone), + dns_fixedname_initname(&fname)); +#else CHECK(dns_name_copy(dns_zone_getorigin(zone), dns_fixedname_initname(&fname), &fname.buffer)); +#endif } else if (result != ISC_R_SUCCESS) goto cleanup; diff --git a/src/str.h b/src/str.h index a4061c0..e716361 100644 --- a/src/str.h +++ b/src/str.h @@ -17,7 +17,7 @@ #define _STR_MEM_FLARG_PASS , file, line #else #define _STR_MEM_FILELINE -#define _STR_MEM_FLAG +#define _STR_MEM_FLARG #define _STR_MEM_FLARG_PASS #endif diff --git a/src/util.h b/src/util.h index 7a8555b..f4b08f9 100644 --- a/src/util.h +++ b/src/util.h @@ -15,9 +15,14 @@ #include #include "log.h" +#include "dyndb-config.h" extern bool verbose_checks; /* from settings.c */ +#ifndef HAVE_DNS_RESULT_TOTEXT +#define dns_result_totext isc_result_totext +#endif + #define CLEANUP_WITH(result_code) \ do { \ result = (result_code); \ From 7206aba205a3155c3459207bd8dea63b71bed30a Mon Sep 17 00:00:00 2001 From: Petr Menšík Date: Feb 22 2022 16:09:36 +0000 Subject: [PATCH 2/4] Add basic support of dns_ssuruletype_t dns_ssutable_addrule changed input types. Add very basic support for the new type, without support for parsing actual rule string including max count. --- diff --git a/src/acl.c b/src/acl.c index c6b3782..8f5f33f 100644 --- a/src/acl.c +++ b/src/acl.c @@ -66,6 +66,10 @@ const enum_txt_assoc_t acl_type_txts[] = { } \ } while (0) +#if LIBDNS_VERSION_MAJOR < 1700 +typedef dns_rdatatype_t dns_ssuruletype_t; +#endif + static isc_result_t ATTR_NONNULLS ATTR_CHECKRESULT get_mode(const cfg_obj_t *obj, bool *value) { @@ -184,14 +188,14 @@ count_list_elements(const cfg_obj_t *list) } static isc_result_t ATTR_NONNULLS ATTR_CHECKRESULT -get_types(isc_mem_t *mctx, const cfg_obj_t *obj, dns_rdatatype_t **typesp, +get_types(isc_mem_t *mctx, const cfg_obj_t *obj, dns_ssuruletype_t **typesp, unsigned int *np) { isc_result_t result = ISC_R_SUCCESS; unsigned int i; unsigned int n = 0; const cfg_listelt_t *el; - dns_rdatatype_t *types = NULL; + dns_ssuruletype_t *types = NULL; REQUIRE(obj != NULL); REQUIRE(typesp != NULL && *typesp == NULL); @@ -201,7 +205,7 @@ get_types(isc_mem_t *mctx, const cfg_obj_t *obj, dns_rdatatype_t **typesp, n = count_list_elements(obj); if (n > 0) { - types = isc_mem_get(mctx, n * sizeof(dns_rdatatype_t)); + types = isc_mem_get(mctx, n * sizeof(dns_ssuruletype_t)); } i = 0; for (el = cfg_list_first(obj); el != NULL; el = cfg_list_next(el)) { @@ -216,7 +220,12 @@ get_types(isc_mem_t *mctx, const cfg_obj_t *obj, dns_rdatatype_t **typesp, DE_CONST(str, r.base); r.length = strlen(str); +#if LIBDNS_VERSION_MAJOR < 1700 result = dns_rdatatype_fromtext(&types[i++], &r); +#else + types[i].max = 0; + result = dns_rdatatype_fromtext(&types[i++].type, &r); +#endif if (result != ISC_R_SUCCESS) { log_error("'%s' is not a valid type", str); goto cleanup; @@ -229,7 +238,7 @@ get_types(isc_mem_t *mctx, const cfg_obj_t *obj, dns_rdatatype_t **typesp, return result; cleanup: - SAFE_MEM_PUT(mctx, types, n * sizeof(dns_rdatatype_t)); + SAFE_MEM_PUT(mctx, types, n * sizeof(dns_ssuruletype_t)); return result; } @@ -292,7 +301,7 @@ acl_configure_zone_ssutable(const char *policy_str, dns_zone_t *zone) bool grant; unsigned int match_type; dns_fixedname_t fname, fident; - dns_rdatatype_t *types; + dns_ssuruletype_t *types; unsigned int n; types = NULL; @@ -333,13 +342,22 @@ acl_configure_zone_ssutable(const char *policy_str, dns_zone_t *zone) CLEANUP_WITH(DNS_R_BADNAME); } +#if LIBDNS_VERSION_MAJOR >= 1700 + result = ISC_R_SUCCESS; + dns_ssutable_addrule(table, grant, + dns_fixedname_name(&fident), + match_type, + dns_fixedname_name(&fname), + n, types); +#else result = dns_ssutable_addrule(table, grant, dns_fixedname_name(&fident), match_type, dns_fixedname_name(&fname), n, types); +#endif - SAFE_MEM_PUT(mctx, types, n * sizeof(dns_rdatatype_t)); + SAFE_MEM_PUT(mctx, types, n * sizeof(dns_ssuruletype_t)); if (result != ISC_R_SUCCESS) goto cleanup; From d28f8ef1ca46b3ba35c6bcc91fa599d2b19d759a Mon Sep 17 00:00:00 2001 From: Petr Menšík Date: Feb 22 2022 16:52:07 +0000 Subject: [PATCH 3/4] Support for 9.18 and 9.17 support Make dns_name_copynf alias to support both older and more recent release. Initialize few other variables to pass new compiler warnings. Remove few changed functions in database interface. --- diff --git a/src/empty_zones.c b/src/empty_zones.c index e3e4545..03f16fc 100644 --- a/src/empty_zones.c +++ b/src/empty_zones.c @@ -15,6 +15,8 @@ #if LIBDNS_VERSION_MAJOR < 1600 #define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL) +#elif LIBDNS_VERSION_MAJOR >= 1714 +#define dns_name_copynf(src, dst) dns_name_copy((src), (dst)) #endif /** diff --git a/src/ldap_convert.c b/src/ldap_convert.c index dc6e32b..f8e4fba 100644 --- a/src/ldap_convert.c +++ b/src/ldap_convert.c @@ -29,6 +29,8 @@ #if LIBDNS_VERSION_MAJOR < 1600 #define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL) +#elif LIBDNS_VERSION_MAJOR >= 1714 +#define dns_name_copynf(src, dst) dns_name_copy((src), (dst)) #endif /** diff --git a/src/ldap_driver.c b/src/ldap_driver.c index 5f9e00a..7367493 100644 --- a/src/ldap_driver.c +++ b/src/ldap_driver.c @@ -11,11 +11,13 @@ #include #include #include -#include #include #include #include #include +#if LIBDNS_VERSION_MAJOR < 1617 +#include +#endif #include #include @@ -238,6 +240,7 @@ endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) { return ISC_R_SUCCESS; } +#if LIBDNS_VERSION_MAJOR < 1719 static isc_result_t serialize(dns_db_t *db, dns_dbversion_t *version, FILE *file) { @@ -247,6 +250,7 @@ serialize(dns_db_t *db, dns_dbversion_t *version, FILE *file) return dns_db_serialize(ldapdb->rbtdb, version, file); } +#endif /* !!! This could be required for optimizations (like on-disk cache). */ static isc_result_t @@ -635,6 +639,7 @@ issecure(dns_db_t *db) return dns_db_issecure(ldapdb->rbtdb); } +#if LIBDNS_VERSION_MAJOR < 1721 static unsigned int nodecount(dns_db_t *db) { @@ -644,6 +649,17 @@ nodecount(dns_db_t *db) return dns_db_nodecount(ldapdb->rbtdb); } +#else +static unsigned int +nodecount(dns_db_t *db, dns_dbtree_t tree) +{ + ldapdb_t *ldapdb = (ldapdb_t *) db; + + REQUIRE(VALID_LDAPDB(ldapdb)); + + return dns_db_nodecount(ldapdb->rbtdb, tree); +} +#endif /** * Return TRUE, because database does not need to be loaded from disk @@ -896,7 +912,7 @@ getservestalettl(dns_db_t *db, dns_ttl_t *ttl) { } #endif -#if LIBDNS_VERSION_MAJOR >= 1606 +#if LIBDNS_VERSION_MAJOR >= 1606 && LIBDNS_VERSION_MAJOR < 1720 /* Used for cache size adjustments, called by dns_cache_setcachesize. * Just proxy to rbtdb implementation. */ static isc_result_t @@ -914,7 +930,9 @@ static dns_dbmethods_t ldapdb_methods = { detach, beginload, endload, +#if LIBDNS_VERSION_MAJOR < 1719 serialize, /* see dns_db_serialize(), implementation is not mandatory */ +#endif dump, currentversion, newversion, @@ -966,7 +984,7 @@ static dns_dbmethods_t ldapdb_methods = { #if LIBDNS_VERSION_MAJOR >= 1600 NULL, /* setgluecachestats */ #endif -#if LIBDNS_VERSION_MAJOR >= 1606 +#if LIBDNS_VERSION_MAJOR >= 1606 && LIBDNS_VERSION_MAJOR < 1720 adjusthashsize, /* adjusthashsize */ #endif }; diff --git a/src/ldap_helper.c b/src/ldap_helper.c index 97a1859..7ea3df9 100644 --- a/src/ldap_helper.c +++ b/src/ldap_helper.c @@ -5,6 +5,7 @@ #include "dyndb-config.h" #define HAVE_TLS 1 #define HAVE_THREAD_LOCAL 1 +#include #include #include @@ -3760,7 +3761,7 @@ static void ATTR_NONNULLS update_zone(isc_task_t *task, isc_event_t *event) { ldap_syncreplevent_t *pevent = (ldap_syncreplevent_t *)event; - isc_result_t result ; + isc_result_t result = ISC_R_SUCCESS; ldap_instance_t *inst = pevent->inst; isc_mem_t *mctx; dns_name_t prevname; diff --git a/src/mldap.c b/src/mldap.c index 3a76153..2c41d5d 100644 --- a/src/mldap.c +++ b/src/mldap.c @@ -44,6 +44,9 @@ #else /* BIND 9.16+ */ #define REFCOUNT_CAST(n) ((isc_refcount_t) (n)) +#if LIBDNS_VERSION_MAJOR >= 1714 +#define dns_name_copynf(src, dst) dns_name_copy((src), (dst)) +#endif #endif /* name "ldap.uuid." */ @@ -495,7 +498,7 @@ mldap_iter_deadnodes_next(mldapdb_t *mldap, metadb_iter_t **iterp, isc_result_t result; dns_dbnode_t *rbt_node = NULL; metadb_iter_t *iter = NULL; - uint32_t node_generation; + uint32_t node_generation = 0; uint32_t cur_generation; metadb_node_t metadb_node; DECLARE_BUFFERED_NAME(name); diff --git a/src/syncptr.c b/src/syncptr.c index 8824679..7d6047d 100644 --- a/src/syncptr.c +++ b/src/syncptr.c @@ -34,6 +34,8 @@ #if LIBDNS_VERSION_MAJOR < 1600 #define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL) +#elif LIBDNS_VERSION_MAJOR >= 1714 +#define dns_name_copynf(src, dst) dns_name_copy((src), (dst)) #endif /* diff --git a/src/syncrepl.c b/src/syncrepl.c index 3baeb78..0bee09a 100644 --- a/src/syncrepl.c +++ b/src/syncrepl.c @@ -129,7 +129,7 @@ void finish(isc_task_t *task, isc_event_t *event) { isc_result_t result = ISC_R_SUCCESS; sync_barrierev_t *bev = NULL; - sync_state_t new_state; + sync_state_t new_state = sync_configinit; REQUIRE(event != NULL); UNUSED(task); @@ -496,8 +496,8 @@ isc_result_t sync_barrier_wait(sync_ctx_t *sctx, ldap_instance_t *inst) { isc_event_t *ev = NULL; sync_barrierev_t *bev = NULL; - sync_state_t barrier_state; - sync_state_t final_state; + sync_state_t barrier_state = sync_configinit; + sync_state_t final_state = sync_configinit; task_element_t *taskel = NULL; task_element_t *next_taskel = NULL; From fa16da22fc6792692537e9faf0bac93ad57703c8 Mon Sep 17 00:00:00 2001 From: Petr Menšík Date: Feb 24 2022 00:51:39 +0000 Subject: [PATCH 4/4] Move common dns_name_copynf compatibility macros to header The same dns_name_copynf is required in multiple places. Because I have already modified util.h to require dyndb-config.h, it can contain also these compatibility defines in single place. Signed-off-by: Petr Menšík --- diff --git a/src/empty_zones.c b/src/empty_zones.c index 03f16fc..4e14a80 100644 --- a/src/empty_zones.c +++ b/src/empty_zones.c @@ -13,12 +13,6 @@ #include "util.h" #include "zone_register.h" -#if LIBDNS_VERSION_MAJOR < 1600 -#define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL) -#elif LIBDNS_VERSION_MAJOR >= 1714 -#define dns_name_copynf(src, dst) dns_name_copy((src), (dst)) -#endif - /** * These zones should not leak onto the Internet. * The list matches BIND commit 8f20f6c9d7ce5a0f0af6ee4c5361832d97b1c5d4 diff --git a/src/ldap_convert.c b/src/ldap_convert.c index f8e4fba..87f635f 100644 --- a/src/ldap_convert.c +++ b/src/ldap_convert.c @@ -27,12 +27,6 @@ #include "util.h" #include "zone_register.h" -#if LIBDNS_VERSION_MAJOR < 1600 -#define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL) -#elif LIBDNS_VERSION_MAJOR >= 1714 -#define dns_name_copynf(src, dst) dns_name_copy((src), (dst)) -#endif - /** * Convert LDAP DN to absolute DNS names. * diff --git a/src/mldap.c b/src/mldap.c index 2c41d5d..0bc2d33 100644 --- a/src/mldap.c +++ b/src/mldap.c @@ -30,7 +30,6 @@ #include "dyndb-config.h" #if LIBDNS_VERSION_MAJOR < 1600 -#define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL) #define REFCOUNT_CAST(n) ((typeof(((isc_refcount_t *)0)->refs)) (n)) /* Static assert is not provided yet, copy from 9.16 */ @@ -44,9 +43,6 @@ #else /* BIND 9.16+ */ #define REFCOUNT_CAST(n) ((isc_refcount_t) (n)) -#if LIBDNS_VERSION_MAJOR >= 1714 -#define dns_name_copynf(src, dst) dns_name_copy((src), (dst)) -#endif #endif /* name "ldap.uuid." */ diff --git a/src/syncptr.c b/src/syncptr.c index 7d6047d..f7b8c02 100644 --- a/src/syncptr.c +++ b/src/syncptr.c @@ -32,12 +32,6 @@ #define SYNCPTR_FMTPRE SYNCPTR_PREF "(%s) for '%s A/AAAA %s' " #define SYNCPTR_FMTPOST ldap_modop_str(mod_op), a_name_str, ip_str -#if LIBDNS_VERSION_MAJOR < 1600 -#define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL) -#elif LIBDNS_VERSION_MAJOR >= 1714 -#define dns_name_copynf(src, dst) dns_name_copy((src), (dst)) -#endif - /* * Event for asynchronous PTR record synchronization. */ diff --git a/src/util.h b/src/util.h index f4b08f9..5088ff3 100644 --- a/src/util.h +++ b/src/util.h @@ -23,6 +23,12 @@ extern bool verbose_checks; /* from settings.c */ #define dns_result_totext isc_result_totext #endif +#if LIBDNS_VERSION_MAJOR < 1600 +#define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL) +#elif LIBDNS_VERSION_MAJOR >= 1714 +#define dns_name_copynf(src, dst) dns_name_copy((src), (dst)) +#endif + #define CLEANUP_WITH(result_code) \ do { \ result = (result_code); \