bc5dde
diff -up bind-9.9.2/bin/named/main.c.dyndb bind-9.9.2/bin/named/main.c
bc5dde
--- bind-9.9.2/bin/named/main.c.dyndb	2012-09-27 02:35:19.000000000 +0200
bc5dde
+++ bind-9.9.2/bin/named/main.c	2012-10-11 13:13:10.626497598 +0200
bc5dde
@@ -45,6 +45,7 @@
bc5dde
 #include <isccc/result.h>
bc5dde
 
bc5dde
 #include <dns/dispatch.h>
bc5dde
+#include <dns/dynamic_db.h>
bc5dde
 #include <dns/name.h>
bc5dde
 #include <dns/result.h>
bc5dde
 #include <dns/view.h>
bc5dde
diff -up bind-9.9.2/bin/named/server.c.dyndb bind-9.9.2/bin/named/server.c
bc5dde
--- bind-9.9.2/bin/named/server.c.dyndb	2012-09-27 02:35:19.000000000 +0200
bc5dde
+++ bind-9.9.2/bin/named/server.c	2012-10-11 13:13:10.630497590 +0200
bc5dde
@@ -63,6 +63,7 @@
bc5dde
 #include <dns/db.h>
bc5dde
 #include <dns/dispatch.h>
bc5dde
 #include <dns/dlz.h>
bc5dde
+#include <dns/dynamic_db.h>
bc5dde
 #include <dns/dns64.h>
bc5dde
 #include <dns/forward.h>
bc5dde
 #include <dns/journal.h>
bc5dde
@@ -1161,6 +1162,72 @@ configure_peer(const cfg_obj_t *cpeer, i
bc5dde
 }
bc5dde
 
bc5dde
 static isc_result_t
