MXS-862: Add authenticator options and instances

Authenticators now have a similar mechanism to the `router_options`
parameter which enables configurable authentication.

The authenticators also have a new initialize entry point which is similar
to the createInstance entry point of the filters and routers. The value of
`authenticator_options` is passed as a parameter to this function. The
return vaulue of the `initialize` entry point is passed to the `create`
entry point.
This commit is contained in:
Markus Makela
2016-10-11 22:44:43 +03:00
parent a2a8562c39
commit 9d8c5cd410
27 changed files with 236 additions and 62 deletions

View File

@ -44,6 +44,7 @@
#include <log_manager.h>
#include <gw_ssl.h>
#include <maxscale/alloc.h>
#include <modules.h>
static SPINLOCK server_spin = SPINLOCK_INIT;
static SERVER *allServers = NULL;
@ -62,18 +63,40 @@ static void server_parameter_free(SERVER_PARAM *tofree);
* @return The newly created server or NULL if an error occured
*/
SERVER *
server_alloc(char *servname, char *protocol, unsigned short port)
server_alloc(char *servname, char *protocol, unsigned short port, char *authenticator,
char *auth_options)
{
if (authenticator)
{
authenticator = MXS_STRDUP(authenticator);
}
else if ((authenticator = get_default_authenticator(protocol)) == NULL)
{
MXS_ERROR("No authenticator defined for server at %s:%u and no default "
"authenticator for protocol '%s'.", servname, port, protocol);
}
void *auth_instance = NULL;
if (!authenticator_init(&auth_instance, authenticator, auth_options))
{
MXS_ERROR("Failed to initialize authenticator module '%s' for server"
" at %s:%u.", authenticator, servname, port);
MXS_FREE(authenticator);
return NULL;
}
servname = MXS_STRNDUP(servname, MAX_SERVER_NAME_LEN);
protocol = MXS_STRDUP(protocol);
SERVER *server = (SERVER *)MXS_CALLOC(1, sizeof(SERVER));
if (!servname || !protocol || !server)
if (!servname || !protocol || !server || !authenticator)
{
MXS_FREE(servname);
MXS_FREE(protocol);
MXS_FREE(server);
MXS_FREE(authenticator);
return NULL;
}
@ -83,7 +106,8 @@ server_alloc(char *servname, char *protocol, unsigned short port)
#endif
server->name = servname;
server->protocol = protocol;
server->authenticator = NULL;
server->authenticator = authenticator;
server->auth_instance = auth_instance;
server->port = port;
server->status = SERVER_RUNNING;
server->node_id = -1;