From 03eb30fbc62500a69e0cd4b6d4831e144a4a87b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 22 Feb 2018 10:06:29 +0200 Subject: [PATCH] Check SHOW DATABASES privilege on startup MySQLAuth requires the SHOW DATABASES privilege to see all the databases so it should be checked that the current user has the permission. A missing permission will cause errors that are hard to resolve. --- .../modules/authenticator/MySQLAuth/dbusers.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/modules/authenticator/MySQLAuth/dbusers.c b/server/modules/authenticator/MySQLAuth/dbusers.c index 0310ff928..8829e5170 100644 --- a/server/modules/authenticator/MySQLAuth/dbusers.c +++ b/server/modules/authenticator/MySQLAuth/dbusers.c @@ -627,6 +627,25 @@ static bool check_server_permissions(SERVICE *service, SERVER* server, } } + // Check whether the current user has the SHOW DATABASES privilege + if (mxs_mysql_query(mysql, "SELECT show_db_priv FROM mysql.user " + "WHERE CONCAT(user, '@', host) = CURRENT_USER()") == 0) + { + MYSQL_RES* res = mysql_use_result(mysql); + if (res) + { + MYSQL_ROW row = mysql_fetch_row(res); + + if (row && strcasecmp(row[0], "Y") != 0) + { + MXS_WARNING("[%s] User '%s' is missing the SHOW DATABASES privilege.", + service->name, user); + } + + mysql_free_result(res); + } + } + mysql_close(mysql); return rval;