From 27b72884d19f7a09b43a9b5f976dcf4ea0fde770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Tue, 28 Sep 2021 21:38:59 +0200 Subject: [PATCH] Fixed 'user_attributes' not being preserved during 'COM_CHANGE_USER' #2021 --- lib/MySQL_Protocol.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index 2ea257b02..701442a74 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -1347,6 +1347,7 @@ bool MySQL_Protocol::process_pkt_COM_CHANGE_USER(unsigned char *pkt, unsigned in unsigned char *user=NULL; char *password=NULL; char *db=NULL; + char* user_attributes=NULL; mysql_hdr hdr; memcpy(&hdr,pkt,sizeof(mysql_hdr)); int default_hostgroup=-1; @@ -1373,11 +1374,12 @@ bool MySQL_Protocol::process_pkt_COM_CHANGE_USER(unsigned char *pkt, unsigned in password=GloClickHouseAuth->lookup((char *)user, USERNAME_FRONTEND, &_ret_use_ssl, &default_hostgroup, NULL, NULL, &transaction_persistent, NULL, NULL, &sha1_pass); #endif /* PROXYSQLCLICKHOUSE */ } else { - password=GloMyAuth->lookup((char *)user, USERNAME_FRONTEND, &_ret_use_ssl, &default_hostgroup, NULL, NULL, &transaction_persistent, NULL, NULL, &sha1_pass, NULL); + password=GloMyAuth->lookup((char *)user, USERNAME_FRONTEND, &_ret_use_ssl, &default_hostgroup, NULL, NULL, &transaction_persistent, NULL, NULL, &sha1_pass, &user_attributes); } // FIXME: add support for default schema and fast forward, see issue #255 and #256 (*myds)->sess->default_hostgroup=default_hostgroup; (*myds)->sess->transaction_persistent=transaction_persistent; + (*myds)->sess->user_attributes=user_attributes; if (password==NULL) { ret=false; } else { @@ -1477,6 +1479,18 @@ bool MySQL_Protocol::process_pkt_COM_CHANGE_USER(unsigned char *pkt, unsigned in ret = false; return ret; } + + char* user_attributes = (*myds)->sess->user_attributes; + if (strlen(user_attributes)) { + nlohmann::json j_user_attributes = nlohmann::json::parse(user_attributes); + auto default_transaction_isolation = j_user_attributes.find("default-transaction_isolation"); + + if (default_transaction_isolation != j_user_attributes.end()) { + std::string def_trx_isolation_val = + j_user_attributes["default-transaction_isolation"].get(); + mysql_variables.client_set_value((*myds)->sess, SQL_ISOLATION_LEVEL, def_trx_isolation_val.c_str()); + } + } } assert(sess); assert(sess->client_myds);