diff --git a/Documentation/Getting-Started/Configuration-Guide.md b/Documentation/Getting-Started/Configuration-Guide.md index 6970f9968..2f8613dbe 100644 --- a/Documentation/Getting-Started/Configuration-Guide.md +++ b/Documentation/Getting-Started/Configuration-Guide.md @@ -442,6 +442,17 @@ files. execdir=/usr/local/bin/ ``` +#### `connector_plugindir` + +Location of the MariaDB Connector-C plugin directory. The MariaDB Connector-C +used in MaxScale can use this directory to load authentication plugins. The +versions of the plugins must be binary compatible with the connector version +that MaxScale was built with. + +``` +connector_plugindir=/usr/lib/plugin/ +``` + #### `persistdir` Configure the directory where persisted configurations are stored. When a new diff --git a/cmake/install_layout.cmake b/cmake/install_layout.cmake index 256fcca24..bc77a8992 100644 --- a/cmake/install_layout.cmake +++ b/cmake/install_layout.cmake @@ -22,6 +22,7 @@ set(DEFAULT_EXEC_SUBPATH "${MAXSCALE_BINDIR}" CACHE PATH "Default executable sub set(DEFAULT_CONFIG_SUBPATH "etc" CACHE PATH "Default configuration subpath") set(DEFAULT_CONFIG_PERSIST_SUBPATH "maxscale.cnf.d" CACHE PATH "Default persisted configuration subpath") set(DEFAULT_MODULE_CONFIG_SUBPATH "${DEFAULT_CONFIG_SUBPATH}/maxscale.modules.d" CACHE PATH "Default configuration subpath") +set(DEFAULT_CONNECTOR_PLUGIN_SUBPATH "lib/plugin" CACHE PATH "Default connector plugin subpath") set(DEFAULT_PIDDIR ${MAXSCALE_VARDIR}/${DEFAULT_PID_SUBPATH} CACHE PATH "Default PID file directory") set(DEFAULT_LOGDIR ${MAXSCALE_VARDIR}/${DEFAULT_LOG_SUBPATH} CACHE PATH "Default log directory") @@ -33,6 +34,7 @@ set(DEFAULT_EXECDIR ${CMAKE_INSTALL_PREFIX}/${DEFAULT_EXEC_SUBPATH} CACHE PATH " set(DEFAULT_CONFIGDIR /${DEFAULT_CONFIG_SUBPATH} CACHE PATH "Default configuration directory") set(DEFAULT_CONFIG_PERSISTDIR ${DEFAULT_DATADIR}/${DEFAULT_CONFIG_PERSIST_SUBPATH} CACHE PATH "Default persisted configuration directory") set(DEFAULT_MODULE_CONFIGDIR /${DEFAULT_MODULE_CONFIG_SUBPATH} CACHE PATH "Default module configuration directory") +set(DEFAULT_CONNECTOR_PLUGINDIR ${MAXSCALE_VARDIR}/${DEFAULT_CONNECTOR_PLUGIN_SUBPATH} CACHE PATH "Default connector plugin directory") # Massage TARGET_COMPONENT into a list if (TARGET_COMPONENT) diff --git a/include/maxscale/paths.h.in b/include/maxscale/paths.h.in index 92d147e75..c30620a1e 100644 --- a/include/maxscale/paths.h.in +++ b/include/maxscale/paths.h.in @@ -31,6 +31,7 @@ MXS_BEGIN_DECLS #define MXS_DEFAULT_CONFIG_SUBPATH "@DEFAULT_CONFIG_SUBPATH@" #define MXS_DEFAULT_CONFIG_PERSIST_SUBPATH "@DEFAULT_CONFIG_PERSIST_SUBPATH@" #define MXS_DEFAULT_MODULE_CONFIG_SUBPATH "@DEFAULT_MODULE_CONFIG_SUBPATH@" +#define MXS_DEFAULT_CONNECTOR_PLUGIN_SUBPATH "@DEFAULT_CONNECTOR_PLUGIN_SUBPATH@" /** Default file locations, configured by CMake */ #define MXS_DEFAULT_CONFIGDIR "@DEFAULT_CONFIGDIR@" @@ -43,6 +44,7 @@ MXS_BEGIN_DECLS #define MXS_DEFAULT_EXECDIR "@DEFAULT_EXECDIR@" #define MXS_DEFAULT_CONFIG_PERSISTDIR "@DEFAULT_CONFIG_PERSISTDIR@" #define MXS_DEFAULT_MODULE_CONFIGDIR "@DEFAULT_MODULE_CONFIGDIR@" +#define MXS_DEFAULT_CONNECTOR_PLUGINDIR "@DEFAULT_CONNECTOR_PLUGINDIR@" static const char* default_cnf_fname = "maxscale.cnf"; static const char* default_configdir = MXS_DEFAULT_CONFIGDIR; @@ -59,6 +61,7 @@ static const char* default_langdir = MXS_DEFAULT_LANGDIR; static const char* default_execdir = MXS_DEFAULT_EXECDIR; static const char* default_config_persistdir = MXS_DEFAULT_CONFIG_PERSISTDIR; static const char* default_module_configdir = MXS_DEFAULT_MODULE_CONFIGDIR; +static const char* default_connector_plugindir = MXS_DEFAULT_CONNECTOR_PLUGINDIR; static char* configdir = NULL; /*< Where the config file is found e.g. /etc/ */ static char* config_persistdir = NULL;/*< Persisted configs e.g. /var/lib/maxscale/maxscale.cnf.d/ */ @@ -71,6 +74,7 @@ static char* processdatadir = NULL; /*< Process specific data directory */ static char* langdir = NULL; static char* piddir = NULL; static char* execdir = NULL; +static char* connector_plugindir = NULL; void set_libdir(char* param); void set_datadir(char* param); @@ -83,6 +87,7 @@ void set_logdir(char* param); void set_langdir(char* param); void set_piddir(char* param); void set_execdir(char* param); +void set_connector_plugindir(char* param); char* get_libdir(); char* get_datadir(); char* get_process_datadir(); @@ -94,5 +99,6 @@ char* get_piddir(); char* get_logdir(); char* get_langdir(); char* get_execdir(); +char* get_connector_plugindir(); MXS_END_DECLS diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 7366b2e62..cffe77ba0 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -138,6 +138,7 @@ static struct option long_options[] = {"version", no_argument, 0, 'v'}, {"version-full", no_argument, 0, 'V'}, {"help", no_argument, 0, '?'}, + {"connector_plugindir", required_argument, 0, 'H'}, {0, 0, 0, 0} }; static bool syslog_configured = false; @@ -927,6 +928,8 @@ static void usage(void) " -E, --execdir=PATH path to the maxscale and other executable files\n" " -F, --persistdir=PATH path to persisted configuration directory\n" " -M, --module_configdir=PATH path to module configuration directory\n" + " -H, --connector_plugindir=PATH\n" + " path to MariaDB Connector-C plugin directory\n" " -N, --language=PATH path to errmsg.sys file\n" " -P, --piddir=PATH path to PID file directory\n" " -R, --basedir=PATH base path for all other paths\n" @@ -1332,7 +1335,7 @@ int main(int argc, char **argv) } } - while ((opt = getopt_long(argc, argv, "dcf:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:M:", + while ((opt = getopt_long(argc, argv, "dcf:l:vVs:S:?L:D:C:B:U:A:P:G:N:E:F:M:H:", long_options, &option_index)) != -1) { bool succp = true; @@ -1496,6 +1499,16 @@ int main(int argc, char **argv) succp = false; } break; + case 'H': + if (handle_path_arg(&tmp_path, optarg, NULL, true, false)) + { + set_connector_plugindir(tmp_path); + } + else + { + succp = false; + } + break; case 'F': if (handle_path_arg(&tmp_path, optarg, NULL, true, true)) { @@ -2532,6 +2545,20 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons } } } + else if (strcmp(name, "connector_plugindir") == 0) + { + if (strcmp(get_connector_plugindir(), default_connector_plugindir) == 0) + { + if (handle_path_arg((char**)&tmp, (char*)value, NULL, true, false)) + { + set_connector_plugindir(tmp); + } + else + { + return 0; + } + } + } else if (strcmp(name, "persistdir") == 0) { if (strcmp(get_config_persistdir(), default_config_persistdir) == 0) diff --git a/server/core/monitor.c b/server/core/monitor.c index 1f34f3809..f163b081e 100644 --- a/server/core/monitor.c +++ b/server/core/monitor.c @@ -1181,10 +1181,10 @@ mon_connect_to_db(MXS_MONITOR* mon, MXS_MONITOR_SERVERS *database) char *dpwd = decrypt_password(passwd); - mysql_options(database->con, MYSQL_OPT_CONNECT_TIMEOUT, (void *) &mon->connect_timeout); - mysql_options(database->con, MYSQL_OPT_READ_TIMEOUT, (void *) &mon->read_timeout); - mysql_options(database->con, MYSQL_OPT_WRITE_TIMEOUT, (void *) &mon->write_timeout); - + mysql_optionsv(database->con, MYSQL_OPT_CONNECT_TIMEOUT, (void *) &mon->connect_timeout); + mysql_optionsv(database->con, MYSQL_OPT_READ_TIMEOUT, (void *) &mon->read_timeout); + mysql_optionsv(database->con, MYSQL_OPT_WRITE_TIMEOUT, (void *) &mon->write_timeout); + mysql_optionsv(database->con, MYSQL_PLUGIN_DIR, get_connector_plugindir()); time_t start = time(NULL); bool result = (mxs_mysql_real_connect(database->con, database->server, uname, dpwd) != NULL); time_t end = time(NULL); diff --git a/server/core/paths.c b/server/core/paths.c index 41461ad14..036c49c1b 100644 --- a/server/core/paths.c +++ b/server/core/paths.c @@ -137,6 +137,17 @@ void set_execdir(char* param) execdir = param; } +/** + * Set the connector plugin directory. + * @param str Path to directory + */ +void set_connector_plugindir(char* param) +{ + MXS_FREE(connector_plugindir); + clean_up_pathname(param); + connector_plugindir = param; +} + /** * Get the directory with all the modules. * @return The module directory @@ -235,3 +246,12 @@ char* get_execdir() { return execdir ? execdir : (char*) default_execdir; } + +/** + * Get connector plugin directory + * @return The connector plugin directory + */ +char* get_connector_plugindir() +{ + return connector_plugindir ? connector_plugindir : (char*) default_connector_plugindir; +} diff --git a/server/modules/authenticator/MySQLAuth/dbusers.c b/server/modules/authenticator/MySQLAuth/dbusers.c index 4ed39d91b..c88d342ac 100644 --- a/server/modules/authenticator/MySQLAuth/dbusers.c +++ b/server/modules/authenticator/MySQLAuth/dbusers.c @@ -31,6 +31,7 @@ #include #include #include +#include /** Don't include the root user */ #define USERS_QUERY_NO_ROOT " AND user.user NOT IN ('root')" @@ -408,22 +409,7 @@ MYSQL *gw_mysql_init() if (con) { - if (gw_mysql_set_timeouts(con) == 0) - { - // MYSQL_OPT_USE_REMOTE_CONNECTION must be set if the embedded - // libary is used. With Connector-C (at least 2.2.1) the call - // fails. -#if !defined(LIBMARIADB) - if (mysql_options(con, MYSQL_OPT_USE_REMOTE_CONNECTION, NULL) != 0) - { - MXS_ERROR("Failed to set external connection. " - "It is needed for backend server connections."); - mysql_close(con); - con = NULL; - } -#endif - } - else + if (gw_mysql_set_timeouts(con) != 0) { MXS_ERROR("Failed to set timeout values for backend connection."); mysql_close(con); @@ -454,21 +440,21 @@ static int gw_mysql_set_timeouts(MYSQL* handle) MXS_CONFIG* cnf = config_get_global_options(); - if ((rc = mysql_options(handle, MYSQL_OPT_READ_TIMEOUT, + if ((rc = mysql_optionsv(handle, MYSQL_OPT_READ_TIMEOUT, (void *) &cnf->auth_read_timeout))) { MXS_ERROR("Failed to set read timeout for backend connection."); goto retblock; } - if ((rc = mysql_options(handle, MYSQL_OPT_CONNECT_TIMEOUT, + if ((rc = mysql_optionsv(handle, MYSQL_OPT_CONNECT_TIMEOUT, (void *) &cnf->auth_conn_timeout))) { MXS_ERROR("Failed to set connect timeout for backend connection."); goto retblock; } - if ((rc = mysql_options(handle, MYSQL_OPT_WRITE_TIMEOUT, + if ((rc = mysql_optionsv(handle, MYSQL_OPT_WRITE_TIMEOUT, (void *) &cnf->auth_write_timeout))) { MXS_ERROR("Failed to set write timeout for backend connection."); @@ -499,9 +485,10 @@ static bool check_server_permissions(SERVICE *service, SERVER* server, } MXS_CONFIG* cnf = config_get_global_options(); - mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, &cnf->auth_read_timeout); - mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &cnf->auth_conn_timeout); - mysql_options(mysql, MYSQL_OPT_WRITE_TIMEOUT, &cnf->auth_write_timeout); + mysql_optionsv(mysql, MYSQL_OPT_READ_TIMEOUT, &cnf->auth_read_timeout); + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &cnf->auth_conn_timeout); + mysql_optionsv(mysql, MYSQL_OPT_WRITE_TIMEOUT, &cnf->auth_write_timeout); + mysql_optionsv(mysql, MYSQL_PLUGIN_DIR, get_connector_plugindir()); if (mxs_mysql_real_connect(mysql, server, user, password) == NULL) {