Replace get_users implementation with new version
The get_users function now combines the functionality of the old get_users and get_all_users. This removes large parts of similar code. Removed the listener resources as MySQLAuth was the only one that used it.
This commit is contained in:
@ -44,7 +44,6 @@ typedef struct servlistener
|
|||||||
SSL_LISTENER *ssl; /**< Structure of SSL data or NULL */
|
SSL_LISTENER *ssl; /**< Structure of SSL data or NULL */
|
||||||
struct dcb *listener; /**< The DCB for the listener */
|
struct dcb *listener; /**< The DCB for the listener */
|
||||||
struct users *users; /**< The user data for this listener */
|
struct users *users; /**< The user data for this listener */
|
||||||
HASHTABLE *resources; /**< hastable for listener resources, i.e. database names */
|
|
||||||
struct service* service; /**< The service which used by this listener */
|
struct service* service; /**< The service which used by this listener */
|
||||||
SPINLOCK lock;
|
SPINLOCK lock;
|
||||||
struct servlistener *next; /**< Next service protocol */
|
struct servlistener *next; /**< Next service protocol */
|
||||||
|
@ -129,7 +129,6 @@ listener_alloc(struct service* service, const char* name, const char *protocol,
|
|||||||
proto->auth_options = my_auth_options;
|
proto->auth_options = my_auth_options;
|
||||||
proto->ssl = ssl;
|
proto->ssl = ssl;
|
||||||
proto->users = NULL;
|
proto->users = NULL;
|
||||||
proto->resources = NULL;
|
|
||||||
proto->next = NULL;
|
proto->next = NULL;
|
||||||
proto->auth_instance = auth_instance;
|
proto->auth_instance = auth_instance;
|
||||||
spinlock_init(&proto->lock);
|
spinlock_init(&proto->lock);
|
||||||
@ -146,10 +145,6 @@ void listener_free(SERV_LISTENER* listener)
|
|||||||
{
|
{
|
||||||
if (listener)
|
if (listener)
|
||||||
{
|
{
|
||||||
if (listener->resources)
|
|
||||||
{
|
|
||||||
hashtable_free(listener->resources);
|
|
||||||
}
|
|
||||||
if (listener->users)
|
if (listener->users)
|
||||||
{
|
{
|
||||||
users_free(listener->users);
|
users_free(listener->users);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -742,102 +742,6 @@ gw_check_mysql_scramble_data(DCB *dcb,
|
|||||||
return (0 == memcmp(password, check_hash, SHA_DIGEST_LENGTH)) ?
|
return (0 == memcmp(password, check_hash, SHA_DIGEST_LENGTH)) ?
|
||||||
MXS_AUTH_SUCCEEDED : MXS_AUTH_FAILED;
|
MXS_AUTH_SUCCEEDED : MXS_AUTH_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief If the client connection specifies a database, check existence
|
|
||||||
*
|
|
||||||
* The client can specify a default database, but if so, it must be one
|
|
||||||
* that exists. This function is chained from the previous one, and will
|
|
||||||
* amend the given return code if it is previously showing success.
|
|
||||||
*
|
|
||||||
* @param dcb Request handler DCB connected to the client
|
|
||||||
* @param database A string containing the database name
|
|
||||||
* @param auth_ret The authentication status prior to calling this function.
|
|
||||||
* @return Authentication status
|
|
||||||
* @note Authentication status codes are defined in maxscale/protocol/mysql.h
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
check_db_name_after_auth(DCB *dcb, char *database, int auth_ret)
|
|
||||||
{
|
|
||||||
int db_exists = -1;
|
|
||||||
|
|
||||||
/* check for database name and possible match in resource hashtable */
|
|
||||||
if (database && strlen(database))
|
|
||||||
{
|
|
||||||
/* if database names are loaded we can check if db name exists */
|
|
||||||
if (dcb->listener->resources != NULL)
|
|
||||||
{
|
|
||||||
if (hashtable_fetch(dcb->listener->resources, database))
|
|
||||||
{
|
|
||||||
db_exists = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
db_exists = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* if database names are not loaded we don't allow connection with db name*/
|
|
||||||
db_exists = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (db_exists == 0 && auth_ret == MXS_AUTH_SUCCEEDED)
|
|
||||||
{
|
|
||||||
auth_ret = MXS_AUTH_FAILED_DB;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (db_exists < 0 && auth_ret == MXS_AUTH_SUCCEEDED)
|
|
||||||
{
|
|
||||||
auth_ret = MXS_AUTH_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return auth_ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Function to easily call authentication and database checks.
|
|
||||||
*
|
|
||||||
* The two functions are called one after the other, with the return from
|
|
||||||
* the first passed to the second. For convenience and clarity this function
|
|
||||||
* combines the calls.
|
|
||||||
*
|
|
||||||
* @param dcb Request handler DCB connected to the client
|
|
||||||
* @param auth_token A string of bytes containing the authentication token
|
|
||||||
* @param auth_token_len An integer, the length of the preceding parameter
|
|
||||||
* @param protocol The protocol structure for the connection
|
|
||||||
* @param username String containing username
|
|
||||||
* @param stage1_hash A password hash for authentication
|
|
||||||
* @param database A string containing the name for the default database
|
|
||||||
* @return Authentication status
|
|
||||||
* @note Authentication status codes are defined in maxscale/protocol/mysql.h
|
|
||||||
*/
|
|
||||||
static int combined_auth_check(
|
|
||||||
DCB *dcb,
|
|
||||||
uint8_t *auth_token,
|
|
||||||
size_t auth_token_len,
|
|
||||||
MySQLProtocol *protocol,
|
|
||||||
char *username,
|
|
||||||
uint8_t *stage1_hash,
|
|
||||||
char *database
|
|
||||||
)
|
|
||||||
{
|
|
||||||
int auth_ret;
|
|
||||||
|
|
||||||
auth_ret = gw_check_mysql_scramble_data(dcb,
|
|
||||||
auth_token,
|
|
||||||
auth_token_len,
|
|
||||||
protocol->scramble,
|
|
||||||
sizeof(protocol->scramble),
|
|
||||||
username,
|
|
||||||
stage1_hash);
|
|
||||||
|
|
||||||
/* check for database name match in resource hashtable */
|
|
||||||
auth_ret = check_db_name_after_auth(dcb, database, auth_ret);
|
|
||||||
return auth_ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Free the client data pointed to by the passed DCB.
|
* @brief Free the client data pointed to by the passed DCB.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user