From: Tomek Mrugalski Date: Tue, 20 Jun 2023 22:31:16 +0000 (+0200) Subject: [#2707] config-get now returns a hash X-Git-Tag: Kea-2.4.0~133 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=348434fdc7ab29348382920e025fa8eedaef9782;p=thirdparty%2Fkea.git [#2707] config-get now returns a hash --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 03917c50a9..d1775e7570 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -286,7 +286,9 @@ ControlledDhcpv4Srv::commandConfigReloadHandler(const string&, ConstElementPtr ControlledDhcpv4Srv::commandConfigGetHandler(const string&, ConstElementPtr /*args*/) { - ConstElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement(); + ElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement(); + string hash = BaseCommandMgr::getHash(config); + config->set("hash", Element::create(hash)); return (createAnswer(CONTROL_RESULT_SUCCESS, config)); } @@ -294,21 +296,12 @@ ControlledDhcpv4Srv::commandConfigGetHandler(const string&, ConstElementPtr ControlledDhcpv4Srv::commandConfigHashGetHandler(const string&, ConstElementPtr /*args*/) { - ConstElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement(); - // Assume that config is never null. - string config_txt = config->str(); - OutputBuffer hash_data(0); - isc::cryptolink::digest(config_txt.c_str(), - config_txt.size(), - isc::cryptolink::HashAlgorithm::SHA256, - hash_data); - vector hash; - hash.resize(hash_data.getLength()); - if (hash.size() > 0) { - memmove(&hash[0], hash_data.getData(), hash.size()); - } + ElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement(); + + string hash = BaseCommandMgr::getHash(config); + ElementPtr params = Element::createMap(); - params->set("hash", Element::create(encode::encodeHex(hash))); + params->set("hash", Element::create(hash)); return (createAnswer(CONTROL_RESULT_SUCCESS, params)); } diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 53c07574ac..dea58cd57c 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -289,7 +289,9 @@ ControlledDhcpv6Srv::commandConfigReloadHandler(const string&, ConstElementPtr ControlledDhcpv6Srv::commandConfigGetHandler(const string&, ConstElementPtr /*args*/) { - ConstElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement(); + ElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement(); + string hash = BaseCommandMgr::getHash(config); + config->set("hash", Element::create(hash)); return (createAnswer(CONTROL_RESULT_SUCCESS, config)); } diff --git a/src/lib/process/d_controller.cc b/src/lib/process/d_controller.cc index 7b240b05ae..363ba01155 100644 --- a/src/lib/process/d_controller.cc +++ b/src/lib/process/d_controller.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include @@ -450,7 +452,9 @@ DControllerBase::checkConfig(ConstElementPtr new_config) { ConstElementPtr DControllerBase::configGetHandler(const std::string&, ConstElementPtr /*args*/) { - ConstElementPtr config = process_->getCfgMgr()->getContext()->toElement(); + ElementPtr config = process_->getCfgMgr()->getContext()->toElement(); + std::string hash = BaseCommandMgr::getHash(config); + config->set("hash", Element::create(hash)); return (createAnswer(CONTROL_RESULT_SUCCESS, config)); }