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.
This commit is contained in:
Markus Mäkelä 2019-07-10 08:55:16 +03:00
parent 3649efde0b
commit f139991a2c
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 12 additions and 7 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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