From 1fb604f7483f3b7a6e301da1a882cba5675a9e1b Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Tue, 30 Jan 2024 12:09:53 -0300 Subject: [PATCH] use mysql_options if mysql_ssl_set isn't available for mysql 8.3 support Co-authored-by: Mike Dalessio --- ext/mysql2/client.c | 19 +++++++++++++++++++ ext/mysql2/extconf.rb | 3 +++ 2 files changed, 22 insertions(+) diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c index a49b3c34..74f56549 100644 --- a/ext/mysql2/client.c +++ b/ext/mysql2/client.c @@ -1435,12 +1435,31 @@ static VALUE set_charset_name(VALUE self, VALUE value) { static VALUE set_ssl_options(VALUE self, VALUE key, VALUE cert, VALUE ca, VALUE capath, VALUE cipher) { GET_CLIENT(self); +#ifdef HAVE_MYSQL_SSL_SET mysql_ssl_set(wrapper->client, NIL_P(key) ? NULL : StringValueCStr(key), NIL_P(cert) ? NULL : StringValueCStr(cert), NIL_P(ca) ? NULL : StringValueCStr(ca), NIL_P(capath) ? NULL : StringValueCStr(capath), NIL_P(cipher) ? NULL : StringValueCStr(cipher)); +#else + /* mysql 8.3 does not provide mysql_ssl_set */ + if (NIL_P(key)) { + mysql_options(wrapper->client, MYSQL_OPT_SSL_KEY, StringValueCStr(key)); + } + if (NIL_P(cert)) { + mysql_options(wrapper->client, MYSQL_OPT_SSL_CERT, StringValueCStr(cert)); + } + if (NIL_P(ca)) { + mysql_options(wrapper->client, MYSQL_OPT_SSL_CA, StringValueCStr(ca)); + } + if (NIL_P(capath)) { + mysql_options(wrapper->client, MYSQL_OPT_SSL_CAPATH, StringValueCStr(capath)); + } + if (NIL_P(cipher)) { + mysql_options(wrapper->client, MYSQL_OPT_SSL_CIPHER, StringValueCStr(cipher)); + } +#endif return self; } diff --git a/ext/mysql2/extconf.rb b/ext/mysql2/extconf.rb index 7a07639c..bee77585 100644 --- a/ext/mysql2/extconf.rb +++ b/ext/mysql2/extconf.rb @@ -164,6 +164,9 @@ def add_ssl_defines(header) # to retain compatibility with the typedef in earlier MySQLs. have_type('my_bool', mysql_h) +# detect mysql functions +have_func('mysql_ssl_set', mysql_h) + ### Compiler flags to help catch errors # This is our wishlist. We use whichever flags work on the host.