bc5dde
+configure_dynamic_db(const cfg_obj_t *dynamic_db, isc_mem_t *mctx,
bc5dde
+		     const dns_dyndb_arguments_t *dyndb_args)
bc5dde
+{
bc5dde
+	isc_result_t result;
bc5dde
+	const cfg_obj_t *obj;
bc5dde
+	const cfg_obj_t *options;
bc5dde
+	const cfg_listelt_t *element;
bc5dde
+	const char *name;
bc5dde
+	const char *libname;
bc5dde
+	const char **argv = NULL;
bc5dde
+	unsigned int i;
bc5dde
+	unsigned int len;
bc5dde
+
bc5dde
+	/* Get the name of the database. */
bc5dde
+	obj = cfg_tuple_get(dynamic_db, "name");
bc5dde
+	name = cfg_obj_asstring(obj);
bc5dde
+
bc5dde
+	/* Get options. */
bc5dde
+	options = cfg_tuple_get(dynamic_db, "options");
bc5dde
+
bc5dde
+	/* Get library name. */
bc5dde
+	obj = NULL;
bc5dde
+	CHECK(cfg_map_get(options, "library", &obj));
bc5dde
+	libname = cfg_obj_asstring(obj);
bc5dde
+
bc5dde
+	/* Create a list of arguments. */
bc5dde
+	obj = NULL;
bc5dde
+	result = cfg_map_get(options, "arg", &obj);
bc5dde
+	if (result == ISC_R_NOTFOUND)
bc5dde
+		len = 0;
bc5dde
+	else if (result == ISC_R_SUCCESS)
bc5dde
+		len = cfg_list_length(obj, isc_boolean_false);
bc5dde
+	else
bc5dde
+		goto cleanup;
bc5dde
+
bc5dde
+	/* Account for the last terminating NULL. */
bc5dde
+	len++;
bc5dde
+
bc5dde
+	argv = isc_mem_allocate(mctx, len * sizeof(const char *));
bc5dde
+	if (argv == NULL) {
bc5dde
+		result = ISC_R_NOMEMORY;
bc5dde
+		goto cleanup;
bc5dde
+	}
bc5dde
+	for (element = cfg_list_first(obj), i = 0;
bc5dde
+	     element != NULL;
bc5dde
+	     element = cfg_list_next(element), i++)
bc5dde
+	{
bc5dde
+		REQUIRE(i < len);
bc5dde
+
bc5dde
+		obj = cfg_listelt_value(element);
bc5dde
+		argv[i] = cfg_obj_asstring(obj);
bc5dde
+	}
bc5dde
+	REQUIRE(i < len);
bc5dde
+	argv[i] = NULL;
bc5dde
+
bc5dde
+	CHECK(dns_dynamic_db_load(libname, name, mctx, argv, dyndb_args));
bc5dde
+
bc5dde
+cleanup:
bc5dde
+	if (argv != NULL)
bc5dde
+		isc_mem_free(mctx, argv);
bc5dde
+
bc5dde
+	return result;
bc5dde
+}
bc5dde
+
bc5dde
+
bc5dde
+static isc_result_t
bc5dde
 disable_algorithms(const cfg_obj_t *disabled, dns_resolver_t *resolver) {
bc5dde
 	isc_result_t result;
bc5dde
 	const cfg_obj_t *algorithms;
bc5dde
@@ -1586,6 +1653,7 @@ configure_view(dns_view_t *view, cfg_obj
bc5dde
 	const cfg_obj_t *dlz;
bc5dde
 	unsigned int dlzargc;
bc5dde
 	char **dlzargv;
bc5dde
+	const cfg_obj_t *dynamic_db_list;
bc5dde
 	const cfg_obj_t *disabled;
bc5dde
 	const cfg_obj_t *obj;
bc5dde
 	const cfg_listelt_t *element;
bc5dde
@@ -1816,6 +1884,8 @@ configure_view(dns_view_t *view, cfg_obj
bc5dde
 		}
bc5dde
 	}
bc5dde
 
bc5dde
+
bc5dde
+
bc5dde
 	/*
bc5dde
 	 * Obtain configuration parameters that affect the decision of whether
bc5dde
 	 * we can reuse/share an existing cache.
bc5dde
@@ -2721,6 +2791,37 @@ configure_view(dns_view_t *view, cfg_obj
bc5dde
 		dns_view_setrootdelonly(view, ISC_FALSE);
bc5dde
 
bc5dde
 	/*
bc5dde
+	 * Configure dynamic databases.
bc5dde
+	 */
bc5dde
+	dynamic_db_list = NULL;
bc5dde
+	if (voptions != NULL)
bc5dde
+		(void)cfg_map_get(voptions, "dynamic-db", &dynamic_db_list);
bc5dde
+	else
bc5dde
+		(void)cfg_map_get(config, "dynamic-db", &dynamic_db_list);
bc5dde
+	element = cfg_list_first(dynamic_db_list);
bc5dde
+	if (element != NULL) {
bc5dde
+		dns_dyndb_arguments_t *args;
bc5dde
+
bc5dde
+		args = dns_dyndb_arguments_create(mctx);
bc5dde
+		if (args == NULL) {
bc5dde
+			result = ISC_R_NOMEMORY;
bc5dde
+			goto cleanup;
bc5dde
+		}
bc5dde
+		dns_dyndb_set_view(args, view);
bc5dde
+		dns_dyndb_set_zonemgr(args, ns_g_server->zonemgr);
bc5dde
+		dns_dyndb_set_task(args, ns_g_server->task);
bc5dde
+		dns_dyndb_set_timermgr(args, ns_g_timermgr);
bc5dde
+		while (element != NULL) {
bc5dde
+			obj = cfg_listelt_value(element);
bc5dde
+			CHECK(configure_dynamic_db(obj, mctx, args));
bc5dde
+		
bc5dde
+			element = cfg_list_next(element);
bc5dde
+		}
bc5dde
+
bc5dde
+		dns_dyndb_arguments_destroy(mctx, args);
bc5dde
+	}
bc5dde
+
bc5dde
+	/*
bc5dde
 	 * Setup automatic empty zones.  If recursion is off then
bc5dde
 	 * they are disabled by default.
bc5dde
 	 */
bc5dde
@@ -4388,6 +4489,7 @@ load_configuration(const char *filename,
bc5dde
 		cfg_aclconfctx_detach(&ns_g_aclconfctx);
bc5dde
 	CHECK(cfg_aclconfctx_create(ns_g_mctx, &ns_g_aclconfctx));
bc5dde
 
bc5dde
+	dns_dynamic_db_cleanup(ISC_FALSE);
bc5dde
 	/*
bc5dde
 	 * Parse the global default pseudo-config file.
bc5dde
 	 */
bc5dde
@@ -5493,6 +5595,8 @@ shutdown_server(isc_task_t *task, isc_ev
bc5dde
 			dns_view_detach(&view);
bc5dde
 	}
bc5dde
 
bc5dde
+	dns_dynamic_db_cleanup(ISC_TRUE);
bc5dde
+
bc5dde
 	while ((nsc = ISC_LIST_HEAD(server->cachelist)) != NULL) {
bc5dde
 		ISC_LIST_UNLINK(server->cachelist, nsc, link);
bc5dde
 		dns_cache_detach(&nsc->cache);
bc5dde
diff -up bind-9.9.2/lib/dns/dynamic_db.c.dyndb bind-9.9.2/lib/dns/dynamic_db.c
bc5dde
--- bind-9.9.2/lib/dns/dynamic_db.c.dyndb	2012-10-11 13:13:10.630497590 +0200
bc5dde
+++ bind-9.9.2/lib/dns/dynamic_db.c	2012-10-11 13:13:10.630497590 +0200
bc5dde
@@ -0,0 +1,366 @@
bc5dde
+/*
bc5dde
+ * Copyright (C) 2008-2011  Red Hat, Inc.
bc5dde
+ *
bc5dde
+ * Permission to use, copy, modify, and/or distribute this software for any
bc5dde
+ * purpose with or without fee is hereby granted, provided that the above
bc5dde
+ * copyright notice and this permission notice appear in all copies.
bc5dde
+ *
bc5dde
+ * THE SOFTWARE IS PROVIDED "AS IS" AND Red Hat DISCLAIMS ALL WARRANTIES WITH
bc5dde
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
bc5dde
+ * AND FITNESS.  IN NO EVENT SHALL Red Hat BE LIABLE FOR ANY SPECIAL, DIRECT,
bc5dde
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
bc5dde
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
bc5dde
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
bc5dde
+ * PERFORMANCE OF THIS SOFTWARE.
bc5dde
+ */
bc5dde
+
bc5dde
+
bc5dde
+#include <config.h>
bc5dde
+
bc5dde
+#include <isc/buffer.h>
bc5dde
+#include <isc/mem.h>
bc5dde
+#include <isc/mutex.h>
bc5dde
+#include <isc/once.h>
bc5dde
+#include <isc/result.h>
bc5dde
+#include <isc/region.h>
bc5dde
+#include <isc/task.h>
bc5dde
+#include <isc/types.h>
bc5dde
+#include <isc/util.h>
bc5dde
+
bc5dde
+#include <dns/dynamic_db.h>
bc5dde
+#include <dns/log.h>
bc5dde
+#include <dns/types.h>
bc5dde
+#include <dns/view.h>
bc5dde
+#include <dns/zone.h>
bc5dde
+
bc5dde
+#include <string.h>
bc5dde
+
bc5dde
+#if HAVE_DLFCN_H
bc5dde
+#include <dlfcn.h>
bc5dde
+#endif
bc5dde
+
bc5dde
+#ifndef DYNDB_LIBDIR
bc5dde
+#define DYNDB_LIBDIR ""
bc5dde
+#endif
bc5dde
+
bc5dde
+#define CHECK(op)						\
bc5dde
+	do { result = (op);					\
bc5dde
+		if (result != ISC_R_SUCCESS) goto cleanup;	\
bc5dde
+	} while (0)
bc5dde
+
bc5dde
+
bc5dde
+typedef isc_result_t (*register_func_t)(isc_mem_t *mctx, const char *name,
bc5dde
+		const char * const *argv,
bc5dde
+		const dns_dyndb_arguments_t *dyndb_args);
bc5dde
+typedef void (*destroy_func_t)(void);
bc5dde
+
bc5dde
+typedef struct dyndb_implementation dyndb_implementation_t;
bc5dde
+
bc5dde
+struct dyndb_implementation {
bc5dde
+	isc_mem_t			*mctx;
bc5dde
+	void				*handle;
bc5dde
+	register_func_t			register_function;
bc5dde
+	destroy_func_t			destroy_function;
bc5dde
+	LINK(dyndb_implementation_t)	link;
bc5dde
+};
bc5dde
+
bc5dde
+struct dns_dyndb_arguments {
bc5dde
+	dns_view_t	*view;
bc5dde
+	dns_zonemgr_t	*zmgr;
bc5dde
+	isc_task_t	*task;
bc5dde
+	isc_timermgr_t	*timermgr;
bc5dde
+};
bc5dde
+
bc5dde
+/* List of implementations. Locked by dyndb_lock. */
bc5dde
+static LIST(dyndb_implementation_t) dyndb_implementations;
bc5dde
+/* Locks dyndb_implementations. */
bc5dde
+static isc_mutex_t dyndb_lock;
bc5dde
+static isc_once_t once = ISC_ONCE_INIT;
bc5dde
+
bc5dde
+static void
bc5dde
+dyndb_initialize(void) {
bc5dde
+	RUNTIME_CHECK(isc_mutex_init(&dyndb_lock) == ISC_R_SUCCESS);
bc5dde
+	INIT_LIST(dyndb_implementations);
bc5dde
+}
bc5dde
+
bc5dde
+
bc5dde
+#if HAVE_DLFCN_H
bc5dde
+static isc_result_t
bc5dde
+load_symbol(void *handle, const char *symbol_name, void **symbolp)
bc5dde
+{
bc5dde
+	const char *errmsg;
bc5dde
+	void *symbol;
bc5dde
+
bc5dde
+	REQUIRE(handle != NULL);
bc5dde
+	REQUIRE(symbolp != NULL && *symbolp == NULL);
bc5dde
+
bc5dde
+	symbol = dlsym(handle, symbol_name);
bc5dde
+	if (symbol == NULL) {
bc5dde
+		errmsg = dlerror();
bc5dde
+		if (errmsg == NULL)
bc5dde
+			errmsg = "returned function pointer is NULL";
bc5dde
+		isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
bc5dde
+			      DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR,
bc5dde
+			      "failed to lookup symbol %s: %s",
bc5dde
+			      symbol_name, errmsg);
bc5dde
+		return ISC_R_FAILURE;
bc5dde
+	}
bc5dde
+	dlerror();
bc5dde
+
bc5dde
+	*symbolp = symbol;
bc5dde
+
bc5dde
+	return ISC_R_SUCCESS;
bc5dde
+}
bc5dde
+
bc5dde
+static isc_result_t
bc5dde
+load_library(isc_mem_t *mctx, const char *filename, dyndb_implementation_t **impp)
bc5dde
+{
bc5dde
+	isc_result_t result;
bc5dde
+	size_t module_size;
bc5dde
+	isc_buffer_t *module_buf = NULL;
bc5dde
+	isc_region_t module_region;
bc5dde
+	void *handle = NULL;
bc5dde
+	dyndb_implementation_t *imp;
bc5dde
+	register_func_t register_function = NULL;
bc5dde
+	destroy_func_t destroy_function = NULL;
bc5dde
+
bc5dde
+	REQUIRE(impp != NULL && *impp == NULL);
bc5dde
+
bc5dde
+	/* Build up the full path. */
bc5dde
+	module_size = strlen(DYNDB_LIBDIR) + strlen(filename) + 1;
bc5dde
+	CHECK(isc_buffer_allocate(mctx, &module_buf, module_size));
bc5dde
+	isc_buffer_putstr(module_buf, DYNDB_LIBDIR);
bc5dde
+	isc_buffer_putstr(module_buf, filename);
bc5dde
+	isc_buffer_putuint8(module_buf, 0);
bc5dde
+	isc_buffer_region(module_buf, &module_region);
bc5dde
+
bc5dde
+	handle = dlopen((char *)module_region.base, RTLD_LAZY);
bc5dde
+	if (handle == NULL) {
bc5dde
+		isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
bc5dde
+			      DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR,
bc5dde
+			      "failed to dynamically load driver '%s': %s",
bc5dde
+			      filename, dlerror());
bc5dde
+		result = ISC_R_FAILURE;
bc5dde
+		goto cleanup;
bc5dde
+	}
bc5dde
+	dlerror();
bc5dde
+
bc5dde
+	CHECK(load_symbol(handle, "dynamic_driver_init",
bc5dde
+			  (void **)&register_function));
bc5dde
+	CHECK(load_symbol(handle, "dynamic_driver_destroy",
bc5dde
+			  (void **)&destroy_function));
bc5dde
+
bc5dde
+	imp = isc_mem_get(mctx, sizeof(dyndb_implementation_t));
bc5dde
+	if (imp == NULL) {
bc5dde
+		result = ISC_R_NOMEMORY;
bc5dde
+		goto cleanup;
bc5dde
+	}
bc5dde
+
bc5dde
+	imp->mctx = NULL;
bc5dde
+	isc_mem_attach(mctx, &imp->mctx);
bc5dde
+	imp->handle = handle;
bc5dde
+	imp->register_function = register_function;
bc5dde
+	imp->destroy_function = destroy_function;
bc5dde
+	INIT_LINK(imp, link);
bc5dde
+
bc5dde
+	*impp = imp;
bc5dde
+
bc5dde
+cleanup:
bc5dde
+	if (result != ISC_R_SUCCESS && handle != NULL)
bc5dde
+		dlclose(handle);
bc5dde
+	if (module_buf != NULL)
bc5dde
+		isc_buffer_free(&module_buf);
bc5dde
+
bc5dde
+	return result;
bc5dde
+}
bc5dde
+
bc5dde
+static void
bc5dde
+unload_library(dyndb_implementation_t **impp)
bc5dde
+{
bc5dde
+	dyndb_implementation_t *imp;
bc5dde
+
bc5dde
+	REQUIRE(impp != NULL && *impp != NULL);
bc5dde
+
bc5dde
+	imp = *impp;
bc5dde
+
bc5dde
+	isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
bc5dde
+
bc5dde
+	*impp = NULL;
bc5dde
+}
bc5dde
+
bc5dde
+#else	/* HAVE_DLFCN_H */
bc5dde
+static isc_result_t
bc5dde
+load_library(isc_mem_t *mctx, const char *filename, dyndb_implementation_t **impp)
bc5dde
+{
bc5dde
+	UNUSED(mctx);
bc5dde
+	UNUSED(filename);
bc5dde
+	UNUSED(impp);
bc5dde
+
bc5dde
+	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DYNDB,
bc5dde
+		      ISC_LOG_ERROR,
bc5dde
+		      "dynamic database support is not implemented")
bc5dde
+
bc5dde
+	return ISC_R_NOTIMPLEMENTED;
bc5dde
+}
bc5dde
+
bc5dde
+static void
bc5dde
+unload_library(dyndb_implementation_t **impp)
bc5dde
+{
bc5dde
+	dyndb_implementation_t *imp;
bc5dde
+
bc5dde
+	REQUIRE(impp != NULL && *impp != NULL);
bc5dde
+
bc5dde
+	imp = *impp;
bc5dde
+
bc5dde
+	isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
bc5dde
+
bc5dde
+	*impp = NULL;
bc5dde
+}
bc5dde
+#endif	/* HAVE_DLFCN_H */
bc5dde
+
bc5dde
+isc_result_t
bc5dde
+dns_dynamic_db_load(const char *libname, const char *name, isc_mem_t *mctx,
bc5dde
+		    const char * const *argv,
bc5dde
+		    const dns_dyndb_arguments_t *dyndb_args)
bc5dde
+{
bc5dde
+	isc_result_t result;
bc5dde
+	dyndb_implementation_t *implementation = NULL;
bc5dde
+
bc5dde
+	RUNTIME_CHECK(isc_once_do(&once, dyndb_initialize) == ISC_R_SUCCESS);
bc5dde
+
bc5dde
+	CHECK(load_library(mctx, libname, &implementation));
bc5dde
+	CHECK(implementation->register_function(mctx, name, argv, dyndb_args));
bc5dde
+
bc5dde
+	LOCK(&dyndb_lock);
bc5dde
+	APPEND(dyndb_implementations, implementation, link);
bc5dde
+	UNLOCK(&dyndb_lock);
bc5dde
+
bc5dde
+	return ISC_R_SUCCESS;
bc5dde
+
bc5dde
+cleanup:
bc5dde
+	if (implementation != NULL)
bc5dde
+		unload_library(&implementation);
bc5dde
+
bc5dde
+	return result;
bc5dde
+}
bc5dde
+
bc5dde
+void
bc5dde
+dns_dynamic_db_cleanup(isc_boolean_t exiting)
bc5dde
+{
bc5dde
+	dyndb_implementation_t *elem;
bc5dde
+	dyndb_implementation_t *prev;
bc5dde
+
bc5dde
+	RUNTIME_CHECK(isc_once_do(&once, dyndb_initialize) == ISC_R_SUCCESS);
bc5dde
+
bc5dde
+	LOCK(&dyndb_lock);
bc5dde
+	elem = TAIL(dyndb_implementations);
bc5dde
+	while (elem != NULL) {
bc5dde
+		prev = PREV(elem, link);
bc5dde
+		UNLINK(dyndb_implementations, elem, link);
bc5dde
+		elem->destroy_function();
bc5dde
+		unload_library(&elem);
bc5dde
+		elem = prev;
bc5dde
+	}
bc5dde
+	UNLOCK(&dyndb_lock);
bc5dde
+
bc5dde
+	if (exiting == ISC_TRUE)
bc5dde
+		isc_mutex_destroy(&dyndb_lock);
bc5dde
+}
bc5dde
+
bc5dde
+dns_dyndb_arguments_t *
bc5dde
+dns_dyndb_arguments_create(isc_mem_t *mctx)
bc5dde
+{
bc5dde
+	dns_dyndb_arguments_t *args;
bc5dde
+
bc5dde
+	args = isc_mem_get(mctx, sizeof(*args));
bc5dde
+	if (args != NULL)
bc5dde
+		memset(args, 0, sizeof(*args));
bc5dde
+
bc5dde
+	return args;
bc5dde
+}
bc5dde
+
bc5dde
+void
bc5dde
+dns_dyndb_arguments_destroy(isc_mem_t *mctx, dns_dyndb_arguments_t *args)
bc5dde
+{
bc5dde
+	REQUIRE(args != NULL);
bc5dde
+
bc5dde
+	dns_dyndb_set_view(args, NULL);
bc5dde
+	dns_dyndb_set_zonemgr(args, NULL);
bc5dde
+	dns_dyndb_set_task(args, NULL);
bc5dde
+	dns_dyndb_set_timermgr(args, NULL);
bc5dde
+
bc5dde
+	isc_mem_put(mctx, args, sizeof(*args));
bc5dde
+}
bc5dde
+
bc5dde
+void
bc5dde
+dns_dyndb_set_view(dns_dyndb_arguments_t *args, dns_view_t *view)
bc5dde
+{
bc5dde
+	REQUIRE(args != NULL);
bc5dde
+
bc5dde
+	if (args->view != NULL)
bc5dde
+		dns_view_detach(&args->view);
bc5dde
+	if (view != NULL)
bc5dde
+		dns_view_attach(view, &args->view);
bc5dde
+}
bc5dde
+
bc5dde
+dns_view_t *
bc5dde
+dns_dyndb_get_view(dns_dyndb_arguments_t *args)
bc5dde
+{
bc5dde
+	REQUIRE(args != NULL);
bc5dde
+
bc5dde
+	return args->view;
bc5dde
+}
bc5dde
+
bc5dde
+void
bc5dde
+dns_dyndb_set_zonemgr(dns_dyndb_arguments_t *args, dns_zonemgr_t *zmgr)
bc5dde
+{
bc5dde
+	REQUIRE(args != NULL);
bc5dde
+
bc5dde
+	if (args->zmgr != NULL)
bc5dde
+		dns_zonemgr_detach(&args->zmgr);
bc5dde
+	if (zmgr != NULL)
bc5dde
+		dns_zonemgr_attach(zmgr, &args->zmgr);
bc5dde
+}
bc5dde
+
bc5dde
+dns_zonemgr_t *
bc5dde
+dns_dyndb_get_zonemgr(dns_dyndb_arguments_t *args)
bc5dde
+{
bc5dde
+	REQUIRE(args != NULL);
bc5dde
+
bc5dde
+	return args->zmgr;
bc5dde
+}
bc5dde
+
bc5dde
+void
bc5dde
+dns_dyndb_set_task(dns_dyndb_arguments_t *args, isc_task_t *task)
bc5dde
+{
bc5dde
+	REQUIRE(args != NULL);
bc5dde
+
bc5dde
+	if (args->task != NULL)
bc5dde
+		isc_task_detach(&args->task);
bc5dde
+	if (task != NULL)
bc5dde
+		isc_task_attach(task, &args->task);
bc5dde
+}
bc5dde
+
bc5dde
+isc_task_t *
bc5dde
+dns_dyndb_get_task(dns_dyndb_arguments_t *args)
bc5dde
+{
bc5dde
+	REQUIRE(args != NULL);
bc5dde
+
bc5dde
+	return args->task;
bc5dde
+}
bc5dde
+
bc5dde
+void
bc5dde
+dns_dyndb_set_timermgr(dns_dyndb_arguments_t *args, isc_timermgr_t *timermgr)
bc5dde
+{
bc5dde
+	REQUIRE(args != NULL);
bc5dde
+
bc5dde
+	args->timermgr = timermgr;
bc5dde
+}
bc5dde
+
bc5dde
+isc_timermgr_t *
bc5dde
+dns_dyndb_get_timermgr(dns_dyndb_arguments_t *args)
bc5dde
+{
bc5dde
+	REQUIRE(args != NULL);
bc5dde
+
bc5dde
+	return args->timermgr;
bc5dde
+}
bc5dde
diff -up bind-9.9.2/lib/dns/include/dns/dynamic_db.h.dyndb bind-9.9.2/lib/dns/include/dns/dynamic_db.h
bc5dde
--- bind-9.9.2/lib/dns/include/dns/dynamic_db.h.dyndb	2012-10-11 13:13:10.631497588 +0200
bc5dde
+++ bind-9.9.2/lib/dns/include/dns/dynamic_db.h	2012-10-11 13:13:10.631497588 +0200
bc5dde
@@ -0,0 +1,50 @@
bc5dde
+/*
bc5dde
+ * Copyright (C) 2008-2011  Red Hat, Inc.
bc5dde
+ *
bc5dde
+ * Permission to use, copy, modify, and/or distribute this software for any
bc5dde
+ * purpose with or without fee is hereby granted, provided that the above
bc5dde
+ * copyright notice and this permission notice appear in all copies.
bc5dde
+ *
bc5dde
+ * THE SOFTWARE IS PROVIDED "AS IS" AND Red Hat DISCLAIMS ALL WARRANTIES WITH
bc5dde
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
bc5dde
+ * AND FITNESS.  IN NO EVENT SHALL Red Hat BE LIABLE FOR ANY SPECIAL, DIRECT,
bc5dde
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
bc5dde
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
bc5dde
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
bc5dde
+ * PERFORMANCE OF THIS SOFTWARE.
bc5dde
+ */
bc5dde
+
bc5dde
+
bc5dde
+#ifndef DYNAMIC_DB_H
bc5dde
+#define DYNAMIC_DB_H
bc5dde
+
bc5dde
+#include <isc/types.h>
bc5dde
+
bc5dde
+#include <dns/types.h>
bc5dde
+
bc5dde
+/*
bc5dde
+ * TODO:
bc5dde
+ * Reformat the prototypes.
bc5dde
+ * Add annotated comments.
bc5dde
+ */
bc5dde
+
bc5dde
+isc_result_t dns_dynamic_db_load(const char *libname, const char *name,
bc5dde
+				 isc_mem_t *mctx, const char * const *argv,
bc5dde
+				 const dns_dyndb_arguments_t *dyndb_args);
bc5dde
+
bc5dde
+void dns_dynamic_db_cleanup(isc_boolean_t exiting);
bc5dde
+
bc5dde
+dns_dyndb_arguments_t *dns_dyndb_arguments_create(isc_mem_t *mctx);
bc5dde
+void dns_dyndb_arguments_destroy(isc_mem_t *mctx, dns_dyndb_arguments_t *args);
bc5dde
+
bc5dde
+void dns_dyndb_set_view(dns_dyndb_arguments_t *args, dns_view_t *view);
bc5dde
+dns_view_t *dns_dyndb_get_view(dns_dyndb_arguments_t *args);
bc5dde
+void dns_dyndb_set_zonemgr(dns_dyndb_arguments_t *args, dns_zonemgr_t *zmgr);
bc5dde
+dns_zonemgr_t *dns_dyndb_get_zonemgr(dns_dyndb_arguments_t *args);
bc5dde
+void dns_dyndb_set_task(dns_dyndb_arguments_t *args, isc_task_t *task);
bc5dde
+isc_task_t *dns_dyndb_get_task(dns_dyndb_arguments_t *args);
bc5dde
+void dns_dyndb_set_timermgr(dns_dyndb_arguments_t *args,
bc5dde
+			    isc_timermgr_t *timermgr);
bc5dde
+isc_timermgr_t *dns_dyndb_get_timermgr(dns_dyndb_arguments_t *args);
bc5dde
+
bc5dde
+#endif
bc5dde
diff -up bind-9.9.2/lib/dns/include/dns/log.h.dyndb bind-9.9.2/lib/dns/include/dns/log.h
bc5dde
--- bind-9.9.2/lib/dns/include/dns/log.h.dyndb	2012-09-27 02:35:19.000000000 +0200
bc5dde
+++ bind-9.9.2/lib/dns/include/dns/log.h	2012-10-11 13:13:45.309399482 +0200
bc5dde
@@ -76,6 +76,7 @@ LIBDNS_EXTERNAL_DATA extern isc_logmodul
bc5dde
 #define DNS_LOGMODULE_DLZ		(&dns_modules[26])
