From 84a5b69f0029952e33c96695f0a7d26c2bb8f7cc Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 9 Nov 2004 21:24:20 +0000 Subject: [PATCH] 1756. [func] named-checkconf now checks the logging configuration. [RT #12352] --- CHANGES | 3 +- bin/check/check-tool.c | 18 ++++++- bin/named/log.c | 5 +- lib/bind9/check.c | 119 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 140 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index a86fe308a4..1b0d036da6 100644 --- a/CHANGES +++ b/CHANGES @@ -14,7 +14,8 @@ 1757. [placeholder] rt12919 -1756. [placeholder] rt12352 +1756. [func] named-checkconf now checks the logging configuration. + [RT #12352] 1755. [placeholder] rt6636 diff --git a/bin/check/check-tool.c b/bin/check/check-tool.c index 6cbc1dc519..8e0863b446 100644 --- a/bin/check/check-tool.c +++ b/bin/check/check-tool.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: check-tool.c,v 1.11 2004/10/06 05:56:28 marka Exp $ */ +/* $Id: check-tool.c,v 1.12 2004/11/09 21:24:20 marka Exp $ */ #include @@ -52,6 +52,20 @@ unsigned int zone_options = DNS_ZONEOPT_CHECKNS | DNS_ZONEOPT_MANYERRORS | DNS_ZONEOPT_CHECKNAMES; +/* + * This needs to match the list in bin/named/log.c. + */ +static isc_logcategory_t categories[] = { + { "", 0 }, + { "client", 0 }, + { "network", 0 }, + { "update", 0 }, + { "queries", 0 }, + { "unmatched", 0 }, + { "update-security", 0 }, + { NULL, 0 } +}; + isc_result_t setup_logging(isc_mem_t *mctx, isc_log_t **logp) { isc_logdestination_t destination; @@ -59,7 +73,9 @@ setup_logging(isc_mem_t *mctx, isc_log_t **logp) { isc_log_t *log = NULL; RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS); + isc_log_registercategories(log, categories); isc_log_setcontext(log); + dns_log_init(log); destination.file.stream = stdout; destination.file.name = NULL; diff --git a/bin/named/log.c b/bin/named/log.c index de74ec75c4..c099c446b7 100644 --- a/bin/named/log.c +++ b/bin/named/log.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: log.c,v 1.37 2004/03/05 04:57:47 marka Exp $ */ +/* $Id: log.c,v 1.38 2004/11/09 21:24:20 marka Exp $ */ #include @@ -31,7 +31,8 @@ /* * When adding a new category, be sure to add the appropriate - * #define to . + * #define to and to update the list in + * bin/check/check-tool.c. */ static isc_logcategory_t categories[] = { { "", 0 }, diff --git a/lib/bind9/check.c b/lib/bind9/check.c index d486e0176b..7b5642a76a 100644 --- a/lib/bind9/check.c +++ b/lib/bind9/check.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: check.c,v 1.49 2004/10/07 02:15:13 marka Exp $ */ +/* $Id: check.c,v 1.50 2004/11/09 21:24:20 marka Exp $ */ #include @@ -1191,6 +1191,120 @@ check_viewconf(cfg_obj_t *config, cfg_obj_t *vconfig, dns_rdataclass_t vclass, return (result); } +static const char * +default_channels[] = { + "default_syslog", + "default_stderr", + "default_debug", + "null", + NULL +}; + +static isc_result_t +bind9_check_logging(cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) { + cfg_obj_t *categories = NULL; + cfg_obj_t *category; + cfg_obj_t *channels = NULL; + cfg_obj_t *channel; + cfg_listelt_t *element; + cfg_listelt_t *delement; + const char *channelname; + const char *catname; + cfg_obj_t *fileobj = NULL; + cfg_obj_t *syslogobj = NULL; + cfg_obj_t *nullobj = NULL; + cfg_obj_t *stderrobj = NULL; + cfg_obj_t *logobj = NULL; + isc_result_t result = ISC_R_SUCCESS; + isc_result_t tresult; + isc_symtab_t *symtab = NULL; + isc_symvalue_t symvalue; + int i; + + (void)cfg_map_get(config, "logging", &logobj); + if (logobj == NULL) + return (ISC_R_SUCCESS); + + result = isc_symtab_create(mctx, 100, NULL, NULL, ISC_FALSE, &symtab); + if (result != ISC_R_SUCCESS) + return (result); + + symvalue.as_pointer = NULL; + for (i = 0; default_channels[i] != NULL; i++) { + tresult = isc_symtab_define(symtab, default_channels[i], 1, + symvalue, isc_symexists_replace); + if (tresult != ISC_R_SUCCESS) + result = tresult; + } + + cfg_map_get(logobj, "channel", &channels); + + for (element = cfg_list_first(channels); + element != NULL; + element = cfg_list_next(element)) + { + channel = cfg_listelt_value(element); + channelname = cfg_obj_asstring(cfg_map_getname(channel)); + fileobj = syslogobj = nullobj = stderrobj = NULL; + (void)cfg_map_get(channel, "file", &fileobj); + (void)cfg_map_get(channel, "syslog", &syslogobj); + (void)cfg_map_get(channel, "null", &nullobj); + (void)cfg_map_get(channel, "stderr", &stderrobj); + i = 0; + if (fileobj != NULL) + i++; + if (syslogobj != NULL) + i++; + if (nullobj != NULL) + i++; + if (stderrobj != NULL) + i++; + if (i != 1) { + cfg_obj_log(channel, logctx, ISC_LOG_ERROR, + "channel '%s': exactly one of file, syslog, " + "null, and stderr must be present", + channelname); + result = ISC_R_FAILURE; + } + tresult = isc_symtab_define(symtab, channelname, 1, + symvalue, isc_symexists_replace); + if (tresult != ISC_R_SUCCESS) + result = tresult; + } + + cfg_map_get(logobj, "category", &categories); + + for (element = cfg_list_first(categories); + element != NULL; + element = cfg_list_next(element)) + { + category = cfg_listelt_value(element); + catname = cfg_obj_asstring(cfg_tuple_get(category, "name")); + if (isc_log_categorybyname(logctx, catname) == NULL) { + cfg_obj_log(category, logctx, ISC_LOG_ERROR, + "undefined category: '%s'", catname); + result = ISC_R_FAILURE; + } + channels = cfg_tuple_get(category, "destinations"); + for (delement = cfg_list_first(channels); + delement != NULL; + delement = cfg_list_next(delement)) + { + channel = cfg_listelt_value(delement); + channelname = cfg_obj_asstring(channel); + tresult = isc_symtab_lookup(symtab, channelname, 1, + &symvalue); + if (tresult != ISC_R_SUCCESS) { + cfg_obj_log(channel, logctx, ISC_LOG_ERROR, + "undefined channel: '%s'", + channelname); + result = tresult; + } + } + } + isc_symtab_destroy(&symtab); + return (result); +} isc_result_t bind9_check_namedconf(cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) { @@ -1219,6 +1333,9 @@ bind9_check_namedconf(cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) { check_servers(servers, logctx) != ISC_R_SUCCESS) result = ISC_R_FAILURE; + if (bind9_check_logging(config, logctx, mctx) != ISC_R_SUCCESS) + result = ISC_R_FAILURE; + if (options != NULL && check_order(options, logctx) != ISC_R_SUCCESS) result = ISC_R_FAILURE;