From: Kees Monshouwer Date: Mon, 9 Dec 2019 12:13:14 +0000 (+0100) Subject: auth: add diff option to 'pdns_control current-config' X-Git-Tag: auth-4.3.0-beta2~10^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8864bdf6b05cca1f6bbde79b4b44049f76cc9993;p=thirdparty%2Fpdns.git auth: add diff option to 'pdns_control current-config' With the diff option only modified options are included in the output. --- diff --git a/docs/manpages/pdns_control.1.rst b/docs/manpages/pdns_control.1.rst index fa28d9b157..1f766c4434 100644 --- a/docs/manpages/pdns_control.1.rst +++ b/docs/manpages/pdns_control.1.rst @@ -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 ^^^^^ diff --git a/docs/manpages/pdns_server.1.rst b/docs/manpages/pdns_server.1.rst index 4f0ea24c19..9c290b546b 100644 --- a/docs/manpages/pdns_server.1.rst +++ b/docs/manpages/pdns_server.1.rst @@ -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= 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 diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 9de4b641d4..35256e084e 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -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 \ diff --git a/pdns/arguments.cc b/pdns/arguments.cc index b41bdbcddf..2c1ad26574 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -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(var, value)); +} + +void ArgvMap::setDefaults() +{ + for(map::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; diff --git a/pdns/arguments.hh b/pdns/arguments.hh index d91a95a533..6e41dae475 100644 --- a/pdns/arguments.hh +++ b/pdns/arguments.hh @@ -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(); vectorlist(); string getHelp(const string &item); @@ -123,6 +125,7 @@ private: typedef map params_t; params_t params; map helpmap; + map defaultmap; map d_typeMap; vector d_cmds; std::set d_cleared; diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 9ad7459e21..bb3f3ff397 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -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); diff --git a/pdns/dnsbackend.cc b/pdns/dnsbackend.cc index cf30da3c3a..7a142f40e8 100644 --- a/pdns/dnsbackend.cc +++ b/pdns/dnsbackend.cc @@ -66,6 +66,7 @@ void BackendFactory::declare(const string &suffix, const string ¶m, const st { string fullname=d_name+suffix+"-"+param; arg().set(fullname,help)=value; + arg().setDefault(fullname,value); } const string &BackendFactory::getName() const diff --git a/pdns/dynhandler.cc b/pdns/dynhandler.cc index 7541fdb656..7d6dcb2642 100644 --- a/pdns/dynhandler.cc +++ b/pdns/dynhandler.cc @@ -68,7 +68,13 @@ static void dokill(int) string DLCurrentConfigHandler(const vector&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&parts, Utility::pid_t ppid) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 52cadda8c1..7316d5e819 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -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()< "); DynListener::registerFunc("RETRIEVE",&DLNotifyRetrieveHandler, "retrieve slave 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", " ");