bc5dde
 #define DNS_LOGMODULE_DNSSEC		(&dns_modules[27])
bc5dde
 #define DNS_LOGMODULE_CRYPTO		(&dns_modules[28])
bc5dde
+#define DNS_LOGMODULE_DYNDB		(&dns_modules[29])
bc5dde
 
bc5dde
 ISC_LANG_BEGINDECLS
bc5dde
 
bc5dde
diff -up bind-9.9.2/lib/dns/include/dns/Makefile.in.dyndb bind-9.9.2/lib/dns/include/dns/Makefile.in
bc5dde
--- bind-9.9.2/lib/dns/include/dns/Makefile.in.dyndb	2012-09-27 02:35:19.000000000 +0200
bc5dde
+++ bind-9.9.2/lib/dns/include/dns/Makefile.in	2012-10-11 13:13:10.632497587 +0200
bc5dde
@@ -22,7 +22,7 @@ top_srcdir =	@top_srcdir@
bc5dde
 @BIND9_VERSION@
bc5dde
 
bc5dde
 HEADERS =	acl.h adb.h byaddr.h cache.h callbacks.h cert.h compress.h \
bc5dde
-		clientinfo.h db.h dbiterator.h dbtable.h diff.h dispatch.h \
bc5dde
+		clientinfo.h db.h dbiterator.h dbtable.h diff.h dispatch.h dynamic_db.h \
bc5dde
 		dlz.h dnssec.h ds.h events.h fixedname.h iptable.h journal.h \
