From 732ff1732f74678dfd80f10ab7b4a92772a0b2df Mon Sep 17 00:00:00 2001 From: Massimiliano Pinto Date: Thu, 13 Jun 2013 10:32:42 +0200 Subject: [PATCH] Added username detection ofr authentication --- core/gateway_mysql_protocol.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/gateway_mysql_protocol.c b/core/gateway_mysql_protocol.c index 9bea5bf61..a5e2cdcb2 100644 --- a/core/gateway_mysql_protocol.c +++ b/core/gateway_mysql_protocol.c @@ -274,21 +274,34 @@ int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) { uint32_t client_capabilities; int compress = -1; int connect_with_db = -1; + uint8_t *client_auth_packet = GWBUF_DATA(queue); + char username[128]=""; + char database[128]=""; + unsigned int auth_token_len = 0; + uint8_t *auth_token = NULL; if (dcb) protocol = DCB_PROTOCOL(dcb, MySQLProtocol); - memcpy(&protocol->client_capabilities, GWBUF_DATA(queue) + 4, 4); + memcpy(&protocol->client_capabilities, client_auth_packet + 4, 4); connect_with_db = GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB & gw_mysql_get_byte4(&protocol->client_capabilities); compress = GW_MYSQL_CAPABILITIES_COMPRESS & gw_mysql_get_byte4(&protocol->client_capabilities); + strncpy(username, client_auth_packet + 4 + 4 + 4 + 1 + 23, 128); + + memcpy(&auth_token_len, client_auth_packet + 4 + 4 + 4 + 1 + 23 + strlen(username) + 1, 1); + + auth_token = (uint8_t *)malloc(auth_token_len); + memcpy(auth_token, client_auth_packet + 4 + 4 + 4 + 1 + 23 + strlen(username) + 1 + 1, auth_token_len); if (connect_with_db) { fprintf(stderr, "<<< Client is connected with db\n"); } else { - fprintf(stderr, "<<< CLient is NOT connected with db\n"); + fprintf(stderr, "<<< Client is NOT connected with db\n"); } + fprintf(stderr, "<<< Client username is [%s]\n", username); + return 0; }