Merge branch 'develop' into firewall
This commit is contained in:
@ -273,7 +273,6 @@ static char* add_slash(char* str);
|
|||||||
|
|
||||||
static bool check_file_and_path(
|
static bool check_file_and_path(
|
||||||
char* filename,
|
char* filename,
|
||||||
bool* nameconflict,
|
|
||||||
bool* writable);
|
bool* writable);
|
||||||
|
|
||||||
static bool file_is_symlink(char* filename);
|
static bool file_is_symlink(char* filename);
|
||||||
|
|||||||
@ -15,7 +15,8 @@
|
|||||||
*
|
*
|
||||||
* Copyright MariaDB Corporation Ab 2013-2014
|
* Copyright MariaDB Corporation Ab 2013-2014
|
||||||
*/
|
*/
|
||||||
|
#if !defined(LOG_MANAGER_H)
|
||||||
|
# define LOG_MANAGER_H
|
||||||
|
|
||||||
typedef struct filewriter_st filewriter_t;
|
typedef struct filewriter_st filewriter_t;
|
||||||
typedef struct logfile_st logfile_t;
|
typedef struct logfile_st logfile_t;
|
||||||
@ -90,3 +91,5 @@ const char* get_msg_suffix_default(void);
|
|||||||
const char* get_err_prefix_default(void);
|
const char* get_err_prefix_default(void);
|
||||||
const char* get_err_suffix_default(void);
|
const char* get_err_suffix_default(void);
|
||||||
const char* get_logpath_default(void);
|
const char* get_logpath_default(void);
|
||||||
|
|
||||||
|
#endif /** LOG_MANAGER_H */
|
||||||
|
|||||||
@ -595,8 +595,8 @@ static skygw_query_type_t resolve_query_type(
|
|||||||
/** Written to binlog, that is, replicated except tmp tables */
|
/** Written to binlog, that is, replicated except tmp tables */
|
||||||
type |= QUERY_TYPE_WRITE; /*< to master */
|
type |= QUERY_TYPE_WRITE; /*< to master */
|
||||||
|
|
||||||
if (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE &&
|
if (lex->sql_command == SQLCOM_CREATE_TABLE &&
|
||||||
lex->sql_command == SQLCOM_CREATE_TABLE)
|
(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
|
||||||
{
|
{
|
||||||
type |= QUERY_TYPE_CREATE_TMP_TABLE; /*< remember in router */
|
type |= QUERY_TYPE_CREATE_TMP_TABLE; /*< remember in router */
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
#include <my_config.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -8,7 +7,7 @@
|
|||||||
#include <mysql.h>
|
#include <mysql.h>
|
||||||
|
|
||||||
static char* server_options[] = {
|
static char* server_options[] = {
|
||||||
"MariaDB Corporation MaxScale",
|
"SkySQL Gateway",
|
||||||
"--datadir=./",
|
"--datadir=./",
|
||||||
"--language=./",
|
"--language=./",
|
||||||
"--skip-innodb",
|
"--skip-innodb",
|
||||||
@ -52,12 +51,13 @@ int main(int argc, char** argv)
|
|||||||
fsz = lseek(fdin,0,SEEK_END);
|
fsz = lseek(fdin,0,SEEK_END);
|
||||||
lseek(fdin,0,SEEK_SET);
|
lseek(fdin,0,SEEK_SET);
|
||||||
|
|
||||||
if(!(buffer = malloc(sizeof(char)*fsz))){
|
if(!(buffer = malloc(sizeof(char)*fsz + 1))){
|
||||||
printf("Error: Failed to allocate memory.");
|
printf("Error: Failed to allocate memory.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
read(fdin,buffer,fsz);
|
read(fdin,buffer,fsz);
|
||||||
|
buffer[fsz] = '\0';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -44,6 +44,10 @@
|
|||||||
#include <skygw_debug.h>
|
#include <skygw_debug.h>
|
||||||
#include <spinlock.h>
|
#include <spinlock.h>
|
||||||
#include <hint.h>
|
#include <hint.h>
|
||||||
|
#include <log_manager.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
extern int lm_enabled_logfiles_bitmask;
|
||||||
|
|
||||||
static buffer_object_t* gwbuf_remove_buffer_object(
|
static buffer_object_t* gwbuf_remove_buffer_object(
|
||||||
GWBUF* buf,
|
GWBUF* buf,
|
||||||
@ -70,22 +74,25 @@ SHARED_BUF *sbuf;
|
|||||||
/* Allocate the buffer header */
|
/* Allocate the buffer header */
|
||||||
if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
|
if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
goto retblock;;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate the shared data buffer */
|
/* Allocate the shared data buffer */
|
||||||
if ((sbuf = (SHARED_BUF *)malloc(sizeof(SHARED_BUF))) == NULL)
|
if ((sbuf = (SHARED_BUF *)malloc(sizeof(SHARED_BUF))) == NULL)
|
||||||
{
|
{
|
||||||
free(rval);
|
free(rval);
|
||||||
return NULL;
|
rval = NULL;
|
||||||
|
goto retblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate the space for the actual data */
|
/* Allocate the space for the actual data */
|
||||||
if ((sbuf->data = (unsigned char *)malloc(size)) == NULL)
|
if ((sbuf->data = (unsigned char *)malloc(size)) == NULL)
|
||||||
{
|
{
|
||||||
|
ss_dassert(sbuf->data != NULL);
|
||||||
free(rval);
|
free(rval);
|
||||||
free(sbuf);
|
free(sbuf);
|
||||||
return NULL;
|
rval = NULL;
|
||||||
|
goto retblock;
|
||||||
}
|
}
|
||||||
spinlock_init(&rval->gwbuf_lock);
|
spinlock_init(&rval->gwbuf_lock);
|
||||||
rval->start = sbuf->data;
|
rval->start = sbuf->data;
|
||||||
@ -100,6 +107,14 @@ SHARED_BUF *sbuf;
|
|||||||
rval->gwbuf_info = GWBUF_INFO_NONE;
|
rval->gwbuf_info = GWBUF_INFO_NONE;
|
||||||
rval->gwbuf_bufobj = NULL;
|
rval->gwbuf_bufobj = NULL;
|
||||||
CHK_GWBUF(rval);
|
CHK_GWBUF(rval);
|
||||||
|
retblock:
|
||||||
|
if (rval == NULL)
|
||||||
|
{
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Memory allocation failed due to %s.",
|
||||||
|
strerror(errno))));
|
||||||
|
}
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,6 +178,11 @@ GWBUF *rval;
|
|||||||
|
|
||||||
if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
|
if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
|
||||||
{
|
{
|
||||||
|
ss_dassert(rval != NULL);
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Memory allocation failed due to %s.",
|
||||||
|
strerror(errno))));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,6 +214,11 @@ GWBUF *gwbuf_clone_portion(
|
|||||||
|
|
||||||
if ((clonebuf = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
|
if ((clonebuf = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
|
||||||
{
|
{
|
||||||
|
ss_dassert(clonebuf != NULL);
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Memory allocation failed due to %s.",
|
||||||
|
strerror(errno))));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
atomic_add(&buf->sbuf->refcount, 1);
|
atomic_add(&buf->sbuf->refcount, 1);
|
||||||
@ -438,6 +463,16 @@ void gwbuf_add_buffer_object(
|
|||||||
|
|
||||||
CHK_GWBUF(buf);
|
CHK_GWBUF(buf);
|
||||||
newb = (buffer_object_t *)malloc(sizeof(buffer_object_t));
|
newb = (buffer_object_t *)malloc(sizeof(buffer_object_t));
|
||||||
|
ss_dassert(newb != NULL);
|
||||||
|
|
||||||
|
if (newb == NULL)
|
||||||
|
{
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Memory allocation failed due to %s.",
|
||||||
|
strerror(errno))));
|
||||||
|
return;
|
||||||
|
}
|
||||||
newb->bo_id = id;
|
newb->bo_id = id;
|
||||||
newb->bo_data = data;
|
newb->bo_data = data;
|
||||||
newb->bo_donefun_fp = donefun_fp;
|
newb->bo_donefun_fp = donefun_fp;
|
||||||
@ -518,8 +553,15 @@ gwbuf_add_property(GWBUF *buf, char *name, char *value)
|
|||||||
BUF_PROPERTY *prop;
|
BUF_PROPERTY *prop;
|
||||||
|
|
||||||
if ((prop = malloc(sizeof(BUF_PROPERTY))) == NULL)
|
if ((prop = malloc(sizeof(BUF_PROPERTY))) == NULL)
|
||||||
return 0;
|
{
|
||||||
|
ss_dassert(prop != NULL);
|
||||||
|
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Memory allocation failed due to %s.",
|
||||||
|
strerror(errno))));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
prop->name = strdup(name);
|
prop->name = strdup(name);
|
||||||
prop->value = strdup(value);
|
prop->value = strdup(value);
|
||||||
spinlock_acquire(&buf->gwbuf_lock);
|
spinlock_acquire(&buf->gwbuf_lock);
|
||||||
|
|||||||
@ -1140,18 +1140,9 @@ dcb_close(DCB *dcb)
|
|||||||
/*<
|
/*<
|
||||||
* Stop dcb's listening and modify state accordingly.
|
* Stop dcb's listening and modify state accordingly.
|
||||||
*/
|
*/
|
||||||
rc = poll_remove_dcb(dcb);
|
if (dcb->state == DCB_STATE_POLLING)
|
||||||
|
|
||||||
ss_dassert(dcb->state == DCB_STATE_NOPOLLING ||
|
|
||||||
dcb->state == DCB_STATE_ZOMBIE);
|
|
||||||
/**
|
|
||||||
* close protocol and router session
|
|
||||||
*/
|
|
||||||
if (dcb->func.close != NULL)
|
|
||||||
{
|
{
|
||||||
dcb->func.close(dcb);
|
rc = poll_remove_dcb(dcb);
|
||||||
}
|
|
||||||
dcb_call_callback(dcb, DCB_REASON_CLOSE);
|
|
||||||
|
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
LOGIF(LD, (skygw_log_write(
|
LOGIF(LD, (skygw_log_write(
|
||||||
@ -1170,6 +1161,18 @@ dcb_close(DCB *dcb)
|
|||||||
dcb,
|
dcb,
|
||||||
STRDCBSTATE(dcb->state))));
|
STRDCBSTATE(dcb->state))));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
ss_dassert(dcb->state == DCB_STATE_NOPOLLING ||
|
||||||
|
dcb->state == DCB_STATE_ZOMBIE);
|
||||||
|
/**
|
||||||
|
* close protocol and router session
|
||||||
|
*/
|
||||||
|
if (dcb->func.close != NULL)
|
||||||
|
{
|
||||||
|
dcb->func.close(dcb);
|
||||||
|
}
|
||||||
|
dcb_call_callback(dcb, DCB_REASON_CLOSE);
|
||||||
|
|
||||||
|
|
||||||
if (dcb->state == DCB_STATE_NOPOLLING)
|
if (dcb->state == DCB_STATE_NOPOLLING)
|
||||||
{
|
{
|
||||||
@ -1891,7 +1894,6 @@ DCB_CALLBACK *cb, *nextcb;
|
|||||||
int
|
int
|
||||||
dcb_isvalid(DCB *dcb)
|
dcb_isvalid(DCB *dcb)
|
||||||
{
|
{
|
||||||
DCB *ptr;
|
|
||||||
int rval = 0;
|
int rval = 0;
|
||||||
|
|
||||||
if (dcb)
|
if (dcb)
|
||||||
|
|||||||
@ -541,6 +541,7 @@ static bool resolve_maxscale_homedir(
|
|||||||
{
|
{
|
||||||
bool succp;
|
bool succp;
|
||||||
char* tmp;
|
char* tmp;
|
||||||
|
char* tmp2;
|
||||||
char* log_context = NULL;
|
char* log_context = NULL;
|
||||||
|
|
||||||
ss_dassert(*p_home_dir == NULL);
|
ss_dassert(*p_home_dir == NULL);
|
||||||
@ -548,6 +549,7 @@ static bool resolve_maxscale_homedir(
|
|||||||
if (*p_home_dir != NULL)
|
if (*p_home_dir != NULL)
|
||||||
{
|
{
|
||||||
log_context = strdup("Command-line argument");
|
log_context = strdup("Command-line argument");
|
||||||
|
tmp = NULL;
|
||||||
goto check_home_dir;
|
goto check_home_dir;
|
||||||
}
|
}
|
||||||
/*<
|
/*<
|
||||||
@ -593,7 +595,8 @@ static bool resolve_maxscale_homedir(
|
|||||||
* isn't specified. Thus, try to access $PWD/MaxScale.cnf .
|
* isn't specified. Thus, try to access $PWD/MaxScale.cnf .
|
||||||
*/
|
*/
|
||||||
tmp = strndup(getenv("PWD"), PATH_MAX);
|
tmp = strndup(getenv("PWD"), PATH_MAX);
|
||||||
get_expanded_pathname(p_home_dir, tmp, default_cnf_fname);
|
tmp2 = get_expanded_pathname(p_home_dir, tmp, default_cnf_fname);
|
||||||
|
free(tmp2); /*< full path isn't needed so simply free it */
|
||||||
|
|
||||||
if (*p_home_dir != NULL)
|
if (*p_home_dir != NULL)
|
||||||
{
|
{
|
||||||
@ -638,7 +641,7 @@ check_home_dir:
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Using %s as MAXSCALE_HOME = %s\n",
|
"Using %s as MAXSCALE_HOME = %s\n",
|
||||||
log_context,
|
log_context,
|
||||||
tmp);
|
(tmp == NULL ? *p_home_dir : tmp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -646,7 +649,10 @@ check_home_dir:
|
|||||||
{
|
{
|
||||||
succp = false;
|
succp = false;
|
||||||
}
|
}
|
||||||
free (tmp);
|
if (tmp != NULL)
|
||||||
|
{
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
if (log_context != NULL)
|
if (log_context != NULL)
|
||||||
{
|
{
|
||||||
@ -880,6 +886,13 @@ static char* get_expanded_pathname(
|
|||||||
|
|
||||||
if (cnf_file_buf == NULL)
|
if (cnf_file_buf == NULL)
|
||||||
{
|
{
|
||||||
|
ss_dassert(cnf_file_buf != NULL);
|
||||||
|
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Memory allocation failed due to %s.",
|
||||||
|
strerror(errno))));
|
||||||
|
|
||||||
free(expanded_path);
|
free(expanded_path);
|
||||||
expanded_path = NULL;
|
expanded_path = NULL;
|
||||||
goto return_cnf_file_buf;
|
goto return_cnf_file_buf;
|
||||||
|
|||||||
@ -245,7 +245,7 @@ GWBUF *modutil_create_mysql_err_msg(
|
|||||||
int affected_rows,
|
int affected_rows,
|
||||||
int merrno,
|
int merrno,
|
||||||
const char *statemsg,
|
const char *statemsg,
|
||||||
const char * msg)
|
const char *msg)
|
||||||
{
|
{
|
||||||
uint8_t *outbuf = NULL;
|
uint8_t *outbuf = NULL;
|
||||||
uint8_t mysql_payload_size = 0;
|
uint8_t mysql_payload_size = 0;
|
||||||
@ -259,6 +259,10 @@ GWBUF *modutil_create_mysql_err_msg(
|
|||||||
const char *mysql_state = NULL;
|
const char *mysql_state = NULL;
|
||||||
GWBUF *errbuf = NULL;
|
GWBUF *errbuf = NULL;
|
||||||
|
|
||||||
|
if (statemsg == NULL || msg == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
mysql_errno = (unsigned int)merrno;
|
mysql_errno = (unsigned int)merrno;
|
||||||
mysql_error_msg = msg;
|
mysql_error_msg = msg;
|
||||||
mysql_state = statemsg;
|
mysql_state = statemsg;
|
||||||
@ -270,9 +274,6 @@ GWBUF *modutil_create_mysql_err_msg(
|
|||||||
mysql_statemsg[0]='#';
|
mysql_statemsg[0]='#';
|
||||||
memcpy(mysql_statemsg+1, mysql_state, 5);
|
memcpy(mysql_statemsg+1, mysql_state, 5);
|
||||||
|
|
||||||
if (msg != NULL) {
|
|
||||||
mysql_error_msg = msg;
|
|
||||||
}
|
|
||||||
mysql_payload_size = sizeof(field_count) +
|
mysql_payload_size = sizeof(field_count) +
|
||||||
sizeof(mysql_err) +
|
sizeof(mysql_err) +
|
||||||
sizeof(mysql_statemsg) +
|
sizeof(mysql_statemsg) +
|
||||||
@ -283,8 +284,9 @@ GWBUF *modutil_create_mysql_err_msg(
|
|||||||
ss_dassert(errbuf != NULL);
|
ss_dassert(errbuf != NULL);
|
||||||
|
|
||||||
if (errbuf == NULL)
|
if (errbuf == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
outbuf = GWBUF_DATA(errbuf);
|
outbuf = GWBUF_DATA(errbuf);
|
||||||
|
|
||||||
/** write packet header and packet number */
|
/** write packet header and packet number */
|
||||||
|
|||||||
@ -254,6 +254,7 @@ MAXKEYS key;
|
|||||||
secret_file,
|
secret_file,
|
||||||
errno,
|
errno,
|
||||||
strerror(errno))));
|
strerror(errno))));
|
||||||
|
close(fd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -192,6 +192,7 @@ int i, cflags = REG_ICASE;
|
|||||||
|
|
||||||
if (my_instance->match == NULL || my_instance->replace == NULL)
|
if (my_instance->match == NULL || my_instance->replace == NULL)
|
||||||
{
|
{
|
||||||
|
free(my_instance);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,6 +387,8 @@ regmatch_t match[10];
|
|||||||
free(orig);
|
free(orig);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
free(orig);
|
||||||
|
|
||||||
res_size = 2 * length;
|
res_size = 2 * length;
|
||||||
result = (char *)malloc(res_size);
|
result = (char *)malloc(res_size);
|
||||||
res_length = 0;
|
res_length = 0;
|
||||||
|
|||||||
@ -377,7 +377,7 @@ static int gw_read_backend_event(DCB *dcb) {
|
|||||||
dcb,
|
dcb,
|
||||||
ERRACT_REPLY_CLIENT,
|
ERRACT_REPLY_CLIENT,
|
||||||
&succp);
|
&succp);
|
||||||
|
gwbuf_free(errbuf);
|
||||||
ss_dassert(!succp);
|
ss_dassert(!succp);
|
||||||
LOGIF(LD, (skygw_log_write(
|
LOGIF(LD, (skygw_log_write(
|
||||||
LOGFILE_DEBUG,
|
LOGFILE_DEBUG,
|
||||||
@ -459,6 +459,7 @@ static int gw_read_backend_event(DCB *dcb) {
|
|||||||
dcb,
|
dcb,
|
||||||
ERRACT_NEW_CONNECTION,
|
ERRACT_NEW_CONNECTION,
|
||||||
&succp);
|
&succp);
|
||||||
|
gwbuf_free(errbuf);
|
||||||
|
|
||||||
if (!succp)
|
if (!succp)
|
||||||
{
|
{
|
||||||
@ -848,6 +849,7 @@ static int gw_error_backend_event(DCB *dcb)
|
|||||||
dcb,
|
dcb,
|
||||||
ERRACT_NEW_CONNECTION,
|
ERRACT_NEW_CONNECTION,
|
||||||
&succp);
|
&succp);
|
||||||
|
gwbuf_free(errbuf);
|
||||||
|
|
||||||
/** There are not required backends available, close session. */
|
/** There are not required backends available, close session. */
|
||||||
if (!succp) {
|
if (!succp) {
|
||||||
@ -1031,7 +1033,8 @@ gw_backend_hangup(DCB *dcb)
|
|||||||
ERRACT_NEW_CONNECTION,
|
ERRACT_NEW_CONNECTION,
|
||||||
&succp);
|
&succp);
|
||||||
|
|
||||||
/** There are not required backends available, close session. */
|
gwbuf_free(errbuf);
|
||||||
|
/** There are no required backends available, close session. */
|
||||||
if (!succp)
|
if (!succp)
|
||||||
{
|
{
|
||||||
#if defined(SS_DEBUG)
|
#if defined(SS_DEBUG)
|
||||||
@ -1039,7 +1042,6 @@ gw_backend_hangup(DCB *dcb)
|
|||||||
LOGFILE_ERROR,
|
LOGFILE_ERROR,
|
||||||
"Backend hangup -> closing session.")));
|
"Backend hangup -> closing session.")));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
spinlock_acquire(&session->ses_lock);
|
spinlock_acquire(&session->ses_lock);
|
||||||
session->state = SESSION_STATE_STOPPING;
|
session->state = SESSION_STATE_STOPPING;
|
||||||
spinlock_release(&session->ses_lock);
|
spinlock_release(&session->ses_lock);
|
||||||
@ -1176,6 +1178,7 @@ static int backend_write_delayqueue(DCB *dcb)
|
|||||||
dcb,
|
dcb,
|
||||||
ERRACT_NEW_CONNECTION,
|
ERRACT_NEW_CONNECTION,
|
||||||
&succp);
|
&succp);
|
||||||
|
gwbuf_free(errbuf);
|
||||||
|
|
||||||
if (!succp)
|
if (!succp)
|
||||||
{
|
{
|
||||||
@ -1300,15 +1303,34 @@ static int gw_change_user(
|
|||||||
backend->session->client->remote,
|
backend->session->client->remote,
|
||||||
password_set,
|
password_set,
|
||||||
"");
|
"");
|
||||||
|
if (message == NULL)
|
||||||
|
{
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Creating error message failed.")));
|
||||||
|
rv = 0;
|
||||||
|
goto retblock;
|
||||||
|
}
|
||||||
/** TODO: Add custom message indicating that retry would probably help */
|
/** TODO: Add custom message indicating that retry would probably help */
|
||||||
buf = modutil_create_mysql_err_msg(1, 0, 1045, "28000", message);
|
buf = modutil_create_mysql_err_msg(1, 0, 1045, "28000", message);
|
||||||
|
free(message);
|
||||||
|
|
||||||
|
if (buf == NULL)
|
||||||
|
{
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Creating buffer for error message failed.")));
|
||||||
|
rv = 0;
|
||||||
|
goto retblock;
|
||||||
|
}
|
||||||
/** Set flags that help router to identify session commans reply */
|
/** Set flags that help router to identify session commans reply */
|
||||||
gwbuf_set_type(buf, GWBUF_TYPE_MYSQL);
|
gwbuf_set_type(buf, GWBUF_TYPE_MYSQL);
|
||||||
gwbuf_set_type(buf, GWBUF_TYPE_SESCMD_RESPONSE);
|
gwbuf_set_type(buf, GWBUF_TYPE_SESCMD_RESPONSE);
|
||||||
gwbuf_set_type(buf, GWBUF_TYPE_RESPONSE_END);
|
gwbuf_set_type(buf, GWBUF_TYPE_RESPONSE_END);
|
||||||
/** Create an incoming event for backend DCB */
|
/** Create an incoming event for backend DCB */
|
||||||
poll_add_epollin_event_to_dcb(backend, buf);
|
poll_add_epollin_event_to_dcb(backend, gwbuf_clone(buf));
|
||||||
rv = 0;
|
gwbuf_free(buf);
|
||||||
|
rv = 1;
|
||||||
} else {
|
} else {
|
||||||
rv = gw_send_change_user_to_backend(database, username, client_sha1, backend_protocol);
|
rv = gw_send_change_user_to_backend(database, username, client_sha1, backend_protocol);
|
||||||
/*
|
/*
|
||||||
@ -1318,6 +1340,8 @@ static int gw_change_user(
|
|||||||
strcpy(current_session->db, database);
|
strcpy(current_session->db, database);
|
||||||
memcpy(current_session->client_sha1, client_sha1, sizeof(current_session->client_sha1));
|
memcpy(current_session->client_sha1, client_sha1, sizeof(current_session->client_sha1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retblock:
|
||||||
gwbuf_free(queue);
|
gwbuf_free(queue);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
|||||||
@ -430,7 +430,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
|
|||||||
|
|
||||||
connect_with_db =
|
connect_with_db =
|
||||||
GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB & gw_mysql_get_byte4(
|
GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB & gw_mysql_get_byte4(
|
||||||
&protocol->client_capabilities);
|
(uint32_t *)&protocol->client_capabilities);
|
||||||
/*
|
/*
|
||||||
compress =
|
compress =
|
||||||
GW_MYSQL_CAPABILITIES_COMPRESS & gw_mysql_get_byte4(
|
GW_MYSQL_CAPABILITIES_COMPRESS & gw_mysql_get_byte4(
|
||||||
@ -859,6 +859,7 @@ int gw_read_client_event(
|
|||||||
dcb,
|
dcb,
|
||||||
ERRACT_REPLY_CLIENT,
|
ERRACT_REPLY_CLIENT,
|
||||||
&succp);
|
&succp);
|
||||||
|
gwbuf_free(errbuf);
|
||||||
ss_dassert(!succp);
|
ss_dassert(!succp);
|
||||||
|
|
||||||
dcb_close(dcb);
|
dcb_close(dcb);
|
||||||
@ -1017,7 +1018,7 @@ int gw_MySQLListener(
|
|||||||
errno,
|
errno,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
fprintf(stderr, "* Can't bind to %s\n\n", config_bind);
|
fprintf(stderr, "* Can't bind to %s\n\n", config_bind);
|
||||||
|
close(l_so);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1039,13 +1040,14 @@ int gw_MySQLListener(
|
|||||||
errno,
|
errno,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
fprintf(stderr, "* Can't bind to %s\n\n", config_bind);
|
fprintf(stderr, "* Can't bind to %s\n\n", config_bind);
|
||||||
|
close(l_so);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "* Socket Family %i not supported\n", current_addr->sa_family);
|
fprintf(stderr, "* Socket Family %i not supported\n", current_addr->sa_family);
|
||||||
|
close(l_so);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1062,6 +1064,7 @@ int gw_MySQLListener(
|
|||||||
"\n* Failed to start listening MySQL due error %d, %s\n\n",
|
"\n* Failed to start listening MySQL due error %d, %s\n\n",
|
||||||
eno,
|
eno,
|
||||||
strerror(eno));
|
strerror(eno));
|
||||||
|
close(l_so);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// assign l_so to dcb
|
// assign l_so to dcb
|
||||||
@ -1191,8 +1194,8 @@ int gw_MySQLAccept(DCB *listener)
|
|||||||
strerror(eno))));
|
strerror(eno))));
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
LOGFILE_ERROR,
|
LOGFILE_ERROR,
|
||||||
"Error %d, %s."
|
"Error : Failed to accept new client "
|
||||||
"Failed to accept new client connection.",
|
"connection due to %d, %s.",
|
||||||
eno,
|
eno,
|
||||||
strerror(eno))));
|
strerror(eno))));
|
||||||
rc = 1;
|
rc = 1;
|
||||||
@ -1223,9 +1226,9 @@ int gw_MySQLAccept(DCB *listener)
|
|||||||
if (client_dcb == NULL) {
|
if (client_dcb == NULL) {
|
||||||
LOGIF(LE, (skygw_log_write_flush(
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
LOGFILE_ERROR,
|
LOGFILE_ERROR,
|
||||||
"%lu [gw_MySQLAccept] Failed to create "
|
"Error : Failed to create "
|
||||||
"dcb object for client connection.",
|
"DCB object for client connection.")));
|
||||||
pthread_self())));
|
close(c_sock);
|
||||||
rc = 1;
|
rc = 1;
|
||||||
goto return_rc;
|
goto return_rc;
|
||||||
}
|
}
|
||||||
@ -1327,6 +1330,7 @@ int gw_MySQLAccept(DCB *listener)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return_rc:
|
return_rc:
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2111,19 +2111,34 @@ char *create_auth_fail_str(
|
|||||||
else
|
else
|
||||||
db_len = 0;
|
db_len = 0;
|
||||||
|
|
||||||
if (db_len>0)
|
if (db_len > 0)
|
||||||
|
{
|
||||||
ferrstr = "Access denied for user '%s'@'%s' (using password: %s) to database '%s'";
|
ferrstr = "Access denied for user '%s'@'%s' (using password: %s) to database '%s'";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
ferrstr = "Access denied for user '%s'@'%s' (using password: %s)";
|
ferrstr = "Access denied for user '%s'@'%s' (using password: %s)";
|
||||||
|
}
|
||||||
errstr = (char *)malloc(strlen(username)+strlen(ferrstr)+strlen(hostaddr)+strlen("YES")-6 + db_len + ((db_len > 0) ? (strlen(" to database ") +2) : 0) + 1);
|
errstr = (char *)malloc(strlen(username)+strlen(ferrstr)+strlen(hostaddr)+strlen("YES")-6 + db_len + ((db_len > 0) ? (strlen(" to database ") +2) : 0) + 1);
|
||||||
|
|
||||||
if (errstr != NULL) {
|
if (errstr == NULL)
|
||||||
if (db_len>0)
|
{
|
||||||
|
LOGIF(LE, (skygw_log_write_flush(
|
||||||
|
LOGFILE_ERROR,
|
||||||
|
"Error : Memory allocation failed due to %s.",
|
||||||
|
strerror(errno))));
|
||||||
|
goto retblock;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (db_len > 0)
|
||||||
|
{
|
||||||
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"), db);
|
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"), db);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"));
|
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retblock:
|
||||||
return errstr;
|
return errstr;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -631,7 +631,7 @@ char *ptr, *lptr;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
if (i >= MAXARGS)
|
if (i >= MAXARGS-1)
|
||||||
break;
|
break;
|
||||||
args[i] = ptr + 1;
|
args[i] = ptr + 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -654,7 +654,7 @@ DCB* backend_dcb;
|
|||||||
* @param instance The router instance
|
* @param instance The router instance
|
||||||
* @param router_session The router session returned from the newSession call
|
* @param router_session The router session returned from the newSession call
|
||||||
* @param queue The queue of data buffers to route
|
* @param queue The queue of data buffers to route
|
||||||
* @return The number of bytes sent
|
* @return if succeed 1, otherwise 0
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
|
routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
|
||||||
@ -697,6 +697,7 @@ routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
|
|||||||
"Error : Failed to route MySQL command %d to backend "
|
"Error : Failed to route MySQL command %d to backend "
|
||||||
"server.",
|
"server.",
|
||||||
mysql_command)));
|
mysql_command)));
|
||||||
|
rc = 0;
|
||||||
goto return_rc;
|
goto return_rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -708,6 +709,7 @@ routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
|
|||||||
backend_dcb->session,
|
backend_dcb->session,
|
||||||
queue);
|
queue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
rc = backend_dcb->func.write(backend_dcb, queue);
|
rc = backend_dcb->func.write(backend_dcb, queue);
|
||||||
break;
|
break;
|
||||||
@ -813,21 +815,33 @@ clientReply(
|
|||||||
* @param action The action: REPLY, REPLY_AND_CLOSE, NEW_CONNECTION
|
* @param action The action: REPLY, REPLY_AND_CLOSE, NEW_CONNECTION
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void
|
static void handleError(
|
||||||
handleError(
|
|
||||||
ROUTER *instance,
|
ROUTER *instance,
|
||||||
void *router_session,
|
void *router_session,
|
||||||
GWBUF *errbuf,
|
GWBUF *errbuf,
|
||||||
DCB *backend_dcb,
|
DCB *backend_dcb,
|
||||||
error_action_t action,
|
error_action_t action,
|
||||||
bool *succp)
|
bool *succp)
|
||||||
|
|
||||||
{
|
{
|
||||||
DCB *client = NULL;
|
DCB *client_dcb;
|
||||||
SESSION *session = backend_dcb->session;
|
SESSION *session = backend_dcb->session;
|
||||||
client = session->client;
|
session_state_t sesstate;
|
||||||
|
|
||||||
|
spinlock_acquire(&session->ses_lock);
|
||||||
|
sesstate = session->state;
|
||||||
|
client_dcb = session->client;
|
||||||
|
spinlock_release(&session->ses_lock);
|
||||||
|
ss_dassert(client_dcb != NULL);
|
||||||
|
|
||||||
|
if (sesstate == SESSION_STATE_ROUTER_READY)
|
||||||
|
{
|
||||||
|
CHK_DCB(client_dcb);
|
||||||
|
client_dcb->func.write(client_dcb, gwbuf_clone(errbuf));
|
||||||
|
}
|
||||||
|
|
||||||
/** false because connection is not available anymore */
|
/** false because connection is not available anymore */
|
||||||
*succp = false;
|
*succp = false;
|
||||||
ss_dassert(client != NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** to be inline'd */
|
/** to be inline'd */
|
||||||
|
|||||||
@ -3829,7 +3829,6 @@ static bool route_session_write(
|
|||||||
{
|
{
|
||||||
succp = false;
|
succp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rses_end_locked_router_action(router_cli_ses);
|
rses_end_locked_router_action(router_cli_ses);
|
||||||
@ -3842,6 +3841,12 @@ static bool route_session_write(
|
|||||||
succp = false;
|
succp = false;
|
||||||
goto return_succp;
|
goto return_succp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (router_cli_ses->rses_nbackends <= 0)
|
||||||
|
{
|
||||||
|
succp = false;
|
||||||
|
goto return_succp;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Additional reference is created to querybuf to
|
* Additional reference is created to querybuf to
|
||||||
* prevent it from being released before properties
|
* prevent it from being released before properties
|
||||||
@ -3909,6 +3914,10 @@ static bool route_session_write(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
succp = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/** Unlock router session */
|
/** Unlock router session */
|
||||||
rses_end_locked_router_action(router_cli_ses);
|
rses_end_locked_router_action(router_cli_ses);
|
||||||
@ -4014,7 +4023,7 @@ static void rwsplit_process_router_options(
|
|||||||
*
|
*
|
||||||
* @param instance The router instance
|
* @param instance The router instance
|
||||||
* @param router_session The router session
|
* @param router_session The router session
|
||||||
* @param message The error message to reply
|
* @param errmsgbuf The error message to reply
|
||||||
* @param backend_dcb The backend DCB
|
* @param backend_dcb The backend DCB
|
||||||
* @param action The action: REPLY, REPLY_AND_CLOSE, NEW_CONNECTION
|
* @param action The action: REPLY, REPLY_AND_CLOSE, NEW_CONNECTION
|
||||||
* @param succp Result of action.
|
* @param succp Result of action.
|
||||||
@ -4093,12 +4102,7 @@ static void handle_error_reply_client(
|
|||||||
if (sesstate == SESSION_STATE_ROUTER_READY)
|
if (sesstate == SESSION_STATE_ROUTER_READY)
|
||||||
{
|
{
|
||||||
CHK_DCB(client_dcb);
|
CHK_DCB(client_dcb);
|
||||||
client_dcb->func.write(client_dcb, errmsg);
|
client_dcb->func.write(client_dcb, gwbuf_clone(errmsg));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while ((errmsg=gwbuf_consume(errmsg, GWBUF_LENGTH(errmsg))) != NULL)
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4148,14 +4152,9 @@ static bool handle_error_new_connection(
|
|||||||
{
|
{
|
||||||
DCB* client_dcb;
|
DCB* client_dcb;
|
||||||
client_dcb = ses->client;
|
client_dcb = ses->client;
|
||||||
client_dcb->func.write(client_dcb, errmsg);
|
client_dcb->func.write(client_dcb, gwbuf_clone(errmsg));
|
||||||
bref_clear_state(bref, BREF_WAITING_RESULT);
|
bref_clear_state(bref, BREF_WAITING_RESULT);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
while ((errmsg=gwbuf_consume(errmsg, GWBUF_LENGTH(errmsg))) != NULL)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
bref_clear_state(bref, BREF_IN_USE);
|
bref_clear_state(bref, BREF_IN_USE);
|
||||||
bref_set_state(bref, BREF_CLOSED);
|
bref_set_state(bref, BREF_CLOSED);
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user