]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: add diff option to 'pdns_control current-config'
authorKees Monshouwer <mind04@monshouwer.org>
Mon, 9 Dec 2019 12:13:14 +0000 (13:13 +0100)
committermind04 <mind04@monshouwer.org>
Mon, 9 Dec 2019 22:24:14 +0000 (23:24 +0100)
With the diff option only modified options are included in the output.

docs/manpages/pdns_control.1.rst
docs/manpages/pdns_server.1.rst
pdns/Makefile.am
pdns/arguments.cc
pdns/arguments.hh
pdns/common_startup.cc
pdns/dnsbackend.cc
pdns/dynhandler.cc
pdns/pdns_recursor.cc
pdns/receiver.cc

index fa28d9b15788cffa4fdae2cb4899856a57e76dba..1f766c44341e897f83c7686500cd0f7b9a96675d 100644 (file)
@@ -55,13 +55,10 @@ ccounts
 
 Show the content of the cache.
 
-current-config
-^^^^^^^^^^^^^^
+current-config [diff]
+^^^^^^^^^^^^^^^^^^^^^
 
-Show the currently running configuration. The output has the same
-format as ``pdns_server --config``. You'll notice that all the
-configuration values are uncommented. This is because PowerDNS
-simply has values, and the default isn't known at runtime.
+Show the currently running configuration. The output has the same format as ``pdns_server --config``. With the diff option only modified options are included in the output.
 
 cycle
 ^^^^^
index 4f0ea24c19eb3cfa6233210c2ca40c97c61d4333..9c290b546beec44f2409f521f1200dac4ce0b1f7 100644 (file)
@@ -27,6 +27,9 @@ See the online documentation for all options
 --control-console       Run the server in a special monitor mode. This enables detailed
                         logging and exposes the raw control socket.
 --loglevel=<LEVEL>      Set the logging level.
+--config                Show the currently configuration. There are two optional values (defaul
+                        is empty). --config=diff will only show modified options. --config=default
+                        will show the default configuration.
 --help                  To view more options that are available use this program.
 
 See also
index 9de4b641d4c475fa9b292e0c3d7374bef2520c04..35256e084efbcfba2e28bc1c718cb093f34ee0a0 100644 (file)
@@ -1250,7 +1250,7 @@ endif
 endif
 
 pdns.conf-dist: pdns_server
-       $(AM_V_GEN)./pdns_server --no-config --config 2>/dev/null > $@
+       $(AM_V_GEN)./pdns_server --no-config --config=default 2>/dev/null > $@
 
 testrunner_SOURCES = \
        arguments.cc \
index b41bdbcddfbb6067673f52b472ced93a6b601807..2c1ad265748998ddcefaeac6a9943b8687968e42 100644 (file)
@@ -50,6 +50,19 @@ string & ArgvMap::set(const string &var)
   return params[var];
 }
 
+void ArgvMap::setDefault(const string &var, const string &value)
+{
+  if(! defaultmap.count(var))
+    defaultmap.insert(pair<string, string>(var, value));
+}
+
+void ArgvMap::setDefaults()
+{
+  for(map<string,string>::const_iterator i=params.begin();i!=params.end();++i)
+    if(! defaultmap.count(i->first))
+      defaultmap.insert(*i);
+}
+
 bool ArgvMap::mustDo(const string &var)
 {
   return ((*this)[var]!="no") && ((*this)[var]!="off");
@@ -141,29 +154,47 @@ string ArgvMap::helpstring(string prefix)
   return help;
 }
 
