From 5ec80aa6c8e7614e3e0a02b6183f9012f9522606 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Mon, 30 Nov 2026 17:04:33 +0000 Subject: [PATCH] Make --conf-file without filename just inhibit reading the default. This is now consistent with the behaviour of --resolv-file. --- man/dnsmasq.8 | 6 +++--- src/option.c | 27 ++++++++++++--------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/man/dnsmasq.8 b/man/dnsmasq.8 index 8923325..2acb304 100644 --- a/man/dnsmasq.8 +++ b/man/dnsmasq.8 @@ -2318,9 +2318,9 @@ Run in a mode where the TFTP server uses ONLY the well-known port (69) for its e of the TFTP transfer. This allows TFTP to work when there in NAT is the path between client and server. Note that this is not strictly compliant with the RFCs specifying the TFTP protocol: use at your own risk. .TP -.B \-C, --conf-file= -Specify a configuration file. The presence of this option stops dnsmasq from reading the default configuration -file (normally /etc/dnsmasq.conf). Multiple files may be specified by repeating the option +.B \-C, --conf-file[=] +Specify a configuration file. The presence of this option (even without a filename) stops dnsmasq from +reading the default configuration file (normally /etc/dnsmasq.conf). Multiple files may be specified by repeating the option either on the command line or in configuration files. A filename of "-" causes dnsmasq to read configuration from stdin. .TP diff --git a/src/option.c b/src/option.c index 012b14a..a303f4a 100644 --- a/src/option.c +++ b/src/option.c @@ -424,7 +424,7 @@ static struct { { 'b', OPT_BOGUSPRIV, NULL, gettext_noop("Fake reverse lookups for RFC1918 private address ranges."), NULL }, { 'B', ARG_DUP, "", gettext_noop("Treat ipaddr as NXDOMAIN (defeats Verisign wildcard)."), NULL }, { 'c', ARG_ONE, "", gettext_noop("Specify the size of the cache in entries (defaults to %s)."), "$" }, - { 'C', ARG_DUP, "", gettext_noop("Specify configuration file (defaults to %s)."), CONFFILE }, + { 'C', ARG_DUP, "[]", gettext_noop("Specify configuration file (defaults to %s)."), CONFFILE }, { 'd', OPT_DEBUG, NULL, gettext_noop("Do NOT fork into the background: run in debug mode."), NULL }, { 'D', OPT_NODOTS_LOCAL, NULL, gettext_noop("Do NOT forward queries with no domain part."), NULL }, { 'e', OPT_SELFMX, NULL, gettext_noop("Return self-pointing MX records for local hosts."), NULL }, @@ -5985,8 +5985,8 @@ void read_opts(int argc, char **argv, char *compile_opts) { size_t argbuf_size = 300; char *argbuf = safe_malloc(argbuf_size); - int option, testmode = 0; - char *arg, *conffile = NULL; + int option, testmode = 0, conf_read = 0; + char *arg; opterr = 0; @@ -6095,13 +6095,15 @@ void read_opts(int argc, char **argv, char *compile_opts) } else if (option == 'C') { - if (!conffile) - conffile = opt_string_alloc(arg); - else + char *conffile = opt_string_alloc(arg); + + /* Inhibit /etc/dnsmasq.conf even if no file given */ + conf_read = 1; + + if (conffile) { - char *extra = opt_string_alloc(arg); - one_file(extra, 0); - free(extra); + one_file(conffile, 0); + free(conffile); } } else @@ -6117,12 +6119,7 @@ void read_opts(int argc, char **argv, char *compile_opts) free(argbuf); - if (conffile) - { - one_file(conffile, 0); - free(conffile); - } - else + if (!conf_read) one_file(CONFFILE, LOPT_CONF_OPT); /* Add TXT records if wanted */