Merge branch 'develop' into MAX-316

This commit is contained in:
MassimilianoPinto
2014-10-31 15:45:05 +01:00
16 changed files with 1703 additions and 46 deletions

View File

@ -160,4 +160,17 @@ configure_file(
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/doxygate.in"
"${CMAKE_CURRENT_BINARY_DIR}/doxygate"
IMMEDIATE @ONLY)
add_custom_target(documentation
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygate)
endif()

1520
doxygate.in Normal file

File diff suppressed because it is too large Load Diff

View File

@ -273,7 +273,6 @@ static char* add_slash(char* str);
static bool check_file_and_path(
char* filename,
bool* nameconflict,
bool* writable);
static bool file_is_symlink(char* filename);
@ -2431,9 +2430,16 @@ static bool filewriter_init(
NULL);
}
if (fw->fwr_file[id] == NULL) {
if (fw->fwr_file[id] == NULL)
{
fprintf(stderr,
"Error : opening %s failed, %s. Exiting "
"MaxScale\n",
lf->lf_full_file_name,
strerror(errno));
goto return_succp;
}
if (lf->lf_enabled) {
start_msg_str = strdup("---\tLogging is enabled.\n");
} else {

View File

@ -15,7 +15,8 @@
*
* Copyright MariaDB Corporation Ab 2013-2014
*/
#if !defined(LOG_MANAGER_H)
# define LOG_MANAGER_H
typedef struct filewriter_st filewriter_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_suffix_default(void);
const char* get_logpath_default(void);
#endif /** LOG_MANAGER_H */

View File

@ -44,6 +44,10 @@
#include <skygw_debug.h>
#include <spinlock.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(
GWBUF* buf,
@ -70,22 +74,23 @@ SHARED_BUF *sbuf;
/* Allocate the buffer header */
if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
{
return NULL;
goto retblock;;
}
/* Allocate the shared data buffer */
if ((sbuf = (SHARED_BUF *)malloc(sizeof(SHARED_BUF))) == NULL)
{
free(rval);
return NULL;
goto retblock;
}
/* Allocate the space for the actual data */
if ((sbuf->data = (unsigned char *)malloc(size)) == NULL)
{
ss_dassert(sbuf->data != NULL);
free(rval);
free(sbuf);
return NULL;
goto retblock;
}
spinlock_init(&rval->gwbuf_lock);
rval->start = sbuf->data;
@ -100,6 +105,15 @@ SHARED_BUF *sbuf;
rval->gwbuf_info = GWBUF_INFO_NONE;
rval->gwbuf_bufobj = NULL;
CHK_GWBUF(rval);
retblock:
if (rval == NULL || sbuf == NULL || sbuf->data == NULL)
{
ss_dassert(rval != NULL && sbuf != NULL && sbuf->data != NULL);
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Memory allocation failed due to %s.",
strerror(errno))));
}
return rval;
}
@ -163,6 +177,11 @@ GWBUF *rval;
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;
}
@ -194,6 +213,11 @@ GWBUF *gwbuf_clone_portion(
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;
}
atomic_add(&buf->sbuf->refcount, 1);
@ -438,6 +462,16 @@ void gwbuf_add_buffer_object(
CHK_GWBUF(buf);
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_data = data;
newb->bo_donefun_fp = donefun_fp;
@ -518,8 +552,15 @@ gwbuf_add_property(GWBUF *buf, char *name, char *value)
BUF_PROPERTY *prop;
if ((prop = malloc(sizeof(BUF_PROPERTY))) == NULL)
{
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->value = strdup(value);
spinlock_acquire(&buf->gwbuf_lock);

View File

@ -47,6 +47,8 @@
#include <log_manager.h>
#include <secrets.h>
#include <mysql_client_server_protocol.h>
#include <mysqld_error.h>
#define USERS_QUERY_NO_ROOT " AND user NOT IN ('root')"
#define LOAD_MYSQL_USERS_QUERY "SELECT user, host, password, concat(user,host,password,Select_priv) AS userdata, Select_priv AS anydb FROM mysql.user WHERE user IS NOT NULL AND user <> ''"
@ -494,7 +496,7 @@ getUsers(SERVICE *service, USERS *users)
/* start with users and db grants for users */
if (mysql_query(con, MYSQL_USERS_WITH_DB_COUNT)) {
if (1142 != mysql_errno(con)) {
if (mysql_errno(con) != ER_TABLEACCESS_DENIED_ERROR) {
/* This is an error we cannot handle, return */
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,

View File

@ -1891,7 +1891,6 @@ DCB_CALLBACK *cb, *nextcb;
int
dcb_isvalid(DCB *dcb)
{
DCB *ptr;
int rval = 0;
if (dcb)

View File

@ -541,6 +541,7 @@ static bool resolve_maxscale_homedir(
{
bool succp;
char* tmp;
char* tmp2;
char* log_context = NULL;
ss_dassert(*p_home_dir == NULL);
@ -593,8 +594,9 @@ static bool resolve_maxscale_homedir(
* isn't specified. Thus, try to access $PWD/MaxScale.cnf .
*/
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)
{
log_context = strdup("Current working directory");
@ -646,7 +648,7 @@ check_home_dir:
{
succp = false;
}
free (tmp);
free(tmp);
if (log_context != NULL)
{
@ -880,6 +882,13 @@ static char* get_expanded_pathname(
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);
expanded_path = NULL;
goto return_cnf_file_buf;

View File

@ -245,7 +245,7 @@ GWBUF *modutil_create_mysql_err_msg(
int affected_rows,
int merrno,
const char *statemsg,
const char * msg)
const char *msg)
{
uint8_t *outbuf = NULL;
uint8_t mysql_payload_size = 0;
@ -259,6 +259,10 @@ GWBUF *modutil_create_mysql_err_msg(
const char *mysql_state = NULL;
GWBUF *errbuf = NULL;
if (statemsg == NULL || msg == NULL)
{
return NULL;
}
mysql_errno = (unsigned int)merrno;
mysql_error_msg = msg;
mysql_state = statemsg;
@ -270,9 +274,6 @@ GWBUF *modutil_create_mysql_err_msg(
mysql_statemsg[0]='#';
memcpy(mysql_statemsg+1, mysql_state, 5);
if (msg != NULL) {
mysql_error_msg = msg;
}
mysql_payload_size = sizeof(field_count) +
sizeof(mysql_err) +
sizeof(mysql_statemsg) +
@ -283,8 +284,9 @@ GWBUF *modutil_create_mysql_err_msg(
ss_dassert(errbuf != NULL);
if (errbuf == NULL)
{
return NULL;
}
outbuf = GWBUF_DATA(errbuf);
/** write packet header and packet number */

View File

@ -74,6 +74,7 @@ typedef enum backend_type_t {
struct router_instance;
typedef enum {
TARGET_UNDEFINED = 0x00,
TARGET_MASTER = 0x01,
TARGET_SLAVE = 0x02,
TARGET_NAMED_SERVER = 0x04,

View File

@ -1300,14 +1300,33 @@ static int gw_change_user(
backend->session->client->remote,
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 */
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 */
gwbuf_set_type(buf, GWBUF_TYPE_MYSQL);
gwbuf_set_type(buf, GWBUF_TYPE_SESCMD_RESPONSE);
gwbuf_set_type(buf, GWBUF_TYPE_RESPONSE_END);
/** 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));
gwbuf_free(buf);
rv = 0;
} else {
rv = gw_send_change_user_to_backend(database, username, client_sha1, backend_protocol);
@ -1318,6 +1337,8 @@ static int gw_change_user(
strcpy(current_session->db, database);
memcpy(current_session->client_sha1, client_sha1, sizeof(current_session->client_sha1));
}
retblock:
gwbuf_free(queue);
return rv;

View File

@ -1062,6 +1062,7 @@ int gw_MySQLListener(
"\n* Failed to start listening MySQL due error %d, %s\n\n",
eno,
strerror(eno));
close(l_so);
return 0;
}
// assign l_so to dcb
@ -1191,8 +1192,8 @@ int gw_MySQLAccept(DCB *listener)
strerror(eno))));
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error %d, %s."
"Failed to accept new client connection.",
"Error : Failed to accept new client "
"connection due to %d, %s.",
eno,
strerror(eno))));
rc = 1;
@ -1223,9 +1224,9 @@ int gw_MySQLAccept(DCB *listener)
if (client_dcb == NULL) {
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"%lu [gw_MySQLAccept] Failed to create "
"dcb object for client connection.",
pthread_self())));
"Error : Failed to create "
"DCB object for client connection.")));
close(c_sock);
rc = 1;
goto return_rc;
}
@ -1327,6 +1328,7 @@ int gw_MySQLAccept(DCB *listener)
}
#endif
return_rc:
return rc;
}

View File

@ -1221,7 +1221,7 @@ int gw_send_change_user_to_backend(
* @param scramble_len The scrable size in bytes
* @param username The current username in the authentication request
* @param stage1_hash The SHA1(candidate_password) decoded by this routine
* @return 0 on succesful check or != 0 on failure
* @return 0 on succesful check or 1 on failure
*
*/
int gw_check_mysql_scramble_data(DCB *dcb, uint8_t *token, unsigned int token_len, uint8_t *scramble, unsigned int scramble_len, char *username, uint8_t *stage1_hash) {
@ -1321,7 +1321,12 @@ int gw_check_mysql_scramble_data(DCB *dcb, uint8_t *token, unsigned int token_le
#endif
/* now compare SHA1(SHA1(gateway_password)) and check_hash: return 0 is MYSQL_AUTH_OK */
return memcmp(password, check_hash, SHA_DIGEST_LENGTH);
ret_val = memcmp(password, check_hash, SHA_DIGEST_LENGTH);
if (ret_val != 0)
return 1;
else
return 0;
}
/**
@ -2106,19 +2111,34 @@ char *create_auth_fail_str(
else
db_len = 0;
if (db_len>0)
if (db_len > 0)
{
ferrstr = "Access denied for user '%s'@'%s' (using password: %s) to database '%s'";
}
else
{
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);
if (errstr != NULL) {
if (db_len>0)
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"), db);
else
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"));
if (errstr == NULL)
{
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);
}
else
{
sprintf(errstr, ferrstr, username, hostaddr, (*sha1 == '\0' ? "NO" : "YES"));
}
retblock:
return errstr;
}

View File

@ -654,7 +654,7 @@ DCB* backend_dcb;
* @param instance The router instance
* @param router_session The router session returned from the newSession call
* @param queue The queue of data buffers to route
* @return The number of bytes sent
* @return if succeed 1, otherwise 0
*/
static int
routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
@ -697,20 +697,22 @@ routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
"Error : Failed to route MySQL command %d to backend "
"server.",
mysql_command)));
rc = 0;
goto return_rc;
}
switch(mysql_command) {
case MYSQL_COM_CHANGE_USER:
rc = backend_dcb->func.auth(
backend_dcb,
NULL,
backend_dcb->session,
queue);
break;
default:
rc = backend_dcb->func.write(backend_dcb, queue);
break;
case MYSQL_COM_CHANGE_USER:
rc = backend_dcb->func.auth(
backend_dcb,
NULL,
backend_dcb->session,
queue);
break;
default:
rc = backend_dcb->func.write(backend_dcb, queue);
break;
}
CHK_PROTOCOL(((MySQLProtocol*)backend_dcb->protocol));

View File

@ -1241,7 +1241,7 @@ static route_target_t get_route_target (
target_t use_sql_variables_in,
HINT* hint)
{
route_target_t target;
route_target_t target = TARGET_UNDEFINED;
/**
* These queries are not affected by hints
*/
@ -1355,6 +1355,11 @@ static route_target_t get_route_target (
}
hint = hint->next;
} /*< while (hint != NULL) */
/** If nothing matches then choose the master */
if ((target & (TARGET_ALL|TARGET_SLAVE|TARGET_MASTER)) == target)
{
target = TARGET_MASTER;
}
}
else
{
@ -3824,7 +3829,6 @@ static bool route_session_write(
{
succp = false;
}
}
}
rses_end_locked_router_action(router_cli_ses);
@ -3837,6 +3841,12 @@ static bool route_session_write(
succp = false;
goto return_succp;
}
if (router_cli_ses->rses_nbackends <= 0)
{
succp = false;
goto return_succp;
}
/**
* Additional reference is created to querybuf to
* prevent it from being released before properties
@ -3904,6 +3914,10 @@ static bool route_session_write(
}
}
}
else
{
succp = false;
}
}
/** Unlock router session */
rses_end_locked_router_action(router_cli_ses);

View File

@ -243,6 +243,8 @@ int skygw_rwlock_init(
strerror(err));
goto return_err;
}
*rwlock = rwl;
return_err:
return err;
}