From dcb54af2204b9764d6b8fbcbc0be9ee295546c32 Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Fri, 16 Dec 2022 10:39:15 +0000 Subject: [PATCH] Move bind9/check to isccfg/check Since it is part of the configuration machinery --- CHANGES | 4 + bin/check/named-checkconf.c | 5 +- bin/named/controlconf.c | 5 +- bin/named/server.c | 7 +- lib/bind9/Makefile.am | 3 +- lib/isccfg/Makefile.am | 14 ++- lib/{bind9 => isccfg}/check.c | 85 ++++++++----------- .../bind9 => isccfg/include/isccfg}/check.h | 10 +-- lib/isccfg/namedconf.c | 2 +- 9 files changed, 67 insertions(+), 68 deletions(-) rename lib/{bind9 => isccfg}/check.c (98%) rename lib/{bind9/include/bind9 => isccfg/include/isccfg}/check.h (81%) diff --git a/CHANGES b/CHANGES index 121b111af2..cb3c764c13 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +6104. [cleanup] Move libbind9's configuration checking code into + libisccfg alongside the other configuration code. + [GL !7461] + 6103. [func] All uses of the isc_task and isc_event APIs have been refactored to use isc_loop instead, and the original APIs have been removed. [GL #3797] diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index 807c2c2592..a24435f03e 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -36,11 +36,10 @@ #include #include +#include #include #include -#include - #include "check-tool.h" static const char *program = "named-checkconf"; @@ -734,7 +733,7 @@ main(int argc, char **argv) { exit(1); } - result = bind9_check_namedconf(config, loadplugins, logc, mctx); + result = isccfg_check_namedconf(config, loadplugins, logc, mctx); if (result != ISC_R_SUCCESS) { exit_status = 1; } diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c index 384ed0fa29..8e1ecd08d4 100644 --- a/bin/named/controlconf.c +++ b/bin/named/controlconf.c @@ -39,10 +39,9 @@ #include #include +#include #include -#include - #include #include #include @@ -839,7 +838,7 @@ get_rndckey(isc_mem_t *mctx, controlkeylist_t *keyids) { CHECK(ISC_R_NOMEMORY); } - CHECK(bind9_check_key(key, named_g_lctx)); + CHECK(isccfg_check_key(key, named_g_lctx)); (void)cfg_map_get(key, "algorithm", &algobj); (void)cfg_map_get(key, "secret", &secretobj); diff --git a/bin/named/server.c b/bin/named/server.c index bf4b3e10c7..c229967531 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -108,6 +108,7 @@ #include +#include #include #include #include @@ -117,8 +118,6 @@ #include #include -#include - #include #include #if defined(HAVE_GEOIP2) @@ -8423,8 +8422,8 @@ load_configuration(const char *filename, named_server_t *server, * checked later when the modules are actually loaded and * registered.) */ - result = bind9_check_namedconf(config, false, named_g_lctx, - named_g_mctx); + result = isccfg_check_namedconf(config, false, named_g_lctx, + named_g_mctx); if (result != ISC_R_SUCCESS) { goto cleanup_config; } diff --git a/lib/bind9/Makefile.am b/lib/bind9/Makefile.am index 7ec5bdd3bc..c48018a906 100644 --- a/lib/bind9/Makefile.am +++ b/lib/bind9/Makefile.am @@ -3,13 +3,12 @@ include $(top_srcdir)/Makefile.top lib_LTLIBRARIES = libbind9.la libbind9_ladir = $(includedir)/bind9 + libbind9_la_HEADERS = \ - include/bind9/check.h \ include/bind9/getaddresses.h libbind9_la_SOURCES = \ $(libbind9_la_HEADERS) \ - check.c \ getaddresses.c libbind9_la_CPPFLAGS = \ diff --git a/lib/isccfg/Makefile.am b/lib/isccfg/Makefile.am index 0c95c4f0d4..2b1f27e3dd 100644 --- a/lib/isccfg/Makefile.am +++ b/lib/isccfg/Makefile.am @@ -6,6 +6,7 @@ libisccfg_ladir = $(includedir)/isccfg libisccfg_la_HEADERS = \ include/isccfg/aclconf.h \ include/isccfg/cfg.h \ + include/isccfg/check.h \ include/isccfg/duration.h \ include/isccfg/grammar.h \ include/isccfg/kaspconf.h \ @@ -15,6 +16,7 @@ libisccfg_la_HEADERS = \ libisccfg_la_SOURCES = \ $(libisccfg_la_HEADERS) \ aclconf.c \ + check.c \ dnsconf.c \ duration.c \ kaspconf.c \ @@ -26,12 +28,20 @@ libisccfg_la_CPPFLAGS = \ $(AM_CPPFLAGS) \ $(LIBISCCFG_CFLAGS) \ $(LIBISC_CFLAGS) \ - $(LIBDNS_CFLAGS) + $(LIBDNS_CFLAGS) \ + $(LIBNS_CFLAGS) \ + $(OPENSSL_CFLAGS) libisccfg_la_LIBADD = \ $(LIBDNS_LIBS) \ - $(LIBISC_LIBS) + $(LIBISC_LIBS) \ + $(LIBNS_LIBS) \ + $(OPENSSL_LIBS) libisccfg_la_LDFLAGS = \ $(AM_LDFLAGS) \ -release "$(PACKAGE_VERSION)" + +if HAVE_DNSTAP +libisccfg_la_CPPFLAGS += $(DNSTAP_CFLAGS) +endif diff --git a/lib/bind9/check.c b/lib/isccfg/check.c similarity index 98% rename from lib/bind9/check.c rename to lib/isccfg/check.c index 1482de1310..1846ee5df7 100644 --- a/lib/bind9/check.c +++ b/lib/isccfg/check.c @@ -62,14 +62,13 @@ #include #include +#include #include #include #include #include -#include - static in_port_t dnsport = 53; static isc_result_t @@ -2012,9 +2011,9 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config, * Check "remote-servers" style list. */ static isc_result_t -bind9_check_remoteserverlist(const cfg_obj_t *cctx, const char *list, - isc_log_t *logctx, isc_symtab_t *symtab, - isc_mem_t *mctx) { +check_remoteserverlist(const cfg_obj_t *cctx, const char *list, + isc_log_t *logctx, isc_symtab_t *symtab, + isc_mem_t *mctx) { isc_symvalue_t symvalue; isc_result_t result, tresult; const cfg_obj_t *obj = NULL; @@ -2072,8 +2071,7 @@ bind9_check_remoteserverlist(const cfg_obj_t *cctx, const char *list, * Check primaries lists for duplicates. */ static isc_result_t -bind9_check_primarylists(const cfg_obj_t *cctx, isc_log_t *logctx, - isc_mem_t *mctx) { +check_primarylists(const cfg_obj_t *cctx, isc_log_t *logctx, isc_mem_t *mctx) { isc_result_t result, tresult; isc_symtab_t *symtab = NULL; @@ -2081,13 +2079,12 @@ bind9_check_primarylists(const cfg_obj_t *cctx, isc_log_t *logctx, if (result != ISC_R_SUCCESS) { return (result); } - tresult = bind9_check_remoteserverlist(cctx, "primaries", logctx, - symtab, mctx); + tresult = check_remoteserverlist(cctx, "primaries", logctx, symtab, + mctx); if (tresult != ISC_R_SUCCESS) { result = tresult; } - tresult = bind9_check_remoteserverlist(cctx, "masters", logctx, symtab, - mctx); + tresult = check_remoteserverlist(cctx, "masters", logctx, symtab, mctx); if (tresult != ISC_R_SUCCESS) { result = tresult; } @@ -2099,8 +2096,8 @@ bind9_check_primarylists(const cfg_obj_t *cctx, isc_log_t *logctx, * Check parental-agents lists for duplicates. */ static isc_result_t -bind9_check_parentalagentlists(const cfg_obj_t *cctx, isc_log_t *logctx, - isc_mem_t *mctx) { +check_parentalagentlists(const cfg_obj_t *cctx, isc_log_t *logctx, + isc_mem_t *mctx) { isc_result_t result, tresult; isc_symtab_t *symtab = NULL; @@ -2108,8 +2105,8 @@ bind9_check_parentalagentlists(const cfg_obj_t *cctx, isc_log_t *logctx, if (result != ISC_R_SUCCESS) { return (result); } - tresult = bind9_check_remoteserverlist(cctx, "parental-agents", logctx, - symtab, mctx); + tresult = check_remoteserverlist(cctx, "parental-agents", logctx, + symtab, mctx); if (tresult != ISC_R_SUCCESS) { result = tresult; } @@ -2119,8 +2116,8 @@ bind9_check_parentalagentlists(const cfg_obj_t *cctx, isc_log_t *logctx, #if HAVE_LIBNGHTTP2 static isc_result_t -bind9_check_httpserver(const cfg_obj_t *http, isc_log_t *logctx, - isc_symtab_t *symtab) { +check_httpserver(const cfg_obj_t *http, isc_log_t *logctx, + isc_symtab_t *symtab) { isc_result_t result, tresult; const char *name = cfg_obj_asstring(cfg_map_getname(http)); const cfg_obj_t *eps = NULL; @@ -2182,8 +2179,7 @@ bind9_check_httpserver(const cfg_obj_t *http, isc_log_t *logctx, } static isc_result_t -bind9_check_httpservers(const cfg_obj_t *config, isc_log_t *logctx, - isc_mem_t *mctx) { +check_httpservers(const cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) { isc_result_t result, tresult; const cfg_obj_t *obj = NULL; const cfg_listelt_t *elt = NULL; @@ -2202,7 +2198,7 @@ bind9_check_httpservers(const cfg_obj_t *config, isc_log_t *logctx, for (elt = cfg_list_first(obj); elt != NULL; elt = cfg_list_next(elt)) { obj = cfg_listelt_value(elt); - tresult = bind9_check_httpserver(obj, logctx, symtab); + tresult = check_httpserver(obj, logctx, symtab); if (result == ISC_R_SUCCESS) { result = tresult; } @@ -2215,8 +2211,8 @@ done: #endif /* HAVE_LIBNGHTTP2 */ static isc_result_t -bind9_check_tls_defintion(const cfg_obj_t *tlsobj, const char *name, - isc_log_t *logctx, isc_symtab_t *symtab) { +check_tls_defintion(const cfg_obj_t *tlsobj, const char *name, + isc_log_t *logctx, isc_symtab_t *symtab) { isc_result_t result, tresult; const cfg_obj_t *tls_proto_list = NULL, *tls_key = NULL, *tls_cert = NULL, *tls_ciphers = NULL; @@ -2338,8 +2334,8 @@ bind9_check_tls_defintion(const cfg_obj_t *tlsobj, const char *name, } static isc_result_t -bind9_check_tls_definitions(const cfg_obj_t *config, isc_log_t *logctx, - isc_mem_t *mctx) { +check_tls_definitions(const cfg_obj_t *config, isc_log_t *logctx, + isc_mem_t *mctx) { isc_result_t result, tresult; const cfg_obj_t *obj = NULL; const cfg_listelt_t *elt = NULL; @@ -2360,7 +2356,7 @@ bind9_check_tls_definitions(const cfg_obj_t *config, isc_log_t *logctx, const char *name; obj = cfg_listelt_value(elt); name = cfg_obj_asstring(cfg_map_getname(obj)); - tresult = bind9_check_tls_defintion(obj, name, logctx, symtab); + tresult = check_tls_defintion(obj, name, logctx, symtab); if (result == ISC_R_SUCCESS) { result = tresult; } @@ -3889,7 +3885,7 @@ typedef struct keyalgorithms { } algorithmtable; isc_result_t -bind9_check_key(const cfg_obj_t *key, isc_log_t *logctx) { +isccfg_check_key(const cfg_obj_t *key, isc_log_t *logctx) { const cfg_obj_t *algobj = NULL; const cfg_obj_t *secretobj = NULL; const char *keyname = cfg_obj_asstring(cfg_map_getname(key)); @@ -4111,7 +4107,7 @@ check_keylist(const cfg_obj_t *keys, isc_symtab_t *symtab, isc_mem_t *mctx, result = tresult; continue; } - tresult = bind9_check_key(key, logctx); + tresult = isccfg_check_key(key, logctx); if (tresult != ISC_R_SUCCESS) { return (tresult); } @@ -5662,8 +5658,7 @@ static const char *default_channels[] = { "default_syslog", "default_stderr", "default_debug", "null", NULL }; static isc_result_t -bind9_check_logging(const cfg_obj_t *config, isc_log_t *logctx, - isc_mem_t *mctx) { +check_logging(const cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) { const cfg_obj_t *categories = NULL; const cfg_obj_t *category; const cfg_obj_t *channels = NULL; @@ -5775,8 +5770,8 @@ bind9_check_logging(const cfg_obj_t *config, isc_log_t *logctx, } static isc_result_t -bind9_check_controlskeys(const cfg_obj_t *control, const cfg_obj_t *keylist, - isc_log_t *logctx) { +check_controlskeys(const cfg_obj_t *control, const cfg_obj_t *keylist, + isc_log_t *logctx) { isc_result_t result = ISC_R_SUCCESS; const cfg_obj_t *control_keylist; const cfg_listelt_t *element; @@ -5804,8 +5799,7 @@ bind9_check_controlskeys(const cfg_obj_t *control, const cfg_obj_t *keylist, } static isc_result_t -bind9_check_controls(const cfg_obj_t *config, isc_log_t *logctx, - isc_mem_t *mctx) { +check_controls(const cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) { isc_result_t result = ISC_R_SUCCESS, tresult; cfg_aclconfctx_t *actx = NULL; const cfg_listelt_t *element, *element2; @@ -5856,8 +5850,7 @@ bind9_check_controls(const cfg_obj_t *config, isc_log_t *logctx, if (tresult != ISC_R_SUCCESS) { result = tresult; } - tresult = bind9_check_controlskeys(control, keylist, - logctx); + tresult = check_controlskeys(control, keylist, logctx); if (tresult != ISC_R_SUCCESS) { result = tresult; } @@ -5896,8 +5889,7 @@ bind9_check_controls(const cfg_obj_t *config, isc_log_t *logctx, "to nobody", path); } - tresult = bind9_check_controlskeys(control, keylist, - logctx); + tresult = check_controlskeys(control, keylist, logctx); if (tresult != ISC_R_SUCCESS) { result = tresult; } @@ -5908,8 +5900,8 @@ bind9_check_controls(const cfg_obj_t *config, isc_log_t *logctx, } isc_result_t -bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, - isc_log_t *logctx, isc_mem_t *mctx) { +isccfg_check_namedconf(const cfg_obj_t *config, bool check_plugins, + isc_log_t *logctx, isc_mem_t *mctx) { const cfg_obj_t *options = NULL; const cfg_obj_t *views = NULL; const cfg_obj_t *acls = NULL; @@ -5932,32 +5924,29 @@ bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, result = ISC_R_FAILURE; } - if (bind9_check_logging(config, logctx, mctx) != ISC_R_SUCCESS) { + if (check_logging(config, logctx, mctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; } - if (bind9_check_controls(config, logctx, mctx) != ISC_R_SUCCESS) { + if (check_controls(config, logctx, mctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; } - if (bind9_check_primarylists(config, logctx, mctx) != ISC_R_SUCCESS) { + if (check_primarylists(config, logctx, mctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; } - if (bind9_check_parentalagentlists(config, logctx, mctx) != - ISC_R_SUCCESS) - { + if (check_parentalagentlists(config, logctx, mctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; } #if HAVE_LIBNGHTTP2 - if (bind9_check_httpservers(config, logctx, mctx) != ISC_R_SUCCESS) { + if (check_httpservers(config, logctx, mctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; } #endif /* HAVE_LIBNGHTTP2 */ - if (bind9_check_tls_definitions(config, logctx, mctx) != ISC_R_SUCCESS) - { + if (check_tls_definitions(config, logctx, mctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; } diff --git a/lib/bind9/include/bind9/check.h b/lib/isccfg/include/isccfg/check.h similarity index 81% rename from lib/bind9/include/bind9/check.h rename to lib/isccfg/include/isccfg/check.h index 26d60fcadf..b96e9f50e5 100644 --- a/lib/bind9/include/bind9/check.h +++ b/lib/isccfg/include/isccfg/check.h @@ -13,7 +13,7 @@ #pragma once -/*! \file bind9/check.h */ +/*! \file isccfg/check.h */ #include #include @@ -35,8 +35,8 @@ ISC_LANG_BEGINDECLS isc_result_t -bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, - isc_log_t *logctx, isc_mem_t *mctx); +isccfg_check_namedconf(const cfg_obj_t *config, bool check_plugins, + isc_log_t *logctx, isc_mem_t *mctx); /*%< * Check the syntactic validity of a configuration parse tree generated from * a named.conf file. @@ -55,9 +55,9 @@ bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, */ isc_result_t -bind9_check_key(const cfg_obj_t *config, isc_log_t *logctx); +isccfg_check_key(const cfg_obj_t *config, isc_log_t *logctx); /*%< - * Same as bind9_check_namedconf(), but for a single 'key' statement. + * Same as isccfg_check_namedconf(), but for a single 'key' statement. */ ISC_LANG_ENDDECLS diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c index d060d7cdc7..80df843cc1 100644 --- a/lib/isccfg/namedconf.c +++ b/lib/isccfg/namedconf.c @@ -2524,7 +2524,7 @@ static cfg_type_t cfg_type_key = { "key", cfg_parse_named_map, /*% * Clauses that can be found in a 'server' statement. * - * Please update lib/bind9/check.c and + * Please update lib/isccfg/check.c and * bin/tests/system/checkconf/good-server-christmas-tree.conf.in to * exercise the new clause when adding new clauses. */