diff options
author | Francis Dupont <fdupont@isc.org> | 2021-03-23 00:23:12 +0100 |
---|---|---|
committer | Andrei Pavel <andrei@isc.org> | 2021-05-21 15:22:00 +0200 |
commit | 396c9ea6b946efbb94c35d464c005f3f521846fb (patch) | |
tree | 1afc1d5af332ad0e9988ea8a0e4550b7ac4160ba /src/bin/agent | |
parent | [#1852] fixed indentation (diff) | |
download | kea-396c9ea6b946efbb94c35d464c005f3f521846fb.tar.xz kea-396c9ea6b946efbb94c35d464c005f3f521846fb.zip |
[#1721] Added redactConfig function
Diffstat (limited to 'src/bin/agent')
-rw-r--r-- | src/bin/agent/ca_cfg_mgr.cc | 56 | ||||
-rw-r--r-- | src/bin/agent/ca_cfg_mgr.h | 14 |
2 files changed, 6 insertions, 64 deletions
diff --git a/src/bin/agent/ca_cfg_mgr.cc b/src/bin/agent/ca_cfg_mgr.cc index d65fee037f..67472c209a 100644 --- a/src/bin/agent/ca_cfg_mgr.cc +++ b/src/bin/agent/ca_cfg_mgr.cc @@ -11,6 +11,7 @@ #include <cc/simple_parser.h> #include <cc/command_interpreter.h> #include <http/basic_auth_config.h> +#include <process/redact_config.h> #include <exceptions/exceptions.h> using namespace isc::config; @@ -141,62 +142,17 @@ CtrlAgentCfgMgr::parse(ConstElementPtr config_set, bool check_only) { ConstElementPtr CtrlAgentCfgMgr::redactConfig(ConstElementPtr config) const { bool redacted = false; - ConstElementPtr result = redactElement(config, redacted); + const std::set<std::string> follow = { + "Control-agent", "authentication", "clients" + }; + ConstElementPtr result = + isc::process::redactConfig(config, redacted, follow); if (redacted) { return (result); } return (config); } -ConstElementPtr -CtrlAgentCfgMgr::redactElement(ConstElementPtr elem, bool& redacted) const { - // From isc::data::copy. - if (!elem) { - isc_throw(BadValue, "redactElement got a null pointer"); - } - // Redact lists. - if (elem->getType() == Element::list) { - ElementPtr result = ElementPtr(new ListElement()); - for (auto item : elem->listValue()) { - // add wants a ElementPtr so use a shallow copy. - ElementPtr copy = data::copy(redactElement(item, redacted), 0); - result->add(copy); - } - if (redacted) { - return (result); - } - return (elem); - } - // Redact maps. - if (elem->getType() == Element::map) { - ElementPtr result = ElementPtr(new MapElement()); - for (auto kv : elem->mapValue()) { - auto key = kv.first; - auto value = kv.second; - - if (key == "password") { - // Handle passwords. - redacted = true; - result->set(key, Element::create(std::string("*****"))); - } else if ((key == "Control-agent") || - (key == "authentication") || - (key == "clients")) { - // Handle the arc where are passwords. - result->set(key, redactElement(value, redacted)); - } else { - // Default case: no password here. - result->set(key, value); - } - } - if (redacted) { - return (result); - } - return (elem); - } - // Handle other element types. - return (elem); -} - data::ConstElementPtr CtrlAgentCfgContext::getControlSocketInfo(const std::string& service) const { auto si = ctrl_sockets_.find(service); diff --git a/src/bin/agent/ca_cfg_mgr.h b/src/bin/agent/ca_cfg_mgr.h index 78c722d827..7ee947fc88 100644 --- a/src/bin/agent/ca_cfg_mgr.h +++ b/src/bin/agent/ca_cfg_mgr.h @@ -308,20 +308,6 @@ protected: /// replaced by asterisks so can be safely logged to an unprivileged place. virtual isc::data::ConstElementPtr redactConfig(isc::data::ConstElementPtr config) const; - -private: - /// @brief Redact an element. - /// - /// Recursive helper of redactConfig. - /// - /// @param elem An element to redact. - /// @param redacted The reference to redacted flag: true means the result - /// was redacted so cannot be shared. - /// @return unmodified element or a copy of the element: in the second - /// case embedded passwords were replaced by asterisks and the redacted - /// flag was set to true. - virtual isc::data::ConstElementPtr - redactElement(isc::data::ConstElementPtr elem, bool& redacted) const; }; /// @brief Defines a shared pointer to CtrlAgentCfgMgr. |