bc5dde
 		keyflags.h keytable.h keyvalues.h lib.h log.h \
bc5dde
 		master.h masterdump.h message.h name.h ncache.h nsec.h \
bc5dde
diff -up bind-9.9.2/lib/dns/include/dns/types.h.dyndb bind-9.9.2/lib/dns/include/dns/types.h
bc5dde
--- bind-9.9.2/lib/dns/include/dns/types.h.dyndb	2012-09-27 02:35:19.000000000 +0200
bc5dde
+++ bind-9.9.2/lib/dns/include/dns/types.h	2012-10-11 13:13:10.632497587 +0200
bc5dde
@@ -60,6 +60,7 @@ typedef struct dns_dbtable			dns_dbtable
bc5dde
 typedef void					dns_dbversion_t;
bc5dde
 typedef struct dns_dlzimplementation		dns_dlzimplementation_t;
bc5dde
 typedef struct dns_dlzdb			dns_dlzdb_t;
bc5dde
+typedef struct dns_dyndb_arguments		dns_dyndb_arguments_t;
bc5dde
 typedef struct dns_sdlzimplementation		dns_sdlzimplementation_t;
bc5dde
 typedef struct dns_decompress			dns_decompress_t;
bc5dde
 typedef struct dns_dispatch			dns_dispatch_t;
