]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2294] also check server global variables ssl_ca, ssl_cert and ssl_key
authorRazvan Becheriu <razvan@isc.org>
Tue, 8 Feb 2022 15:57:13 +0000 (17:57 +0200)
committerRazvan Becheriu <razvan@isc.org>
Wed, 9 Feb 2022 12:08:12 +0000 (12:08 +0000)
12 files changed:
src/bin/d2/nc_add.cc
src/bin/d2/nc_remove.cc
src/bin/d2/simple_add.cc
src/bin/d2/simple_remove.cc
src/bin/lfc/lfc_controller.cc
src/lib/config/command_mgr.cc
src/lib/dhcp/iface_mgr_linux.cc
src/lib/dhcp_ddns/ncr_udp.cc
src/lib/dhcpsrv/d2_client_mgr.h
src/lib/dhcpsrv/pgsql_host_data_source.cc
src/lib/mysql/testutils/mysql_schema.cc
src/lib/mysql/testutils/mysql_schema.h

index 0d517cb4d52ffe549d4f72aef45fbc521e2b3b60..7b95c80af53e66cd59ab9b5d40dadeb4a252c0e6 100644 (file)
@@ -162,8 +162,7 @@ NameAddTransaction::selectingFwdServerHandler() {
     if (selectNextServer()) {
         // We have a server to try.
         transition(ADDING_FWD_ADDRS_ST, SERVER_SELECTED_EVT);
-    }
-    else {
+    } else {
         // Server list is exhausted, so fail the transaction.
         transition(PROCESS_TRANS_FAILED_ST, NO_MORE_SERVERS_EVT);
     }
@@ -422,8 +421,7 @@ NameAddTransaction::selectingRevServerHandler() {
     if (selectNextServer()) {
         // We have a server to try.
         transition(REPLACING_REV_PTRS_ST, SERVER_SELECTED_EVT);
-    }
-    else {
+    } else {
         // Server list is exhausted, so fail the transaction.
         transition(PROCESS_TRANS_FAILED_ST, NO_MORE_SERVERS_EVT);
     }
index cd9c6794bf67664a5c611e91448947a93bf15cbc..a927d7215bfccb67eeef804f96b081037ddf3f72 100644 (file)
@@ -166,8 +166,7 @@ NameRemoveTransaction::selectingFwdServerHandler() {
     if (selectNextServer()) {
         // We have a server to try.
         transition(REMOVING_FWD_ADDRS_ST, SERVER_SELECTED_EVT);
-    }
-    else {
+    } else {
         // Server list is exhausted, so fail the transaction.
         transition(PROCESS_TRANS_FAILED_ST, NO_MORE_SERVERS_EVT);
     }
@@ -429,8 +428,7 @@ NameRemoveTransaction::selectingRevServerHandler() {
     if (selectNextServer()) {
         // We have a server to try.
         transition(REMOVING_REV_PTRS_ST, SERVER_SELECTED_EVT);
-    }
-    else {
+    } else {
         // Server list is exhausted, so fail the transaction.
         transition(PROCESS_TRANS_FAILED_ST, NO_MORE_SERVERS_EVT);
     }
index c1814c77b4d10df9bb9ae453ce0b66e67e70a216..4477e6b2653c705877095414c4aecc131b841155 100644 (file)
@@ -157,8 +157,7 @@ SimpleAddTransaction::selectingFwdServerHandler() {
     if (selectNextServer()) {
         // We have a server to try.
         transition(REPLACING_FWD_ADDRS_ST, SERVER_SELECTED_EVT);
-    }
-    else {
+    } else {
         // Server list is exhausted, so fail the transaction.
         transition(PROCESS_TRANS_FAILED_ST, NO_MORE_SERVERS_EVT);
     }
@@ -292,8 +291,7 @@ SimpleAddTransaction::selectingRevServerHandler() {
     if (selectNextServer()) {
         // We have a server to try.
         transition(REPLACING_REV_PTRS_ST, SERVER_SELECTED_EVT);
-    }
-    else {
+    } else {
         // Server list is exhausted, so fail the transaction.
         transition(PROCESS_TRANS_FAILED_ST, NO_MORE_SERVERS_EVT);
     }
index 457afe712527c1868f1cfb35faa191e6b1d3dc41..ae213369a7d7729aaeba9c43e624548a7666d3b8 100644 (file)
@@ -160,8 +160,7 @@ SimpleRemoveTransaction::selectingFwdServerHandler() {
     if (selectNextServer()) {
         // We have a server to try.
         transition(REMOVING_FWD_RRS_ST, SERVER_SELECTED_EVT);
-    }
-    else {
+    } else {
         // Server list is exhausted, so fail the transaction.
         transition(PROCESS_TRANS_FAILED_ST, NO_MORE_SERVERS_EVT);
     }
@@ -305,8 +304,7 @@ SimpleRemoveTransaction::selectingRevServerHandler() {
     if (selectNextServer()) {
         // We have a server to try.
         transition(REMOVING_REV_PTRS_ST, SERVER_SELECTED_EVT);
-    }
-    else {
+    } else {
         // Server list is exhausted, so fail the transaction.
         transition(PROCESS_TRANS_FAILED_ST, NO_MORE_SERVERS_EVT);
     }
index 50f747080664c06db3ffe9a083419da15b32df3f..4f51238f92302edb820e55897d4bfd181e81c4f6 100644 (file)
@@ -139,7 +139,7 @@ LFCController::launch(int argc, char* argv[], const bool test_mode) {
     try {
         pid_file.deleteFile();
     } catch (const PIDFileError& pid_ex) {
-          LOG_FATAL(lfc_logger, LFC_FAIL_PID_DEL).arg(pid_ex.what());
+        LOG_FATAL(lfc_logger, LFC_FAIL_PID_DEL).arg(pid_ex.what());
     }
 
     LOG_INFO(lfc_logger, LFC_TERMINATE);
@@ -414,8 +414,7 @@ LFCController::startLogger(const bool test_mode) const {
     // else use our defaults
     if (test_mode) {
         initLogger();
-    }
-    else {
+    } else {
         OutputOption option;
         LoggerManager manager;
 
index 8dab259cf10a3c15e70e2574e0dc7b432f8fdf94..53cddb44867e165ad0e5b05c027c799ee8575d58 100644 (file)
@@ -295,8 +295,7 @@ Connection::receiveHandler(const boost::system::error_code& ec,
             std::stringstream os;
             if (feed_.getProcessedText().empty()) {
                os << "no input data to discard";
-            }
-            else {
+            } else {
                os << "discarding partial command of "
                   << feed_.getProcessedText().size() << " bytes";
             }
index 6b1fddcb125aee331e185f3a14a47c7b410498b9..bf8d6ae9c9fbeec811293f85f155ecbc61ad3de4 100644 (file)
@@ -485,8 +485,7 @@ void IfaceMgr::detectIfaces() {
         if (attribs_table[IFLA_ADDRESS]) {
             iface->setMac(static_cast<const uint8_t*>(RTA_DATA(attribs_table[IFLA_ADDRESS])),
                           RTA_PAYLOAD(attribs_table[IFLA_ADDRESS]));
-        }
-        else {
+        } else {
             // Tunnels can have no LL_ADDR. RTA_PAYLOAD doesn't check it and
             // try to dereference it in this manner
         }
index 43629d18188ca274ff5703b8eaaee032236e5032..bba40002302956bed1f688be89541097f83dddc3 100644 (file)
@@ -333,8 +333,7 @@ NameChangeUDPSender::sendCompletionHandler(const bool successful,
     Result result;
     if (successful) {
         result = SUCCESS;
-    }
-    else {
+    } else {
         // On a failure, log the error and set the result to ERROR.
         boost::system::error_code error_code = send_callback->getErrorCode();
         if (error_code.value() == boost::asio::error::operation_aborted) {
index 33eb55a398296b6d648224bb9688fc9221e91202..ee3cc1d365851b2df03147f0c629eec0dcbf6032 100644 (file)
@@ -513,8 +513,7 @@ D2ClientMgr::adjustDomainName(const T& fqdn, T& fqdn_resp, const DdnsParams& ddn
         // If the supplied name is partial, qualify it by adding the suffix.
         if (fqdn.getDomainNameType() == T::PARTIAL) {
             fqdn_resp.setDomainName(qualifyName(client_name, ddns_params, true), T::FULL);
-        }
-        else  {
+        } else  {
             fqdn_resp.setDomainName(client_name, T::FULL);
         }
     }
index f0e0ff1635633bb8724d9e3d53cbb0055bb99adf..b595793d891bd1f6619f37aa898bc3b73d3609f5 100644 (file)
@@ -278,7 +278,6 @@ public:
                 bind_array->add(host->getIPv4SubnetID()); // subnet_id
             }
 
-
         } catch (const std::exception& ex) {
             host_.reset();
             isc_throw(DbOperationError,
@@ -3176,7 +3175,6 @@ PgSqlHostDataSource::getAll6(const SubnetID& subnet_id,
     return (collection);
 }
 
-
 // Miscellaneous database methods.
 
 std::string
index 6ff194e8d846290126aca0f7a0662b0dd8c0e284..0a7677b5dd88d66ba5c92adbdb1c555a0453179b 100644 (file)
@@ -93,14 +93,16 @@ string getMySQLTlsEnv() {
     return (val ? string(val) : "");
 }
 
-string getMySQLTlsServer() {
-    DatabaseConnection::ParameterMap parameters =
-        DatabaseConnection::parse(validMySQLConnectionString());
-    MySqlConnection conn(parameters);
+string getMySQLTlsServerVariable(string variable) {
     MYSQL_RES* result(0);
     try {
+        DatabaseConnection::ParameterMap parameters =
+            DatabaseConnection::parse(validMySQLConnectionString());
+        MySqlConnection conn(parameters);
         conn.openDatabase();
-        string sql("SHOW GLOBAL VARIABLES LIKE 'have_ssl'");
+        string sql("SHOW GLOBAL VARIABLES LIKE '");
+        sql += variable;
+        sql += "'";
         if (mysql_query(conn.mysql_, sql.c_str())) {
             isc_throw(DbOperationError,
                       sql << ": " << mysql_error(conn.mysql_));
@@ -117,14 +119,12 @@ string getMySQLTlsServer() {
         }
         // first column is 'have_ssl', second is the status.
         string name(row[0]);
-        if (name != "have_ssl") {
+        if (name != variable) {
             isc_throw(DbOperationError,
                       sql << " returned a wrong name '" << name
-                      << "', expected 'have_ssl'");
+                      << "', expected " << variable);
         }
         string value(row[1]);
-        const string env("KEA_MYSQL_HAVE_SSL");
-        static_cast<void>(setenv(env.c_str(), value.c_str(), 1));
         mysql_free_result(result);
         return (value);
     } catch (...) {
@@ -135,6 +135,29 @@ string getMySQLTlsServer() {
     }
 }
 
+bool isMySQLTlsConfigured() {
+    if (getMySQLTlsServerVariable("ssl_ca").find("kea-ca.crt") == string::npos) {
+        return (false);
+    }
+    if (getMySQLTlsServerVariable("ssl_cert").find("kea-server.crt") == string::npos) {
+        return (false);
+    }
+    if (getMySQLTlsServerVariable("ssl_key").find("kea-server.key") == string::npos) {
+        return (false);
+    }
+    return (true);
+}
+
+string getMySQLTlsServer() {
+    string value = getMySQLTlsServerVariable("have_ssl");
+    if (value == "YES" && !isMySQLTlsConfigured()) {
+        value = "UNCONFIGURED";
+    }
+    const string env("KEA_MYSQL_HAVE_SSL");
+    static_cast<void>(setenv(env.c_str(), value.c_str(), 1));
+    return (value);
+}
+
 }  // namespace test
 }  // namespace db
 }  // namespace isc
index 43aa1ad7cdef6cffd8373f55e7582b8fa17137f1..a3df21fe38da0c14938ae7a9ba0103f915b5f362 100644 (file)
@@ -107,6 +107,15 @@ std::string getMySQLTlsEnv();
 /// @note the returned value is set in the environment
 std::string getMySQLTlsServer();
 
+/// @brief Return true if the server has been configured with proper SSL/TLS
+/// credentials, false otherwise
+bool isMySQLTlsConfigured();
+
+/// @brief Get the server global variable value
+///
+/// @param variable The server global variable name
+std::string getMySQLTlsServerVariable(std::string variable);
+
 }
 }
 }