Return correct value for failed db authentication
The unknown database error was never triggered as all authentication errors returned MXS_AUTH_FAILED.
This commit is contained in:
@ -218,13 +218,13 @@ static int auth_cb(void *data, int columns, char** rows, char** row_names)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool validate_mysql_user(sqlite3 *handle, DCB *dcb, MYSQL_session *session,
|
||||
uint8_t *scramble, size_t scramble_len)
|
||||
int validate_mysql_user(sqlite3 *handle, DCB *dcb, MYSQL_session *session,
|
||||
uint8_t *scramble, size_t scramble_len)
|
||||
{
|
||||
size_t len = sizeof(mysqlauth_validate_user_query) + strlen(session->user) * 2 +
|
||||
strlen(session->db) * 2 + MYSQL_HOST_MAXLEN + session->auth_token_len * 4 + 1;
|
||||
char sql[len + 1];
|
||||
bool rval = false;
|
||||
int rval = MXS_AUTH_FAILED;
|
||||
char *err;
|
||||
|
||||
sprintf(sql, mysqlauth_validate_user_query, session->user, dcb->remote,
|
||||
@ -259,18 +259,25 @@ bool validate_mysql_user(sqlite3 *handle, DCB *dcb, MYSQL_session *session,
|
||||
if (res.ok)
|
||||
{
|
||||
/** Found a matching row */
|
||||
if (session->auth_token_len)
|
||||
{
|
||||
/** If authentication fails, this will trigger the right
|
||||
* error message with `Using password : YES` */
|
||||
session->client_sha1[0] = '_';
|
||||
}
|
||||
|
||||
if (check_password(res.output, session->auth_token, session->auth_token_len,
|
||||
scramble, scramble_len, session->client_sha1))
|
||||
{
|
||||
/** Password is OK, check that the database exists */
|
||||
rval = check_database(handle, session->db);
|
||||
if (check_database(handle, session->db))
|
||||
{
|
||||
rval = MXS_AUTH_SUCCEEDED;
|
||||
}
|
||||
else
|
||||
{
|
||||
rval = MXS_AUTH_FAILED_DB;
|
||||
}
|
||||
}
|
||||
else if (session->auth_token_len)
|
||||
{
|
||||
/** If authentication fails, this will trigger the right
|
||||
* error message with `Using password : YES` */
|
||||
session->client_sha1[0] = '_';
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user