From d94654e1007524604e8b7d36c91083dccc175495 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 28 Jan 2024 16:04:29 +0000 Subject: [PATCH] getdata: only emit warning when config include file cannot be read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not being able to open primary config file will cause fatal error, where as include files will only warn. This is useful for setups that want to publish some of the dhcp lease data, but not all. Such setup obviously required dhcpd server to have differnt account than dhcpd-pools, with carefully managed read permissions. Requested-by: Björn Lässig Signed-off-by: Sami Kerola --- THANKS | 1 + src/getdata.c | 8 +++++++- tests/expected/errors | 11 ++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/THANKS b/THANKS index 8fe47e0..2639556 100644 --- a/THANKS +++ b/THANKS @@ -50,3 +50,4 @@ Brent Swingle Mathieu Morier Jean Benoit Belkacem Daheb +Björn Lässig diff --git a/src/getdata.c b/src/getdata.c index 966fe5d..ff05804 100644 --- a/src/getdata.c +++ b/src/getdata.c @@ -238,8 +238,14 @@ void parse_config(struct conf_t *state, const int is_include, const char *restri shared_p->name = state->shared_net_root->name; /* Open configuration file */ dhcpd_config = fopen(config_file, "r"); - if (dhcpd_config == NULL) + if (dhcpd_config == NULL) { + if (is_include) { + error(0, errno, "cannot open inlude: %s", config_file); + return; + } + /* config if from command line, just exit with error */ error(EXIT_FAILURE, errno, "parse_config: %s", config_file); + } #ifdef HAVE_POSIX_FADVISE # ifdef POSIX_FADV_SEQUENTIAL if (posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL) != 0) diff --git a/tests/expected/errors b/tests/expected/errors index b85e282..6903ac6 100644 --- a/tests/expected/errors +++ b/tests/expected/errors @@ -7,7 +7,16 @@ dhcpd-pools: unknown color mode: 'sometimes' === IPv5 dhcpd-pools: unknown --ip-version argument: 5 === missing conf -dhcpd-pools: parse_config: ./tests/confs/complete_NXFILE: No such file or directory +dhcpd-pools: cannot open inlude: ./tests/confs/complete_NXFILE: No such file or directory +Ranges: +shared net name first ip last ip max cur percent touch t+c t+c perc + +Shared networks: +name max cur percent touch t+c t+c perc + +Sum of all ranges: +name max cur percent touch t+c t+c perc +All networks 0 0 nan 0 0 nan === missing leases dhcpd-pools: parse_leases: ./tests/leases/complete_NXFILE: No such file or directory === html table