Merge branch '2.3' into 2.4

This commit is contained in:
Markus Mäkelä
2020-01-07 11:12:02 +02:00
6 changed files with 67 additions and 45 deletions

View File

@ -478,6 +478,10 @@ int validate_mysql_user(MYSQL_AUTH* instance,
rval = MXS_AUTH_FAILED_DB;
}
}
else
{
rval = MXS_AUTH_FAILED_WRONG_PASSWORD;
}
}
return rval;

View File

@ -37,6 +37,8 @@
#include <maxscale/utils.h>
#include <maxscale/routingworker.hh>
#include <sstream>
static void* mysql_auth_init(char** options);
static bool mysql_auth_set_protocol_data(DCB* dcb, GWBUF* buf);
static bool mysql_auth_is_client_ssl_capable(DCB* dcb);
@ -305,6 +307,48 @@ static GWBUF* gen_auth_switch_request_packet(MySQLProtocol* proto, MYSQL_session
*bufdata = '\0';
return buffer;
}
static void log_auth_failure(DCB* dcb, int auth_ret)
{
MYSQL_session* client_data = (MYSQL_session*)dcb->data;
std::ostringstream extra;
if (auth_ret == MXS_AUTH_FAILED_DB)
{
extra << "Unknown database: " << client_data->db;
}
else if (auth_ret == MXS_AUTH_FAILED_WRONG_PASSWORD)
{
extra << "Wrong password.";
}
else
{
extra << "User not found.";
}
std::ostringstream host;
host << "[" << dcb->remote << "]:" << dcb_get_port(dcb);
std::ostringstream db;
if (*client_data->db)
{
db << " to database '" << client_data->db << "'";
}
MXS_LOG_EVENT(maxscale::event::AUTHENTICATION_FAILURE,
"%s: login attempt for user '%s'@%s%s, authentication failed. %s",
dcb->service->name(), client_data->user, host.str().c_str(),
db.str().c_str(), extra.str().c_str());
if (is_localhost_address(&dcb->ip) && !dcb->service->localhost_match_wildcard_host)
{
MXS_NOTICE("If you have a wildcard grant that covers this address, "
"try adding 'localhost_match_wildcard_host=true' for "
"service '%s'. ", dcb->service->name());
}
}
/**
* @brief Authenticates a MySQL user who is a client to MaxScale.
*
@ -368,34 +412,7 @@ static int mysql_auth_authenticate(DCB* dcb)
}
else if (dcb->service->log_auth_warnings)
{
// The default failure is a `User not found` one
char extra[256] = "User not found.";
if (auth_ret == MXS_AUTH_FAILED_DB)
{
snprintf(extra, sizeof(extra), "Unknown database: %s", client_data->db);
}
else if (auth_ret == MXS_AUTH_FAILED_WRONG_PASSWORD)
{
strcpy(extra, "Wrong password.");
}
MXS_LOG_EVENT(maxscale::event::AUTHENTICATION_FAILURE,
"%s: login attempt for user '%s'@[%s]:%d, authentication failed. %s",
dcb->service->name(),
client_data->user,
dcb->remote,
dcb_get_port(dcb),
extra);
if (is_localhost_address(&dcb->ip)
&& !dcb->service->localhost_match_wildcard_host)
{
MXS_NOTICE("If you have a wildcard grant that covers this address, "
"try adding 'localhost_match_wildcard_host=true' for "
"service '%s'. ",
dcb->service->name());
}
log_auth_failure(dcb, auth_ret);
}
/* let's free the auth_token now */