Move dbusers.c out of the core

The dbusers.c was a MySQL protocol specific file which was used directly
by some of the modules.

Added a new return value for the loadusers authenticator entry point which
allows fatal failures to occur when users are loaded. Currently this is
only taken into notice when the service is first started. If a listener
later returns a fatal error, it is only logged but the service stays in
operation.

Moved the MySQLAuth authenticator sources and the tests that relate to
this module into a subdirectory in the authenticator
directory. Eventually, all authenticators could have a subdirectory of
their own.
This commit is contained in:
Markus Makela
2016-10-20 21:26:06 +03:00
parent fe689504b0
commit 4e07c3313c
23 changed files with 127 additions and 352 deletions

View File

@ -53,7 +53,6 @@
#include <maxscale/dcb.h>
#include <maxscale/users.h>
#include <maxscale/filter.h>
#include <maxscale/dbusers.h>
#include <maxscale/poll.h>
#include <maxscale/log_manager.h>
#include <sys/stat.h>
@ -210,6 +209,16 @@ service_isvalid(SERVICE *service)
return rval;
}
static inline void close_port(SERV_LISTENER *port)
{
port->service->state = SERVICE_STATE_FAILED;
if (port->listener)
{
dcb_close(port->listener);
port->listener = NULL;
}
}
/**
* Start an individual port/protocol pair
*
@ -232,7 +241,9 @@ serviceStartPort(SERVICE *service, SERV_LISTENER *port)
{
/* Should never happen, this guarantees it can't */
MXS_ERROR("Attempt to start port with null or incomplete service");
goto retblock;
close_port(port);
ss_dassert(false);
return 0;
}
port->listener = dcb_alloc(DCB_ROLE_SERVICE_LISTENER, port);
@ -240,7 +251,8 @@ serviceStartPort(SERVICE *service, SERV_LISTENER *port)
if (port->listener == NULL)
{
MXS_ERROR("Failed to create listener for service %s.", service->name);
goto retblock;
close_port(port);
return 0;
}
port->listener->service = service;
@ -252,13 +264,10 @@ serviceStartPort(SERVICE *service, SERV_LISTENER *port)
if ((funcs = (GWPROTOCOL *)load_module(port->protocol, MODULE_PROTOCOL)) == NULL)
{
dcb_close(port->listener);
port->listener = NULL;
MXS_ERROR("Unable to load protocol module %s. Listener "
"for service %s not started.",
port->protocol,
service->name);
goto retblock;
MXS_ERROR("Unable to load protocol module %s. Listener for service %s not started.",
port->protocol, service->name);
close_port(port);
return 0;
}
memcpy(&(port->listener->func), funcs, sizeof(GWPROTOCOL));
@ -280,8 +289,7 @@ serviceStartPort(SERVICE *service, SERV_LISTENER *port)
{
MXS_ERROR("Failed to load authenticator module '%s' for listener '%s'",
authenticator_name, port->name);
dcb_close(port->listener);
port->listener = NULL;
close_port(port);
return 0;
}
@ -302,11 +310,24 @@ serviceStartPort(SERVICE *service, SERV_LISTENER *port)
}
/** Load the authentication users before before starting the listener */
if (port->listener->authfunc.loadusers &&
port->listener->authfunc.loadusers(port) != MXS_AUTH_LOADUSERS_OK)
if (port->listener->authfunc.loadusers)
{
MXS_ERROR("[%s] Failed to load users for listener '%s', authentication might not work.",
service->name, port->name);
switch (port->listener->authfunc.loadusers(port))
{
case MXS_AUTH_LOADUSERS_FATAL:
MXS_ERROR("[%s] Fatal error when loading users for listener '%s', "
"service is not started.", service->name, port->name);
close_port(port);
return 0;
case MXS_AUTH_LOADUSERS_ERROR:
MXS_WARNING("[%s] Failed to load users for listener '%s', authentication"
" might not work.", service->name, port->name);
break;
default:
break;
}
}
/**
@ -327,24 +348,16 @@ serviceStartPort(SERVICE *service, SERV_LISTENER *port)
}
else
{
MXS_ERROR("Failed to create session to service %s.",
service->name);
dcb_close(port->listener);
port->listener = NULL;
goto retblock;
MXS_ERROR("[%s] Failed to create listener session.", service->name);
close_port(port);
}
}
else
{
MXS_ERROR("Unable to start to listen port %d for %s %s.",
port->port,
port->protocol,
service->name);
dcb_close(port->listener);
port->listener = NULL;
MXS_ERROR("[%s] Failed to listen on %s", service->name, config_bind);
close_port(port);
}
retblock:
return listeners;
}
@ -369,7 +382,11 @@ int serviceStartAllPorts(SERVICE* service)
port = port->next;
}
if (listeners)
if (service->state == SERVICE_STATE_FAILED)
{
listeners = 0;
}
else if (listeners)
{
service->state = SERVICE_STATE_STARTED;
service->stats.started = time(0);
@ -457,29 +474,20 @@ int
serviceStart(SERVICE *service)
{
int listeners = 0;
char **router_options = copy_string_array(service->routerOptions);
if (check_service_permissions(service))
if ((service->router_instance = service->router->createInstance(service, router_options)))
{
char **router_options = copy_string_array(service->routerOptions);
if ((service->router_instance = service->router->createInstance(
service, router_options)))
{
listeners += serviceStartAllPorts(service);
}
else
{
MXS_ERROR("%s: Failed to create router instance for service. Service not started.",
service->name);
service->state = SERVICE_STATE_FAILED;
}
free_string_array(router_options);
listeners = serviceStartAllPorts(service);
}
else
{
MXS_ERROR("%s: Inadequate user permissions for service. Service not started.",
service->name);
MXS_ERROR("%s: Failed to create router instance. Service not started.", service->name);
service->state = SERVICE_STATE_FAILED;
}
free_string_array(router_options);
return listeners;
}
@ -1461,12 +1469,26 @@ int service_refresh_users(SERVICE *service)
for (SERV_LISTENER *port = service->ports; port; port = port->next)
{
if (port->listener->authfunc.loadusers &&
port->listener->authfunc.loadusers(port) != MXS_AUTH_LOADUSERS_OK)
/** Load the authentication users before before starting the listener */
if (port->listener->authfunc.loadusers)
{
MXS_ERROR("[%s] Failed to load users for listener '%s', authentication might not work.",
service->name, port->name);
ret = 1;
switch (port->listener->authfunc.loadusers(port))
{
case MXS_AUTH_LOADUSERS_FATAL:
MXS_ERROR("[%s] Fatal error when loading users for listener '%s',"
" authentication will not work.", service->name, port->name);
ret = 1;
break;
case MXS_AUTH_LOADUSERS_ERROR:
MXS_WARNING("[%s] Failed to load users for listener '%s', authentication"
" might not work.", service->name, port->name);
ret = 1;
break;
default:
break;
}
}
}
}