bc5dde
diff -up bind-9.9.2/lib/dns/log.c.dyndb bind-9.9.2/lib/dns/log.c
bc5dde
--- bind-9.9.2/lib/dns/log.c.dyndb	2012-09-27 02:35:19.000000000 +0200
bc5dde
+++ bind-9.9.2/lib/dns/log.c	2012-10-11 13:15:15.085414483 +0200
bc5dde
@@ -82,6 +82,7 @@ LIBDNS_EXTERNAL_DATA isc_logmodule_t dns
bc5dde
 	{ "dns/dlz",		0 },
bc5dde
 	{ "dns/dnssec",		0 },
bc5dde
 	{ "dns/crypto",		0 },
bc5dde
+	{ "dns/dynamic_db",	0 },
bc5dde
 	{ NULL, 		0 }
bc5dde
 };
bc5dde
 
bc5dde
diff -up bind-9.9.2/lib/dns/Makefile.in.dyndb bind-9.9.2/lib/dns/Makefile.in
bc5dde
--- bind-9.9.2/lib/dns/Makefile.in.dyndb	2012-10-11 13:13:10.605497637 +0200
bc5dde
+++ bind-9.9.2/lib/dns/Makefile.in	2012-10-11 13:13:10.633497585 +0200
bc5dde
@@ -59,7 +59,7 @@ DNSOBJS =	acache.@O@ acl.@O@ adb.@O@ bya
bc5dde
 		cache.@O@ callbacks.@O@ clientinfo.@O@ compress.@O@ \
