Merge branch 'develop' into binlog_server_mariadb_master_encryption

This commit is contained in:
MassimilianoPinto
2016-10-31 15:49:48 +01:00
139 changed files with 3162 additions and 1863 deletions

View File

@ -1,10 +1,11 @@
if(AVRO_FOUND)
if(AVRO_FOUND AND JANSSON_FOUND)
include_directories(${AVRO_INCLUDE_DIR})
include_directories(${JANSSON_INCLUDE_DIR})
add_library(avrorouter SHARED avro.c ../binlog/binlog_common.c avro_client.c avro_schema.c avro_rbr.c avro_file.c avro_index.c)
set_target_properties(avrorouter PROPERTIES VERSION "1.0.0")
set_target_properties(avrorouter PROPERTIES LINK_FLAGS -Wl,-z,defs)
target_link_libraries(avrorouter maxscale-common jansson ${AVRO_LIBRARIES} maxavro sqlite3 lzma)
target_link_libraries(avrorouter maxscale-common ${JANSSON_LIBRARIES} ${AVRO_LIBRARIES} maxavro sqlite3 lzma)
install_module(avrorouter core)
else()
message(STATUS "Avro C libraries were not found, avrorouter will not be built.")
message(STATUS "No Avro C or Jansson libraries found, not building avrorouter.")
endif()

View File

@ -79,7 +79,7 @@ static void clientReply(ROUTER *instance, void *router_session, GWBUF *queue,
DCB *backend_dcb);
static void errorReply(ROUTER *instance, void *router_session, GWBUF *message,
DCB *backend_dcb, error_action_t action, bool *succp);
static int getCapabilities();
static uint64_t getCapabilities(void);
extern int MaxScaleUptime();
extern void avro_get_used_tables(AVRO_INSTANCE *router, DCB *dcb);
void converter_func(void* data);
@ -955,7 +955,7 @@ errorReply(ROUTER *instance, void *router_session, GWBUF *message, DCB *backend_
ss_dassert(false);
}
static int getCapabilities()
static uint64_t getCapabilities(void)
{
return RCAP_TYPE_NO_RSESSION;
}

View File

@ -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);

View File

@ -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>

View File

@ -101,10 +101,9 @@ static void errorReply(ROUTER *instance,
error_action_t action,
bool *succp);
static int getCapabilities();
static uint64_t getCapabilities(void);
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);
@ -579,18 +578,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)
{
@ -675,19 +662,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);
}
}
/**
@ -937,9 +915,8 @@ static void freeSession(ROUTER* router_instance,
{
ROUTER_INSTANCE *router = (ROUTER_INSTANCE *)router_instance;
ROUTER_SLAVE *slave = (ROUTER_SLAVE *)router_client_ses;
int prev_val;
prev_val = atomic_add(&router->stats.n_slaves, -1);
ss_debug(int prev_val = ) atomic_add(&router->stats.n_slaves, -1);
ss_dassert(prev_val > 0);
/*
@ -1790,9 +1767,9 @@ static void rses_end_locked_router_action(ROUTER_SLAVE *rses)
}
static int getCapabilities()
static uint64_t getCapabilities(void)
{
return (int)(RCAP_TYPE_NO_RSESSION | RCAP_TYPE_NO_USERS_INIT);
return RCAP_TYPE_NO_RSESSION;
}
/**
@ -2136,140 +2113,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
*

View File

@ -434,7 +434,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),
@ -3412,8 +3412,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)
{
@ -3543,28 +3541,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);
}

View File

@ -102,7 +102,7 @@ int main(int argc, char **argv) {
serviceAddRouterOption(service, s);
s = strtok_r(NULL, ",", &lasts);
}
set_libdir(MXS_STRDUP_A("../../../authenticator/"));
server = server_alloc("_none_", "MySQLBackend", 3306, "MySQLBackendAuth", NULL);
if (server == NULL) {
return 1;

View File

@ -58,7 +58,7 @@ static void closeSession(ROUTER *instance, void *router_session);
static void freeSession(ROUTER *instance, void *router_session);
static int execute(ROUTER *instance, void *router_session, GWBUF *queue);
static void diagnostics(ROUTER *instance, DCB *dcb);
static int getCapabilities();
static uint64_t getCapabilities(void);
/** The module object definition */
static ROUTER_OBJECT MyObject =
@ -302,7 +302,7 @@ diagnostics(ROUTER *instance, DCB *dcb)
return; /* Nothing to do currently */
}
static int getCapabilities()
static uint64_t getCapabilities(void)
{
return 0;
}

