Adam Tkac 95c9b3f
diff -up bind-9.8.0-P2/bin/named/main.c.dyndb bind-9.8.0-P2/bin/named/main.c
Adam Tkac 95c9b3f
--- bind-9.8.0-P2/bin/named/main.c.dyndb	2010-12-22 04:59:02.000000000 +0100
Adam Tkac 95c9b3f
+++ bind-9.8.0-P2/bin/named/main.c	2011-06-02 12:13:15.957660734 +0200
Adam Tkac e99cc34
@@ -45,6 +45,7 @@
b1c08c1
 #include <isccc/result.h>
b1c08c1
 
b1c08c1
 #include <dns/dispatch.h>
b1c08c1
+#include <dns/dynamic_db.h>
b1c08c1
 #include <dns/name.h>
b1c08c1
 #include <dns/result.h>
b1c08c1
 #include <dns/view.h>
Adam Tkac 5bc2b4b
@@ -871,6 +872,8 @@ setup(void) {
b1c08c1
 
fc549c6
 static void
fc549c6
 cleanup(void) {
01aab7c
+	dns_dynamic_db_cleanup(ISC_TRUE);
b1c08c1
+
fc549c6
 	destroy_managers();
b1c08c1
 
fc549c6
 	ns_server_destroy(&ns_g_server);
Adam Tkac 95c9b3f
diff -up bind-9.8.0-P2/bin/named/server.c.dyndb bind-9.8.0-P2/bin/named/server.c
Adam Tkac 95c9b3f
--- bind-9.8.0-P2/bin/named/server.c.dyndb	2011-02-16 20:46:12.000000000 +0100
Adam Tkac 95c9b3f
+++ bind-9.8.0-P2/bin/named/server.c	2011-06-02 12:13:15.960660734 +0200
Adam Tkac 5bc2b4b
@@ -63,6 +63,7 @@
b1c08c1
 #ifdef DLZ
b1c08c1
 #include <dns/dlz.h>
b1c08c1
 #endif
b1c08c1
+#include <dns/dynamic_db.h>
Adam Tkac 5bc2b4b
 #include <dns/dns64.h>
b1c08c1
 #include <dns/forward.h>
b1c08c1
 #include <dns/journal.h>
Adam Tkac 5bc2b4b
@@ -1158,6 +1159,72 @@ configure_peer(const cfg_obj_t *cpeer, i
b1c08c1
 }
b1c08c1
 
b1c08c1
 static isc_result_t
b1c08c1
+configure_dynamic_db(const cfg_obj_t *dynamic_db, isc_mem_t *mctx,
32aa839
+		     const dns_dyndb_arguments_t *dyndb_args)
b1c08c1
+{
b1c08c1
+	isc_result_t result;
b1c08c1
+	const cfg_obj_t *obj;
b1c08c1
+	const cfg_obj_t *options;
b1c08c1
+	const cfg_listelt_t *element;
b1c08c1
+	const char *name;
b1c08c1
+	const char *libname;
b1c08c1
+	const char **argv = NULL;
b1c08c1
+	unsigned int i;
b1c08c1
+	unsigned int len;
b1c08c1
+
b1c08c1
+	/* Get the name of the database. */
b1c08c1
+	obj = cfg_tuple_get(dynamic_db, "name");
b1c08c1
+	name = cfg_obj_asstring(obj);
b1c08c1
+
b1c08c1
+	/* Get options. */
b1c08c1
+	options = cfg_tuple_get(dynamic_db, "options");
b1c08c1
+
b1c08c1
+	/* Get library name. */
b1c08c1
+	obj = NULL;
b1c08c1
+	CHECK(cfg_map_get(options, "library", &obj));
b1c08c1
+	libname = cfg_obj_asstring(obj);
b1c08c1
+
b1c08c1
+	/* Create a list of arguments. */
b1c08c1
+	obj = NULL;
205f42d
+	result = cfg_map_get(options, "arg", &obj);
205f42d
+	if (result == ISC_R_NOTFOUND)
205f42d
+		len = 0;
205f42d
+	else if (result == ISC_R_SUCCESS)
205f42d
+		len = cfg_list_length(obj, isc_boolean_false);
205f42d
+	else
205f42d
+		goto cleanup;
205f42d
+
205f42d
+	/* Account for the last terminating NULL. */
205f42d
+	len++;
205f42d
+
205f42d
+	argv = isc_mem_allocate(mctx, len * sizeof(const char *));
205f42d
+	if (argv == NULL) {
205f42d
+		result = ISC_R_NOMEMORY;
205f42d
+		goto cleanup;
b1c08c1
+	}
b1c08c1
+	for (element = cfg_list_first(obj), i = 0;
b1c08c1
+	     element != NULL;
b1c08c1
+	     element = cfg_list_next(element), i++)
b1c08c1
+	{
b1c08c1
+		REQUIRE(i < len);
b1c08c1
+
b1c08c1
+		obj = cfg_listelt_value(element);
b1c08c1
+		argv[i] = cfg_obj_asstring(obj);
b1c08c1
+	}
b1c08c1
+	REQUIRE(i < len);
b1c08c1
+	argv[i] = NULL;
b1c08c1
+
32aa839
+	CHECK(dns_dynamic_db_load(libname, name, mctx, argv, dyndb_args));
b1c08c1
+
b1c08c1
+cleanup:
b1c08c1
+	if (argv != NULL)
b1c08c1
+		isc_mem_free(mctx, argv);
b1c08c1
+
b1c08c1
+	return result;
b1c08c1
+}
b1c08c1
+
b1c08c1
+
b1c08c1
+static isc_result_t
b1c08c1
 disable_algorithms(const cfg_obj_t *disabled, dns_resolver_t *resolver) {
b1c08c1
 	isc_result_t result;
b1c08c1
 	const cfg_obj_t *algorithms;
Adam Tkac 5bc2b4b
@@ -1574,6 +1641,7 @@ configure_view(dns_view_t *view, cfg_par
b1c08c1
 	unsigned int dlzargc;
b1c08c1
 	char **dlzargv;
b1c08c1
 #endif
b1c08c1
+	const cfg_obj_t *dynamic_db_list;
b1c08c1
 	const cfg_obj_t *disabled;
b1c08c1
 	const cfg_obj_t *obj;
b1c08c1
 	const cfg_listelt_t *element;
Adam Tkac 5bc2b4b
@@ -1834,6 +1902,37 @@ configure_view(dns_view_t *view, cfg_par
ec60046
 #endif
b1c08c1
 
b1c08c1
 	/*
b1c08c1
+	 * Configure dynamic databases.
b1c08c1
+	 */
b1c08c1
+	dynamic_db_list = NULL;
b1c08c1
+	if (voptions != NULL)
b1c08c1
+		(void)cfg_map_get(voptions, "dynamic-db", &dynamic_db_list);
b1c08c1
+	else
b1c08c1
+		(void)cfg_map_get(config, "dynamic-db", &dynamic_db_list);
32aa839
+	element = cfg_list_first(dynamic_db_list);
32aa839
+	if (element != NULL) {
32aa839
+		dns_dyndb_arguments_t *args;
32aa839
+
32aa839
+		args = dns_dyndb_arguments_create(mctx);
32aa839
+		if (args == NULL) {
32aa839
+			result = ISC_R_NOMEMORY;
32aa839
+			goto cleanup;
32aa839
+		}
32aa839
+		dns_dyndb_set_view(args, view);
32aa839
+		dns_dyndb_set_zonemgr(args, ns_g_server->zonemgr);
32aa839
+		dns_dyndb_set_task(args, ns_g_server->task);
32aa839
+		dns_dyndb_set_timermgr(args, ns_g_timermgr);
32aa839
+		while (element != NULL) {
32aa839
+			obj = cfg_listelt_value(element);
32aa839
+			CHECK(configure_dynamic_db(obj, mctx, args));
32aa839
+
32aa839
+			element = cfg_list_next(element);
32aa839
+		}
32aa839
+
32aa839
+		dns_dyndb_arguments_destroy(mctx, args);
b1c08c1
+	}
b1c08c1
+
b1c08c1
+	/*
146866c
 	 * Obtain configuration parameters that affect the decision of whether
146866c
 	 * we can reuse/share an existing cache.
146866c
 	 */
Adam Tkac 95c9b3f
@@ -4187,6 +4286,7 @@ load_configuration(const char *filename,
01aab7c
 	result = isc_task_beginexclusive(server->task);
01aab7c
 	RUNTIME_CHECK(result == ISC_R_SUCCESS);
01aab7c
 
01aab7c
+	dns_dynamic_db_cleanup(ISC_FALSE);
01aab7c
 	/*
01aab7c
 	 * Parse the global default pseudo-config file.
01aab7c
 	 */
Adam Tkac 95c9b3f
@@ -5542,6 +5642,8 @@ loadconfig(ns_server_t *server) {
01aab7c
 static isc_result_t
01aab7c
 reload(ns_server_t *server) {
01aab7c
 	isc_result_t result;
01aab7c
+
01aab7c
+	dns_dynamic_db_cleanup(ISC_FALSE);
01aab7c
 	CHECK(loadconfig(server));
01aab7c
 
01aab7c
 	result = load_zones(server, ISC_FALSE);
Adam Tkac 95c9b3f
diff -up bind-9.8.0-P2/lib/dns/dynamic_db.c.dyndb bind-9.8.0-P2/lib/dns/dynamic_db.c
Adam Tkac 95c9b3f
--- bind-9.8.0-P2/lib/dns/dynamic_db.c.dyndb	2011-06-02 12:13:15.984660736 +0200
Adam Tkac 95c9b3f
+++ bind-9.8.0-P2/lib/dns/dynamic_db.c	2011-06-02 12:13:15.984660736 +0200
Adam Tkac 95c9b3f
@@ -0,0 +1,366 @@
b1c08c1
+/*
Adam Tkac 95c9b3f
+ * Copyright (C) 2008-2011  Red Hat, Inc.
b1c08c1
+ *
b1c08c1
+ * Permission to use, copy, modify, and/or distribute this software for any
b1c08c1
+ * purpose with or without fee is hereby granted, provided that the above
b1c08c1
+ * copyright notice and this permission notice appear in all copies.
b1c08c1
+ *
32aa839
+ * THE SOFTWARE IS PROVIDED "AS IS" AND Red Hat DISCLAIMS ALL WARRANTIES WITH
b1c08c1
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
32aa839
+ * AND FITNESS.  IN NO EVENT SHALL Red Hat BE LIABLE FOR ANY SPECIAL, DIRECT,
b1c08c1
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
b1c08c1
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
b1c08c1
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
b1c08c1
+ * PERFORMANCE OF THIS SOFTWARE.
b1c08c1
+ */
b1c08c1
+
b1c08c1
+
b1c08c1
+#include <config.h>
b1c08c1
+
ec60046
+#include <isc/buffer.h>
b1c08c1
+#include <isc/mem.h>
b1c08c1
+#include <isc/mutex.h>
b1c08c1
+#include <isc/once.h>
b1c08c1
+#include <isc/result.h>
ec60046
+#include <isc/region.h>
32aa839
+#include <isc/task.h>
b1c08c1
+#include <isc/types.h>
b1c08c1
+#include <isc/util.h>
b1c08c1
+
b1c08c1
+#include <dns/dynamic_db.h>
b1c08c1
+#include <dns/log.h>
b1c08c1
+#include <dns/types.h>
32aa839
+#include <dns/view.h>
32aa839
+#include <dns/zone.h>
b1c08c1
+
32aa839
+#include <string.h>
b1c08c1
+
b1c08c1
+#if HAVE_DLFCN_H
b1c08c1
+#include <dlfcn.h>
b1c08c1
+#endif
b1c08c1
+
ec60046
+#ifndef DYNDB_LIBDIR
ec60046
+#define DYNDB_LIBDIR ""
ec60046
+#endif
ec60046
+
b1c08c1
+#define CHECK(op)						\
b1c08c1
+	do { result = (op);					\
b1c08c1
+		if (result != ISC_R_SUCCESS) goto cleanup;	\
b1c08c1
+	} while (0)
b1c08c1
+
b1c08c1
+
b1c08c1
+typedef isc_result_t (*register_func_t)(isc_mem_t *mctx, const char *name,
Adam Tkac 95c9b3f
+		const char * const *argv,
Adam Tkac 95c9b3f
+		const dns_dyndb_arguments_t *dyndb_args);
b1c08c1
+typedef void (*destroy_func_t)(void);
b1c08c1
+
b1c08c1
+typedef struct dyndb_implementation dyndb_implementation_t;
b1c08c1
+
b1c08c1
+struct dyndb_implementation {
b1c08c1
+	isc_mem_t			*mctx;
b1c08c1
+	void				*handle;
b1c08c1
+	register_func_t			register_function;
b1c08c1
+	destroy_func_t			destroy_function;
b1c08c1
+	LINK(dyndb_implementation_t)	link;
b1c08c1
+};
b1c08c1
+
32aa839
+struct dns_dyndb_arguments {
32aa839
+	dns_view_t	*view;
32aa839
+	dns_zonemgr_t	*zmgr;
32aa839
+	isc_task_t	*task;
32aa839
+	isc_timermgr_t	*timermgr;
32aa839
+};
32aa839
+
b1c08c1
+/* List of implementations. Locked by dyndb_lock. */
b1c08c1
+static LIST(dyndb_implementation_t) dyndb_implementations;
b1c08c1
+/* Locks dyndb_implementations. */
b1c08c1
+static isc_mutex_t dyndb_lock;
b1c08c1
+static isc_once_t once = ISC_ONCE_INIT;
b1c08c1
+
b1c08c1
+static void
b1c08c1
+dyndb_initialize(void) {
b1c08c1
+	RUNTIME_CHECK(isc_mutex_init(&dyndb_lock) == ISC_R_SUCCESS);
b1c08c1
+	INIT_LIST(dyndb_implementations);
b1c08c1
+}
b1c08c1
+
b1c08c1
+
b1c08c1
+#if HAVE_DLFCN_H
b1c08c1
+static isc_result_t
b1c08c1
+load_symbol(void *handle, const char *symbol_name, void **symbolp)
b1c08c1
+{
b1c08c1
+	const char *errmsg;
b1c08c1
+	void *symbol;
b1c08c1
+
b1c08c1
+	REQUIRE(handle != NULL);
b1c08c1
+	REQUIRE(symbolp != NULL && *symbolp == NULL);
b1c08c1
+
b1c08c1
+	symbol = dlsym(handle, symbol_name);
b1c08c1
+	if (symbol == NULL) {
b1c08c1
+		errmsg = dlerror();
b1c08c1
+		if (errmsg == NULL)
b1c08c1
+			errmsg = "returned function pointer is NULL";
b1c08c1
+		isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
b1c08c1
+			      DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR,
b1c08c1
+			      "failed to lookup symbol %s: %s",
b1c08c1
+			      symbol_name, errmsg);
b1c08c1
+		return ISC_R_FAILURE;
b1c08c1
+	}
b1c08c1
+	dlerror();
b1c08c1
+
b1c08c1
+	*symbolp = symbol;
b1c08c1
+
b1c08c1
+	return ISC_R_SUCCESS;
b1c08c1
+}
b1c08c1
+
b1c08c1
+static isc_result_t
b1c08c1
+load_library(isc_mem_t *mctx, const char *filename, dyndb_implementation_t **impp)
b1c08c1
+{
b1c08c1
+	isc_result_t result;
ec60046
+	size_t module_size;
ec60046
+	isc_buffer_t *module_buf = NULL;
ec60046
+	isc_region_t module_region;
Adam Tkac 95c9b3f
+	void *handle = NULL;
b1c08c1
+	dyndb_implementation_t *imp;
b1c08c1
+	register_func_t register_function = NULL;
b1c08c1
+	destroy_func_t destroy_function = NULL;
b1c08c1
+
b1c08c1
+	REQUIRE(impp != NULL && *impp == NULL);
b1c08c1
+
ec60046
+	/* Build up the full path. */
ec60046
+	module_size = strlen(DYNDB_LIBDIR) + strlen(filename) + 1;
ec60046
+	CHECK(isc_buffer_allocate(mctx, &module_buf, module_size));
ec60046
+	isc_buffer_putstr(module_buf, DYNDB_LIBDIR);
ec60046
+	isc_buffer_putstr(module_buf, filename);
ec60046
+	isc_buffer_putuint8(module_buf, 0);
ec60046
+	isc_buffer_region(module_buf, &module_region);
ec60046
+
ec60046
+	handle = dlopen((char *)module_region.base, RTLD_LAZY);
b1c08c1
+	if (handle == NULL) {
b1c08c1
+		isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
b1c08c1
+			      DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR,
b1c08c1
+			      "failed to dynamically load driver '%s': %s",
b1c08c1
+			      filename, dlerror());
b1c08c1
+		result = ISC_R_FAILURE;
b1c08c1
+		goto cleanup;
b1c08c1
+	}
b1c08c1
+	dlerror();
b1c08c1
+
b1c08c1
+	CHECK(load_symbol(handle, "dynamic_driver_init",
b1c08c1
+			  (void **)&register_function));
b1c08c1
+	CHECK(load_symbol(handle, "dynamic_driver_destroy",
b1c08c1
+			  (void **)&destroy_function));
b1c08c1
+
b1c08c1
+	imp = isc_mem_get(mctx, sizeof(dyndb_implementation_t));
b1c08c1
+	if (imp == NULL) {
b1c08c1
+		result = ISC_R_NOMEMORY;
b1c08c1
+		goto cleanup;
b1c08c1
+	}
b1c08c1
+
b1c08c1
+	imp->mctx = NULL;
b1c08c1
+	isc_mem_attach(mctx, &imp->mctx);
b1c08c1
+	imp->handle = handle;
b1c08c1
+	imp->register_function = register_function;
b1c08c1
+	imp->destroy_function = destroy_function;
b1c08c1
+	INIT_LINK(imp, link);
b1c08c1
+
b1c08c1
+	*impp = imp;
b1c08c1
+
b1c08c1
+cleanup:
ec60046
+	if (result != ISC_R_SUCCESS && handle != NULL)
b1c08c1
+		dlclose(handle);
ec60046
+	if (module_buf != NULL)
ec60046
+		isc_buffer_free(&module_buf);
b1c08c1
+
b1c08c1
+	return result;
b1c08c1
+}
b1c08c1
+
b1c08c1
+static void
b1c08c1
+unload_library(dyndb_implementation_t **impp)
b1c08c1
+{
b1c08c1
+	dyndb_implementation_t *imp;
b1c08c1
+
b1c08c1
+	REQUIRE(impp != NULL && *impp != NULL);
b1c08c1
+
b1c08c1
+	imp = *impp;
b1c08c1
+
b1c08c1
+	isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
b1c08c1
+
b1c08c1
+	*impp = NULL;
b1c08c1
+}
b1c08c1
+
b1c08c1
+#else	/* HAVE_DLFCN_H */
b1c08c1
+static isc_result_t
b1c08c1
+load_library(isc_mem_t *mctx, const char *filename, dyndb_implementation_t **impp)
b1c08c1
+{
b1c08c1
+	UNUSED(mctx);
b1c08c1
+	UNUSED(filename);
b1c08c1
+	UNUSED(impp);
b1c08c1
+
b1c08c1
+	isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DYNDB,
b1c08c1
+		      ISC_LOG_ERROR,
b1c08c1
+		      "dynamic database support is not implemented")
b1c08c1
+
b1c08c1
+	return ISC_R_NOTIMPLEMENTED;
b1c08c1
+}
b1c08c1
+
b1c08c1
+static void
b1c08c1
+unload_library(dyndb_implementation_t **impp)
b1c08c1
+{
b1c08c1
+	dyndb_implementation_t *imp;
b1c08c1
+
b1c08c1
+	REQUIRE(impp != NULL && *impp != NULL);
b1c08c1
+
b1c08c1
+	imp = *impp;
b1c08c1
+
b1c08c1
+	isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
b1c08c1
+
b1c08c1
+	*impp = NULL;
b1c08c1
+}
b1c08c1
+#endif	/* HAVE_DLFCN_H */
b1c08c1
+
b1c08c1
+isc_result_t
b1c08c1
+dns_dynamic_db_load(const char *libname, const char *name, isc_mem_t *mctx,
Adam Tkac 95c9b3f
+		    const char * const *argv,
Adam Tkac 95c9b3f
+		    const dns_dyndb_arguments_t *dyndb_args)
b1c08c1
+{
b1c08c1
+	isc_result_t result;
b1c08c1
+	dyndb_implementation_t *implementation = NULL;
b1c08c1
+
b1c08c1
+	RUNTIME_CHECK(isc_once_do(&once, dyndb_initialize) == ISC_R_SUCCESS);
b1c08c1
+
b1c08c1
+	CHECK(load_library(mctx, libname, &implementation));
32aa839
+	CHECK(implementation->register_function(mctx, name, argv, dyndb_args));
b1c08c1
+
b1c08c1
+	LOCK(&dyndb_lock);
b1c08c1
+	APPEND(dyndb_implementations, implementation, link);
b1c08c1
+	UNLOCK(&dyndb_lock);
b1c08c1
+
b1c08c1
+	return ISC_R_SUCCESS;
b1c08c1
+
b1c08c1
+cleanup:
b1c08c1
+	if (implementation != NULL)
b1c08c1
+		unload_library(&implementation);
b1c08c1
+
b1c08c1
+	return result;
b1c08c1
+}
b1c08c1
+
205f42d
+void
01aab7c
+dns_dynamic_db_cleanup(isc_boolean_t exiting)
b1c08c1
+{
b1c08c1
+	dyndb_implementation_t *elem;
01aab7c
+	dyndb_implementation_t *prev;
b1c08c1
+
b1c08c1
+	RUNTIME_CHECK(isc_once_do(&once, dyndb_initialize) == ISC_R_SUCCESS);
b1c08c1
+
b1c08c1
+	LOCK(&dyndb_lock);
01aab7c
+	elem = TAIL(dyndb_implementations);
b1c08c1
+	while (elem != NULL) {
01aab7c
+		prev = PREV(elem, link);
b1c08c1
+		UNLINK(dyndb_implementations, elem, link);
b1c08c1
+		elem->destroy_function();
b1c08c1
+		unload_library(&elem);
01aab7c
+		elem = prev;
b1c08c1
+	}
b1c08c1
+	UNLOCK(&dyndb_lock);
b1c08c1
+
01aab7c
+	if (exiting == ISC_TRUE)
01aab7c
+		isc_mutex_destroy(&dyndb_lock);
b1c08c1
+}
32aa839
+
32aa839
+dns_dyndb_arguments_t *
32aa839
+dns_dyndb_arguments_create(isc_mem_t *mctx)
32aa839
+{
32aa839
+	dns_dyndb_arguments_t *args;
32aa839
+
32aa839
+	args = isc_mem_get(mctx, sizeof(*args));
32aa839
+	if (args != NULL)
32aa839
+		memset(args, 0, sizeof(*args));
32aa839
+
32aa839
+	return args;
32aa839
+}
32aa839
+
32aa839
+void
32aa839
+dns_dyndb_arguments_destroy(isc_mem_t *mctx, dns_dyndb_arguments_t *args)
32aa839
+{
32aa839
+	REQUIRE(args != NULL);
32aa839
+
32aa839
+	dns_dyndb_set_view(args, NULL);
32aa839
+	dns_dyndb_set_zonemgr(args, NULL);
32aa839
+	dns_dyndb_set_task(args, NULL);
32aa839
+	dns_dyndb_set_timermgr(args, NULL);
32aa839
+
32aa839
+	isc_mem_put(mctx, args, sizeof(*args));
32aa839
+}
32aa839
+
32aa839
+void
32aa839
+dns_dyndb_set_view(dns_dyndb_arguments_t *args, dns_view_t *view)
32aa839
+{
32aa839
+	REQUIRE(args != NULL);
32aa839
+
32aa839
+	if (args->view != NULL)
32aa839
+		dns_view_detach(&args->view);
32aa839
+	if (view != NULL)
32aa839
+		dns_view_attach(view, &args->view);
32aa839
+}
32aa839
+
32aa839
+dns_view_t *
32aa839
+dns_dyndb_get_view(dns_dyndb_arguments_t *args)
32aa839
+{
32aa839
+	REQUIRE(args != NULL);
32aa839
+
32aa839
+	return args->view;
32aa839
+}
32aa839
+
32aa839
+void
32aa839
+dns_dyndb_set_zonemgr(dns_dyndb_arguments_t *args, dns_zonemgr_t *zmgr)
32aa839
+{
32aa839
+	REQUIRE(args != NULL);
32aa839
+
32aa839
+	if (args->zmgr != NULL)
32aa839
+		dns_zonemgr_detach(&args->zmgr);
32aa839
+	if (zmgr != NULL)
32aa839
+		dns_zonemgr_attach(zmgr, &args->zmgr);
32aa839
+}
32aa839
+
32aa839
+dns_zonemgr_t *
32aa839
+dns_dyndb_get_zonemgr(dns_dyndb_arguments_t *args)
32aa839
+{
32aa839
+	REQUIRE(args != NULL);
32aa839
+
32aa839
+	return args->zmgr;
32aa839
+}
32aa839
+
32aa839
+void
32aa839
+dns_dyndb_set_task(dns_dyndb_arguments_t *args, isc_task_t *task)
32aa839
+{
32aa839
+	REQUIRE(args != NULL);
32aa839
+
32aa839
+	if (args->task != NULL)
32aa839
+		isc_task_detach(&args->task);
32aa839
+	if (task != NULL)
32aa839
+		isc_task_attach(task, &args->task);
32aa839
+}
32aa839
+
32aa839
+isc_task_t *
32aa839
+dns_dyndb_get_task(dns_dyndb_arguments_t *args)
32aa839
+{
32aa839
+	REQUIRE(args != NULL);
32aa839
+
32aa839
+	return args->task;
32aa839
+}
32aa839
+
32aa839
+void
32aa839
+dns_dyndb_set_timermgr(dns_dyndb_arguments_t *args, isc_timermgr_t *timermgr)
32aa839
+{
32aa839
+	REQUIRE(args != NULL);
32aa839
+
32aa839
+	args->timermgr = timermgr;
32aa839
+}
32aa839
+
32aa839
+isc_timermgr_t *
32aa839
+dns_dyndb_get_timermgr(dns_dyndb_arguments_t *args)
32aa839
+{
32aa839
+	REQUIRE(args != NULL);
32aa839
+
32aa839
+	return args->timermgr;
32aa839
+}
Adam Tkac 95c9b3f
diff -up bind-9.8.0-P2/lib/dns/include/dns/dynamic_db.h.dyndb bind-9.8.0-P2/lib/dns/include/dns/dynamic_db.h
Adam Tkac 95c9b3f
--- bind-9.8.0-P2/lib/dns/include/dns/dynamic_db.h.dyndb	2011-06-02 12:13:15.962660734 +0200
Adam Tkac 95c9b3f
+++ bind-9.8.0-P2/lib/dns/include/dns/dynamic_db.h	2011-06-02 12:13:15.962660734 +0200
32aa839
@@ -0,0 +1,50 @@
b1c08c1
+/*
Adam Tkac 95c9b3f
+ * Copyright (C) 2008-2011  Red Hat, Inc.
b1c08c1
+ *
b1c08c1
+ * Permission to use, copy, modify, and/or distribute this software for any
b1c08c1
+ * purpose with or without fee is hereby granted, provided that the above
b1c08c1
+ * copyright notice and this permission notice appear in all copies.
b1c08c1
+ *
32aa839
+ * THE SOFTWARE IS PROVIDED "AS IS" AND Red Hat DISCLAIMS ALL WARRANTIES WITH
b1c08c1
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
32aa839
+ * AND FITNESS.  IN NO EVENT SHALL Red Hat BE LIABLE FOR ANY SPECIAL, DIRECT,
b1c08c1
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
b1c08c1
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
b1c08c1
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
b1c08c1
+ * PERFORMANCE OF THIS SOFTWARE.
b1c08c1
+ */
b1c08c1
+
b1c08c1
+
b1c08c1
+#ifndef DYNAMIC_DB_H
b1c08c1
+#define DYNAMIC_DB_H
b1c08c1
+
b1c08c1
+#include <isc/types.h>
205f42d
+
b1c08c1
+#include <dns/types.h>
b1c08c1
+
32aa839
+/*
32aa839
+ * TODO:
32aa839
+ * Reformat the prototypes.
32aa839
+ * Add annotated comments.
32aa839
+ */
32aa839
+
b1c08c1
+isc_result_t dns_dynamic_db_load(const char *libname, const char *name,
b1c08c1
+				 isc_mem_t *mctx, const char * const *argv,
Adam Tkac 95c9b3f
+				 const dns_dyndb_arguments_t *dyndb_args);
b1c08c1
+
01aab7c
+void dns_dynamic_db_cleanup(isc_boolean_t exiting);
b1c08c1
+
32aa839
+dns_dyndb_arguments_t *dns_dyndb_arguments_create(isc_mem_t *mctx);
32aa839
+void dns_dyndb_arguments_destroy(isc_mem_t *mctx, dns_dyndb_arguments_t *args);
32aa839
+
32aa839
+void dns_dyndb_set_view(dns_dyndb_arguments_t *args, dns_view_t *view);
32aa839
+dns_view_t *dns_dyndb_get_view(dns_dyndb_arguments_t *args);
32aa839
+void dns_dyndb_set_zonemgr(dns_dyndb_arguments_t *args, dns_zonemgr_t *zmgr);
32aa839
+dns_zonemgr_t *dns_dyndb_get_zonemgr(dns_dyndb_arguments_t *args);
32aa839
+void dns_dyndb_set_task(dns_dyndb_arguments_t *args, isc_task_t *task);
32aa839
+isc_task_t *dns_dyndb_get_task(dns_dyndb_arguments_t *args);
32aa839
+void dns_dyndb_set_timermgr(dns_dyndb_arguments_t *args,
32aa839
+			    isc_timermgr_t *timermgr);
32aa839
+isc_timermgr_t *dns_dyndb_get_timermgr(dns_dyndb_arguments_t *args);
32aa839
+
b1c08c1
+#endif
Adam Tkac 95c9b3f
diff -up bind-9.8.0-P2/lib/dns/include/dns/log.h.dyndb bind-9.8.0-P2/lib/dns/include/dns/log.h
Adam Tkac 95c9b3f
--- bind-9.8.0-P2/lib/dns/include/dns/log.h.dyndb	2009-12-18 23:16:49.000000000 +0100
Adam Tkac 95c9b3f
+++ bind-9.8.0-P2/lib/dns/include/dns/log.h	2011-06-02 12:13:15.962660734 +0200
Adam Tkac 7f138a6
@@ -74,6 +74,7 @@ LIBDNS_EXTERNAL_DATA extern isc_logmodul
b1c08c1
 #define DNS_LOGMODULE_ACACHE		(&dns_modules[25])
b1c08c1
 #define DNS_LOGMODULE_DLZ		(&dns_modules[26])
Adam Tkac 7f138a6
 #define DNS_LOGMODULE_DNSSEC		(&dns_modules[27])
Adam Tkac 7f138a6
+#define DNS_LOGMODULE_DYNDB		(&dns_modules[28])
b1c08c1
 
b1c08c1
 ISC_LANG_BEGINDECLS
b1c08c1
 
Adam Tkac 95c9b3f
diff -up bind-9.8.0-P2/lib/dns/include/dns/Makefile.in.dyndb bind-9.8.0-P2/lib/dns/include/dns/Makefile.in
Adam Tkac 95c9b3f
--- bind-9.8.0-P2/lib/dns/include/dns/Makefile.in.dyndb	2009-10-09 01:48:10.000000000 +0200
Adam Tkac 95c9b3f
+++ bind-9.8.0-P2/lib/dns/include/dns/Makefile.in	2011-06-02 12:13:15.963660734 +0200
Adam Tkac 2fc1c6e
@@ -22,7 +22,7 @@ top_srcdir =	@top_srcdir@
Adam Tkac 2fc1c6e
 @BIND9_VERSION@
Adam Tkac f12e46d
 
Adam Tkac 2fc1c6e
 HEADERS =	acl.h adb.h byaddr.h cache.h callbacks.h cert.h compress.h \
Adam Tkac f12e46d
-		db.h dbiterator.h dbtable.h diff.h dispatch.h dlz.h \
Adam Tkac f12e46d
+		db.h dbiterator.h dbtable.h diff.h dispatch.h dlz.h dynamic_db.h \
Adam Tkac 2fc1c6e
 		dnssec.h ds.h events.h fixedname.h iptable.h journal.h \
Adam Tkac 2fc1c6e
 		keyflags.h keytable.h keyvalues.h lib.h log.h \
Adam Tkac 2fc1c6e
 		master.h masterdump.h message.h name.h ncache.h nsec.h \
Adam Tkac 95c9b3f
diff -up bind-9.8.0-P2/lib/dns/include/dns/types.h.dyndb bind-9.8.0-P2/lib/dns/include/dns/types.h
Adam Tkac 95c9b3f
--- bind-9.8.0-P2/lib/dns/include/dns/types.h.dyndb	2010-12-08 03:46:16.000000000 +0100
Adam Tkac 95c9b3f
+++ bind-9.8.0-P2/lib/dns/include/dns/types.h	2011-06-02 12:13:15.974660734 +0200
Adam Tkac e99cc34
@@ -60,6 +60,7 @@ typedef struct dns_dbtable			dns_dbtable
32aa839
 typedef void					dns_dbversion_t;
32aa839
 typedef struct dns_dlzimplementation		dns_dlzimplementation_t;
32aa839
 typedef struct dns_dlzdb			dns_dlzdb_t;
32aa839
+typedef struct dns_dyndb_arguments		dns_dyndb_arguments_t;
32aa839
 typedef struct dns_sdlzimplementation		dns_sdlzimplementation_t;
32aa839
 typedef struct dns_decompress			dns_decompress_t;
32aa839
 typedef struct dns_dispatch			dns_dispatch_t;
Adam Tkac 95c9b3f
diff -up bind-9.8.0-P2/lib/dns/log.c.dyndb bind-9.8.0-P2/lib/dns/log.c
Adam Tkac 95c9b3f
--- bind-9.8.0-P2/lib/dns/log.c.dyndb	2009-12-19 00:49:03.000000000 +0100
Adam Tkac 95c9b3f
+++ bind-9.8.0-P2/lib/dns/log.c	2011-06-02 12:13:15.981660733 +0200
Adam Tkac 7f138a6
@@ -80,6 +80,7 @@ LIBDNS_EXTERNAL_DATA isc_logmodule_t dns
b1c08c1
 	{ "dns/acache",		0 },
b1c08c1
 	{ "dns/dlz",		0 },
Adam Tkac 7f138a6
 	{ "dns/dnssec",		0 },
b1c08c1
+	{ "dns/dynamic_db",	0 },
b1c08c1
 	{ NULL, 		0 }
b1c08c1
 };
b1c08c1
 
Adam Tkac 95c9b3f
diff -up bind-9.8.0-P2/lib/dns/Makefile.in.dyndb bind-9.8.0-P2/lib/dns/Makefile.in
Adam Tkac 95c9b3f
--- bind-9.8.0-P2/lib/dns/Makefile.in.dyndb	2011-06-02 12:13:15.943660734 +0200
Adam Tkac 95c9b3f
+++ bind-9.8.0-P2/lib/dns/Makefile.in	2011-06-02 12:13:15.981660733 +0200
Adam Tkac 5bc2b4b
@@ -58,7 +58,7 @@ DNSOBJS =	acache.@O@ acl.@O@ adb.@O@ bya
Adam Tkac f12e46d
 		cache.@O@ callbacks.@O@ compress.@O@ \
Adam Tkac f12e46d
 		db.@O@ dbiterator.@O@ dbtable.@O@ diff.@O@ dispatch.@O@ \
Adam Tkac 5bc2b4b
 		dlz.@O@ dns64.@O@ dnssec.@O@ ds.@O@ forward.@O@ iptable.@O@ \
Adam Tkac 5bc2b4b
-		journal.@O@ keydata.@O@ keytable.@O@ \
Adam Tkac 5bc2b4b
+		dynamic_db.@O@ journal.@O@ keydata.@O@ keytable.@O@ \
Adam Tkac 5bc2b4b
 		lib.@O@ log.@O@ lookup.@O@ \
Adam Tkac f12e46d
 		master.@O@ masterdump.@O@ message.@O@ \
Adam Tkac f12e46d
 		name.@O@ ncache.@O@ nsec.@O@ nsec3.@O@ order.@O@ peer.@O@ \
Adam Tkac 5bc2b4b
@@ -87,7 +87,7 @@ DNSSRCS =	acache.c acl.c adb.c byaddr.c 
Adam Tkac f12e46d
 		cache.c callbacks.c compress.c \
Adam Tkac f12e46d
 		db.c dbiterator.c dbtable.c diff.c dispatch.c \
Adam Tkac 5bc2b4b
 		dlz.c dns64.c dnssec.c ds.c forward.c iptable.c journal.c \
Adam Tkac 5bc2b4b
-		keydata.c keytable.c lib.c log.c lookup.c \
Adam Tkac 5bc2b4b
+		dynamic_db.c keydata.c keytable.c lib.c log.c lookup.c \
Adam Tkac f12e46d
 		master.c masterdump.c message.c \
Adam Tkac f12e46d
 		name.c ncache.c nsec.c nsec3.c order.c peer.c portlist.c \
Adam Tkac 5bc2b4b
 		rbt.c rbtdb.c rbtdb64.c rcode.c rdata.c rdatalist.c \
Adam Tkac 5bc2b4b
@@ -116,6 +116,11 @@ version.@O@: version.c
Adam Tkac f12e46d
 		-DLIBAGE=${LIBAGE} \
Adam Tkac f12e46d
 		-c ${srcdir}/version.c
Adam Tkac f12e46d
 
Adam Tkac f12e46d
+dynamic_db.@O@: dynamic_db.c
Adam Tkac f12e46d
+	${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} \
Adam Tkac f12e46d
+	-DDYNDB_LIBDIR=\"@libdir@/bind/\" \
Adam Tkac f12e46d
+	-c ${srcdir}/dynamic_db.c
Adam Tkac f12e46d
+
Adam Tkac f12e46d
 libdns.@SA@: ${OBJS}
Adam Tkac f12e46d
 	${AR} ${ARFLAGS} $@ ${OBJS}
Adam Tkac f12e46d
 	${RANLIB} $@
Adam Tkac 95c9b3f
diff -up bind-9.8.0-P2/lib/isccfg/namedconf.c.dyndb bind-9.8.0-P2/lib/isccfg/namedconf.c
Adam Tkac 95c9b3f
--- bind-9.8.0-P2/lib/isccfg/namedconf.c.dyndb	2011-02-03 06:50:08.000000000 +0100
Adam Tkac 95c9b3f
+++ bind-9.8.0-P2/lib/isccfg/namedconf.c	2011-06-02 12:13:15.983660735 +0200
Adam Tkac 5bc2b4b
@@ -89,6 +89,7 @@ static cfg_type_t cfg_type_controls;
b1c08c1
 static cfg_type_t cfg_type_controls_sockaddr;
b1c08c1
 static cfg_type_t cfg_type_destinationlist;
b1c08c1
 static cfg_type_t cfg_type_dialuptype;
b1c08c1
+static cfg_type_t cfg_type_dynamic_db;
b1c08c1
 static cfg_type_t cfg_type_ixfrdifftype;
b1c08c1
 static cfg_type_t cfg_type_key;
b1c08c1
 static cfg_type_t cfg_type_logfile;
Adam Tkac 5bc2b4b
@@ -861,6 +862,7 @@ namedconf_or_view_clauses[] = {
b1c08c1
 	{ "zone", &cfg_type_zone, CFG_CLAUSEFLAG_MULTI },
b1c08c1
 	/* only 1 DLZ per view allowed */
b1c08c1
 	{ "dlz", &cfg_type_dynamically_loadable_zones, 0 },
b1c08c1
+	{ "dynamic-db", &cfg_type_dynamic_db, CFG_CLAUSEFLAG_MULTI },
b1c08c1
 	{ "server", &cfg_type_server, CFG_CLAUSEFLAG_MULTI },
Adam Tkac f12e46d
 	{ "trusted-keys", &cfg_type_dnsseckeys, CFG_CLAUSEFLAG_MULTI },
Adam Tkac e99cc34
 	{ "managed-keys", &cfg_type_managedkeys, CFG_CLAUSEFLAG_MULTI },
Adam Tkac 5bc2b4b
@@ -1843,6 +1845,40 @@ static cfg_type_t cfg_type_dialuptype = 
b1c08c1
 	&cfg_rep_string, dialup_enums
b1c08c1
 };
b1c08c1
 
b1c08c1
+/*
b1c08c1
+ * Dynamic database clauses.
b1c08c1
+ */
b1c08c1
+
b1c08c1
+static cfg_clausedef_t
b1c08c1
+dynamic_db_clauses[] = {
b1c08c1
+	{ "library", &cfg_type_qstring, 0 },
b1c08c1
+	{ "arg", &cfg_type_qstring, CFG_CLAUSEFLAG_MULTI },
b1c08c1
+	{ NULL, NULL, 0 }
b1c08c1
+};
b1c08c1
+
b1c08c1
+static cfg_clausedef_t *
b1c08c1
+dynamic_db_clausesets[] = {
b1c08c1
+	dynamic_db_clauses,
b1c08c1
+	NULL
b1c08c1
+};
b1c08c1
+
b1c08c1
+static cfg_type_t cfg_type_dynamic_db_opts = {
b1c08c1
+	"dynamically_loadable_zones_opts", cfg_parse_map,
b1c08c1
+	cfg_print_map, cfg_doc_map, &cfg_rep_map,
b1c08c1
+	dynamic_db_clausesets
b1c08c1
+};
b1c08c1
+
b1c08c1
+static cfg_tuplefielddef_t dynamic_db_fields[] = {
b1c08c1
+	{ "name", &cfg_type_astring, 0 },
b1c08c1
+	{ "options", &cfg_type_dynamic_db_opts, 0 },
b1c08c1
+	{ NULL, NULL, 0 }
b1c08c1
+};
b1c08c1
+
b1c08c1
+static cfg_type_t cfg_type_dynamic_db = {
b1c08c1
+	"dynamic_db", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
b1c08c1
+	&cfg_rep_tuple, dynamic_db_fields
b1c08c1
+};
b1c08c1
+
b1c08c1
 static const char *notify_enums[] = { "explicit", "master-only", NULL };
b1c08c1
 static isc_result_t
b1c08c1
 parse_notify_type(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {