From f139991a2c19fa0ac58654257c00aba4eb69d487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 10 Jul 2019 08:55:16 +0300 Subject: [PATCH] MXS-2559: Log source of loaded users MySQLAuth now logs the server where the users were loaded from. As only the initial loading of users causes a log message, it is still possible for the source server to change without any indication of it. --- server/modules/authenticator/MySQLAuth/dbusers.cc | 9 +++++---- server/modules/authenticator/MySQLAuth/mysql_auth.cc | 7 +++++-- server/modules/authenticator/MySQLAuth/mysql_auth.h | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/server/modules/authenticator/MySQLAuth/dbusers.cc b/server/modules/authenticator/MySQLAuth/dbusers.cc index 69f17ac35..a80ade0b8 100644 --- a/server/modules/authenticator/MySQLAuth/dbusers.cc +++ b/server/modules/authenticator/MySQLAuth/dbusers.cc @@ -136,7 +136,7 @@ const char* mariadb_users_query // We only care about users that have a default role assigned "WHERE t.default_role = u.user %s;"; -static int get_users(SERV_LISTENER* listener, bool skip_local); +static int get_users(SERV_LISTENER* listener, bool skip_local, SERVER** srv); static MYSQL* gw_mysql_init(void); static int gw_mysql_set_timeouts(MYSQL* handle); static char* mysql_format_user_entry(void* data); @@ -192,9 +192,9 @@ static char* get_users_query(const char* server_version, int version, bool inclu return rval; } -int replace_mysql_users(SERV_LISTENER* listener, bool skip_local) +int replace_mysql_users(SERV_LISTENER* listener, bool skip_local, SERVER** srv) { - int i = get_users(listener, skip_local); + int i = get_users(listener, skip_local, srv); return i; } @@ -1092,7 +1092,7 @@ int get_users_from_server(MYSQL* con, SERVER_REF* server_ref, SERVICE* service, * @param users The users table into which to load the users * @return -1 on any error or the number of users inserted */ -static int get_users(SERV_LISTENER* listener, bool skip_local) +static int get_users(SERV_LISTENER* listener, bool skip_local, SERVER** srv) { const char* service_user = NULL; const char* service_passwd = NULL; @@ -1148,6 +1148,7 @@ static int get_users(SERV_LISTENER* listener, bool skip_local) if (users > total_users) { + *srv = server->server; total_users = users; } diff --git a/server/modules/authenticator/MySQLAuth/mysql_auth.cc b/server/modules/authenticator/MySQLAuth/mysql_auth.cc index e9a53ca45..5107a77aa 100644 --- a/server/modules/authenticator/MySQLAuth/mysql_auth.cc +++ b/server/modules/authenticator/MySQLAuth/mysql_auth.cc @@ -787,7 +787,8 @@ static int mysql_auth_load_users(SERV_LISTENER* port) first_load = true; } - int loaded = replace_mysql_users(port, first_load); + SERVER* srv = nullptr; + int loaded = replace_mysql_users(port, first_load, &srv); bool injected = false; if (loaded <= 0) @@ -834,7 +835,9 @@ static int mysql_auth_load_users(SERV_LISTENER* port) } else if (loaded > 0 && first_load) { - MXS_NOTICE("[%s] Loaded %d MySQL users for listener %s.", service->name, loaded, port->name); + mxb_assert(srv); + MXS_NOTICE("[%s] Loaded %d MySQL users for listener %s from server %s.", + service->name, loaded, port->name, srv->name); } return rc; diff --git a/server/modules/authenticator/MySQLAuth/mysql_auth.h b/server/modules/authenticator/MySQLAuth/mysql_auth.h index 2f4c6d986..f278ce1a0 100644 --- a/server/modules/authenticator/MySQLAuth/mysql_auth.h +++ b/server/modules/authenticator/MySQLAuth/mysql_auth.h @@ -198,10 +198,11 @@ bool dbusers_save(sqlite3* src, const char* filename); * * @param service The current service * @param skip_local Skip loading of users on local MaxScale services + * @param srv Server where the users were loaded from (output) * * @return -1 on any error or the number of users inserted (0 means no users at all) */ -int replace_mysql_users(SERV_LISTENER* listener, bool skip_local); +int replace_mysql_users(SERV_LISTENER* listener, bool skip_local, SERVER** srv); /** * @brief Verify the user has access to the database