-string ArgvMap::configstring(bool current)
+string ArgvMap::configstring(bool running, bool full)
 {
   string help;
 
-  if (current)
-    help="# Autogenerated configuration file based on running instance\n";
+  if (running)
+    help="# Autogenerated configuration file based on running instance ("+nowTime()+")\n\n";
   else
-    help="# Autogenerated configuration file template\n";
-  
+    help="# Autogenerated configuration file template\n\n";
+
   for(const auto& i: helpmap) {
     if(d_typeMap[i.first]=="Command")
       continue;
 
-    help+="#################################\n";
-    help+="# ";
-    help+=i.first;
-    help+="\t";
-    help+=i.second;
-    help+="\n#\n";
-    if (current) {
-      help+=i.first+"="+params[i.first]+"\n\n";
+    if (! defaultmap.count(i.first)) {
+      throw ArgException(string("Default for parameter '")+i.first+"' not set");
+    }
+
+    if (!running || full) {
+      help+="#################################\n";
+      help+="# ";
+      help+=i.first;
+      help+="\t";
+      help+=i.second;
+      help+="\n#\n";
+    } else {
+      if (defaultmap[i.first] == params[i.first]) {
+        continue;
+      }
+    }
+
+    if (! running || defaultmap[i.first] == params[i.first]) {
+      help+="# ";
+    }
+
+    if (running) {
+      help+=i.first+"="+params[i.first]+"\n";
+      if (full) {
+        help+="\n";
+      }
     } else {
-      help+="# "+i.first+"="+params[i.first]+"\n\n";
+      help+=i.first+"="+defaultmap[i.first]+"\n\n";
     }
   }
   return help;
index d91a95a533e07b853da9c006782f9987ae777502..6e41dae475a441a55670b211c76fd49e8558b709 100644 (file)
@@ -106,9 +106,11 @@ public:
   void setCmd(const string &, const string &); //!< Add a command flag
   string &setSwitch(const string &, const string &); //!< Add a switch flag
   string helpstring(string prefix=""); //!< generates the --help
-  string configstring(bool current=false); //!< generates the --mkconfig
+  string configstring(bool current, bool full); //!< generates the --config
   bool contains(const string &var, const string &val);
   bool isEmpty(const string &var); //!< checks if variable has value
+  void setDefault(const string &var, const string &value);
+  void setDefaults();
 
   vector<string>list();
   string getHelp(const string &item);
@@ -123,6 +125,7 @@ private:
   typedef map<string,string> params_t;
   params_t params;
   map<string,string> helpmap;
+  map<string,string> defaultmap;
   map<string,string> d_typeMap;
   vector<string> d_cmds;
   std::set<string> d_cleared;
index 9ad7459e21805234f204b9b6f3c0428215bf7ff7..bb3f3ff397828629d63ba971b35cb17f620cea04 100644 (file)
@@ -229,6 +229,7 @@ void declareArguments()
   ::arg().set("max-generate-steps", "Maximum number of $GENERATE steps when loading a zone from a file")="0";
 
   ::arg().set("rng", "Specify the random number generator to use. Valid values are auto,sodium,openssl,getrandom,arc4random,urandom.")="auto";
+  ::arg().setDefaults();
 }
 
 static time_t s_start=time(0);
index cf30da3c3a60e016392c8ad9f91ad285f0b077c4..7a142f40e841d443871de76398a8b6a1098ffc0c 100644 (file)
@@ -66,6 +66,7 @@ void BackendFactory::declare(const string &suffix, const string &param, const st
 {
   string fullname=d_name+suffix+"-"+param;
   arg().set(fullname,help)=value;
+  arg().setDefault(fullname,value);
 }
 
 const string &BackendFactory::getName() const
index 7541fdb656a53089a9b2281f8576e3eb6e625657..7d6dcb2642a304472b545982b0f9694a09e757e4 100644 (file)
@@ -68,7 +68,13 @@ static void dokill(int)
 
 string DLCurrentConfigHandler(const vector<string>&parts, Utility::pid_t ppid)
 {
-  return ::arg().configstring(true);
+  if(parts.size() > 1) {
+    if(parts.size() == 2 && parts[1] == "diff") {
+      return ::arg().configstring(true, false);
+    }
+    return "Syntax: current-config [diff]";
+  }
+  return ::arg().configstring(true, true);
 }
 
 string DLRQuitHandler(const vector<string>&parts, Utility::pid_t ppid)
index 52cadda8c13034cb86daba7fe9bd9a93ec7ddac9..7316d5e819baa716303e6d16bb2c47b179b87fca 100644 (file)
@@ -4756,6 +4756,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().setDefaults();
     g_log.toConsole(Logger::Info);
     ::arg().laxParse(argc,argv); // do a lax parse
 
@@ -4785,7 +4786,7 @@ int main(int argc, char **argv)
     }
 
     if(::arg().mustDo("config")) {
-      cout<<::arg().configstring()<<endl;
+      cout<<::arg().configstring(false, true);
       exit(0);
     }
 
index 3caf56e49322c5d1fab6fe2bca93530f5f739af4..f3d210d4caacb3ddf81fa3e4a6ba14cb797db92d 100644 (file)
@@ -415,7 +415,7 @@ int main(int argc, char **argv)
     string configname=::arg()["config-dir"]+"/"+s_programname+".conf";
     cleanSlashes(configname);
 
-    if(!::arg().mustDo("config") && !::arg().mustDo("no-config")) // "config" == print a configuration file
+    if(!::arg().mustDo("no-config")) // "config" == print a configuration file
       ::arg().laxFile(configname.c_str());
     
     ::arg().laxParse(argc,argv); // reparse so the commandline still wins
@@ -512,7 +512,14 @@ int main(int argc, char **argv)
     }
     
     if(::arg().mustDo("config")) {
-      cout<<::arg().configstring()<<endl;
+      string config = ::arg()["config"];
+      if (config == "default") {
+        cout<<::arg().configstring(false, true);
+      } else if (config == "diff") {
+          cout<<::arg().configstring(true, false);
+      } else {
+        cout<<::arg().configstring(true, true);
+      }
       exit(0);
     }
 
@@ -569,7 +576,7 @@ int main(int argc, char **argv)
     DynListener::registerFunc("REMOTES", &DLRemotesHandler, "get top remotes");
     DynListener::registerFunc("SET",&DLSettingsHandler, "set config variables", "<var> <value>");
     DynListener::registerFunc("RETRIEVE",&DLNotifyRetrieveHandler, "retrieve slave domain", "<domain>");
-    DynListener::registerFunc("CURRENT-CONFIG",&DLCurrentConfigHandler, "retrieve the current configuration");
+    DynListener::registerFunc("CURRENT-CONFIG",&DLCurrentConfigHandler, "retrieve the current configuration", "[diff|default]");
     DynListener::registerFunc("LIST-ZONES",&DLListZones, "show list of zones", "[master|slave|native]");
     DynListener::registerFunc("TOKEN-LOGIN", &DLTokenLogin, "Login to a PKCS#11 token", "<module> <slot> <pin>");