MXS-862: Add create/destroy and remove plugin_name entry points

The create and destroy entry points allow authenticators to store data in
the DCB. This data is not shared by other DCBs related to the same
session.

The plugin_name entry point wasn't really useful as the plugins would
still need to send a AuthSwitchRequest packet if they wanted to change the
authentication mechanism.
This commit is contained in:
Markus Makela
2016-10-04 12:06:52 +03:00
parent 829d5a7453
commit dfeb5c46c9
15 changed files with 155 additions and 89 deletions

View File

@ -50,7 +50,7 @@ typedef struct mysql_backend_auth
* @brief Allocate a new mysql_backend_auth object
* @return Allocated object or NULL if memory allocation failed
*/
mysql_backend_auth_t* mba_alloc()
void* auth_backend_create()
{
mysql_backend_auth_t* mba = MXS_MALLOC(sizeof(*mba));
@ -62,6 +62,18 @@ mysql_backend_auth_t* mba_alloc()
return mba;
}
/**
* @brief Free allocated mysql_backend_auth object
* @param data Allocated mysql_backend_auth object
*/
void auth_backend_destroy(void *data)
{
if (data)
{
MXS_FREE(data);
}
}
/**
* Receive the MySQL authentication packet from backend, packet # is 2
*
@ -95,9 +107,9 @@ auth_backend_extract(DCB *dcb, GWBUF *buf)
{
int rval = MXS_AUTH_FAILED;
if (dcb->backend_data || (dcb->backend_data = mba_alloc()))
if (dcb->authenticator_data)
{
mysql_backend_auth_t *mba = (mysql_backend_auth_t*)dcb->backend_data;
mysql_backend_auth_t *mba = (mysql_backend_auth_t*)dcb->authenticator_data;
switch (mba->state)
{
@ -146,7 +158,7 @@ static int
auth_backend_authenticate(DCB *dcb)
{
int rval = MXS_AUTH_FAILED;
mysql_backend_auth_t *mba = (mysql_backend_auth_t*)dcb->backend_data;
mysql_backend_auth_t *mba = (mysql_backend_auth_t*)dcb->authenticator_data;
if (mba->state == MBA_SEND_RESPONSE)
{
@ -192,16 +204,6 @@ auth_backend_ssl(DCB *dcb)
return dcb->server->server_ssl != NULL;
}
/**
* @brief Dummy function for the free entry point
*/
static void
auth_backend_free(DCB *dcb)
{
MXS_FREE(dcb->backend_data);
dcb->backend_data = NULL;
}
/**
* @brief Dummy function for the loadusers entry point
*/
@ -230,12 +232,13 @@ static char *version_str = "V1.0.0";
*/
static GWAUTHENTICATOR MyObject =
{
auth_backend_extract, /* Extract data into structure */
auth_backend_ssl, /* Check if client supports SSL */
auth_backend_authenticate, /* Authenticate user credentials */
auth_backend_free, /* Free the client data held in DCB */
auth_backend_load_users, /* Load users from backend databases */
DEFAULT_MYSQL_AUTH_PLUGIN
auth_backend_create, /* Create authenticator */
auth_backend_extract, /* Extract data into structure */
auth_backend_ssl, /* Check if client supports SSL */
auth_backend_authenticate, /* Authenticate user credentials */
NULL, /* The shared data is freed by the client DCB */
auth_backend_destroy, /* Destroy authenticator */
NULL /* We don't need to load users */
};
/**