]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2707] config-get now returns a hash
authorTomek Mrugalski <tomek@isc.org>
Tue, 20 Jun 2023 22:31:16 +0000 (00:31 +0200)
committerTomek Mrugalski <tomek@isc.org>
Thu, 22 Jun 2023 14:23:38 +0000 (16:23 +0200)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/lib/process/d_controller.cc

index 03917c50a9f4d2575f1eadcc9b91237abf388dad..d1775e757018cbd5a2778bb69b99f02481b65f22 100644 (file)
@@ -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<uint8_t> 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));
 }
 
index 53c07574ac1ecf5f0cb4778de1c7cb69ca75a64e..dea58cd57c4f7639515b3e7b0d72c911f0d9098c 100644 (file)
@@ -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));
 }
index 7b240b05aeecaf7eb2b160cc0247ffd917736f75..363ba0115559d302aa3cc7f0f7d9b89dde5789a6 100644 (file)
@@ -9,6 +9,7 @@
 #include <process/cfgrpt/config_report.h>
 #include <cryptolink/crypto_hash.h>
 #include <exceptions/exceptions.h>
+#include <config/command_mgr.h>
 #include <hooks/hooks_manager.h>
 #include <log/logger.h>
 #include <log/logger_support.h>
@@ -20,6 +21,7 @@
 #include <kea_version.h>
 #include <functional>
 #include <sstream>
+#include <string>
 #include <unistd.h>
 #include <signal.h>
 
@@ -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));
 }