From b0b52c55e7ee12287eb4360b0fc1dd5751ee105e Mon Sep 17 00:00:00 2001 From: Tomas Krizek Date: Fri, 17 Feb 2017 14:35:13 +0100 Subject: [PATCH 3/3] Revert "BIND 9.11: Remove #if blocks for older BIND versions." This reverts commit 2649ef1da1cbfc1203337665c4e589e1fe75f04b. --- src/Makefile.am | 1 + src/compat.h | 44 +++++++++++++++++++++++ src/fwd.c | 60 +++++++++++++++++++++++++++++-- src/ldap_driver.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 202 insertions(+), 6 deletions(-) create mode 100644 src/compat.h diff --git a/src/Makefile.am b/src/Makefile.am index e1e3968682a675573fbebcefefdee53bf6499f5b..fe96c4c82d3fe5ee4763dd1834c074e08365cdcc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,6 +4,7 @@ bindplugindir=$(libdir)/bind HDRS = \ acl.h \ bindcfg.h \ + compat.h \ empty_zones.h \ fs.h \ fwd.h \ diff --git a/src/compat.h b/src/compat.h new file mode 100644 index 0000000000000000000000000000000000000000..00e3da58bc270e3e21f8780af1056caae5151c87 --- /dev/null +++ b/src/compat.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2009 bind-dyndb-ldap authors; see COPYING for license + */ + +#ifdef HAVE_CONFIG_H +#include +#else +#error "Can't compile without config.h" +#endif + +/* + * dns_rdatalist_fromrdataset() did not exist in older versions of libdns. + * Add a substitude function here. + */ +#if LIBDNS_VERSION_MAJOR < 40 +static inline isc_result_t +dns_rdatalist_fromrdataset(dns_rdataset_t *rdataset, + dns_rdatalist_t **rdatalist) +{ + REQUIRE(rdatalist != NULL && rdataset != NULL); + + *rdatalist = rdataset->private1; + + return ISC_R_SUCCESS; +} +#endif /* LIBDNS_VERSION_MAJOR < 40 */ + +/* + * In older libdns versions, isc_refcount_init() was defined as a macro. + * However, in newer versions, it is a function returning isc_result_t type. + * This piece of code should take care of that problem. + */ +#if LIBDNS_VERSION_MAJOR < 30 +#include + +static inline isc_result_t +isc_refcount_init_func(isc_refcount_t *ref, unsigned int n) +{ + isc_refcount_init(ref, n); + return ISC_R_SUCCESS; +} +#undef isc_refcount_init +#define isc_refcount_init isc_refcount_init_func +#endif /* LIBDNS_VERSION_MAJOR < 30 */ diff --git a/src/fwd.c b/src/fwd.c index 840f0e8f232969b2b726fa4a338a10c010654279..1f6a9e5d922d6a14dec88e04d41ad911f2dfd389 100644 --- a/src/fwd.c +++ b/src/fwd.c @@ -69,7 +69,11 @@ fwd_list_len(dns_forwarders_t *fwdrs) { REQUIRE(fwdrs != NULL); +#if LIBDNS_VERSION_MAJOR < 140 + for (isc_sockaddr_t *fwdr = ISC_LIST_HEAD(fwdrs->addrs); +#else /* LIBDNS_VERSION_MAJOR >= 140 */ for (dns_forwarder_t *fwdr = ISC_LIST_HEAD(fwdrs->fwdrs); +#endif fwdr != NULL; fwdr = ISC_LIST_NEXT(fwdr, link)) { len++; @@ -165,7 +169,11 @@ fwd_print_list_buff(isc_mem_t *mctx, dns_forwarders_t *fwdrs, const cfg_obj_t *faddresses; const cfg_listelt_t *fwdr_cfg; /* config representation */ /* internal representation */ +#if LIBDNS_VERSION_MAJOR < 140 + isc_sockaddr_t *fwdr_int; +#else /* LIBDNS_VERSION_MAJOR >= 140 */ dns_forwarder_t *fwdr_int; +#endif isc_buffer_initnull(&tmp_buf); tmp_buf.mctx = mctx; @@ -189,12 +197,20 @@ fwd_print_list_buff(isc_mem_t *mctx, dns_forwarders_t *fwdrs, * data from the internal one to cfg data structures.*/ faddresses = cfg_tuple_get(forwarders_cfg, "addresses"); for (fwdr_int = ISC_LIST_HEAD( +#if LIBDNS_VERSION_MAJOR < 140 + fwdrs->addrs +#else /* LIBDNS_VERSION_MAJOR >= 140 */ fwdrs->fwdrs +#endif ), fwdr_cfg = cfg_list_first(faddresses); INSIST((fwdr_int == NULL) == (fwdr_cfg == NULL)), fwdr_int != NULL; fwdr_int = ISC_LIST_NEXT(fwdr_int, link), fwdr_cfg = cfg_list_next(fwdr_cfg)) { +#if LIBDNS_VERSION_MAJOR < 140 + fwdr_cfg->obj->value.sockaddr = *fwdr_int; +#else /* LIBDNS_VERSION_MAJOR >= 140 */ fwdr_cfg->obj->value.sockaddrdscp.sockaddr = fwdr_int->addr; fwdr_cfg->obj->value.sockaddrdscp.dscp = fwdr_int->dscp; +#endif } cfg_print(faddresses, buffer_append_str, &tmp_buf); @@ -243,7 +259,12 @@ cleanup: static isc_result_t fwd_parse_str(const char *fwdrs_str, isc_mem_t *mctx, - dns_forwarderlist_t *fwdrs) +#if LIBDNS_VERSION_MAJOR < 140 + isc_sockaddrlist_t *fwdrs +#else /* LIBDNS_VERSION_MAJOR >= 140 */ + dns_forwarderlist_t *fwdrs +#endif + ) { isc_result_t result = ISC_R_SUCCESS; cfg_parser_t *parser = NULL; @@ -253,7 +274,11 @@ fwd_parse_str(const char *fwdrs_str, isc_mem_t *mctx, const cfg_listelt_t *listel; const cfg_obj_t *fwdr_cfg; isc_sockaddr_t addr; +#if LIBDNS_VERSION_MAJOR < 140 + isc_sockaddr_t *fwdr; +#else /* LIBDNS_VERSION_MAJOR >= 140 */ dns_forwarder_t *fwdr; +#endif in_port_t port = 53; @@ -276,8 +301,12 @@ fwd_parse_str(const char *fwdrs_str, isc_mem_t *mctx, if (isc_sockaddr_getport(&addr) == 0) isc_sockaddr_setport(&addr, port); CHECKED_MEM_GET_PTR(mctx, fwdr); +#if LIBDNS_VERSION_MAJOR < 140 + *fwdr = addr; +#else /* LIBDNS_VERSION_MAJOR >= 140 */ fwdr->addr = addr; fwdr->dscp = cfg_obj_getdscp(fwdr_cfg); +#endif ISC_LINK_INIT(fwdr, link); ISC_LIST_APPEND(*fwdrs, fwdr, link); } @@ -291,8 +320,18 @@ cleanup: } static void -fwdr_list_free(isc_mem_t *mctx, dns_forwarderlist_t *fwdrs) { +fwdr_list_free(isc_mem_t *mctx, +#if LIBDNS_VERSION_MAJOR < 140 + isc_sockaddrlist_t *fwdrs +#else /* LIBDNS_VERSION_MAJOR >= 140 */ + dns_forwarderlist_t *fwdrs +#endif + ) { +#if LIBDNS_VERSION_MAJOR < 140 + isc_sockaddr_t *fwdr; +#else /* LIBDNS_VERSION_MAJOR >= 140 */ dns_forwarder_t *fwdr; +#endif while (!ISC_LIST_EMPTY(*fwdrs)) { fwdr = ISC_LIST_HEAD(*fwdrs); ISC_LIST_UNLINK(*fwdrs, fwdr, link); @@ -318,7 +357,11 @@ fwd_setting_isexplicit(isc_mem_t *mctx, const settings_set_t *set, isc_result_t result; setting_t *setting = NULL; dns_fwdpolicy_t fwdpolicy; +#if LIBDNS_VERSION_MAJOR < 140 + isc_sockaddrlist_t fwdrs; +#else /* LIBDNS_VERSION_MAJOR >= 140 */ dns_forwarderlist_t fwdrs; +#endif REQUIRE(isexplicit != NULL); ISC_LIST_INIT(fwdrs); @@ -397,7 +440,11 @@ fwd_parse_ldap(ldap_entry_t *entry, settings_set_t *set) { ldap_valuelist_t values; ldap_value_t *value; isc_buffer_t *tmp_buf = NULL; /* hack: only the base buffer is allocated */ +#if LIBDNS_VERSION_MAJOR < 140 + isc_sockaddrlist_t fwdrs; +#else /* LIBDNS_VERSION_MAJOR >= 140 */ dns_forwarderlist_t fwdrs; +#endif const char *setting_str = NULL; /** @@ -500,7 +547,11 @@ fwd_configure_zone(const settings_set_t *set, ldap_instance_t *inst, isc_mem_t *mctx = NULL; dns_view_t *view = NULL; isc_result_t lock_state = ISC_R_IGNORE; +#if LIBDNS_VERSION_MAJOR < 140 + isc_sockaddrlist_t fwdrs; +#else /* LIBDNS_VERSION_MAJOR >= 140 */ dns_forwarderlist_t fwdrs; +#endif isc_boolean_t is_global_config; dns_fixedname_t foundname; const char *msg_use_global_fwds; @@ -579,8 +630,13 @@ fwd_configure_zone(const settings_set_t *set, ldap_instance_t *inst, run_exclusive_enter(inst, &lock_state); CHECK(fwd_delete_table(view, name, msg_obj_type, set->name)); if (isconfigured == ISC_TRUE) { +#if LIBDNS_VERSION_MAJOR < 140 + CHECK(dns_fwdtable_add(view->fwdtable, name, &fwdrs, + fwdpolicy)); +#else /* LIBDNS_VERSION_MAJOR >= 140 */ CHECK(dns_fwdtable_addfwd(view->fwdtable, name, &fwdrs, fwdpolicy)); +#endif } dns_view_flushcache(view); run_exclusive_exit(inst, lock_state); diff --git a/src/ldap_driver.c b/src/ldap_driver.c index ed31d50321072a8100e20bbd0cf7da2e3741b0d4..4e842cb0f122c49080128a81892f9737d29a299e 100644 --- a/src/ldap_driver.c +++ b/src/ldap_driver.c @@ -34,6 +34,7 @@ #include /* For memcpy */ #include "bindcfg.h" +#include "compat.h" #include "ldap_driver.h" #include "ldap_helper.h" #include "ldap_convert.h" @@ -184,9 +185,18 @@ detach(dns_db_t **dbp) /* !!! This could be required for optimizations (like on-disk cache). */ static isc_result_t +#if LIBDNS_VERSION_MAJOR < 140 +beginload(dns_db_t *db, dns_addrdatasetfunc_t *addp, dns_dbload_t **dbloadp) +{ + + UNUSED(db); + UNUSED(addp); + UNUSED(dbloadp); +#else /* LIBDNS_VERSION_MAJOR >= 140 */ beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) { UNUSED(db); UNUSED(callbacks); +#endif /* LIBDNS_VERSION_MAJOR >= 140 */ fatal_error("ldapdb: method beginload() should never be called"); @@ -201,9 +211,17 @@ beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) { /* !!! This could be required for optimizations (like on-disk cache). */ static isc_result_t +#if LIBDNS_VERSION_MAJOR < 140 +endload(dns_db_t *db, dns_dbload_t **dbloadp) +{ + + UNUSED(db); + UNUSED(dbloadp); +#else /* LIBDNS_VERSION_MAJOR >= 140 */ endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) { UNUSED(db); UNUSED(callbacks); +#endif /* LIBDNS_VERSION_MAJOR >= 140 */ fatal_error("ldapdb: method endload() should never be called"); @@ -211,6 +229,7 @@ endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) { return ISC_R_SUCCESS; } +#if LIBDNS_VERSION_MAJOR >= 140 static isc_result_t serialize(dns_db_t *db, dns_dbversion_t *version, FILE *file) { @@ -220,17 +239,23 @@ serialize(dns_db_t *db, dns_dbversion_t *version, FILE *file) return dns_db_serialize(ldapdb->rbtdb, version, file); } +#endif /* LIBDNS_VERSION_MAJOR >= 140 */ /* !!! This could be required for optimizations (like on-disk cache). */ static isc_result_t -dump(dns_db_t *db, dns_dbversion_t *version, const char *filename, - dns_masterformat_t masterformat) +dump(dns_db_t *db, dns_dbversion_t *version, const char *filename +#if LIBDNS_VERSION_MAJOR >= 31 + , dns_masterformat_t masterformat +#endif + ) { UNUSED(db); UNUSED(version); UNUSED(filename); +#if LIBDNS_VERSION_MAJOR >= 31 UNUSED(masterformat); +#endif fatal_error("ldapdb: method dump() should never be called"); @@ -401,14 +426,22 @@ printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out) } static isc_result_t -createiterator(dns_db_t *db, unsigned int options, +createiterator(dns_db_t *db, +#if LIBDNS_VERSION_MAJOR >= 50 + unsigned int options, +#else + isc_boolean_t relative_names, +#endif dns_dbiterator_t **iteratorp) { ldapdb_t *ldapdb = (ldapdb_t *) db; REQUIRE(VALID_LDAPDB(ldapdb)); - +#if LIBDNS_VERSION_MAJOR >= 50 return dns_db_createiterator(ldapdb->rbtdb, options, iteratorp); +#else + return dns_db_createiterator(ldapdb->rbtdb, relative_names, iteratorp); +#endif } static isc_result_t @@ -646,6 +679,7 @@ settask(dns_db_t *db, isc_task_t *task) dns_db_settask(ldapdb->rbtdb, task); } +#if LIBDNS_VERSION_MAJOR >= 31 static isc_result_t getoriginnode(dns_db_t *db, dns_dbnode_t **nodep) { @@ -655,7 +689,9 @@ getoriginnode(dns_db_t *db, dns_dbnode_t **nodep) return dns_db_getoriginnode(ldapdb->rbtdb, nodep); } +#endif /* LIBDNS_VERSION_MAJOR >= 31 */ +#if LIBDNS_VERSION_MAJOR >= 45 static void transfernode(dns_db_t *db, dns_dbnode_t **sourcep, dns_dbnode_t **targetp) { @@ -666,7 +702,9 @@ transfernode(dns_db_t *db, dns_dbnode_t **sourcep, dns_dbnode_t **targetp) dns_db_transfernode(ldapdb->rbtdb, sourcep, targetp); } +#endif /* LIBDNS_VERSION_MAJOR >= 45 */ +#if LIBDNS_VERSION_MAJOR >= 50 static isc_result_t getnsec3parameters(dns_db_t *db, dns_dbversion_t *version, dns_hash_t *hash, isc_uint8_t *flags, @@ -733,7 +771,9 @@ isdnssec(dns_db_t *db) return dns_db_isdnssec(ldapdb->rbtdb); } +#endif /* LIBDNS_VERSION_MAJOR >= 50 */ +#if LIBDNS_VERSION_MAJOR >= 45 static dns_stats_t * getrrsetstats(dns_db_t *db) { ldapdb_t *ldapdb = (ldapdb_t *) db; @@ -743,7 +783,35 @@ getrrsetstats(dns_db_t *db) { return dns_db_getrrsetstats(ldapdb->rbtdb); } +#endif /* LIBDNS_VERSION_MAJOR >= 45 */ +#if LIBDNS_VERSION_MAJOR >= 82 && LIBDNS_VERSION_MAJOR < 140 +static isc_result_t +rpz_enabled(dns_db_t *db, dns_rpz_st_t *st) +{ + ldapdb_t *ldapdb = (ldapdb_t *) db; + + REQUIRE(VALID_LDAPDB(ldapdb)); + + return dns_db_rpz_enabled(ldapdb->rbtdb, st); +} + +static void +rpz_findips(dns_rpz_zone_t *rpz, dns_rpz_type_t rpz_type, + dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *version, + dns_rdataset_t *ardataset, dns_rpz_st_t *st, + dns_name_t *query_qname) +{ + ldapdb_t *ldapdb = (ldapdb_t *) db; + + REQUIRE(VALID_LDAPDB(ldapdb)); + + dns_db_rpz_findips(rpz, rpz_type, zone, ldapdb->rbtdb, version, + ardataset, st, query_qname); +} +#endif /* LIBDNS_VERSION_MAJOR >= 82 && LIBDNS_VERSION_MAJOR < 140 */ + +#if LIBDNS_VERSION_MAJOR >= 140 void rpz_attach(dns_db_t *db, dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num) { @@ -763,7 +831,9 @@ rpz_ready(dns_db_t *db) return dns_db_rpz_ready(ldapdb->rbtdb); } +#endif /* LIBDNS_VERSION_MAJOR >= 140 */ +#if LIBDNS_VERSION_MAJOR >= 90 static isc_result_t findnodeext(dns_db_t *db, dns_name_t *name, isc_boolean_t create, dns_clientinfomethods_t *methods, @@ -792,7 +862,9 @@ findext(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version, nodep, foundname, methods, clientinfo, rdataset, sigrdataset); } +#endif /* LIBDNS_VERSION_MAJOR >= 90 */ +#if LIBDNS_VERSION_MAJOR >= 140 isc_result_t setcachestats(dns_db_t *db, isc_stats_t *stats) { @@ -803,7 +875,11 @@ setcachestats(dns_db_t *db, isc_stats_t *stats) return dns_db_setcachestats(ldapdb->rbtdb, stats); } +#if LIBDNS_VERSION_MAJOR >= 164 size_t +#else +unsigned int +#endif /* LIBDNS_VERSION_MAJOR >= 164 */ hashsize(dns_db_t *db) { ldapdb_t *ldapdb = (ldapdb_t *) db; @@ -812,13 +888,16 @@ hashsize(dns_db_t *db) return dns_db_hashsize(ldapdb->rbtdb); } +#endif /* LIBDNS_VERSION_MAJOR >= 140 */ static dns_dbmethods_t ldapdb_methods = { attach, detach, beginload, endload, +#if LIBDNS_VERSION_MAJOR >= 140 serialize, /* see dns_db_serialize(), implementation is not mandatory */ +#endif /* LIBDNS_VERSION_MAJOR >= 140 */ dump, currentversion, newversion, @@ -842,21 +921,37 @@ static dns_dbmethods_t ldapdb_methods = { ispersistent, overmem, settask, +#if LIBDNS_VERSION_MAJOR >= 31 getoriginnode, +#endif /* LIBDNS_VERSION_MAJOR >= 31 */ +#if LIBDNS_VERSION_MAJOR >= 45 transfernode, +#if LIBDNS_VERSION_MAJOR >= 50 getnsec3parameters, findnsec3node, setsigningtime, getsigningtime, resigned, isdnssec, +#endif /* LIBDNS_VERSION_MAJOR >= 50 */ getrrsetstats, +#endif /* LIBDNS_VERSION_MAJOR >= 45 */ +#if LIBDNS_VERSION_MAJOR >= 82 && LIBDNS_VERSION_MAJOR < 140 + rpz_enabled, + rpz_findips, +#endif /* LIBDNS_VERSION_MAJOR >= 82 && LIBDNS_VERSION_MAJOR < 140 */ +#if LIBDNS_VERSION_MAJOR >= 140 rpz_attach, rpz_ready, +#endif /* LIBDNS_VERSION_MAJOR >= 140 */ +#if LIBDNS_VERSION_MAJOR >= 90 findnodeext, findext, +#endif /* LIBDNS_VERSION_MAJOR >= 90 */ +#if LIBDNS_VERSION_MAJOR >= 140 setcachestats, hashsize +#endif /* LIBDNS_VERSION_MAJOR >= 140 */ }; isc_result_t ATTR_NONNULLS -- 2.9.3