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:
@ -1,4 +1,4 @@
|
||||
add_library(maxscale-common SHARED adminusers.c alloc.c authenticator.c atomic.c buffer.c config.c dbusers.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c hashtable.c hint.c housekeeper.c listmanager.c load_utils.c log_manager.cc maxscale_pcre2.c memlog.c misc.c mlist.c modutil.c monitor.c queuemanager.c query_classifier.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c gw_ssl.c mysql_utils.c mysql_binlog.c)
|
||||
add_library(maxscale-common SHARED adminusers.c alloc.c authenticator.c atomic.c buffer.c config.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c hashtable.c hint.c housekeeper.c listmanager.c load_utils.c log_manager.cc maxscale_pcre2.c memlog.c misc.c mlist.c modutil.c monitor.c queuemanager.c query_classifier.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c gw_ssl.c mysql_utils.c mysql_binlog.c)
|
||||
|
||||
target_link_libraries(maxscale-common ${MARIADB_CONNECTOR_LIBRARIES} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${CURL_LIBRARIES} ssl pthread crypt dl crypto inih z rt m stdc++)
|
||||
|
||||
|
@ -89,14 +89,14 @@ bool authenticator_init(void** dest, const char *authenticator, const char *opti
|
||||
* @return The default authenticator for the protocol or NULL if the protocol
|
||||
* does not provide one
|
||||
*/
|
||||
char* get_default_authenticator(const char *protocol)
|
||||
const char* get_default_authenticator(const char *protocol)
|
||||
{
|
||||
char *rval = NULL;
|
||||
GWPROTOCOL *protofuncs = (GWPROTOCOL*)load_module(protocol, MODULE_PROTOCOL);
|
||||
|
||||
if (protofuncs && protofuncs->auth_default)
|
||||
{
|
||||
rval = MXS_STRDUP(protofuncs->auth_default());
|
||||
rval = protofuncs->auth_default();
|
||||
}
|
||||
|
||||
return rval;
|
||||
|
@ -72,7 +72,6 @@
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <maxscale/dbusers.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/limits.h>
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
|
@ -71,7 +71,8 @@ listener_alloc(struct service* service, char* name, char *protocol, char *addres
|
||||
{
|
||||
authenticator = MXS_STRDUP(authenticator);
|
||||
}
|
||||
else if ((authenticator = get_default_authenticator(protocol)) == NULL)
|
||||
else if ((authenticator = (char*)get_default_authenticator(protocol)) == NULL ||
|
||||
(authenticator = MXS_STRDUP(authenticator)) == NULL)
|
||||
{
|
||||
MXS_ERROR("No authenticator defined for listener '%s' and could not get "
|
||||
"default authenticator for protocol '%s'.", name, protocol);
|
||||
@ -83,6 +84,9 @@ listener_alloc(struct service* service, char* name, char *protocol, char *addres
|
||||
{
|
||||
MXS_ERROR("Failed to initialize authenticator module '%s' for "
|
||||
"listener '%s'.", authenticator, name);
|
||||
MXS_FREE(address);
|
||||
MXS_FREE(authenticator);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
protocol = MXS_STRDUP(protocol);
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include <string.h>
|
||||
#include <maxscale/debug.h>
|
||||
#include <maxscale/users.h>
|
||||
#include <maxscale/dbusers.h>
|
||||
#include <strings.h>
|
||||
|
||||
/**
|
||||
|
@ -69,7 +69,8 @@ server_alloc(char *servname, char *protocol, unsigned short port, char *authenti
|
||||
{
|
||||
authenticator = MXS_STRDUP(authenticator);
|
||||
}
|
||||
else if ((authenticator = get_default_authenticator(protocol)) == NULL)
|
||||
else if ((authenticator = (char*)get_default_authenticator(protocol)) == NULL ||
|
||||
(authenticator = MXS_STRDUP(authenticator)) == NULL)
|
||||
{
|
||||
MXS_ERROR("No authenticator defined for server at %s:%u and no default "
|
||||
"authenticator for protocol '%s'.", servname, port, protocol);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ add_executable(test_log testlog.c)
|
||||
add_executable(test_logorder testlogorder.c)
|
||||
add_executable(test_logthrottling testlogthrottling.cc)
|
||||
add_executable(test_modutil testmodutil.c)
|
||||
add_executable(test_mysql_users test_mysql_users.c)
|
||||
add_executable(test_poll testpoll.c)
|
||||
add_executable(test_queuemanager testqueuemanager.c)
|
||||
add_executable(test_server testserver.c)
|
||||
@ -30,7 +29,6 @@ target_link_libraries(test_log maxscale-common)
|
||||
target_link_libraries(test_logorder maxscale-common)
|
||||
target_link_libraries(test_logthrottling maxscale-common)
|
||||
target_link_libraries(test_modutil maxscale-common)
|
||||
target_link_libraries(test_mysql_users MySQLAuth MySQLCommon maxscale-common)
|
||||
target_link_libraries(test_poll maxscale-common)
|
||||
target_link_libraries(test_queuemanager maxscale-common)
|
||||
target_link_libraries(test_server maxscale-common)
|
||||
@ -53,7 +51,6 @@ add_test(TestLogThrottling test_logthrottling)
|
||||
add_test(TestMaxScalePCRE2 testmaxscalepcre2)
|
||||
add_test(TestMemlog testmemlog)
|
||||
add_test(TestModutil test_modutil)
|
||||
add_test(TestMySQLUsers test_mysql_users)
|
||||
add_test(NAME TestMaxPasswd COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/testmaxpasswd.sh)
|
||||
add_test(TestPoll test_poll)
|
||||
add_test(TestQueueManager test_queuemanager)
|
||||
|
@ -1,7 +1,4 @@
|
||||
add_library(MySQLAuth SHARED mysql_auth.c)
|
||||
target_link_libraries(MySQLAuth maxscale-common MySQLCommon)
|
||||
set_target_properties(MySQLAuth PROPERTIES VERSION "1.0.0")
|
||||
install_module(MySQLAuth core)
|
||||
add_subdirectory(MySQLAuth)
|
||||
|
||||
add_library(MySQLBackendAuth SHARED mysql_backend_auth.c)
|
||||
target_link_libraries(MySQLBackendAuth maxscale-common MySQLCommon)
|
||||
|
10
server/modules/authenticator/MySQLAuth/CMakeLists.txt
Normal file
10
server/modules/authenticator/MySQLAuth/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
add_library(MySQLAuth SHARED mysql_auth.c dbusers.c)
|
||||
target_link_libraries(MySQLAuth maxscale-common MySQLCommon)
|
||||
set_target_properties(MySQLAuth PROPERTIES VERSION "1.0.0")
|
||||
install_module(MySQLAuth core)
|
||||
|
||||
if (BUILD_TESTS)
|
||||
add_executable(test_mysql_users test_mysql_users.c)
|
||||
target_link_libraries(test_mysql_users MySQLAuth MySQLCommon maxscale-common)
|
||||
add_test(TestMySQLUsers test_mysql_users)
|
||||
endif()
|
@ -42,7 +42,7 @@
|
||||
#include <maxscale/dcb.h>
|
||||
#include <maxscale/service.h>
|
||||
#include <maxscale/users.h>
|
||||
#include <maxscale/dbusers.h>
|
||||
#include "dbusers.h"
|
||||
#include <maxscale/log_manager.h>
|
||||
#include <maxscale/secrets.h>
|
||||
#include <maxscale/protocol/mysql.h>
|
71
server/modules/authenticator/MySQLAuth/dbusers.h
Normal file
71
server/modules/authenticator/MySQLAuth/dbusers.h
Normal file
@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
#ifndef _MAXSCALE_DBUSERS_H
|
||||
#define _MAXSCALE_DBUSERS_H
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
|
||||
*
|
||||
* Change Date: 2019-07-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file dbusers.h Extarct user information form the backend database
|
||||
*
|
||||
* @verbatim
|
||||
* Revision History
|
||||
*
|
||||
* Date Who Description
|
||||
* 25/06/13 Mark Riddoch Initial implementation
|
||||
* 25/02/13 Massimiliano Pinto Added users table refresh rate default values
|
||||
* 28/02/14 Massimiliano Pinto Added MySQL user and host data structure
|
||||
* 03/10/14 Massimiliano Pinto Added netmask to MySQL user and host data structure
|
||||
* 13/10/14 Massimiliano Pinto Added resource to MySQL user and host data structure
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
|
||||
#include <maxscale/cdefs.h>
|
||||
#include <maxscale/service.h>
|
||||
#include <maxscale/protocol/mysql.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
MXS_BEGIN_DECLS
|
||||
|
||||
|
||||
/** Cache directory and file names */
|
||||
static const char DBUSERS_DIR[] = "cache";
|
||||
static const char DBUSERS_FILE[] = "dbusers";
|
||||
|
||||
/**
|
||||
* MySQL user and host data structure
|
||||
*/
|
||||
typedef struct mysql_user_host_key
|
||||
{
|
||||
char *user;
|
||||
struct sockaddr_in ipv4;
|
||||
int netmask;
|
||||
char *resource;
|
||||
char hostname[MYSQL_HOST_MAXLEN + 1];
|
||||
} MYSQL_USER_HOST;
|
||||
|
||||
extern int add_mysql_users_with_host_ipv4(USERS *users, const char *user, const char *host,
|
||||
char *passwd, const char *anydb, const char *db);
|
||||
extern bool check_service_permissions(SERVICE* service);
|
||||
extern int dbusers_load(USERS *, const char *filename);
|
||||
extern int dbusers_save(USERS *, const char *filename);
|
||||
extern int load_mysql_users(SERV_LISTENER *listener);
|
||||
extern int mysql_users_add(USERS *users, MYSQL_USER_HOST *key, char *auth);
|
||||
extern USERS *mysql_users_alloc();
|
||||
extern char *mysql_users_fetch(USERS *users, MYSQL_USER_HOST *key);
|
||||
extern int reload_mysql_users(SERV_LISTENER *listener);
|
||||
extern int replace_mysql_users(SERV_LISTENER *listener);
|
||||
|
||||
MXS_END_DECLS
|
||||
|
||||
#endif
|
@ -30,7 +30,7 @@
|
||||
#include <maxscale/gw_authenticator.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/poll.h>
|
||||
#include <maxscale/dbusers.h>
|
||||
#include "dbusers.h"
|
||||
#include <maxscale/gwdirs.h>
|
||||
#include <maxscale/secrets.h>
|
||||
#include <maxscale/utils.h>
|
||||
@ -884,13 +884,20 @@ static bool add_service_user(SERV_LISTENER *port)
|
||||
* This function loads MySQL users from the backend database.
|
||||
*
|
||||
* @param port Listener definition
|
||||
* @return AUTH_LOADUSERS_OK on success, AUTH_LOADUSERS_ERROR on error
|
||||
* @return MXS_AUTH_LOADUSERS_OK on success, MXS_AUTH_LOADUSERS_ERROR and
|
||||
* MXS_AUTH_LOADUSERS_FATAL on fatal error
|
||||
*/
|
||||
static int mysql_auth_load_users(SERV_LISTENER *port)
|
||||
{
|
||||
int rc = MXS_AUTH_LOADUSERS_OK;
|
||||
SERVICE *service = port->listener->service;
|
||||
MYSQL_AUTH *instance = (MYSQL_AUTH*)port->auth_instance;
|
||||
|
||||
if (port->users == NULL && !check_service_permissions(port->service))
|
||||
{
|
||||
return MXS_AUTH_LOADUSERS_FATAL;
|
||||
}
|
||||
|
||||
int loaded = replace_mysql_users(port);
|
||||
char path[PATH_MAX];
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include <maxscale/users.h>
|
||||
#include <maxscale/log_manager.h>
|
||||
#include <maxscale/secrets.h>
|
||||
#include <maxscale/dbusers.h>
|
||||
#include "dbusers.h"
|
||||
#include <maxscale/protocol/mysql.h>
|
||||
#include <mysql_auth.h>
|
||||
#include <maxscale/listener.h>
|
@ -40,7 +40,6 @@
|
||||
#include "avrorouter.h"
|
||||
#include <maxavro.h>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/dbusers.h>
|
||||
|
||||
extern char *blr_extract_column(GWBUF *buf, int col);
|
||||
extern uint32_t extract_field(uint8_t *src, int bits);
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <maxscale/spinlock.h>
|
||||
#include <maxscale/mysql_binlog.h>
|
||||
#include <maxscale/users.h>
|
||||
#include <maxscale/dbusers.h>
|
||||
#include <avro.h>
|
||||
#include <cdc.h>
|
||||
#include <maxscale/pcre2.h>
|
||||
|
@ -103,7 +103,6 @@ static void errorReply(ROUTER *instance,
|
||||
static uint64_t getCapabilities();
|
||||
static int blr_handler_config(void *userdata, const char *section, const char *name, const char *value);
|
||||
static int blr_handle_config_item(const char *name, const char *value, ROUTER_INSTANCE *inst);
|
||||
static int blr_set_service_mysql_user(SERVICE *service);
|
||||
static int blr_load_dbusers(const ROUTER_INSTANCE *router);
|
||||
static int blr_check_binlog(ROUTER_INSTANCE *router);
|
||||
int blr_read_events_all_events(ROUTER_INSTANCE *router, int fix, int debug);
|
||||
@ -578,18 +577,6 @@ createInstance(SERVICE *service, char **options)
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate dbusers for this router here instead of serviceStartPort() */
|
||||
for (SERV_LISTENER *port = service->ports; port; port = port->next)
|
||||
{
|
||||
if ((port->users = mysql_users_alloc()) == NULL)
|
||||
{
|
||||
MXS_ERROR("%s: Error allocating dbusers in createInstance",
|
||||
inst->service->name);
|
||||
free_instance(inst);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Dynamically allocate master_host server struct, not written in any cnf file */
|
||||
if (service->dbref == NULL)
|
||||
{
|
||||
@ -674,19 +661,10 @@ createInstance(SERVICE *service, char **options)
|
||||
inst->service->name, inst->binlogdir);
|
||||
}
|
||||
|
||||
/* Set service user or load db users */
|
||||
blr_set_service_mysql_user(inst->service);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
inst->master_state = BLRM_UNCONNECTED;
|
||||
|
||||
/* Try loading dbusers */
|
||||
if (inst->service->ports)
|
||||
{
|
||||
blr_load_dbusers(inst);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2134,140 +2112,6 @@ blr_handle_config_item(const char *name, const char *value, ROUTER_INSTANCE *ins
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the service user to mysql dbusers (service->users)
|
||||
* via mysql_users_alloc and add_mysql_users_with_host_ipv4
|
||||
* User is added for '%' and 'localhost' hosts
|
||||
*
|
||||
* @param service The current service
|
||||
* @return 0 on success, 1 on failure
|
||||
*/
|
||||
static int
|
||||
blr_set_service_mysql_user(SERVICE *service)
|
||||
{
|
||||
char *dpwd = NULL;
|
||||
char *newpasswd = NULL;
|
||||
char *service_user = NULL;
|
||||
char *service_passwd = NULL;
|
||||
|
||||
if (serviceGetUser(service, &service_user, &service_passwd) == 0)
|
||||
{
|
||||
MXS_ERROR("failed to get service user details for service %s",
|
||||
service->name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
dpwd = decryptPassword(service->credentials.authdata);
|
||||
|
||||
if (!dpwd)
|
||||
{
|
||||
MXS_ERROR("decrypt password failed for service user %s, service %s",
|
||||
service_user,
|
||||
service->name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
newpasswd = create_hex_sha1_sha1_passwd(dpwd);
|
||||
|
||||
if (!newpasswd)
|
||||
{
|
||||
MXS_ERROR("create hex_sha1_sha1_password failed for service user %s",
|
||||
service_user);
|
||||
|
||||
MXS_FREE(dpwd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Add the service user for % and localhost to all listeners so that
|
||||
* it can always be used. */
|
||||
for (SERV_LISTENER *port = service->ports; port; port = port->next)
|
||||
{
|
||||
add_mysql_users_with_host_ipv4(port->users, service->credentials.name,
|
||||
"%", newpasswd, "Y", "");
|
||||
add_mysql_users_with_host_ipv4(port->users, service->credentials.name,
|
||||
"localhost", newpasswd, "Y", "");
|
||||
}
|
||||
|
||||
MXS_FREE(newpasswd);
|
||||
MXS_FREE(dpwd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load mysql dbusers into (service->users)
|
||||
*
|
||||
* @param router The router instance
|
||||
* @return -1 on failure, 0 for no users found, > 0 for found users
|
||||
*/
|
||||
static int
|
||||
blr_load_dbusers(const ROUTER_INSTANCE *router)
|
||||
{
|
||||
int loaded_total = 0;
|
||||
SERVICE *service;
|
||||
char path[PATH_MAX];
|
||||
service = router->service;
|
||||
|
||||
for (SERV_LISTENER *port = service->ports; port; port = port->next)
|
||||
{
|
||||
sprintf(path, "%s/%s/%s/", router->binlogdir, BLR_DBUSERS_DIR, port->name);
|
||||
|
||||
if (mxs_mkdir_all(path, 0775))
|
||||
{
|
||||
strcat(path, BLR_DBUSERS_FILE);
|
||||
}
|
||||
|
||||
/* Try loading dbusers from configured backends */
|
||||
int loaded = load_mysql_users(port);
|
||||
|
||||
if (loaded < 0)
|
||||
{
|
||||
MXS_ERROR("Unable to load users for service %s", service->name);
|
||||
|
||||
/* Try loading authentication data from file cache */
|
||||
loaded = dbusers_load(port->users, path);
|
||||
|
||||
if (loaded != -1)
|
||||
{
|
||||
MXS_ERROR("Service %s, Listener %s, Using cached credential information file %s.",
|
||||
service->name, port->name, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Service %s, Listener %s, Unable to read cache credential"
|
||||
" information from %s. No database user added to service users table.",
|
||||
service->name, port->name, path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* don't update cache if no user was loaded */
|
||||
if (loaded == 0)
|
||||
{
|
||||
MXS_ERROR("Service %s, Listener %s: failed to load any user information."
|
||||
" Authentication will probably fail as a result.",
|
||||
service->name, port->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* update cached data */
|
||||
dbusers_save(port->users, path);
|
||||
}
|
||||
}
|
||||
loaded_total += loaded;
|
||||
}
|
||||
|
||||
/* At service start last update is set to USERS_REFRESH_TIME seconds earlier.
|
||||
* This way MaxScale could try reloading users' just after startup
|
||||
*/
|
||||
service->rate_limit.last = time(NULL) - USERS_REFRESH_TIME;
|
||||
service->rate_limit.nloads = 1;
|
||||
|
||||
return loaded_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a numeric field from a packet of the specified number of bits
|
||||
*
|
||||
|
@ -432,7 +432,7 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue)
|
||||
else if (strcasecmp(word, "USER()") == 0)
|
||||
{
|
||||
/* Return user@host */
|
||||
char user_host[MYSQL_USER_MAXLEN + 1 + MYSQL_HOSTNAME_MAXLEN + 1] = "";
|
||||
char user_host[MYSQL_USER_MAXLEN + 1 + MYSQL_HOST_MAXLEN + 1] = "";
|
||||
|
||||
MXS_FREE(query_text);
|
||||
snprintf(user_host, sizeof(user_host),
|
||||
@ -3401,8 +3401,6 @@ blr_stop_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave)
|
||||
static int
|
||||
blr_start_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave)
|
||||
{
|
||||
int loaded;
|
||||
|
||||
/* if unconfigured return an error */
|
||||
if (router->master_state == BLRM_UNCONFIGURED)
|
||||
{
|
||||
@ -3532,28 +3530,7 @@ blr_start_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave)
|
||||
router->current_pos, router->binlog_position);
|
||||
|
||||
/* Try reloading new users and update cached credentials */
|
||||
loaded = service_refresh_users(router->service);
|
||||
|
||||
if (loaded == 0)
|
||||
{
|
||||
for (SERV_LISTENER *port = router->service->ports; port; port = port->next)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
sprintf(path, "%s/%s/%s/", router->binlogdir, BLR_DBUSERS_DIR, port->name);
|
||||
|
||||
if (mxs_mkdir_all(path, 0775))
|
||||
{
|
||||
strcat(path, BLR_DBUSERS_FILE);
|
||||
dbusers_save(port->users, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_NOTICE("Service %s: user credentials could not be refreshed. "
|
||||
"Will use existing cached credentials (%s/%s) if possible.",
|
||||
router->service->name, router->binlogdir, BLR_DBUSERS_DIR);
|
||||
}
|
||||
service_refresh_users(router->service);
|
||||
|
||||
return blr_slave_send_ok(router, slave);
|
||||
}
|
||||
|
@ -63,7 +63,6 @@
|
||||
#include <maxscale/dcb.h>
|
||||
#include <maxscale/poll.h>
|
||||
#include <maxscale/users.h>
|
||||
#include <maxscale/dbusers.h>
|
||||
#include <maxscale/config.h>
|
||||
#include <telnetd.h>
|
||||
#include <maxscale/adminusers.h>
|
||||
|
@ -50,7 +50,6 @@
|
||||
#include <maxscale/resultset.h>
|
||||
#include <maxscale/secrets.h>
|
||||
#include <maxscale/users.h>
|
||||
#include <maxscale/dbusers.h>
|
||||
|
||||
|
||||
MODULE_INFO info =
|
||||
@ -69,7 +68,6 @@ static int maxinfo_statistics(INFO_INSTANCE *, INFO_SESSION *, GWBUF *);
|
||||
static int maxinfo_ping(INFO_INSTANCE *, INFO_SESSION *, GWBUF *);
|
||||
static int maxinfo_execute_query(INFO_INSTANCE *, INFO_SESSION *, char *);
|
||||
static int handle_url(INFO_INSTANCE *instance, INFO_SESSION *router_session, GWBUF *queue);
|
||||
static int maxinfo_add_mysql_user(SERVICE *service);
|
||||
|
||||
|
||||
/* The router entry points */
|
||||
@ -182,13 +180,6 @@ createInstance(SERVICE *service, char **options)
|
||||
instances = inst;
|
||||
spinlock_release(&instlock);
|
||||
|
||||
/*
|
||||
* The following add the service user to service->users via mysql_users_alloc()
|
||||
* password to be used.
|
||||
*/
|
||||
|
||||
maxinfo_add_mysql_user(service);
|
||||
|
||||
return (ROUTER *)inst;
|
||||
}
|
||||
|
||||
@ -736,74 +727,3 @@ handle_url(INFO_INSTANCE *instance, INFO_SESSION *session, GWBUF *queue)
|
||||
gwbuf_free(queue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the service user to the service->users
|
||||
* via mysql_users_alloc and add_mysql_users_with_host_ipv4
|
||||
* User is added for '%' and 'localhost' hosts
|
||||
*
|
||||
* @param service The service for this router
|
||||
* @return 0 on success, 1 on failure
|
||||
*/
|
||||
static int
|
||||
maxinfo_add_mysql_user(SERVICE *service)
|
||||
{
|
||||
int rval = 1;
|
||||
char *service_user = NULL;
|
||||
char *service_passwd = NULL;
|
||||
|
||||
if (serviceGetUser(service, &service_user, &service_passwd) == 0)
|
||||
{
|
||||
MXS_ERROR("maxinfo: failed to get service user details");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *dpwd = decryptPassword(service->credentials.authdata);
|
||||
|
||||
if (!dpwd)
|
||||
{
|
||||
MXS_ERROR("maxinfo: decrypt password failed for service user %s", service_user);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SERV_LISTENER *port = service->ports;
|
||||
|
||||
while (port)
|
||||
{
|
||||
while (port && strcmp(port->protocol, "MySQLClient"))
|
||||
{
|
||||
port = port->next;
|
||||
}
|
||||
|
||||
if (port)
|
||||
{
|
||||
port->users = (void *)mysql_users_alloc();
|
||||
|
||||
char *newpasswd = create_hex_sha1_sha1_passwd(dpwd);
|
||||
|
||||
if (!newpasswd)
|
||||
{
|
||||
MXS_ERROR("maxinfo: create hex_sha1_sha1_password failed for "
|
||||
"service user %s", service_user);
|
||||
users_free(port->users);
|
||||
break;
|
||||
}
|
||||
|
||||
/* add service user for % and localhost */
|
||||
add_mysql_users_with_host_ipv4(port->users, service->credentials.name,
|
||||
"%", newpasswd, "Y", "");
|
||||
add_mysql_users_with_host_ipv4(port->users, service->credentials.name,
|
||||
"localhost", newpasswd, "Y", "");
|
||||
rval = 0;
|
||||
MXS_FREE(newpasswd);
|
||||
|
||||
/** Continue processing listeners in case there are multiple
|
||||
* MySQLClient listeners*/
|
||||
port = port->next;
|
||||
}
|
||||
}
|
||||
|
||||
MXS_FREE(dpwd);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
Reference in New Issue
Block a user