From 633b08ed0dbbd719671658dbdc7c5c39340bba4c Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 13 Mar 2018 09:41:16 +0200 Subject: [PATCH] MXS-1717 Show which listener users are coming from Earlier, if a service had multiple listeners you would have had MaxScale> show dbusers MyService User names: alice@% ... User names: bob@% ... That is, no indication of which listener is reporting what. With this commit the result will be User names (MyListener1): alice@% ... User names (MyListener2): bob@% ... Further, the diagnostics function of an authenticator is now expected to write the list of users to the provided DCB, without performing any other formatting. The formatting (printing "User names" and appending a line-feed) is now handled by the handler for the MaxAdmin command "show dbusers". --- server/core/service.cc | 4 ++++ server/core/users.cc | 13 +------------ server/modules/authenticator/MySQLAuth/mysql_auth.c | 7 ++----- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/server/core/service.cc b/server/core/service.cc index 5cf41ea5a..ab4e3a315 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -2485,7 +2485,11 @@ void service_print_users(DCB *dcb, const SERVICE *service) if (listener_is_active(listener) && listener->listener && listener->listener->authfunc.diagnostic) { + dcb_printf(dcb, "User names (%s): ", listener->name); + listener->listener->authfunc.diagnostic(dcb, listener); + + dcb_printf(dcb, "\n"); } } } diff --git a/server/core/users.cc b/server/core/users.cc index 436d07b79..26e3a2b8f 100644 --- a/server/core/users.cc +++ b/server/core/users.cc @@ -166,7 +166,6 @@ public: dcb_printf(dcb, "%s%s", sep, it->first.c_str()); sep = ", "; } - dcb_printf(dcb, "\n"); } } @@ -324,17 +323,7 @@ void users_default_diagnostic(DCB* dcb, SERV_LISTENER* port) { if (port->users) { - Users* u = reinterpret_cast(port->users); - - if (u->empty()) - { - dcb_printf(dcb, "Users table is empty\n"); - } - else - { - dcb_printf(dcb, "User names: "); - users_diagnostic(dcb, port->users); - } + users_diagnostic(dcb, port->users); } } diff --git a/server/modules/authenticator/MySQLAuth/mysql_auth.c b/server/modules/authenticator/MySQLAuth/mysql_auth.c index 21aa6deb6..20f3ce2c2 100644 --- a/server/modules/authenticator/MySQLAuth/mysql_auth.c +++ b/server/modules/authenticator/MySQLAuth/mysql_auth.c @@ -641,8 +641,6 @@ int diag_cb(void *data, int columns, char **row, char **field_names) void mysql_auth_diagnostic(DCB *dcb, SERV_LISTENER *port) { - dcb_printf(dcb, "User names: "); - MYSQL_AUTH *instance = (MYSQL_AUTH*)port->auth_instance; sqlite3* handle = get_handle(instance); char *err; @@ -650,11 +648,10 @@ void mysql_auth_diagnostic(DCB *dcb, SERV_LISTENER *port) if (sqlite3_exec(handle, "SELECT user, host FROM " MYSQLAUTH_USERS_TABLE_NAME, diag_cb, dcb, &err) != SQLITE_OK) { - dcb_printf(dcb, "Failed to print users: %s\n", err); - MXS_ERROR("Failed to print users: %s", err); + dcb_printf(dcb, "Could not access users: %s", err); + MXS_ERROR("Could not access users: %s", err); sqlite3_free(err); } - dcb_printf(dcb, "\n"); } int diag_cb_json(void *data, int columns, char **row, char **field_names)