]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3256] convert mysql_ssl_set to mysql_options
authorAndrei Pavel <andrei@isc.org>
Wed, 15 May 2024 16:09:21 +0000 (19:09 +0300)
committerAndrei Pavel <andrei@isc.org>
Mon, 20 May 2024 20:28:16 +0000 (23:28 +0300)
src/lib/mysql/mysql_connection.cc
src/lib/mysql/tests/mysql_connection_unittest.cc

index 1bb2bcc78d4277acf04f75d89404c555d5049a60..8a78c4c844dbfd10e2f591bf59ea19be3f3aea0a 100644 (file)
@@ -237,8 +237,12 @@ MySqlConnection::openDatabase() {
     // If TLS is enabled set it. If something should go wrong it will happen
     // later at the mysql_real_connect call.
     if (tls_) {
-        mysql_ssl_set(mysql_, key_file, cert_file, ca_file, ca_dir,
-                      cipher_list);
+        mysql_options(mysql_, MYSQL_OPT_SSL_KEY, key_file);
+        mysql_options(mysql_, MYSQL_OPT_SSL_CERT, cert_file);
+        mysql_options(mysql_, MYSQL_OPT_SSL_CA, ca_file);
+        mysql_options(mysql_, MYSQL_OPT_SSL_CAPATH, ca_dir);
+        mysql_options(mysql_, MYSQL_OPT_SSL_CIPHER, cipher_list);
+
     }
 
     // Open the database.
index 0adc6b619e70cb33ebc7d7cfa179d1692d3e85fc..8ac4e13c5c5df33cf2dab60000988b4bd4f3bc58 100644 (file)
@@ -1008,4 +1008,19 @@ TEST_F(MySqlConnectionTest, toKeaAdminParameters) {
                               "--ssl-ca " TEST_CA_DIR "/kea-ca.crt", "--user", "keatest_secure"}));
 }
 
+/// @brief Checks that the mysql_options call does not crash when passed a null option value.
+///
+/// An unconventional test, but the MySQL docs are not clear:
+/// > Any unused SSL arguments may be given as NULL.
+/// > Because of that equivalence, applications can, instead of calling mysql_ssl_set(), call
+///   mysql_options() directly, omitting calls for those options for which the option value is NULL.
+TEST_F(MySqlConnectionTest, mysqlOptions) {
+    MySqlHolder mysql;
+    mysql_options(mysql, MYSQL_OPT_SSL_KEY, nullptr);
+    mysql_options(mysql, MYSQL_OPT_SSL_CERT, nullptr);
+    mysql_options(mysql, MYSQL_OPT_SSL_CA, nullptr);
+    mysql_options(mysql, MYSQL_OPT_SSL_CAPATH, nullptr);
+    mysql_options(mysql, MYSQL_OPT_SSL_CIPHER, nullptr);
+}
+
 }  // namespace