bc5dde
 		db.@O@ dbiterator.@O@ dbtable.@O@ diff.@O@ dispatch.@O@ \
bc5dde
 		dlz.@O@ dns64.@O@ dnssec.@O@ ds.@O@ forward.@O@ iptable.@O@ \
bc5dde
-		journal.@O@ keydata.@O@ keytable.@O@ \
bc5dde
+		dynamic_db.@O@ journal.@O@ keydata.@O@ keytable.@O@ \
bc5dde
 		lib.@O@ log.@O@ lookup.@O@ \
bc5dde
 		master.@O@ masterdump.@O@ message.@O@ \
bc5dde
 		name.@O@ ncache.@O@ nsec.@O@ nsec3.@O@ order.@O@ peer.@O@ \
bc5dde
@@ -88,7 +88,7 @@ DNSSRCS =	acache.c acl.c adb.c byaddr.c
bc5dde
 		cache.c callbacks.c clientinfo.c compress.c \
bc5dde
 		db.c dbiterator.c dbtable.c diff.c dispatch.c \
bc5dde
 		dlz.c dns64.c dnssec.c ds.c forward.c iptable.c journal.c \
bc5dde
-		keydata.c keytable.c lib.c log.c lookup.c \
bc5dde
+		dynamic_db.c keydata.c keytable.c lib.c log.c lookup.c \
bc5dde
 		master.c masterdump.c message.c \
