Skip to content

Commit

Permalink
db_mysql: enable TLS when building with mariadb-connector-c
Browse files Browse the repository at this point in the history
- mariadb-connector-c requires at least one non-NULL configuration
  value to use TLS
- emulate MySQL SSL_MODE_XXXX options
  • Loading branch information
space88man authored and linuxmaniac committed Jan 30, 2024
1 parent e470f67 commit d772b4c
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/modules/db_mysql/km_my_con.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,32 @@ struct my_con *db_mysql_new_connection(const struct db_id *id)
(const void *)&db_mysql_timeout_interval);
mysql_options(ptr->con, MYSQL_OPT_WRITE_TIMEOUT,
(const void *)&db_mysql_timeout_interval);
#if MYSQL_VERSION_ID > 50710 && !defined(MARIADB_BASE_VERSION)

#ifdef MARIADB_BASE_VERSION
/*
* emulate SSL_MODE_XXXX from MySQL
*/

switch(db_mysql_opt_ssl_mode) {
case 0: /* opt_ssl_mode = 0(off) */
case 1: /* SSL_MODE_DISABLED */
break;
case 2: /* SSL_MODE_PREFERRED */
case 3: /* SSL_MODE_REQUIRED */
case 4: /* SSL_MODE_VERIFY_CA */
mysql_optionsv(ptr->con, MYSQL_OPT_SSL_ENFORCE, (void *)&(int){1});
break;
case 5: /* SSL_MODE_VERIFY_IDENTITY */
mysql_optionsv(ptr->con, MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
(void *)&(int){1});
break;
default:
LM_WARN("opt_ssl_mode = %d not supported by MariaDB Connector/C\n",
db_mysql_opt_ssl_mode);
break;
}
#else
#ifdef MYSQL_VERSION_ID> 50710
if(db_mysql_opt_ssl_mode != 0) {
unsigned int optuint = 0;
if(db_mysql_opt_ssl_mode == 1) {
Expand All @@ -136,7 +161,8 @@ struct my_con *db_mysql_new_connection(const struct db_id *id)
"ignoring\n",
(unsigned int)db_mysql_opt_ssl_mode);
}
#endif
#endif /* MYSQL_VERSION_ID */
#endif /* MARIADB_BASE_VERSION */

#if MYSQL_VERSION_ID > 50012
/* set reconnect flag if enabled */
Expand Down

0 comments on commit d772b4c

Please sign in to comment.