Reverted versions
This commit is contained in:
@ -30,12 +30,12 @@
|
|||||||
|
|
||||||
static char *version_str = "V1.0.0";
|
static char *version_str = "V1.0.0";
|
||||||
extern char *gw_strend(register const char *s);
|
extern char *gw_strend(register const char *s);
|
||||||
int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *passwd, MySQLProtocol *conn);
|
static int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *passwd, MySQLProtocol *conn);
|
||||||
int gw_create_backend_connection(DCB *client_dcb, SERVER *server, SESSION *in_session);
|
static int gw_create_backend_connection(DCB *client_dcb, SERVER *server, SESSION *in_session);
|
||||||
int gw_read_backend_event(DCB* dcb);
|
static int gw_read_backend_event(DCB* dcb);
|
||||||
int gw_write_backend_event(DCB *dcb);
|
static int gw_write_backend_event(DCB *dcb);
|
||||||
int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue);
|
static int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue);
|
||||||
int gw_error_backend_event(DCB *dcb);
|
static int gw_error_backend_event(DCB *dcb);
|
||||||
static int gw_backend_close(DCB *dcb);
|
static int gw_backend_close(DCB *dcb);
|
||||||
|
|
||||||
static GWPROTOCOL MyObject = {
|
static GWPROTOCOL MyObject = {
|
||||||
@ -102,10 +102,7 @@ int gw_read_backend_event(DCB *dcb) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((client_protocol->state == MYSQL_WAITING_RESULT) || (client_protocol->state == MYSQL_IDLE)) {
|
if ((client_protocol->state == MYSQL_WAITING_RESULT) || (client_protocol->state == MYSQL_IDLE)) {
|
||||||
int w;
|
|
||||||
int b = -1;
|
int b = -1;
|
||||||
int tot_b = -1;
|
|
||||||
uint8_t *ptr_buffer;
|
|
||||||
GWBUF *buffer, *head;
|
GWBUF *buffer, *head;
|
||||||
|
|
||||||
if (ioctl(dcb->fd, FIONREAD, &b)) {
|
if (ioctl(dcb->fd, FIONREAD, &b)) {
|
||||||
@ -232,7 +229,6 @@ int w, saved_errno = 0;
|
|||||||
}
|
}
|
||||||
|
|
||||||
int gw_error_backend_event(DCB *dcb) {
|
int gw_error_backend_event(DCB *dcb) {
|
||||||
MySQLProtocol *protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
|
|
||||||
|
|
||||||
fprintf(stderr, "#### Handle Backend error function for %i\n", dcb->fd);
|
fprintf(stderr, "#### Handle Backend error function for %i\n", dcb->fd);
|
||||||
|
|
||||||
@ -265,6 +261,7 @@ int gw_error_backend_event(DCB *dcb) {
|
|||||||
fprintf(stderr, "Freeing backend MySQL conn %p, %p\n", dcb->protocol, &dcb->protocol);
|
fprintf(stderr, "Freeing backend MySQL conn %p, %p\n", dcb->protocol, &dcb->protocol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -324,10 +321,11 @@ int gw_create_backend_connection(DCB *backend, SERVER *server, SESSION *session)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
int
|
||||||
gw_backend_close(DCB *dcb)
|
gw_backend_close(DCB *dcb)
|
||||||
{
|
{
|
||||||
dcb_close(dcb);
|
dcb_close(dcb);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -359,7 +357,7 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *pa
|
|||||||
int rv;
|
int rv;
|
||||||
int so = 0;
|
int so = 0;
|
||||||
int ciclo = 0;
|
int ciclo = 0;
|
||||||
char buffer[SMALL_CHUNK];
|
uint8_t buffer[SMALL_CHUNK];
|
||||||
uint8_t packet_buffer[SMALL_CHUNK];
|
uint8_t packet_buffer[SMALL_CHUNK];
|
||||||
uint8_t *payload = NULL;
|
uint8_t *payload = NULL;
|
||||||
int server_protocol;
|
int server_protocol;
|
||||||
@ -385,7 +383,7 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *pa
|
|||||||
if (strlen(dbname))
|
if (strlen(dbname))
|
||||||
curr_db = dbname;
|
curr_db = dbname;
|
||||||
|
|
||||||
if (strlen(passwd))
|
if (strlen((char *)passwd))
|
||||||
curr_passwd = passwd;
|
curr_passwd = passwd;
|
||||||
|
|
||||||
conn->state = MYSQL_ALLOC;
|
conn->state = MYSQL_ALLOC;
|
||||||
@ -668,7 +666,7 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *pa
|
|||||||
|
|
||||||
// 4 + 4 + 4 + 1 + 23 = 36
|
// 4 + 4 + 4 + 1 + 23 = 36
|
||||||
payload += 23;
|
payload += 23;
|
||||||
strcpy(payload, user);
|
memcpy(payload, user, strlen(user));
|
||||||
|
|
||||||
// 4 + 4 + 1 + 23 = 32 + 1 (scramble_len) + 20 (fixed_scramble) + 1 (user NULL term) + 1 (db NULL term) = 55
|
// 4 + 4 + 1 + 23 = 32 + 1 (scramble_len) + 20 (fixed_scramble) + 1 (user NULL term) + 1 (db NULL term) = 55
|
||||||
bytes = 32;
|
bytes = 32;
|
||||||
@ -700,7 +698,7 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *pa
|
|||||||
|
|
||||||
// if the db is not NULL append it
|
// if the db is not NULL append it
|
||||||
if (curr_db) {
|
if (curr_db) {
|
||||||
strcpy(payload, curr_db);
|
memcpy(payload, curr_db, strlen(curr_db));
|
||||||
payload += strlen(curr_db);
|
payload += strlen(curr_db);
|
||||||
payload++;
|
payload++;
|
||||||
bytes += strlen(curr_db);
|
bytes += strlen(curr_db);
|
||||||
@ -708,7 +706,7 @@ int gw_mysql_connect(char *host, int port, char *dbname, char *user, uint8_t *pa
|
|||||||
bytes++;
|
bytes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(payload, "mysql_native_password");
|
memcpy(payload, "mysql_native_password", strlen("mysql_native_password"));
|
||||||
|
|
||||||
payload += strlen("mysql_native_password");
|
payload += strlen("mysql_native_password");
|
||||||
payload++;
|
payload++;
|
||||||
|
@ -112,6 +112,7 @@ GetModuleObject()
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
mysql_send_ok(DCB *dcb, int packet_number, int in_affected_rows, const char* mysql_message) {
|
mysql_send_ok(DCB *dcb, int packet_number, int in_affected_rows, const char* mysql_message) {
|
||||||
|
int n = 0;
|
||||||
uint8_t *outbuf = NULL;
|
uint8_t *outbuf = NULL;
|
||||||
uint8_t mysql_payload_size = 0;
|
uint8_t mysql_payload_size = 0;
|
||||||
uint8_t mysql_packet_header[4];
|
uint8_t mysql_packet_header[4];
|
||||||
@ -199,6 +200,8 @@ mysql_send_custom_error (DCB *dcb, int packet_number, int in_affected_rows, cons
|
|||||||
uint8_t mysql_packet_header[4];
|
uint8_t mysql_packet_header[4];
|
||||||
uint8_t *mysql_payload = NULL;
|
uint8_t *mysql_payload = NULL;
|
||||||
uint8_t field_count = 0;
|
uint8_t field_count = 0;
|
||||||
|
uint8_t affected_rows = 0;
|
||||||
|
uint8_t insert_id = 0;
|
||||||
uint8_t mysql_err[2];
|
uint8_t mysql_err[2];
|
||||||
uint8_t mysql_statemsg[6];
|
uint8_t mysql_statemsg[6];
|
||||||
unsigned int mysql_errno = 0;
|
unsigned int mysql_errno = 0;
|
||||||
@ -278,6 +281,8 @@ mysql_send_auth_error (DCB *dcb, int packet_number, int in_affected_rows, const
|
|||||||
uint8_t mysql_packet_header[4];
|
uint8_t mysql_packet_header[4];
|
||||||
uint8_t *mysql_payload = NULL;
|
uint8_t *mysql_payload = NULL;
|
||||||
uint8_t field_count = 0;
|
uint8_t field_count = 0;
|
||||||
|
uint8_t affected_rows = 0;
|
||||||
|
uint8_t insert_id = 0;
|
||||||
uint8_t mysql_err[2];
|
uint8_t mysql_err[2];
|
||||||
uint8_t mysql_statemsg[6];
|
uint8_t mysql_statemsg[6];
|
||||||
unsigned int mysql_errno = 0;
|
unsigned int mysql_errno = 0;
|
||||||
@ -347,6 +352,7 @@ mysql_send_auth_error (DCB *dcb, int packet_number, int in_affected_rows, const
|
|||||||
int
|
int
|
||||||
MySQLSendHandshake(DCB* dcb)
|
MySQLSendHandshake(DCB* dcb)
|
||||||
{
|
{
|
||||||
|
int n = 0;
|
||||||
uint8_t *outbuf = NULL;
|
uint8_t *outbuf = NULL;
|
||||||
uint8_t mysql_payload_size = 0;
|
uint8_t mysql_payload_size = 0;
|
||||||
uint8_t mysql_packet_header[4];
|
uint8_t mysql_packet_header[4];
|
||||||
@ -410,9 +416,8 @@ MySQLSendHandshake(DCB* dcb)
|
|||||||
mysql_handshake_payload = mysql_handshake_payload + sizeof(mysql_protocol_version);
|
mysql_handshake_payload = mysql_handshake_payload + sizeof(mysql_protocol_version);
|
||||||
|
|
||||||
// write server version plus 0 filler
|
// write server version plus 0 filler
|
||||||
memcpy(mysql_handshake_payload, GW_MYSQL_VERSION, strlen(GW_MYSQL_VERSION));
|
strcpy(mysql_handshake_payload, GW_MYSQL_VERSION);
|
||||||
mysql_handshake_payload = mysql_handshake_payload + strlen(GW_MYSQL_VERSION);
|
mysql_handshake_payload = mysql_handshake_payload + strlen(GW_MYSQL_VERSION);
|
||||||
|
|
||||||
*mysql_handshake_payload = 0x00;
|
*mysql_handshake_payload = 0x00;
|
||||||
|
|
||||||
mysql_handshake_payload++;
|
mysql_handshake_payload++;
|
||||||
@ -502,6 +507,7 @@ MySQLSendHandshake(DCB* dcb)
|
|||||||
|
|
||||||
static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
|
static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
|
||||||
MySQLProtocol *protocol = NULL;
|
MySQLProtocol *protocol = NULL;
|
||||||
|
uint32_t client_capabilities;
|
||||||
int compress = -1;
|
int compress = -1;
|
||||||
int connect_with_db = -1;
|
int connect_with_db = -1;
|
||||||
uint8_t *client_auth_packet = GWBUF_DATA(queue);
|
uint8_t *client_auth_packet = GWBUF_DATA(queue);
|
||||||
@ -511,6 +517,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
|
|||||||
uint8_t *auth_token = NULL;
|
uint8_t *auth_token = NULL;
|
||||||
uint8_t *stage1_hash = NULL;
|
uint8_t *stage1_hash = NULL;
|
||||||
int auth_ret = -1;
|
int auth_ret = -1;
|
||||||
|
SESSION *session = NULL;
|
||||||
MYSQL_session *client_data = NULL;
|
MYSQL_session *client_data = NULL;
|
||||||
|
|
||||||
if (dcb)
|
if (dcb)
|
||||||
@ -528,7 +535,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
|
|||||||
compress = GW_MYSQL_CAPABILITIES_COMPRESS & gw_mysql_get_byte4(&protocol->client_capabilities);
|
compress = GW_MYSQL_CAPABILITIES_COMPRESS & gw_mysql_get_byte4(&protocol->client_capabilities);
|
||||||
|
|
||||||
// now get the user
|
// now get the user
|
||||||
strncpy(username, (char *)(client_auth_packet + 4 + 4 + 4 + 1 + 23), 128);
|
strncpy(username, client_auth_packet + 4 + 4 + 4 + 1 + 23, 128);
|
||||||
fprintf(stderr, "<<< Client username is [%s]\n", username);
|
fprintf(stderr, "<<< Client username is [%s]\n", username);
|
||||||
|
|
||||||
// get the auth token len
|
// get the auth token len
|
||||||
@ -536,7 +543,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
|
|||||||
|
|
||||||
if (connect_with_db) {
|
if (connect_with_db) {
|
||||||
database = client_data->db;
|
database = client_data->db;
|
||||||
strncpy(database, (char *)(client_auth_packet + 4 + 4 + 4 + 1 + 23 + strlen(username) + 1 + 1 + auth_token_len), 128);
|
strncpy(database, client_auth_packet + 4 + 4 + 4 + 1 + 23 + strlen(username) + 1 + 1 + auth_token_len, 128);
|
||||||
fprintf(stderr, "<<< Client selected db is [%s]\n", database);
|
fprintf(stderr, "<<< Client selected db is [%s]\n", database);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "<<< Client is NOT connected with db\n");
|
fprintf(stderr, "<<< Client is NOT connected with db\n");
|
||||||
@ -770,7 +777,11 @@ int gw_read_client_event(DCB* dcb) {
|
|||||||
ROUTER *router_instance = NULL;
|
ROUTER *router_instance = NULL;
|
||||||
void *rsession = NULL;
|
void *rsession = NULL;
|
||||||
MySQLProtocol *protocol = NULL;
|
MySQLProtocol *protocol = NULL;
|
||||||
|
uint8_t buffer[MAX_BUFFER_SIZE] = "";
|
||||||
|
int n = 0;
|
||||||
int b = -1;
|
int b = -1;
|
||||||
|
GWBUF *head = NULL;
|
||||||
|
GWBUF *gw_buffer = NULL;
|
||||||
|
|
||||||
if (dcb) {
|
if (dcb) {
|
||||||
protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
|
protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
|
||||||
@ -844,7 +855,7 @@ int gw_read_client_event(DCB* dcb) {
|
|||||||
router = session->service->router;
|
router = session->service->router;
|
||||||
router_instance = session->service->router_instance;
|
router_instance = session->service->router_instance;
|
||||||
rsession = session->router_session;
|
rsession = session->router_session;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
// read and handle errors & close, or return if busy
|
// read and handle errors & close, or return if busy
|
||||||
@ -931,6 +942,7 @@ int gw_read_client_event(DCB* dcb) {
|
|||||||
//////////////////////////////////////////////
|
//////////////////////////////////////////////
|
||||||
int gw_write_client_event(DCB *dcb) {
|
int gw_write_client_event(DCB *dcb) {
|
||||||
MySQLProtocol *protocol = NULL;
|
MySQLProtocol *protocol = NULL;
|
||||||
|
int n;
|
||||||
|
|
||||||
if (dcb == NULL) {
|
if (dcb == NULL) {
|
||||||
fprintf(stderr, "DCB is NULL, return\n");
|
fprintf(stderr, "DCB is NULL, return\n");
|
||||||
@ -950,6 +962,7 @@ int gw_write_client_event(DCB *dcb) {
|
|||||||
|
|
||||||
if(protocol->state == MYSQL_AUTH_RECV) {
|
if(protocol->state == MYSQL_AUTH_RECV) {
|
||||||
SESSION *session = NULL;
|
SESSION *session = NULL;
|
||||||
|
MYSQL_session *s_data = dcb->data;
|
||||||
|
|
||||||
//write to client mysql AUTH_OK packet, packet n. is 2
|
//write to client mysql AUTH_OK packet, packet n. is 2
|
||||||
mysql_send_ok(dcb, 2, 0, NULL);
|
mysql_send_ok(dcb, 2, 0, NULL);
|
||||||
@ -989,7 +1002,10 @@ int gw_write_client_event(DCB *dcb) {
|
|||||||
///
|
///
|
||||||
int gw_MySQLListener(DCB *listener, char *config_bind) {
|
int gw_MySQLListener(DCB *listener, char *config_bind) {
|
||||||
int l_so;
|
int l_so;
|
||||||
|
int fl;
|
||||||
struct sockaddr_in serv_addr;
|
struct sockaddr_in serv_addr;
|
||||||
|
struct sockaddr_in local;
|
||||||
|
socklen_t addrlen;
|
||||||
char *bind_address_and_port = NULL;
|
char *bind_address_and_port = NULL;
|
||||||
char *p;
|
char *p;
|
||||||
char address[1024]="";
|
char address[1024]="";
|
||||||
@ -1076,7 +1092,9 @@ int gw_MySQLAccept(DCB *listener) {
|
|||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
addrlen = sizeof(local);
|
addrlen = sizeof(local);
|
||||||
DCB *client;
|
DCB *client;
|
||||||
|
SESSION *session;
|
||||||
MySQLProtocol *protocol;
|
MySQLProtocol *protocol;
|
||||||
|
MySQLProtocol *ptr_proto;
|
||||||
int sendbuf = GW_BACKEND_SO_SNDBUF;
|
int sendbuf = GW_BACKEND_SO_SNDBUF;
|
||||||
socklen_t optlen = sizeof(sendbuf);
|
socklen_t optlen = sizeof(sendbuf);
|
||||||
|
|
||||||
@ -1147,6 +1165,8 @@ int gw_MySQLAccept(DCB *listener) {
|
|||||||
static int gw_error_client_event(DCB *dcb) {
|
static int gw_error_client_event(DCB *dcb) {
|
||||||
|
|
||||||
|
|
||||||
|
MySQLProtocol *protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
|
||||||
|
|
||||||
fprintf(stderr, "#### Handle error function gw_error_client_event, for [%i] is [%s]\n", dcb->state, gw_dcb_state2string(dcb->state));
|
fprintf(stderr, "#### Handle error function gw_error_client_event, for [%i] is [%s]\n", dcb->state, gw_dcb_state2string(dcb->state));
|
||||||
|
|
||||||
fprintf(stderr, "#### Handle error function RETURN for [%i] is [%s]\n", dcb->state, gw_dcb_state2string(dcb->state));
|
fprintf(stderr, "#### Handle error function RETURN for [%i] is [%s]\n", dcb->state, gw_dcb_state2string(dcb->state));
|
||||||
@ -1158,5 +1178,4 @@ static int
|
|||||||
gw_client_close(DCB *dcb)
|
gw_client_close(DCB *dcb)
|
||||||
{
|
{
|
||||||
dcb_close(dcb);
|
dcb_close(dcb);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,13 @@
|
|||||||
|
|
||||||
#include "mysql_client_server_protocol.h"
|
#include "mysql_client_server_protocol.h"
|
||||||
|
|
||||||
|
static char *version_str = "V1.0.0";
|
||||||
|
|
||||||
MySQLProtocol *gw_mysql_init(MySQLProtocol *data);
|
MySQLProtocol *gw_mysql_init(MySQLProtocol *data);
|
||||||
void gw_mysql_close(MySQLProtocol **ptr);
|
void gw_mysql_close(MySQLProtocol **ptr);
|
||||||
|
|
||||||
extern int gw_read_backend_event(DCB* dcb);
|
extern gw_read_backend_event(DCB* dcb);
|
||||||
extern int gw_write_backend_event(DCB *dcb);
|
extern gw_write_backend_event(DCB *dcb);
|
||||||
extern int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue);
|
extern int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue);
|
||||||
extern int gw_error_backend_event(DCB *dcb);
|
extern int gw_error_backend_event(DCB *dcb);
|
||||||
|
|
||||||
@ -38,6 +40,8 @@ extern int gw_error_backend_event(DCB *dcb);
|
|||||||
// Initialize mysql protocol struct
|
// Initialize mysql protocol struct
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
MySQLProtocol *gw_mysql_init(MySQLProtocol *data) {
|
MySQLProtocol *gw_mysql_init(MySQLProtocol *data) {
|
||||||
|
int rv = -1;
|
||||||
|
|
||||||
MySQLProtocol *input = NULL;
|
MySQLProtocol *input = NULL;
|
||||||
|
|
||||||
if (input == NULL) {
|
if (input == NULL) {
|
||||||
|
Reference in New Issue
Block a user