bc5dde
 		name.c ncache.c nsec.c nsec3.c order.c peer.c portlist.c \
bc5dde
 		rbt.c rbtdb.c rbtdb64.c rcode.c rdata.c rdatalist.c \
bc5dde
@@ -119,6 +119,11 @@ version.@O@: version.c
bc5dde
 		-DLIBAGE=${LIBAGE} \
bc5dde
 		-c ${srcdir}/version.c
bc5dde
 
bc5dde
+dynamic_db.@O@: dynamic_db.c
bc5dde
+	${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} \
bc5dde
+	-DDYNDB_LIBDIR=\"@libdir@/bind/\" \
bc5dde
+	-c ${srcdir}/dynamic_db.c
bc5dde
+
bc5dde
 libdns.@SA@: ${OBJS}
bc5dde
 	${AR} ${ARFLAGS} $@ ${OBJS}
bc5dde
 	${RANLIB} $@
bc5dde
diff -up bind-9.9.2/lib/isccfg/namedconf.c.dyndb bind-9.9.2/lib/isccfg/namedconf.c
bc5dde
--- bind-9.9.2/lib/isccfg/namedconf.c.dyndb	2012-09-27 02:35:19.000000000 +0200
bc5dde
+++ bind-9.9.2/lib/isccfg/namedconf.c	2012-10-11 13:13:10.634497583 +0200
bc5dde
@@ -89,6 +89,7 @@ static cfg_type_t cfg_type_controls;
bc5dde
 static cfg_type_t cfg_type_controls_sockaddr;
