]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2799] set error if IOService is null in callouts
authorRazvan Becheriu <razvan@isc.org>
Fri, 24 Mar 2023 06:37:40 +0000 (08:37 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 24 Mar 2023 10:12:40 +0000 (12:12 +0200)
src/hooks/dhcp/high_availability/ha_callouts.cc
src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc
src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc
src/hooks/dhcp/run_script/run_script_callouts.cc

index 9988f01b9668367d9c2a7a9777f59981de5707af..1d3e99d990a51df19bacba85493c1e264f4c2cfc 100644 (file)
@@ -20,6 +20,9 @@
 #include <hooks/hooks.h>
 #include <process/daemon.h>
 
+#include <sstream>
+#include <string>
+
 namespace isc {
 namespace ha {
 
@@ -34,6 +37,7 @@ using namespace isc::dhcp;
 using namespace isc::ha;
 using namespace isc::hooks;
 using namespace isc::process;
+using namespace std;
 
 extern "C" {
 
@@ -44,6 +48,13 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
     try {
         isc::asiolink::IOServicePtr io_service;
         handle.getArgument("io_context", io_service);
+        if (!io_service) {
+            // Should not happen!
+            handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
+            const string error("Error: io_context is null");
+            handle.setArgument("error", error);
+            return (1);
+        }
         isc::dhcp::NetworkStatePtr network_state;
         handle.getArgument("network_state", network_state);
         impl->startService(io_service, network_state, HAServerType::DHCPv4);
@@ -52,6 +63,10 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
         LOG_ERROR(ha_logger, HA_DHCP4_START_SERVICE_FAILED)
             .arg(ex.what());
         handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
+        ostringstream os;
+        os << "Error: " << ex.what();
+        string error(os.str());
+        handle.setArgument("error", error);
         return (1);
     }
     return (0);
@@ -107,6 +122,13 @@ int dhcp6_srv_configured(CalloutHandle& handle) {
     try {
         isc::asiolink::IOServicePtr io_service;
         handle.getArgument("io_context", io_service);
+        if (!io_service) {
+            // Should not happen!
+            handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
+            const string error("Error: io_context is null");
+            handle.setArgument("error", error);
+            return (1);
+        }
         isc::dhcp::NetworkStatePtr network_state;
         handle.getArgument("network_state", network_state);
         impl->startService(io_service, network_state, HAServerType::DHCPv6);
@@ -115,6 +137,10 @@ int dhcp6_srv_configured(CalloutHandle& handle) {
         LOG_ERROR(ha_logger, HA_DHCP6_START_SERVICE_FAILED)
             .arg(ex.what());
         handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
+        ostringstream os;
+        os << "Error: " << ex.what();
+        string error(os.str());
+        handle.setArgument("error", error);
         return (1);
     }
     return (0);
index fb30474e6cbcd5ad1878e5c62ea93c862d9e26ea..c9e0dbefb2b945fa1673d38c5a41b80c739f9327 100644 (file)
 #include <mysql_cb_dhcp6.h>
 #include <mysql_cb_log.h>
 
+#include <sstream>
+#include <string>
+
 using namespace isc::cb;
 using namespace isc::dhcp;
 using namespace isc::hooks;
 using namespace isc::log;
 using namespace isc::process;
+using namespace std;
 
 extern "C" {
 
@@ -65,6 +69,12 @@ int load(LibraryHandle& /* handle */) {
 int dhcp4_srv_configured(CalloutHandle& handle) {
     isc::asiolink::IOServicePtr io_service;
     handle.getArgument("io_context", io_service);
+    if (!io_service) {
+        const string error("Error: io_context is null");
+        handle.setArgument("error", error);
+        handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
+        return (1);
+    }
     isc::dhcp::MySqlConfigBackendImpl::setIOService(io_service);
     return (0);
 }
@@ -78,6 +88,12 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
 int dhcp6_srv_configured(CalloutHandle& handle) {
     isc::asiolink::IOServicePtr io_service;
     handle.getArgument("io_context", io_service);
+    if (!io_service) {
+        const string error("Error: io_context is null");
+        handle.setArgument("error", error);
+        handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
+        return (1);
+    }
     isc::dhcp::MySqlConfigBackendImpl::setIOService(io_service);
     return (0);
 }
index 669fb840257971d2b3c2892992517f67d63d56e8..7e85401f2714e1472a7ad91fcd4de4ab5a552dbe 100644 (file)
 #include <pgsql_cb_dhcp6.h>
 #include <pgsql_cb_log.h>
 
+#include <sstream>
+#include <string>
+
 using namespace isc::cb;
 using namespace isc::dhcp;
 using namespace isc::hooks;
 using namespace isc::log;
 using namespace isc::process;
+using namespace std;
 
 extern "C" {
 
@@ -65,6 +69,12 @@ int load(LibraryHandle& /* handle */) {
 int dhcp4_srv_configured(CalloutHandle& handle) {
     isc::asiolink::IOServicePtr io_service;
     handle.getArgument("io_context", io_service);
+    if (!io_service) {
+        const string error("Error: io_context is null");
+        handle.setArgument("error", error);
+        handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
+        return (1);
+    }
     isc::dhcp::PgSqlConfigBackendImpl::setIOService(io_service);
     return (0);
 }
@@ -78,6 +88,12 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
 int dhcp6_srv_configured(CalloutHandle& handle) {
     isc::asiolink::IOServicePtr io_service;
     handle.getArgument("io_context", io_service);
+    if (!io_service) {
+        const string error("Error: io_context is null");
+        handle.setArgument("error", error);
+        handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
+        return (1);
+    }
     isc::dhcp::PgSqlConfigBackendImpl::setIOService(io_service);
     return (0);
 }
index 4a339278f0288fc9fc2357c34ebada0c44c27ae8..8ecdc14c9dea9889a2102124adf09ce015147907 100644 (file)
@@ -18,6 +18,8 @@
 #include <dhcpsrv/subnet.h>
 #include <process/daemon.h>
 
+#include <string>
+
 namespace isc {
 namespace run_script {
 
@@ -34,6 +36,7 @@ using namespace isc::hooks;
 using namespace isc::process;
 using namespace isc::run_script;
 using namespace isc::util;
+using namespace std;
 
 // Functions accessed by the hooks framework use C linkage to avoid the name
 // mangling that accompanies use of the C++ compiler as well as to avoid
@@ -48,7 +51,7 @@ int load(LibraryHandle& handle) {
     try {
         // Make the hook library not loadable by d2 or ca.
         uint16_t family = CfgMgr::instance().getFamily();
-        const std::string& proc_name = Daemon::getProcName();
+        const string& proc_name = Daemon::getProcName();
         if (family == AF_INET) {
             if (proc_name != "kea-dhcp4") {
                 isc_throw(isc::Unexpected, "Bad process name: " << proc_name
@@ -63,7 +66,7 @@ int load(LibraryHandle& handle) {
 
         impl.reset(new RunScriptImpl());
         impl->configure(handle);
-    } catch (const std::exception& ex) {
+    } catch (const exception& ex) {
         LOG_ERROR(run_script_logger, RUN_SCRIPT_LOAD_ERROR)
             .arg(ex.what());
         return (1);
@@ -90,9 +93,16 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
     try {
         isc::asiolink::IOServicePtr io_service;
         handle.getArgument("io_context", io_service);
+        if (!io_service) {
+            // Should not happen!
+            handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
+            const string error("Error: io_context is null");
+            handle.setArgument("error", error);
+            return (1);
+        }
         RunScriptImpl::setIOService(io_service);
 
-    } catch (const std::exception& ex) {
+    } catch (const exception& ex) {
         LOG_ERROR(run_script_logger, RUN_SCRIPT_LOAD_ERROR)
             .arg(ex.what());
         handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
@@ -108,9 +118,16 @@ int dhcp6_srv_configured(CalloutHandle& handle) {
     try {
         isc::asiolink::IOServicePtr io_service;
         handle.getArgument("io_context", io_service);
+        if (!io_service) {
+            // Should not happen!
+            handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
+            const string error("Error: io_context is null");
+            handle.setArgument("error", error);
+            return (1);
+        }
         RunScriptImpl::setIOService(io_service);
 
-    } catch (const std::exception& ex) {
+    } catch (const exception& ex) {
         LOG_ERROR(run_script_logger, RUN_SCRIPT_LOAD_ERROR)
             .arg(ex.what());
         handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);