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:
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user