From fca674b16a5395caf455c3a249608f31a5590bc3 Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Mon, 19 Jan 2015 00:01:08 +0200 Subject: [PATCH] modutil.c: added modutil_reply_auth_error mysql_backend.c:gw_change_user: instead of setting flags directly to replybuffer, set server command to backend's protocol object and reply the message directly to backend where flags are set and it is replied back to client. --- server/core/modutil.c | 21 +++++++++++++++++++- server/include/modutil.h | 1 + server/modules/protocol/mysql_backend.c | 26 +++++++------------------ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/server/core/modutil.c b/server/core/modutil.c index bcfbb0940..07ef9af85 100644 --- a/server/core/modutil.c +++ b/server/core/modutil.c @@ -616,6 +616,25 @@ void modutil_reply_parse_error( modutil_reply_routing_error(backend_dcb, 1064, "42000", errstr, flags); } +/** + * Create authentication error and EPOLLIN event to event queue of the backend DCB. + * When event is notified the error message is processed as error reply and routed + * upstream to client. + * + * @param backend_dcb DCB where event is added + * @param errstr Plain-text string error + * @param flags GWBUF type flags + */ +void modutil_reply_auth_error( + DCB* backend_dcb, + char* errstr, + uint32_t flags) +{ + CHK_DCB(backend_dcb); + modutil_reply_routing_error(backend_dcb, 1045, "28000", errstr, flags); +} + + /** * Create error message and EPOLLIN event to event queue of the backend DCB. * When event is notified the message is processed as error reply and routed @@ -644,7 +663,7 @@ static void modutil_reply_routing_error( { LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, - "Error : Creating buffer for error message failed."))); + "Error : Creating routing error message failed."))); return; } /** Set flags that help router to process reply correctly */ diff --git a/server/include/modutil.h b/server/include/modutil.h index 28abc1686..d40779c4c 100644 --- a/server/include/modutil.h +++ b/server/include/modutil.h @@ -51,6 +51,7 @@ GWBUF* modutil_get_next_MySQL_packet(GWBUF** p_readbuf); GWBUF* modutil_get_complete_packets(GWBUF** p_readbuf); int modutil_MySQL_query_len(GWBUF* buf, int* nbytes_missing); void modutil_reply_parse_error(DCB* backend_dcb, char* errstr, uint32_t flags); +void modutil_reply_auth_error(DCB* backend_dcb, char* errstr, uint32_t flags); GWBUF *modutil_create_mysql_err_msg( int packet_number, diff --git a/server/modules/protocol/mysql_backend.c b/server/modules/protocol/mysql_backend.c index 5d3939868..f7491e418 100644 --- a/server/modules/protocol/mysql_backend.c +++ b/server/modules/protocol/mysql_backend.c @@ -1451,25 +1451,13 @@ static int gw_change_user( 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 commands 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, gwbuf_clone(buf)); - gwbuf_free(buf); + /** + * Add command to backend's protocol, create artificial reply + * packet and add it to client's read buffer. + */ + protocol_add_srv_command((MySQLProtocol*)backend->protocol, + MYSQL_COM_CHANGE_USER); + modutil_reply_auth_error(backend, message, 0); rv = 1; } else { rv = gw_send_change_user_to_backend(database, username, client_sha1, backend_protocol);