]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add rlm_sql_mysql driver option to set connection character set
authorNick Porter <nick@portercomputing.co.uk>
Wed, 14 Aug 2024 07:38:53 +0000 (08:38 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Wed, 14 Aug 2024 07:38:53 +0000 (08:38 +0100)
raddb/mods-config/sql/driver/mysql
raddb/mods-config/sql/main/mysql/queries.conf
src/modules/rlm_sql/drivers/rlm_sql_mysql/rlm_sql_mysql.c

index d84f19aae140ba5316934a642e2f36ac099c3659..aedf8f05820989033c5d18f71695abd1d3d92294 100644 (file)
@@ -1,6 +1,6 @@
 #  -*- text -*-
 #
-#  SQL driver configuration for MySQL
+#  SQL driver configuration for MySQL/MariaDB
 #
 #  Should be included inside of a SQL module's configuration section
 #
@@ -16,8 +16,13 @@ mysql {
 #              cipher = "DHE-RSA-AES256-SHA:AES128-SHA"
 #      }
 #
-       # If yes, (or auto and libmysqlclient reports warnings are
+       # If yes, (or auto and libmariadb reports warnings are
        # available), will retrieve and log additional warnings from
        # the server if an error has occurred. Defaults to 'auto'
        warnings = auto
+
+       # The character set to use for connections
+       # See https://mariadb.com/kb/en/mysql_set_character_set/
+       # for a list of valid options
+#      character_set = utf8mb4
 }
index c7ee059b769444844ea0de0d58ded1540ea1c70b..95338016364a78eac35b781f2552ae84b91e6f4b 100644 (file)
 #######################################################################
 #  Connection config
 #######################################################################
-# The character set is not configurable. The default character set of
-# the mysql client library is used. To control the character set,
-# create/edit my.cnf (typically in /etc/mysql/my.cnf or /etc/my.cnf)
-# and enter
-# [client]
-# default-character-set = utf8
+# The character set is configured using the driver option `character_set`
+# in mods-config/sql/driver/mysql
+#
+# To control other client library options, create / edit my.cnf (typically
+# in /etc/mysql/my.cnf or /etc/my.cnf) and enter
+# [freeradius]
+# <option> = <value>
 #
 
 #######################################################################
index 76213d7b461bc23b4c778c0e5bae0372d2f01418..d42cadcd426dc820b1436682f41aa37f57b558c1 100644 (file)
@@ -95,6 +95,8 @@ typedef struct {
        char const      *warnings_str;          //!< Whether we always query the server for additional warnings.
        rlm_sql_mysql_warnings  warnings;       //!< mysql_warning_count() doesn't
                                                //!< appear to work with NDB cluster
+
+       char const      *character_set;         //!< Character set to use on connections.
 } rlm_sql_mysql_t;
 
 static conf_parser_t tls_config[] = {
@@ -127,6 +129,7 @@ static const conf_parser_t driver_config[] = {
        { FR_CONF_POINTER("tls", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) tls_config },
 
        { FR_CONF_OFFSET("warnings", rlm_sql_mysql_t, warnings_str), .dflt = "auto" },
+       { FR_CONF_OFFSET("character_set", rlm_sql_mysql_t, character_set) },
        CONF_PARSER_TERMINATOR
 };
 
@@ -312,6 +315,8 @@ static connection_state_t _sql_connection_init(void **h, connection_t *conn, voi
 
        mysql_options(&(c->db), MYSQL_READ_DEFAULT_GROUP, "freeradius");
 
+       if (inst->character_set) mysql_options(&(c->db), MYSQL_SET_CHARSET_NAME, inst->character_set);
+
        /*
         *      We need to know about connection errors, and are capable
         *      of reconnecting automatically.