]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Tweaks and add a command to get default config parameter values
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 30 Oct 2025 12:57:50 +0000 (13:57 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 4 Nov 2025 12:40:38 +0000 (13:40 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/docs/manpages/rec_control.1.rst
pdns/recursordist/rec-rust-lib/cxxsupport.cc
pdns/recursordist/rec-rust-lib/rust-bridge-in.rs
pdns/recursordist/rec-rust-lib/rust/src/bridge.rs
pdns/recursordist/rec_channel_rec.cc

index fb0469d9ee904241f0ff7948ee12ffefed2b1853..6750a0f22b6438aebc8c08da24c32d3fd54eea8c 100644 (file)
@@ -172,8 +172,15 @@ get-ntas
 get-tas
     Get a list of the currently configured Trust Anchors.
 
-get-parameter *KEY* [*KEY*]...
-    Retrieves the specified configuration parameter(s).
+get-parameter [*KEY*]...
+    Retrieves the configuration parameter(s).
+    If YAML configuration is active, *KEY* is of the form ``section[.name]``
+    and no keys produces a full dump.
+
+get-default-parameter [*KEY*]...
+    Retrieves the default values of configuration parameter(s).
+    If YAML configuration is active, *KEY* is of the form ``section[.name]``
+    and no keys produces a full dump.
 
 get-proxymapping-stats
     Get the list of proxy-mapped subnets and associated counters.
index 0c7a7cb918621eb52e0639dac045fdb3b3ec5d5c..0bc466a55b034359d015da85a865ca9fe361a206 100644 (file)
@@ -687,7 +687,7 @@ std::string pdns::settings::rec::defaultsToYaml(bool postProcess)
   for (const auto& entry : map) {
     vec.emplace_back(entry.second);
   }
-  const auto defs = std::string(pdns::rust::settings::rec::map_to_yaml_string(vec));
+  auto defs = std::string(pdns::rust::settings::rec::map_to_yaml_string(vec));
 
   if (!postProcess) {
     return defs;
index 5851c748a7364f6929fc739d3f7fec08f35c1250..af9c8778ccd92973dd56f388835d2a8b19b9db09 100644 (file)
@@ -403,7 +403,7 @@ extern "Rust" {
 
     // Prdoduce a YAML formatted string given a data structure known to Serde
     fn to_yaml_string(self: &Recursorsettings) -> Result<String>;
-    fn get_value(self: &Recursorsettings, field: &[String], defaults: &str) -> Result<String>;
+    fn get_value(self: &Recursorsettings, field: &[String], defaults: &str, with_comment: bool) -> Result<String>;
     // When doing a conversion of old-style to YAML style we use a vector of OldStyle structs
     fn map_to_yaml_string(map: &Vec<OldStyle>) -> Result<String>;
     fn forward_zones_to_yaml_string(vec: &Vec<ForwardZone>) -> Result<String>;
index 3d4a3f1fc5b23203a613415bbc28fe1c12cfeebf..c6c94c68e1949030e5d3bf71bfe3f39f50671940 100644 (file)
@@ -1000,7 +1000,7 @@ impl Recursorsettings {
         serde_yaml::Value::Mapping(map)
     }
 
-    pub fn get_value(&self, field: &[String], defaults: &str) -> Result<String, std::io::Error> {
+    pub fn get_value(&self, field: &[String], defaults: &str, with_comment: bool) -> Result<String, std::io::Error> {
         let value = serde_yaml::to_value(self);
         let value = match value {
             Ok(value) => value,
@@ -1018,9 +1018,14 @@ impl Recursorsettings {
                     Ok(value) => {
                         let map = Self::buildnestedmaps(field, &value);
                         let res = serde_yaml::to_string(&map).unwrap();
-                        let name = field.join(".");
-                        let msg = format!("# {}: not explicitly set, default value(s) listed below:\n{}", name, res);
-                        Ok(msg)
+                        if with_comment {
+                            let name = field.join(".");
+                            let msg = format!("# {}: not explicitly set, default value(s) listed below:\n{}", name, res);
+                            Ok(msg)
+                        }
+                        else {
+                            Ok(res)
+                        }
                     },
                     Err(x) => Err(x)
                 }
index 627be977941074c7f5dcef60c1ffc821b60d6fa1..b91d10d9d42e9a3eae9d0fe97c4a110154589a87 100644 (file)
@@ -299,8 +299,8 @@ static Answer doGetParameter(ArgIterator begin, ArgIterator end)
 {
   std::stringstream ret;
   int err = 0;
-  if (!g_yamlSettings) {
 
+  if (!g_yamlSettings) {
     for (auto i = begin; i != end; ++i) {
       if (::arg().parmIsset(*i)) {
         const auto& parm = arg()[*i];
@@ -314,9 +314,50 @@ static Answer doGetParameter(ArgIterator begin, ArgIterator end)
   }
   else {
     auto settings = g_yamlStruct.lock();
-    ret << "# YAML settings active" << endl;
     if (begin == end) {
-      auto yaml = settings->get_value({}, pdns::settings::rec::defaultsToYaml(false));
+      auto yaml = settings->get_value({}, pdns::settings::rec::defaultsToYaml(false), true);
+      ret << std::string(yaml);
+    }
+    else {
+      for (auto i = begin; i != end; ++i) {
+        rust::Vec<::rust::String> field;
+        stringtok(field, *i, ".");
+        rust::Slice<const ::rust::String> slice{field};
+        try {
+          auto yaml = settings->get_value(slice, pdns::settings::rec::defaultsToYaml(false), true);
+          ret << std::string(yaml);
+        }
+        catch (const std::exception& stdex) {
+          ret << std::string(stdex.what()) << endl;
+          err = 1;
+        }
+      }
+    }
+  }
+  return {err, ret.str()};
+}
+
+static Answer doGetDefaultParameter(ArgIterator begin, ArgIterator end)
+{
+  std::stringstream ret;
+  int err = 0;
+
+  if (!g_yamlSettings) {
+    for (auto i = begin; i != end; ++i) {
+      if (::arg().parmIsset(*i)) {
+        ret << *i << '=' << ::arg().getDefault(*i) << endl;
+      }
+      else {
+        ret << *i << " not known" << endl;
+        err = 1;
+      }
+    }
+  }
+  else {
+    auto settings = g_yamlStruct.lock();
+    auto defaults = pdns::rust::settings::rec::parse_yaml_string("");
+    if (begin == end) {
+      auto yaml = pdns::settings::rec::defaultsToYaml(false);
       ret << std::string(yaml);
     }
     else {
@@ -325,7 +366,7 @@ static Answer doGetParameter(ArgIterator begin, ArgIterator end)
         stringtok(field, *i, ".");
         rust::Slice<const ::rust::String> slice{field};
         try {
-          auto yaml = settings->get_value(slice, pdns::settings::rec::defaultsToYaml(false));
+          auto yaml = defaults.get_value(slice, pdns::settings::rec::defaultsToYaml(false), false);
           ret << std::string(yaml);
         }
         catch (const std::exception& stdex) {
@@ -1963,7 +2004,8 @@ static RecursorControlChannel::Answer help(ArgIterator /* begin */, ArgIterator
     {"get-dont-throttle-netmasks", "Get the list of netmasks that are not allowed to be throttled"},
     {"get-ntas", "Get all configured Negative Trust Anchors"},
     {"get-tas", "Get all configured Trust Anchors"},
-    {"get-parameter [key1] [key2] ..", "Get configuration parameters"},
+    {"get-parameter [key1] ..", "Get configuration parameters"},
+    {"get-default-parameter [key1] ..", "Get default configuration parameters"},
     {"get-proxymapping-stats", "Get proxy mapping statistics"},
     {"get-qtypelist", "Get QType statistics. Note queries from cache aren't being counted yet"},
     {"get-remotelogger-stats", "Get remote logger statistics"},
@@ -2148,6 +2190,7 @@ RecursorControlChannel::Answer RecursorControlParser::getAnswer(int socket, cons
     {"get-all", getAllStats},
     {"get", doGet},
     {"get-parameter", doGetParameter},
+    {"get-default-parameter", doGetDefaultParameter},
     {"quit", [&](ArgIterator, ArgIterator) -> Answer { *command = doExit; return {0, "bye\n"}; }},
     {"version", [&](ArgIterator, ArgIterator) -> Answer { return {0, getPDNSVersion() + "\n"}; }},
     {"quit-nicely", [&](ArgIterator, ArgIterator) -> Answer { *command = doExitNicely; return {0, "bye nicely\n"}; }},