Fix Auth Error server status
The mon_ping_or_connect_to_db resets the MYSQL handle which caused the loss of the error message. Returning a new enumeration value for authentication errors solves this problem.
This commit is contained in:
parent
96ba2da40c
commit
67fee60f80
@ -179,7 +179,8 @@ typedef enum
|
||||
MONITOR_CONN_NEWCONN_OK, /* No existing connection or no ping reply. New connection created
|
||||
* successfully. */
|
||||
MONITOR_CONN_REFUSED, /* No existing connection or no ping reply. Server refused new connection. */
|
||||
MONITOR_CONN_TIMEOUT /* No existing connection or no ping reply. Timeout on new connection. */
|
||||
MONITOR_CONN_TIMEOUT, /* No existing connection or no ping reply. Timeout on new connection. */
|
||||
MONITOR_CONN_ACCESS_DENIED /* Server refused new connection due to authentication failure */
|
||||
} mxs_connect_result_t;
|
||||
|
||||
/** Monitor events */
|
||||
|
@ -772,25 +772,20 @@ bool check_monitor_permissions(MXS_MONITOR* monitor, const char* query)
|
||||
|
||||
for (MXS_MONITORED_SERVER* mondb = monitor->monitored_servers; mondb; mondb = mondb->next)
|
||||
{
|
||||
if (!mon_connection_is_ok(mon_ping_or_connect_to_db(monitor, mondb)))
|
||||
auto result = mon_ping_or_connect_to_db(monitor, mondb);
|
||||
|
||||
if (!mon_connection_is_ok(result))
|
||||
{
|
||||
MXS_ERROR("[%s] Failed to connect to server '%s' ([%s]:%d) when"
|
||||
" checking monitor user credentials and permissions: %s",
|
||||
" checking monitor user credentials and permissions.",
|
||||
monitor->name,
|
||||
mondb->server->name,
|
||||
mondb->server->address,
|
||||
mondb->server->port,
|
||||
mysql_error(mondb->con));
|
||||
switch (mysql_errno(mondb->con))
|
||||
{
|
||||
case ER_ACCESS_DENIED_ERROR:
|
||||
case ER_DBACCESS_DENIED_ERROR:
|
||||
case ER_ACCESS_DENIED_NO_PASSWORD_ERROR:
|
||||
break;
|
||||
mondb->server->port);
|
||||
|
||||
default:
|
||||
if (result != MONITOR_CONN_ACCESS_DENIED)
|
||||
{
|
||||
rval = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (mxs_mysql_query(mondb->con, query) != 0)
|
||||
@ -1499,7 +1494,13 @@ mxs_connect_result_t mon_ping_or_connect_to_db(MXS_MONITOR* mon, MXS_MONITORED_S
|
||||
}
|
||||
else
|
||||
{
|
||||
auto err = mysql_errno(mysql);
|
||||
mysql_close(mysql);
|
||||
|
||||
if (err == ER_ACCESS_DENIED_ERROR || err == ER_ACCESS_DENIED_NO_PASSWORD_ERROR)
|
||||
{
|
||||
conn_result = MONITOR_CONN_ACCESS_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
if (conn_result == MONITOR_CONN_REFUSED && (int)difftime(end, start) >= mon->connect_timeout)
|
||||
@ -2844,7 +2845,7 @@ void MonitorInstanceSimple::tick()
|
||||
*/
|
||||
monitor_clear_pending_status(pMs, SERVER_DOWN_CLEAR_BITS);
|
||||
|
||||
if (mysql_errno(pMs->con) == ER_ACCESS_DENIED_ERROR)
|
||||
if (rval == MONITOR_CONN_ACCESS_DENIED)
|
||||
{
|
||||
monitor_set_pending_status(pMs, SERVER_AUTH_ERROR);
|
||||
}
|
||||
|
@ -382,8 +382,8 @@ void MariaDBMonitor::update_server(MariaDBServer* server)
|
||||
// The server is not running. Clear some of the bits. User-set bits and some long-term bits
|
||||
// can stay.
|
||||
server->clear_status(SERVER_DOWN_CLEAR_BITS);
|
||||
auto conn_errno = mysql_errno(conn);
|
||||
if (conn_errno == ER_ACCESS_DENIED_ERROR || conn_errno == ER_ACCESS_DENIED_NO_PASSWORD_ERROR)
|
||||
|
||||
if (conn_status == MONITOR_CONN_ACCESS_DENIED)
|
||||
{
|
||||
server->set_status(SERVER_AUTH_ERROR);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user