From 8a0b6005a4cadcdfcbbeea9e3a2c8cc10bc5c53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 18 Feb 2019 13:03:44 +0200 Subject: [PATCH] MXS-2335: Fix lower_case_table_names The database check always used the case-sensitive SQL to check that the database exists. --- server/modules/authenticator/MySQLAuth/dbusers.c | 11 +++++++---- server/modules/authenticator/MySQLAuth/mysql_auth.h | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/modules/authenticator/MySQLAuth/dbusers.c b/server/modules/authenticator/MySQLAuth/dbusers.c index bda31ba8c..baa4893e8 100644 --- a/server/modules/authenticator/MySQLAuth/dbusers.c +++ b/server/modules/authenticator/MySQLAuth/dbusers.c @@ -244,17 +244,20 @@ static int database_cb(void *data, int columns, char** rows, char** row_names) return 0; } -static bool check_database(sqlite3 *handle, const char *database) +static bool check_database(MYSQL_AUTH* instance, sqlite3 *handle, const char *database) { bool rval = true; if (*database) { rval = false; - size_t len = sizeof(mysqlauth_validate_database_query) + strlen(database) + 1; + const char* query = instance->lower_case_table_names ? + mysqlauth_validate_database_query_lower : + mysqlauth_validate_database_query; + size_t len = strlen(query) + strlen(database) + 1; char sql[len]; - sprintf(sql, mysqlauth_validate_database_query, database); + sprintf(sql, query, database); char *err; @@ -363,7 +366,7 @@ int validate_mysql_user(MYSQL_AUTH* instance, DCB *dcb, MYSQL_session *session, scramble, scramble_len, session->client_sha1)) { /** Password is OK, check that the database exists */ - if (check_database(handle, session->db)) + if (check_database(instance, handle, session->db)) { rval = MXS_AUTH_SUCCEEDED; } diff --git a/server/modules/authenticator/MySQLAuth/mysql_auth.h b/server/modules/authenticator/MySQLAuth/mysql_auth.h index 73c3304e5..7baff4de8 100644 --- a/server/modules/authenticator/MySQLAuth/mysql_auth.h +++ b/server/modules/authenticator/MySQLAuth/mysql_auth.h @@ -81,6 +81,8 @@ static const char mysqlauth_skip_auth_query[] = /** Query that checks that the database exists */ static const char mysqlauth_validate_database_query[] = "SELECT * FROM " MYSQLAUTH_DATABASES_TABLE_NAME " WHERE db = '%s' LIMIT 1"; +static const char mysqlauth_validate_database_query_lower[] = + "SELECT * FROM " MYSQLAUTH_DATABASES_TABLE_NAME " WHERE LOWER(db) = LOWER('%s') LIMIT 1"; /** Delete query used to clean up the database before loading new users */ static const char delete_users_query[] = "DELETE FROM " MYSQLAUTH_USERS_TABLE_NAME;