View File

@ -57,7 +57,7 @@ static void closeSession(ROUTER *instance, void *router_session);
static void freeSession(ROUTER *instance, void *router_session);
static int execute(ROUTER *instance, void *router_session, GWBUF *queue);
static void diagnostics(ROUTER *instance, DCB *dcb);
static int getCapabilities ();
static uint64_t getCapabilities ();
/** The module object definition */
static ROUTER_OBJECT MyObject =
@ -333,7 +333,7 @@ diagnostics(ROUTER *instance, DCB *dcb)
return; /* Nothing to do currently */
}
static int getCapabilities()
static uint64_t getCapabilities(void)
{
return 0;
}

View File

@ -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>

View File

@ -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 */
@ -79,7 +77,7 @@ static void closeSession(ROUTER *instance, void *router_session);
static void freeSession(ROUTER *instance, void *router_session);
static int execute(ROUTER *instance, void *router_session, GWBUF *queue);
static void diagnostics(ROUTER *instance, DCB *dcb);
static int getCapabilities();
static uint64_t getCapabilities(void);
static void handleError(ROUTER *instance,
void *router_session,
GWBUF *errbuf,
@ -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;
}
@ -409,8 +400,8 @@ diagnostics(ROUTER *instance, DCB *dcb)
*
* Not used for the maxinfo router
*/
static int
getCapabilities()
static uint64_t
getCapabilities(void)
{
return 0;
}
@ -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;
}

View File

@ -59,7 +59,6 @@ typedef struct router_client_session
DCB *backend_dcb; /*< DCB Connection to the backend */
DCB *client_dcb; /**< Client DCB */
struct router_client_session *next;
int rses_capabilities; /*< input type, for example */
#if defined(SS_DEBUG)
skygw_chk_t rses_chk_tail;
#endif

View File

@ -111,7 +111,7 @@ static void clientReply(ROUTER *instance, void *router_session, GWBUF *queue,
DCB *backend_dcb);
static void handleError(ROUTER *instance, void *router_session, GWBUF *errbuf,
DCB *problem_dcb, error_action_t action, bool *succp);
static int getCapabilities();
static uint64_t getCapabilities(void);
/** The module object definition */
@ -561,8 +561,6 @@ newSession(ROUTER *instance, SESSION *session)
}
}
client_rses->rses_capabilities = RCAP_TYPE_PACKET_INPUT;
/*
* We now have the server with the least connections.
* Bump the connection count for this server
@ -635,9 +633,8 @@ static void freeSession(ROUTER* router_instance, void* router_client_ses)
ROUTER_INSTANCE* router = (ROUTER_INSTANCE *) router_instance;
ROUTER_CLIENT_SES* router_cli_ses =
(ROUTER_CLIENT_SES *) router_client_ses;
int prev_val;
prev_val = atomic_add(&router_cli_ses->backend->current_connection_count, -1);
ss_debug(int prev_val = ) atomic_add(&router_cli_ses->backend->current_connection_count, -1);
ss_dassert(prev_val > 0);
spinlock_acquire(&router->lock);
@ -987,9 +984,9 @@ static void rses_end_locked_router_action(ROUTER_CLIENT_SES* rses)
spinlock_release(&rses->rses_lock);
}
static int getCapabilities()
static uint64_t getCapabilities(void)
{
return RCAP_TYPE_PACKET_INPUT;
return RCAP_TYPE_NONE;
}
/********************************

View File

@ -82,7 +82,7 @@ static void clientReply(ROUTER *instance, void *router_session, GWBUF *queue,
static void handleError(ROUTER *instance, void *router_session,
GWBUF *errmsgbuf, DCB *backend_dcb,
error_action_t action, bool *succp);
static int getCapabilities();
static uint64_t getCapabilities(void);
/*
* End of the API functions; now the module structure that links to them.
@ -1055,14 +1055,14 @@ lock_failed:
/**
* @brief Get router capabilities (API)
*
*
* Return a bit map indicating the characteristics of this particular router.
* In this case, the only bit set indicates that the router wants to receive
* data for routing as whole SQL statements.
*
* @return int RCAP_TYPE_STMT_INPUT.
*
* @return RCAP_TYPE_STMT_INPUT.
*/
static int getCapabilities()
static uint64_t getCapabilities(void)
{
return RCAP_TYPE_STMT_INPUT;
}

View File

