Corrected some error messages. Added checking for protocol state in gw_MySQLWrite_backend. If protocol is in MYSQL_AUTH_FAILED state (=authentication is comleted and failed) write to backend is discarded.

This commit is contained in:
VilhoRaatikka
2014-03-19 14:36:47 +02:00
parent 4d1f3f4efc
commit 5ef657d833
4 changed files with 86 additions and 39 deletions

View File

@ -246,7 +246,7 @@ static int gw_read_backend_event(DCB *dcb) {
LOGIF(LE, (skygw_log_write_flush( LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, LOGFILE_ERROR,
"Error : backend server didn't " "Error : Backend server didn't "
"accept authentication for user " "accept authentication for user "
"%s.", "%s.",
current_session->user))); current_session->user)));
@ -522,12 +522,12 @@ static int
gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue) gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
{ {
MySQLProtocol *backend_protocol = dcb->protocol; MySQLProtocol *backend_protocol = dcb->protocol;
int rc; int rc = 0;
/*< /*<
* Don't write to backend if backend_dcb is not in poll set anymore. * Don't write to backend if backend_dcb is not in poll set anymore.
*/ */
spinlock_acquire(&dcb->authlock); spinlock_acquire(&dcb->dcb_initlock);
if (dcb->state != DCB_STATE_POLLING) { if (dcb->state != DCB_STATE_POLLING) {
/*< vraa : errorHandle */ /*< vraa : errorHandle */
@ -542,33 +542,79 @@ gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
dcb, dcb,
dcb->fd, dcb->fd,
STRDCBSTATE(dcb->state)))); STRDCBSTATE(dcb->state))));
spinlock_release(&dcb->dcb_initlock);
spinlock_release(&dcb->authlock); rc = 0;
return 0; goto return_rc;
} }
spinlock_release(&dcb->dcb_initlock);
spinlock_acquire(&dcb->authlock);
/**
* Pick action according to state of protocol.
* If auth failed, return value is 0, write and buffered write
* return 1.
*/
switch(backend_protocol->state) {
case MYSQL_AUTH_FAILED:
{
size_t len;
char* str;
uint8_t* packet = (uint8_t *)queue->start;
uint8_t* startpoint;
len = (size_t)MYSQL_GET_PACKET_LEN(packet);
startpoint = &packet[5];
str = (char *)malloc(len+1);
snprintf(str, len+1, "%s", startpoint);
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Routing query \"%s\" failed due to "
"authentication failure.",
str)));
/** Consume query buffer */
while ((queue = gwbuf_consume(
queue,
GWBUF_LENGTH(queue))) != NULL);
free(str);
}
rc = 0;
spinlock_release(&dcb->authlock);
goto return_rc;
break;
case MYSQL_IDLE:
LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG,
"%lu [gw_MySQLWrite_backend] write to dcb %p "
"fd %d protocol state %s.",
pthread_self(),
dcb,
dcb->fd,
STRPROTOCOLSTATE(backend_protocol->state))));
spinlock_release(&dcb->authlock);
rc = dcb_write(dcb, queue);
goto return_rc;
break;
default:
/*< /*<
* Now put the incoming data to the delay queue unless backend is * Now put the incoming data to the delay queue unless backend is
* connected with auth ok * connected with auth ok
*/ */
if (backend_protocol->state != MYSQL_IDLE) {
LOGIF(LD, (skygw_log_write( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [gw_MySQLWrite_backend] dcb %p fd %d protocol " "%lu [gw_MySQLWrite_backend] delayed write to "
"state %s.", "dcb %p fd %d protocol state %s.",
pthread_self(), pthread_self(),
dcb, dcb,
dcb->fd, dcb->fd,
STRPROTOCOLSTATE(backend_protocol->state)))); STRPROTOCOLSTATE(backend_protocol->state))));
backend_set_delayqueue(dcb, queue); backend_set_delayqueue(dcb, queue);
spinlock_release(&dcb->authlock); spinlock_release(&dcb->authlock);
return 1; rc = 1;
goto return_rc;
break;
} }
return_rc:
/*<
* Now we set the last command received, from the current queue
*/
spinlock_release(&dcb->authlock);
rc = dcb_write(dcb, queue);
return rc; return rc;
} }

View File

@ -706,12 +706,17 @@ int gw_read_client_event(DCB* dcb) {
} }
else else
{ {
LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG,
"%lu [gw_read_client_event] Reading router "
"capabilities failed.",
pthread_self())));
mysql_send_custom_error(dcb, mysql_send_custom_error(dcb,
1, 1,
0, 0,
"Reading router capabilities " "Operation failed. Router "
"failed. Router session is " "session is closed.");
"closed.");
rc = 1; rc = 1;
goto return_rc; goto return_rc;
} }

View File

@ -332,10 +332,6 @@ int gw_receive_backend_auth(
tmpbuf[4], tmpbuf[4],
tmpbuf))); tmpbuf)));
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Invalid authentication message from "
"backend server. Authentication failed.")));
free(tmpbuf); free(tmpbuf);
rc = -1; rc = -1;
} }

View File

@ -589,8 +589,8 @@ routeQuery(ROUTER *instance, void *router_session, GWBUF *queue)
if (rses_is_closed || backend_dcb == NULL) if (rses_is_closed || backend_dcb == NULL)
{ {
LOGIF(LE, (skygw_log_write( LOGIF(LT, (skygw_log_write(
LOGFILE_ERROR, LOGFILE_TRACE,
"Error : Failed to route MySQL command %d to backend " "Error : Failed to route MySQL command %d to backend "
"server.", "server.",
mysql_command))); mysql_command)));