mysql_common.c and mysql_client.c astyled
This commit is contained in:
parent
623acfe1b5
commit
e9f94dcd9d
@ -59,9 +59,9 @@
|
||||
|
||||
#include <maxscale/gw_authenticator.h>
|
||||
|
||||
/* @see function load_module in load_utils.c for explanation of the following
|
||||
* lint directives.
|
||||
*/
|
||||
/* @see function load_module in load_utils.c for explanation of the following
|
||||
* lint directives.
|
||||
*/
|
||||
/*lint -e14 */
|
||||
MODULE_INFO info =
|
||||
{
|
||||
@ -90,7 +90,7 @@ static void mysql_client_auth_error_handling(DCB *dcb, int auth_val);
|
||||
static int gw_read_do_authentication(DCB *dcb, GWBUF *read_buffer, int nbytes_read);
|
||||
static int gw_read_normal_data(DCB *dcb, GWBUF *read_buffer, int nbytes_read);
|
||||
static int gw_read_finish_processing(DCB *dcb, GWBUF *read_buffer, uint8_t capabilities);
|
||||
extern char* create_auth_fail_str(char *username, char *hostaddr, char *sha1, char *db,int);
|
||||
extern char* create_auth_fail_str(char *username, char *hostaddr, char *sha1, char *db, int);
|
||||
static bool ensure_complete_packet(DCB *dcb, GWBUF **read_buffer, int nbytes_read);
|
||||
static void gw_process_one_new_client(DCB *client_dcb);
|
||||
|
||||
@ -185,7 +185,7 @@ int MySQLSendHandshake(DCB* dcb)
|
||||
uint8_t mysql_scramble_len = 21;
|
||||
uint8_t mysql_filler_ten[10];
|
||||
/* uint8_t mysql_last_byte = 0x00; not needed */
|
||||
char server_scramble[GW_MYSQL_SCRAMBLE_SIZE + 1]="";
|
||||
char server_scramble[GW_MYSQL_SCRAMBLE_SIZE + 1] = "";
|
||||
char *version_string;
|
||||
int len_version_string = 0;
|
||||
int id_num;
|
||||
@ -249,7 +249,7 @@ int MySQLSendHandshake(DCB* dcb)
|
||||
gw_mysql_set_byte3(mysql_packet_header, mysql_payload_size);
|
||||
|
||||
// write packet number, now is 0
|
||||
mysql_packet_header[3]= mysql_packet_id;
|
||||
mysql_packet_header[3] = mysql_packet_id;
|
||||
memcpy(outbuf, mysql_packet_header, sizeof(mysql_packet_header));
|
||||
|
||||
// current buffer pointer
|
||||
@ -427,19 +427,19 @@ int gw_read_client_event(DCB* dcb)
|
||||
* will be changed to MYSQL_IDLE (see below).
|
||||
*
|
||||
*/
|
||||
case MXS_AUTH_STATE_MESSAGE_READ:
|
||||
/* After this call read_buffer will point to freed data */
|
||||
if (nbytes_read < 3 || (0 == max_bytes && nbytes_read <
|
||||
(MYSQL_GET_PACKET_LEN((uint8_t *) GWBUF_DATA(read_buffer)) + 4)) ||
|
||||
(0 != max_bytes && nbytes_read < max_bytes))
|
||||
{
|
||||
spinlock_acquire(&dcb->authlock);
|
||||
dcb->dcb_readqueue = read_buffer;
|
||||
spinlock_release(&dcb->authlock);
|
||||
return 0;
|
||||
}
|
||||
return_code = gw_read_do_authentication(dcb, read_buffer, nbytes_read);
|
||||
break;
|
||||
case MXS_AUTH_STATE_MESSAGE_READ:
|
||||
/* After this call read_buffer will point to freed data */
|
||||
if (nbytes_read < 3 || (0 == max_bytes && nbytes_read <
|
||||
(MYSQL_GET_PACKET_LEN((uint8_t *) GWBUF_DATA(read_buffer)) + 4)) ||
|
||||
(0 != max_bytes && nbytes_read < max_bytes))
|
||||
{
|
||||
spinlock_acquire(&dcb->authlock);
|
||||
dcb->dcb_readqueue = read_buffer;
|
||||
spinlock_release(&dcb->authlock);
|
||||
return 0;
|
||||
}
|
||||
return_code = gw_read_do_authentication(dcb, read_buffer, nbytes_read);
|
||||
break;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -448,19 +448,19 @@ int gw_read_client_event(DCB* dcb)
|
||||
* result in a call that comes to this section of code.
|
||||
*
|
||||
*/
|
||||
case MXS_AUTH_STATE_COMPLETE:
|
||||
/* After this call read_buffer will point to freed data */
|
||||
return_code = gw_read_normal_data(dcb, read_buffer, nbytes_read);
|
||||
break;
|
||||
case MXS_AUTH_STATE_COMPLETE:
|
||||
/* After this call read_buffer will point to freed data */
|
||||
return_code = gw_read_normal_data(dcb, read_buffer, nbytes_read);
|
||||
break;
|
||||
|
||||
case MXS_AUTH_STATE_FAILED:
|
||||
gwbuf_free(read_buffer);
|
||||
return_code = 1;
|
||||
break;
|
||||
case MXS_AUTH_STATE_FAILED:
|
||||
gwbuf_free(read_buffer);
|
||||
return_code = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
MXS_ERROR("In mysql_client.c unexpected protocol authentication state");
|
||||
break;
|
||||
default:
|
||||
MXS_ERROR("In mysql_client.c unexpected protocol authentication state");
|
||||
break;
|
||||
}
|
||||
|
||||
return return_code;
|
||||
@ -799,7 +799,7 @@ gw_read_normal_data(DCB *dcb, GWBUF *read_buffer, int nbytes_read)
|
||||
|
||||
/** Ask what type of input the router expects */
|
||||
capabilities = session->service->router->getCapabilities(
|
||||
session->service->router_instance, session->router_session);
|
||||
session->service->router_instance, session->router_session);
|
||||
|
||||
/** Update the current protocol command being executed */
|
||||
if (!process_client_commands(dcb, nbytes_read, &read_buffer))
|
||||
@ -933,84 +933,84 @@ mysql_client_auth_error_handling(DCB *dcb, int auth_val)
|
||||
|
||||
switch (auth_val)
|
||||
{
|
||||
case MXS_AUTH_NO_SESSION:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] session "
|
||||
"creation failed. fd %d, "
|
||||
"state = MYSQL_AUTH_NO_SESSION.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
case MXS_AUTH_NO_SESSION:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] session "
|
||||
"creation failed. fd %d, "
|
||||
"state = MYSQL_AUTH_NO_SESSION.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
|
||||
/** Send ERR 1045 to client */
|
||||
mysql_send_auth_error(dcb,
|
||||
packet_number,
|
||||
0,
|
||||
"failed to create new session");
|
||||
break;
|
||||
case MXS_AUTH_FAILED_DB:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] database "
|
||||
"specified was not valid. fd %d, "
|
||||
"state = MYSQL_FAILED_AUTH_DB.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
/** Send error 1049 to client */
|
||||
message_len = 25 + MYSQL_DATABASE_MAXLEN;
|
||||
/** Send ERR 1045 to client */
|
||||
mysql_send_auth_error(dcb,
|
||||
packet_number,
|
||||
0,
|
||||
"failed to create new session");
|
||||
break;
|
||||
case MXS_AUTH_FAILED_DB:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] database "
|
||||
"specified was not valid. fd %d, "
|
||||
"state = MYSQL_FAILED_AUTH_DB.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
/** Send error 1049 to client */
|
||||
message_len = 25 + MYSQL_DATABASE_MAXLEN;
|
||||
|
||||
fail_str = MXS_CALLOC(1, message_len+1);
|
||||
MXS_ABORT_IF_NULL(fail_str);
|
||||
snprintf(fail_str, message_len, "Unknown database '%s'",
|
||||
(char*)((MYSQL_session *)dcb->data)->db);
|
||||
fail_str = MXS_CALLOC(1, message_len + 1);
|
||||
MXS_ABORT_IF_NULL(fail_str);
|
||||
snprintf(fail_str, message_len, "Unknown database '%s'",
|
||||
(char*)((MYSQL_session *)dcb->data)->db);
|
||||
|
||||
modutil_send_mysql_err_packet(dcb, packet_number, 0, 1049, "42000", fail_str);
|
||||
break;
|
||||
case MXS_AUTH_FAILED_SSL:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] client is "
|
||||
"not SSL capable for SSL listener. fd %d, "
|
||||
"state = MYSQL_FAILED_AUTH_SSL.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
modutil_send_mysql_err_packet(dcb, packet_number, 0, 1049, "42000", fail_str);
|
||||
break;
|
||||
case MXS_AUTH_FAILED_SSL:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] client is "
|
||||
"not SSL capable for SSL listener. fd %d, "
|
||||
"state = MYSQL_FAILED_AUTH_SSL.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
|
||||
/** Send ERR 1045 to client */
|
||||
mysql_send_auth_error(dcb,
|
||||
packet_number,
|
||||
0,
|
||||
"failed to complete SSL authentication");
|
||||
break;
|
||||
case MXS_AUTH_SSL_INCOMPLETE:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] unable to "
|
||||
"complete SSL authentication. fd %d, "
|
||||
"state = MYSQL_AUTH_SSL_INCOMPLETE.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
/** Send ERR 1045 to client */
|
||||
mysql_send_auth_error(dcb,
|
||||
packet_number,
|
||||
0,
|
||||
"failed to complete SSL authentication");
|
||||
break;
|
||||
case MXS_AUTH_SSL_INCOMPLETE:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] unable to "
|
||||
"complete SSL authentication. fd %d, "
|
||||
"state = MYSQL_AUTH_SSL_INCOMPLETE.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
|
||||
/** Send ERR 1045 to client */
|
||||
mysql_send_auth_error(dcb,
|
||||
packet_number,
|
||||
0,
|
||||
"failed to complete SSL authentication");
|
||||
break;
|
||||
case MXS_AUTH_FAILED:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] authentication failed. fd %d, "
|
||||
"state = MYSQL_FAILED_AUTH.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
/** Send error 1045 to client */
|
||||
fail_str = create_auth_fail_str((char *)((MYSQL_session *)dcb->data)->user,
|
||||
dcb->remote,
|
||||
(char*)((MYSQL_session *)dcb->data)->client_sha1,
|
||||
(char*)((MYSQL_session *)dcb->data)->db, auth_val);
|
||||
modutil_send_mysql_err_packet(dcb, packet_number, 0, 1045, "28000", fail_str);
|
||||
break;
|
||||
default:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] authentication failed. fd %d, "
|
||||
"state unrecognized.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
/** Send error 1045 to client */
|
||||
fail_str = create_auth_fail_str((char *)((MYSQL_session *)dcb->data)->user,
|
||||
dcb->remote,
|
||||
(char*)((MYSQL_session *)dcb->data)->client_sha1,
|
||||
(char*)((MYSQL_session *)dcb->data)->db, auth_val);
|
||||
modutil_send_mysql_err_packet(dcb, packet_number, 0, 1045, "28000", fail_str);
|
||||
/** Send ERR 1045 to client */
|
||||
mysql_send_auth_error(dcb,
|
||||
packet_number,
|
||||
0,
|
||||
"failed to complete SSL authentication");
|
||||
break;
|
||||
case MXS_AUTH_FAILED:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] authentication failed. fd %d, "
|
||||
"state = MYSQL_FAILED_AUTH.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
/** Send error 1045 to client */
|
||||
fail_str = create_auth_fail_str((char *)((MYSQL_session *)dcb->data)->user,
|
||||
dcb->remote,
|
||||
(char*)((MYSQL_session *)dcb->data)->client_sha1,
|
||||
(char*)((MYSQL_session *)dcb->data)->db, auth_val);
|
||||
modutil_send_mysql_err_packet(dcb, packet_number, 0, 1045, "28000", fail_str);
|
||||
break;
|
||||
default:
|
||||
MXS_DEBUG("%lu [gw_read_client_event] authentication failed. fd %d, "
|
||||
"state unrecognized.",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
/** Send error 1045 to client */
|
||||
fail_str = create_auth_fail_str((char *)((MYSQL_session *)dcb->data)->user,
|
||||
dcb->remote,
|
||||
(char*)((MYSQL_session *)dcb->data)->client_sha1,
|
||||
(char*)((MYSQL_session *)dcb->data)->db, auth_val);
|
||||
modutil_send_mysql_err_packet(dcb, packet_number, 0, 1045, "28000", fail_str);
|
||||
}
|
||||
MXS_FREE(fail_str);
|
||||
}
|
||||
@ -1145,8 +1145,8 @@ static void gw_process_one_new_client(DCB *client_dcb)
|
||||
/** delete client_dcb */
|
||||
dcb_close(client_dcb);
|
||||
MXS_ERROR("%lu [gw_MySQLAccept] Failed to create "
|
||||
"protocol object for client connection.",
|
||||
pthread_self());
|
||||
"protocol object for client connection.",
|
||||
pthread_self());
|
||||
return;
|
||||
}
|
||||
CHK_PROTOCOL(protocol);
|
||||
@ -1174,29 +1174,29 @@ static void gw_process_one_new_client(DCB *client_dcb)
|
||||
{
|
||||
/* Send a custom error as MySQL command reply */
|
||||
mysql_send_custom_error(client_dcb,
|
||||
1,
|
||||
0,
|
||||
"MaxScale encountered system limit while "
|
||||
"attempting to register on an epoll instance.");
|
||||
1,
|
||||
0,
|
||||
"MaxScale encountered system limit while "
|
||||
"attempting to register on an epoll instance.");
|
||||
|
||||
/** close client_dcb */
|
||||
dcb_close(client_dcb);
|
||||
|
||||
/** Previous state is recovered in poll_add_dcb. */
|
||||
MXS_ERROR("%lu [gw_MySQLAccept] Failed to add dcb %p for "
|
||||
"fd %d to epoll set.",
|
||||
pthread_self(),
|
||||
client_dcb,
|
||||
client_dcb->fd);
|
||||
"fd %d to epoll set.",
|
||||
pthread_self(),
|
||||
client_dcb,
|
||||
client_dcb->fd);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_DEBUG("%lu [gw_MySQLAccept] Added dcb %p for fd "
|
||||
"%d to epoll set.",
|
||||
pthread_self(),
|
||||
client_dcb,
|
||||
client_dcb->fd);
|
||||
"%d to epoll set.",
|
||||
pthread_self(),
|
||||
client_dcb,
|
||||
client_dcb->fd);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1342,7 +1342,7 @@ static int route_by_statement(SESSION* session, GWBUF** p_readbuf)
|
||||
while (tmpbuf != NULL)
|
||||
{
|
||||
ss_dassert(GWBUF_IS_TYPE_MYSQL(tmpbuf));
|
||||
tmpbuf=tmpbuf->next;
|
||||
tmpbuf = tmpbuf->next;
|
||||
}
|
||||
#endif
|
||||
do
|
||||
|
@ -160,24 +160,24 @@ retblock:
|
||||
*/
|
||||
const char* gw_mysql_protocol_state2string (int state)
|
||||
{
|
||||
switch(state)
|
||||
switch (state)
|
||||
{
|
||||
case MXS_AUTH_STATE_INIT:
|
||||
return "Authentication initialized";
|
||||
case MXS_AUTH_STATE_PENDING_CONNECT:
|
||||
return "Network connection pending";
|
||||
case MXS_AUTH_STATE_CONNECTED:
|
||||
return "Network connection created";
|
||||
case MXS_AUTH_STATE_MESSAGE_READ:
|
||||
return "Read server handshake";
|
||||
case MXS_AUTH_STATE_RESPONSE_SENT:
|
||||
return "Response to handshake sent";
|
||||
case MXS_AUTH_STATE_FAILED:
|
||||
return "Authentication failed";
|
||||
case MXS_AUTH_STATE_COMPLETE:
|
||||
return "Authentication is complete.";
|
||||
default:
|
||||
return "MySQL (unknown protocol state)";
|
||||
case MXS_AUTH_STATE_INIT:
|
||||
return "Authentication initialized";
|
||||
case MXS_AUTH_STATE_PENDING_CONNECT:
|
||||
return "Network connection pending";
|
||||
case MXS_AUTH_STATE_CONNECTED:
|
||||
return "Network connection created";
|
||||
case MXS_AUTH_STATE_MESSAGE_READ:
|
||||
return "Read server handshake";
|
||||
case MXS_AUTH_STATE_RESPONSE_SENT:
|
||||
return "Response to handshake sent";
|
||||
case MXS_AUTH_STATE_FAILED:
|
||||
return "Authentication failed";
|
||||
case MXS_AUTH_STATE_COMPLETE:
|
||||
return "Authentication is complete.";
|
||||
default:
|
||||
return "MySQL (unknown protocol state)";
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ GWBUF* mysql_create_custom_error(int packet_number,
|
||||
|
||||
field_count = 0xff;
|
||||
gw_mysql_set_byte2(mysql_err, /* mysql_errno */ 2003);
|
||||
mysql_statemsg[0]='#';
|
||||
mysql_statemsg[0] = '#';
|
||||
memcpy(mysql_statemsg + 1, mysql_state, 5);
|
||||
|
||||
if (msg != NULL)
|
||||
@ -333,8 +333,8 @@ GWBUF* mysql_create_custom_error(int packet_number,
|
||||
*/
|
||||
GWBUF *
|
||||
mysql_create_standard_error(int packet_number,
|
||||
int error_number,
|
||||
const char *error_message)
|
||||
int error_number,
|
||||
const char *error_message)
|
||||
{
|
||||
uint8_t *outbuf = NULL;
|
||||
uint32_t mysql_payload_size = 0;
|
||||
@ -356,7 +356,7 @@ mysql_create_standard_error(int packet_number,
|
||||
gw_mysql_set_byte3(mysql_packet_header, mysql_payload_size);
|
||||
|
||||
// write packet number, now is 0
|
||||
mysql_packet_header[3]= 0;
|
||||
mysql_packet_header[3] = 0;
|
||||
memcpy(outbuf, mysql_packet_header, sizeof(mysql_packet_header));
|
||||
|
||||
// current buffer pointer
|
||||
@ -392,9 +392,9 @@ mysql_create_standard_error(int packet_number,
|
||||
*/
|
||||
int
|
||||
mysql_send_standard_error(DCB *dcb,
|
||||
int packet_number,
|
||||
int error_number,
|
||||
const char *error_message)
|
||||
int packet_number,
|
||||
int error_number,
|
||||
const char *error_message)
|
||||
{
|
||||
GWBUF *buf;
|
||||
buf = mysql_create_standard_error(packet_number, error_number, error_message);
|
||||
@ -469,7 +469,7 @@ int mysql_send_auth_error(DCB *dcb,
|
||||
|
||||
field_count = 0xff;
|
||||
gw_mysql_set_byte2(mysql_err, /*mysql_errno */ 1045);
|
||||
mysql_statemsg[0]='#';
|
||||
mysql_statemsg[0] = '#';
|
||||
memcpy(mysql_statemsg + 1, mysql_state, 5);
|
||||
|
||||
if (mysql_message != NULL)
|
||||
@ -837,27 +837,27 @@ void init_response_status(GWBUF* buf,
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case MYSQL_COM_STMT_PREPARE:
|
||||
gwbuf_copy_data(buf, 9, 2, readbuf);
|
||||
nparam = gw_mysql_get_byte2(readbuf);
|
||||
gwbuf_copy_data(buf, 11, 2, readbuf);
|
||||
nattr = gw_mysql_get_byte2(readbuf);
|
||||
*npackets = 1 + nparam + MXS_MIN(1, nparam) + nattr + MXS_MIN(nattr, 1);
|
||||
break;
|
||||
case MYSQL_COM_STMT_PREPARE:
|
||||
gwbuf_copy_data(buf, 9, 2, readbuf);
|
||||
nparam = gw_mysql_get_byte2(readbuf);
|
||||
gwbuf_copy_data(buf, 11, 2, readbuf);
|
||||
nattr = gw_mysql_get_byte2(readbuf);
|
||||
*npackets = 1 + nparam + MXS_MIN(1, nparam) + nattr + MXS_MIN(nattr, 1);
|
||||
break;
|
||||
|
||||
case MYSQL_COM_QUIT:
|
||||
case MYSQL_COM_STMT_SEND_LONG_DATA:
|
||||
case MYSQL_COM_STMT_CLOSE:
|
||||
*npackets = 0; /*< these don't reply anything */
|
||||
break;
|
||||
case MYSQL_COM_QUIT:
|
||||
case MYSQL_COM_STMT_SEND_LONG_DATA:
|
||||
case MYSQL_COM_STMT_CLOSE:
|
||||
*npackets = 0; /*< these don't reply anything */
|
||||
break;
|
||||
|
||||
default:
|
||||
/**
|
||||
* assume that other session commands respond
|
||||
* OK or ERR
|
||||
*/
|
||||
*npackets = 1;
|
||||
break;
|
||||
default:
|
||||
/**
|
||||
* assume that other session commands respond
|
||||
* OK or ERR
|
||||
*/
|
||||
*npackets = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -923,7 +923,7 @@ char* create_auth_failed_msg(GWBUF*readbuf,
|
||||
uint8_t* sha1)
|
||||
{
|
||||
char* errstr;
|
||||
char* uname=(char *)GWBUF_DATA(readbuf) + 5;
|
||||
char* uname = (char *)GWBUF_DATA(readbuf) + 5;
|
||||
const char* ferrstr = "Access denied for user '%s'@'%s' (using password: %s)";
|
||||
|
||||
/** -4 comes from 2X'%s' minus terminating char */
|
||||
|
Loading…
x
Reference in New Issue
Block a user