From fcb2ecdb52a594a5c0d07c2e98e67c14708c16df Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 4 Mar 2002 05:07:06 +0000 Subject: [PATCH] 1216. [bug] Multiple server clauses for the same server were not reported. [RT #2514] --- CHANGES | 3 +++ lib/bind9/check.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index da0a2aac43..6cc866a77e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1216. [bug] Multiple server clauses for the same server were not + reported. [RT #2514] + 1215. [port] solaris: add support to ifconfig.sh for x86 2.5.1 1214. [bug] Win32: isc_file_renameunique() could leave zero length diff --git a/lib/bind9/check.c b/lib/bind9/check.c index 55f9dcf58e..a07e17f3a1 100644 --- a/lib/bind9/check.c +++ b/lib/bind9/check.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: check.c,v 1.25 2002/02/20 03:34:09 marka Exp $ */ +/* $Id: check.c,v 1.26 2002/03/04 05:07:06 marka Exp $ */ #include @@ -25,8 +25,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -440,11 +442,53 @@ freekey(char *key, unsigned int type, isc_symvalue_t value, void *userarg) { UNUSED(value); isc_mem_free(userarg, key); } + +static isc_result_t +check_servers(cfg_obj_t *servers, isc_log_t *logctx) { + isc_result_t result = ISC_R_SUCCESS; + cfg_listelt_t *e1, *e2; + cfg_obj_t *v1, *v2; + isc_sockaddr_t *s1, *s2; + isc_netaddr_t na; + + for (e1 = cfg_list_first(servers); e1 != NULL; e1 = cfg_list_next(e1)) { + v1 = cfg_listelt_value(e1); + s1 = cfg_obj_assockaddr(cfg_map_getname(v1)); + e2 = e1; + while ((e2 = cfg_list_next(e2)) != NULL) { + v2 = cfg_listelt_value(e2); + s2 = cfg_obj_assockaddr(cfg_map_getname(v2)); + if (isc_sockaddr_eqaddr(s1, s2)) { + const char *file = cfg_obj_file(v1); + unsigned int line = cfg_obj_line(v1); + isc_buffer_t target; + char buf[128]; + + if (file == NULL) + file = ""; + + isc_netaddr_fromsockaddr(&na, s2); + isc_buffer_init(&target, buf, sizeof(buf) - 1); + INSIST(isc_netaddr_totext(&na, &target) + == ISC_R_SUCCESS); + buf[isc_buffer_usedlength(&target)] = '\0'; + + cfg_obj_log(v2, logctx, ISC_LOG_ERROR, + "server '%s': already exists " + "previous definition: %s:%u", + buf, file, line); + result = ISC_R_FAILURE; + } + } + } + return (result); +} static isc_result_t check_viewconf(cfg_obj_t *config, cfg_obj_t *vconfig, dns_rdataclass_t vclass, isc_log_t *logctx, isc_mem_t *mctx) { + cfg_obj_t *servers = NULL; cfg_obj_t *zones = NULL; cfg_obj_t *keys = NULL; cfg_listelt_t *element; @@ -525,6 +569,14 @@ check_viewconf(cfg_obj_t *config, cfg_obj_t *vconfig, dns_rdataclass_t vclass, result = ISC_R_FAILURE; } + + if (vconfig != NULL) { + (void)cfg_map_get(vconfig, "server", &servers); + if (servers != NULL && + check_servers(servers, logctx) != ISC_R_SUCCESS) + result = ISC_R_FAILURE; + } + if (vconfig != NULL) tresult = check_options(vconfig, logctx); else @@ -539,6 +591,7 @@ check_viewconf(cfg_obj_t *config, cfg_obj_t *vconfig, dns_rdataclass_t vclass, isc_result_t bind9_check_namedconf(cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) { cfg_obj_t *options = NULL; + cfg_obj_t *servers = NULL; cfg_obj_t *views = NULL; cfg_obj_t *acls = NULL; cfg_obj_t *obj; @@ -555,6 +608,11 @@ bind9_check_namedconf(cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) { check_options(options, logctx) != ISC_R_SUCCESS) result = ISC_R_FAILURE; + (void)cfg_map_get(config, "server", &servers); + if (servers != NULL && + check_servers(servers, logctx) != ISC_R_SUCCESS) + result = ISC_R_FAILURE; + (void)cfg_map_get(config, "view", &views); if (views == NULL) {