@ -166,7 +166,7 @@ log_transaction_status(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, qc_query_type_t
MYSQL_GET_PACKET_LEN((unsigned char *)querybuf->start) - 1);
char *data = (char *)&packet[5];
char *contentstr = strndup(data, MXS_MIN(len, RWSPLIT_TRACE_MSG_LEN));
char *qtypestr = qc_get_qtype_str(qtype);
char *qtypestr = qc_typemask_to_string(qtype);
MXS_INFO("> Autocommit: %s, trx is %s, cmd: %s, type: %s, stmt: %s%s %s",
(rses->rses_autocommit_enabled ? "[enabled]" : "[disabled]"),
(rses->rses_transaction_active ? "[open]" : "[not open]"),
@ -221,7 +221,7 @@ handle_target_is_all(route_target_t route_target,
/* NOTE: modutil_get_query is MySQL specific */
char *query_str = modutil_get_query(querybuf);
char *qtype_str = qc_get_qtype_str(qtype);
char *qtype_str = qc_typemask_to_string(qtype);
/* NOTE: packet_type is MySQL specific */
MXS_ERROR("Can't route %s:%s:\"%s\". SELECT with session data "

View File

@ -92,7 +92,7 @@ static route_target_t get_shard_route_target(qc_query_type_t qtype,
bool trx_active,
HINT* hint);
static int getCapabilities();
static uint64_t getCapabilities(void);
static bool connect_backend_servers(backend_ref_t* backend_ref,
int router_nservers,
@ -2007,7 +2007,7 @@ static int routeQuery(ROUTER* instance,
MYSQL_GET_PACKET_LEN((unsigned char *)querybuf->start) - 1);
char* data = (char*)&packet[5];
char* contentstr = strndup(data, len);
char* qtypestr = qc_get_qtype_str(qtype);
char* qtypestr = qc_typemask_to_string(qtype);
MXS_INFO("> Cmd: %s, type: %s, "
"stmt: %s%s %s",
@ -3578,17 +3578,14 @@ static void tracelog_routed_query(ROUTER_CLIENT_SES* rses,
size_t buflen = GWBUF_LENGTH(buf);
char* querystr;
char* startpos = (char *)&packet[5];
BACKEND* b;
backend_type_t be_type;
DCB* dcb;
CHK_BACKEND_REF(bref);
b = bref->bref_backend;
ss_debug(BACKEND *b = bref->bref_backend);
CHK_BACKEND(b);
dcb = bref->bref_dcb;
ss_debug(DCB *dcb = bref->bref_dcb);
CHK_DCB(dcb);
be_type = BACKEND_TYPE(b);
ss_debug(backend_type_t be_type = BACKEND_TYPE(b));
if (GWBUF_IS_TYPE_MYSQL(buf))
{
@ -3642,7 +3639,7 @@ static void tracelog_routed_query(ROUTER_CLIENT_SES* rses,
/**
* Return RCAP_TYPE_STMT_INPUT.
*/
static int getCapabilities()
static uint64_t getCapabilities(void)
{
return RCAP_TYPE_STMT_INPUT;
}

View File

@ -32,7 +32,7 @@ static void freeSession(ROUTER *instance, void *session);
static int routeQuery(ROUTER *instance, void *session, GWBUF *queue);
static void clientReply(ROUTER *instance, void *session, GWBUF *queue, DCB*);
static void diagnostic(ROUTER *instance, DCB *dcb);
static int getCapabilities ();
static uint64_t getCapabilities ();
static void handleError(ROUTER *instance,
void *router_session,
GWBUF *errbuf,
@ -164,7 +164,7 @@ diagnostic(ROUTER *instance, DCB *dcb)
{
}
static int getCapabilities()
static uint64_t getCapabilities(void)
{
return 0;
}

View File

@ -51,7 +51,7 @@ static void closeSession(ROUTER *instance, void *session);
static void freeSession(ROUTER *instance, void *session);
static int routeQuery(ROUTER *instance, void *session, GWBUF *queue);
static void diagnostic(ROUTER *instance, DCB *dcb);
static uint8_t getCapabilities(ROUTER* inst, void* router_session);
static uint64_t getCapabilities(ROUTER* inst, void* router_session);
static ROUTER_OBJECT MyObject =
@ -257,7 +257,7 @@ diagnostic(ROUTER *instance, DCB *dcb)
* @param router_session The router session
* @return Router capabilities bitmask
*/
static uint8_t
static uint64_t
getCapabilities(ROUTER *inst, void *router_session)
{
return 0;