bc5dde
 static cfg_type_t cfg_type_destinationlist;
bc5dde
 static cfg_type_t cfg_type_dialuptype;
bc5dde
+static cfg_type_t cfg_type_dynamic_db;
bc5dde
 static cfg_type_t cfg_type_ixfrdifftype;
bc5dde
 static cfg_type_t cfg_type_key;
bc5dde
 static cfg_type_t cfg_type_logfile;
bc5dde
@@ -871,6 +872,7 @@ namedconf_or_view_clauses[] = {
bc5dde
 	{ "zone", &cfg_type_zone, CFG_CLAUSEFLAG_MULTI },
bc5dde
 	/* only 1 DLZ per view allowed */
bc5dde
 	{ "dlz", &cfg_type_dynamically_loadable_zones, 0 },
bc5dde
+	{ "dynamic-db", &cfg_type_dynamic_db, CFG_CLAUSEFLAG_MULTI },
bc5dde
 	{ "server", &cfg_type_server, CFG_CLAUSEFLAG_MULTI },
bc5dde
 	{ "trusted-keys", &cfg_type_dnsseckeys, CFG_CLAUSEFLAG_MULTI },
bc5dde
 	{ "managed-keys", &cfg_type_managedkeys, CFG_CLAUSEFLAG_MULTI },
bc5dde
@@ -1983,6 +1985,40 @@ static cfg_type_t cfg_type_dialuptype =
bc5dde
 	&cfg_rep_string, dialup_enums
bc5dde
 };
bc5dde
 
bc5dde
+/*
bc5dde
+ * Dynamic database clauses.
bc5dde
+ */
bc5dde
+
bc5dde
+static cfg_clausedef_t
bc5dde
+dynamic_db_clauses[] = {
bc5dde
+	{ "library", &cfg_type_qstring, 0 },
bc5dde
+	{ "arg", &cfg_type_qstring, CFG_CLAUSEFLAG_MULTI },
bc5dde
+	{ NULL, NULL, 0 }
bc5dde
+};
bc5dde
+
bc5dde
+static cfg_clausedef_t *
bc5dde
+dynamic_db_clausesets[] = {
bc5dde
+	dynamic_db_clauses,
bc5dde
+	NULL
bc5dde
+};
bc5dde
+
bc5dde
+static cfg_type_t cfg_type_dynamic_db_opts = {
bc5dde
+	"dynamically_loadable_zones_opts", cfg_parse_map,
bc5dde
+	cfg_print_map, cfg_doc_map, &cfg_rep_map,
bc5dde
+	dynamic_db_clausesets
bc5dde
+};
bc5dde
+
bc5dde
+static cfg_tuplefielddef_t dynamic_db_fields[] = {
bc5dde
+	{ "name", &cfg_type_astring, 0 },
bc5dde
+	{ "options", &cfg_type_dynamic_db_opts, 0 },
bc5dde
+	{ NULL, NULL, 0 }
bc5dde
+};
bc5dde
+
bc5dde
+static cfg_type_t cfg_type_dynamic_db = {
bc5dde
+	"dynamic_db", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
bc5dde
+	&cfg_rep_tuple, dynamic_db_fields
bc5dde
+};
bc5dde
+
bc5dde
 static const char *notify_enums[] = { "explicit", "master-only", NULL };
bc5dde
 static isc_result_t
bc5dde
 parse_notify_type(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {