]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Implement --config[=default|=check|=diff] 11907/head
authorFred Morcos <fred.morcos@open-xchange.com>
Tue, 6 Sep 2022 13:18:37 +0000 (15:18 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Fri, 9 Sep 2022 11:10:46 +0000 (13:10 +0200)
Closes #9435

pdns/recursordist/Makefile.am
pdns/recursordist/docs/manpages/pdns_recursor.1.rst
pdns/recursordist/rec-main.cc

index 8be3d49b441766904bb6a1b062f509e13b9948cb..d0a9a18ac52ae33a77bbd0806c66743002a722cd 100644 (file)
@@ -508,7 +508,7 @@ pubsuffix.cc: $(srcdir)/effective_tld_names.dat
 sysconf_DATA = recursor.conf-dist
 
 recursor.conf-dist: pdns_recursor
-       $(AM_V_GEN)./pdns_recursor --config > $@
+       $(AM_V_GEN)./pdns_recursor --config=default > $@
 
 ## Manpages
 MANPAGES=pdns_recursor.1 \
index 47103dce8757d285e4f48a7893ebb630db3b2f53..496f4a44629be427505ae76f4422d1349247d3f7 100644 (file)
@@ -46,6 +46,11 @@ at `<https://doc.powerdns.com/>`
     chroot the process to *directory*.
 --client-tcp-timeout=<num>
     Timeout in seconds when talking to TCP clients.
+--config
+    Show the current configuration. There are three optional values:
+    ``--config=default`` to show the default configuration.
+    ``--config=diff``    show modified options in the current configuration.
+    ``--config=check``   to check the current configuration for errors.
 --config-dir=<directory>
     Location of configuration directory (recursor.conf), the default
     depends on the SYSCONFDIR option at build-time, which is usually
index 033abae93d84279417721f31ca325890db1b3420..0f1e62437236fe67024eae4216f9d7b3ec8b2dc0 100644 (file)
@@ -2814,7 +2814,7 @@ int main(int argc, char** argv)
 
     ::arg().setCmd("help", "Provide a helpful message");
     ::arg().setCmd("version", "Print version string");
-    ::arg().setCmd("config", "Output blank configuration");
+    ::arg().setCmd("config", "Output blank configuration. You can use --config=check to test the config file and command line arguments.");
     ::arg().setDefaults();
     g_log.toConsole(Logger::Info);
     ::arg().laxParse(argc, argv); // do a lax parse
@@ -2871,11 +2871,6 @@ int main(int argc, char** argv)
       exit(99);
     }
 
-    if (::arg().mustDo("config")) {
-      cout << ::arg().configstring(false, true);
-      exit(0);
-    }
-
     if (s_structured_logger_backend == "systemd-journal") {
 #ifdef HAVE_SYSTEMD
       if (int fd = sd_journal_stream_fd("pdns-recusor", LOG_DEBUG, 0); fd >= 0) {
@@ -2899,6 +2894,49 @@ int main(int argc, char** argv)
     g_slogout = g_slog->withName("out");
 
     ::arg().setSLog(startupLog);
+
+    if (::arg().mustDo("config")) {
+      string config = ::arg()["config"];
+      if (config == "check") {
+        try {
+          if (!::arg().file(configname.c_str())) {
+            SLOG(g_log << Logger::Warning << "Unable to open configuration file '" << configname << "'" << endl,
+                 startupLog->error("No such file", "Unable to open configuration file", "config_file", Logging::Loggable(configname)));
+            exit(1);
+          }
+          ::arg().parse(argc, argv);
+          exit(0);
+        }
+        catch (const ArgException& argException) {
+          SLOG(g_log << Logger::Warning << "Unable to parse configuration file '" << configname << "': " << argException.reason << endl,
+               startupLog->error("Cannot parse configuration", "Unable to parse configuration file", "config_file", Logging::Loggable(configname), "reason", Logging::Loggable(argException.reason)));
+          exit(1);
+        }
+      }
+      else if (config == "default") {
+        cout << ::arg().configstring(false, true);
+      }
+      else if (config == "diff") {
+        if (!::arg().laxFile(configname.c_str())) {
+          SLOG(g_log << Logger::Warning << "Unable to open configuration file '" << configname << "'" << endl,
+               startupLog->error("No such file", "Unable to open configuration file", "config_file", Logging::Loggable(configname)));
+          exit(1);
+        }
+        ::arg().laxParse(argc, argv);
+        cout << ::arg().configstring(true, false);
+      }
+      else {
+        if (!::arg().laxFile(configname.c_str())) {
+          SLOG(g_log << Logger::Warning << "Unable to open configuration file '" << configname << "'" << endl,
+               startupLog->error("No such file", "Unable to open configuration file", "config_file", Logging::Loggable(configname)));
+          exit(1);
+        }
+        ::arg().laxParse(argc, argv);
+        cout << ::arg().configstring(true, true);
+      }
+      exit(0);
+    }
+
     if (!::arg().file(configname.c_str())) {
       SLOG(g_log << Logger::Warning << "Unable to open configuration file '" << configname << "'" << endl,
            startupLog->error("No such file", "Unable to open configuration file", "config_file", Logging::Loggable(configname)));