diff options
author | Martin Nagy <mnagy@redhat.com> | 2008-12-09 19:43:46 +0100 |
---|---|---|
committer | Martin Nagy <mnagy@redhat.com> | 2009-02-11 20:40:41 +0100 |
commit | aad64960a5681975b032c1e4fcd133e8f806c9cb (patch) | |
tree | e3099ae4b413a16558c8834d2d4b8f7f003f5b8b /lib/dns | |
parent | f50ae72ec3417cae55dd4e085991c01af9fdc5f1 (diff) | |
download | bind_dynamic-aad64960a5681975b032c1e4fcd133e8f806c9cb.tar.gz bind_dynamic-aad64960a5681975b032c1e4fcd133e8f806c9cb.tar.xz bind_dynamic-aad64960a5681975b032c1e4fcd133e8f806c9cb.zip |
Add support for runtime loading of database backends.
Diffstat (limited to 'lib/dns')
-rw-r--r-- | lib/dns/Makefile.in | 5 | ||||
-rw-r--r-- | lib/dns/dynamic_db.c | 108 | ||||
-rw-r--r-- | lib/dns/include/dns/Makefile.in | 2 | ||||
-rw-r--r-- | lib/dns/include/dns/dynamic_db.h | 30 | ||||
-rw-r--r-- | lib/dns/include/dns/log.h | 1 | ||||
-rw-r--r-- | lib/dns/log.c | 1 |
6 files changed, 144 insertions, 3 deletions
diff --git a/lib/dns/Makefile.in b/lib/dns/Makefile.in index ef5c12a..0f7abba 100644 --- a/lib/dns/Makefile.in +++ b/lib/dns/Makefile.in @@ -57,7 +57,8 @@ DSTOBJS = @DST_EXTRA_OBJS@ \ DNSOBJS = acache.@O@ acl.@O@ adb.@O@ byaddr.@O@ \ cache.@O@ callbacks.@O@ compress.@O@ \ db.@O@ dbiterator.@O@ dbtable.@O@ diff.@O@ dispatch.@O@ \ - dlz.@O@ dnssec.@O@ ds.@O@ forward.@O@ iptable.@O@ journal.@O@ \ + dlz.@O@ dnssec.@O@ ds.@O@ dynamic_db.@O@ forward.@O@ \ + iptable.@O@ journal.@O@ \ keytable.@O@ lib.@O@ log.@O@ lookup.@O@ \ master.@O@ masterdump.@O@ message.@O@ \ name.@O@ ncache.@O@ nsec.@O@ nsec3.@O@ order.@O@ peer.@O@ portlist.@O@ \ @@ -83,7 +84,7 @@ DSTSRCS = @DST_EXTRA_SRCS@ \ DNSSRCS = acache.c acl.c adb.c byaddr.c \ cache.c callbacks.c compress.c \ db.c dbiterator.c dbtable.c diff.c dispatch.c \ - dlz.c dnssec.c ds.c forward.c iptable.c journal.c \ + dlz.c dnssec.c ds.c dynamic_db.c forward.c iptable.c journal.c \ keytable.c lib.c log.c lookup.c \ master.c masterdump.c message.c \ name.c ncache.c nsec.c nsec3.c order.c peer.c portlist.c \ diff --git a/lib/dns/dynamic_db.c b/lib/dns/dynamic_db.c new file mode 100644 index 0000000..fcee6a5 --- /dev/null +++ b/lib/dns/dynamic_db.c @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1996-2003 Internet Software Consortium. + * + * 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 <isc/result.h> +#include <isc/types.h> +#include <isc/util.h> + +#include <dns/dynamic_db.h> +#include <dns/log.h> +#include <dns/types.h> + + +/* TODO: Adjust configure.ac accordingly. */ +#define HAVE_DLOPEN 1 + +#if HAVE_DLOPEN +#include <dlfcn.h> +#endif + +#define CHECK(op) \ + do { result = (op); \ + if (result != ISC_R_SUCCESS) goto cleanup; \ + } while (0) + +typedef isc_result_t (*register_func_t)(isc_mem_t *mctx, const char *name, + const char * const *argv, dns_view_t *view); + +#if HAVE_DLOPEN +static isc_result_t +load_library(const char *filename, register_func_t *register_function) +{ + isc_result_t result; + void *handle; /* XXX: We don't keep the handle around. Should we? */ + const char *errmsg; + + REQUIRE(register_function != NULL && *register_function == NULL); + + handle = dlopen(filename, RTLD_LAZY); + if (handle == NULL) { + isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, + DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR, + "Failed to dynamically load driver '%s': %s", + filename, dlerror()); + CHECK(ISC_R_FAILURE); + } + dlerror(); + + *register_function = dlsym(handle, "dynamic_driver_init"); + if (*register_function == NULL) { + errmsg = dlerror(); + if (errmsg == NULL) + errmsg = "returned function pointer is NULL"; + isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, + DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR, + "Failed to lookup symbol dynamic_driver_init from %s: %s", + filename, errmsg); + CHECK(ISC_R_FAILURE); + } + dlerror(); + + return ISC_R_SUCCESS; + +cleanup: + if (handle != NULL) + dlclose(handle); + *register_function = NULL; + + return result; +} +#else +static isc_result_t +load_library(const char *filename, register_func_t *register_function) +{ + UNUSED(filename); + UNUSED(register_function); + + return ISC_R_NOTIMPLEMENTED; +} +#endif + +isc_result_t +dns_dynamic_db_load(const char *libname, const char *name, isc_mem_t *mctx, + const char * const *argv, dns_view_t *view) +{ + isc_result_t result; + register_func_t register_func = NULL; + + CHECK(load_library(libname, ®ister_func)); + CHECK(register_func(mctx, name, argv, view)); + +cleanup: + return result; +} diff --git a/lib/dns/include/dns/Makefile.in b/lib/dns/include/dns/Makefile.in index e9e049e..27fdc45 100644 --- a/lib/dns/include/dns/Makefile.in +++ b/lib/dns/include/dns/Makefile.in @@ -23,7 +23,7 @@ top_srcdir = @top_srcdir@ HEADERS = acl.h adb.h byaddr.h cache.h callbacks.h \ cert.h compress.h \ - db.h dbiterator.h dbtable.h diff.h dispatch.h dlz.h \ + db.h dbiterator.h dbtable.h diff.h dispatch.h dlz.h dynamic_db.h \ dnssec.h ds.h events.h fixedname.h iptable.h journal.h keyflags.h \ keytable.h keyvalues.h lib.h log.h master.h masterdump.h \ message.h name.h ncache.h \ diff --git a/lib/dns/include/dns/dynamic_db.h b/lib/dns/include/dns/dynamic_db.h new file mode 100644 index 0000000..c37fb83 --- /dev/null +++ b/lib/dns/include/dns/dynamic_db.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1996-2003 Internet Software Consortium. + * + * 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. + */ + + +#ifndef DYNAMIC_DB_H +#define DYNAMIC_DB_H + +#include <isc/types.h> +#include <dns/types.h> + +isc_result_t dns_dynamic_db_load(const char *libname, const char *name, + isc_mem_t *mctx, const char * const *argv, + dns_view_t *view); + + +#endif diff --git a/lib/dns/include/dns/log.h b/lib/dns/include/dns/log.h index 5adcedd..e171028 100644 --- a/lib/dns/include/dns/log.h +++ b/lib/dns/include/dns/log.h @@ -73,6 +73,7 @@ LIBDNS_EXTERNAL_DATA extern isc_logmodule_t dns_modules[]; #define DNS_LOGMODULE_HINTS (&dns_modules[24]) #define DNS_LOGMODULE_ACACHE (&dns_modules[25]) #define DNS_LOGMODULE_DLZ (&dns_modules[26]) +#define DNS_LOGMODULE_DYNDB (&dns_modules[27]) ISC_LANG_BEGINDECLS diff --git a/lib/dns/log.c b/lib/dns/log.c index 7551e15..b9864eb 100644 --- a/lib/dns/log.c +++ b/lib/dns/log.c @@ -79,6 +79,7 @@ LIBDNS_EXTERNAL_DATA isc_logmodule_t dns_modules[] = { { "dns/hints", 0 }, { "dns/acache", 0 }, { "dns/dlz", 0 }, + { "dns/dynamic_db", 0 }, { NULL, 0 } }; |