From dcd371be7d481b242d277d735e4c2d974297c164 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 13 Jun 2002 05:12:54 +0000 Subject: [PATCH] 1220. [func] Extended rndc dumpdb to support dumping of zones and view selection: 'dumpdb [-all|-zones|-cache] [view]'. --- CHANGES | 3 ++ bin/named/control.c | 4 +- bin/named/include/named/server.h | 4 +- bin/named/server.c | 65 ++++++++++++++++++++++++++++++-- 4 files changed, 68 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 46c5d7d923..42af1ee1a1 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1220. [func] Extended rndc dumpdb to support dumping of zones and + view selection: 'dumpdb [-all|-zones|-cache] [view]'. + 1219. [func] New category 'update-security'. 1218. [port] Compaq Trucluster support. diff --git a/bin/named/control.c b/bin/named/control.c index 4061f816f8..5ff74b8d5d 100644 --- a/bin/named/control.c +++ b/bin/named/control.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: control.c,v 1.12 2002/02/20 03:33:12 marka Exp $ */ +/* $Id: control.c,v 1.13 2002/06/13 05:12:51 marka Exp $ */ #include @@ -103,7 +103,7 @@ ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) { } else if (command_compare(command, NS_COMMAND_QUERYLOG)) { result = ns_server_togglequerylog(ns_g_server); } else if (command_compare(command, NS_COMMAND_DUMPDB)) { - ns_server_dumpdb(ns_g_server); + ns_server_dumpdb(ns_g_server, command); result = ISC_R_SUCCESS; } else if (command_compare(command, NS_COMMAND_TRACE)) { result = ns_server_setdebuglevel(ns_g_server, command); diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h index d8f9379cc1..26c3480dd6 100644 --- a/bin/named/include/named/server.h +++ b/bin/named/include/named/server.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.h,v 1.65 2002/02/20 03:33:33 marka Exp $ */ +/* $Id: server.h,v 1.66 2002/06/13 05:12:54 marka Exp $ */ #ifndef NAMED_SERVER_H #define NAMED_SERVER_H 1 @@ -159,7 +159,7 @@ ns_server_dumpstats(ns_server_t *server); * Dump the current cache to the dump file. */ isc_result_t -ns_server_dumpdb(ns_server_t *server); +ns_server_dumpdb(ns_server_t *server, char *args); /* * Change or increment the server debug level. diff --git a/bin/named/server.c b/bin/named/server.c index 5092cf5b30..fead20c07c 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: server.c,v 1.376 2002/05/08 04:45:40 marka Exp $ */ +/* $Id: server.c,v 1.377 2002/06/13 05:12:53 marka Exp $ */ #include @@ -2761,23 +2761,80 @@ ns_server_dumpstats(ns_server_t *server) { return (result); } +static isc_result_t +printzone(dns_zone_t *zone, void *uap) { + FILE *fp = uap; + char buf[1024+32]; + isc_result_t result; + + dns_zone_name(zone, buf, sizeof(buf)); + fprintf(fp, ";\n; Zone dump of '%s'\n;\n", buf); + result = dns_zone_dumptostream(zone, fp); + if (result == ISC_R_NOTIMPLEMENTED) { + fprintf(fp, "; %s\n", dns_result_totext(result)); + result = ISC_R_SUCCESS; + } + return (result); +} + isc_result_t -ns_server_dumpdb(ns_server_t *server) { +ns_server_dumpdb(ns_server_t *server, char *args) { FILE *fp = NULL; dns_view_t *view; isc_result_t result; + isc_boolean_t zones = ISC_FALSE; + isc_boolean_t cache = ISC_TRUE; + char *ptr; + const char *sep; CHECKM(isc_stdio_open(server->dumpfile, "w", &fp), "could not open dump file"); + /* Skip the command name. */ + ptr = next_token(&args, " \t"); + if (ptr == NULL) + return (ISC_R_UNEXPECTEDEND); + + sep = (*args == '\0') ? "" : ": "; + isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, + NS_LOGMODULE_SERVER, ISC_LOG_INFO, + "dumpdb started%s%s", sep, args); + + ptr = next_token(&args, " \t"); + if (ptr != NULL && strcmp(ptr, "-all") == 0) { + zones = ISC_TRUE; + cache = ISC_TRUE; + ptr = next_token(&args, " \t"); + } else if (ptr != NULL && strcmp(ptr, "-cache") == 0) { + zones = ISC_FALSE; + cache = ISC_TRUE; + ptr = next_token(&args, " \t"); + } else if (ptr != NULL && strcmp(ptr, "-zones") == 0) { + zones = ISC_TRUE; + cache = ISC_FALSE; + ptr = next_token(&args, " \t"); + } + for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (view->cachedb != NULL) + if (ptr != NULL && strcmp(view->name, ptr) != 0) + continue; + fprintf(fp, ";\n; Start view %s\n;\n", view->name); + if (cache && view->cachedb != NULL) CHECKM(dns_view_dumpdbtostream(view, fp), - "could not dump view databases"); + "could not dump cache"); + if (zones && view->zonetable != NULL) + CHECKM(dns_zt_apply(view->zonetable, ISC_TRUE, + printzone, fp), + "could not dump zones"); } + fprintf(fp, "; Dump complete\n"); + result = isc_stdio_flush(fp); + isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, + NS_LOGMODULE_SERVER, ISC_LOG_INFO, + "dumpdb complete"); cleanup: if (fp != NULL) (void)isc_stdio_close(fp);