diff options
author | Ashish Agarwal <ashish.y.agarwal@oracle.com> | 2013-07-02 11:58:39 +0530 |
---|---|---|
committer | Ashish Agarwal <ashish.y.agarwal@oracle.com> | 2013-07-02 11:58:39 +0530 |
commit | e879caf845f3f1209eb2065fc4463a293ad9518c (patch) | |
tree | e923a916e758c6cde635765b285649506d0fe00a /sql/sql_class.cc | |
parent | 8723f47391d00fcdac268f276b76047058543706 (diff) | |
download | mariadb-git-e879caf845f3f1209eb2065fc4463a293ad9518c.tar.gz |
WL#7076: Backporting wl6715 to support both formats in 5.5, 5.6, 5.7
Backporting wl6715 to mysql-5.5
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r-- | sql/sql_class.cc | 82 |
1 files changed, 65 insertions, 17 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc index fb4ed99b8bb..fbe42e0c2da 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -675,7 +675,7 @@ char *thd_security_context(THD *thd, char *buffer, unsigned int length, unsigned int max_query_len) { String str(buffer, length, &my_charset_latin1); - const Security_context *sctx= &thd->main_security_ctx; + Security_context *sctx= &thd->main_security_ctx; char header[256]; int len; /* @@ -695,16 +695,16 @@ char *thd_security_context(THD *thd, char *buffer, unsigned int length, str.length(0); str.append(header, len); - if (sctx->host) + if (sctx->get_host()->length()) { str.append(' '); - str.append(sctx->host); + str.append(sctx->get_host()->ptr()); } - if (sctx->ip) + if (sctx->get_ip()->length()) { str.append(' '); - str.append(sctx->ip); + str.append(sctx->get_ip()->ptr()); } if (sctx->user) @@ -3341,7 +3341,10 @@ void THD::set_status_var_init() void Security_context::init() { - host= user= ip= external_user= 0; + user= 0; + ip.set("", 0, system_charset_info); + host.set("", 0, system_charset_info); + external_user.set("", 0, system_charset_info); host_or_ip= "connecting host"; priv_user[0]= priv_host[0]= proxy_user[0]= '\0'; master_access= 0; @@ -3350,29 +3353,35 @@ void Security_context::init() #endif } - void Security_context::destroy() { - // If not pointer to constant - if (host != my_localhost) + if (host.ptr() != my_localhost && host.length()) { - my_free(host); - host= NULL; + char *c= (char *) host.ptr(); + host.set("", 0, system_charset_info); + my_free(c); } - if (user != delayed_user) + + if (user) { my_free(user); user= NULL; } - if (external_user) + if (external_user.length()) { - my_free(external_user); - user= NULL; + char *c= (char *) external_user.ptr(); + external_user.set("", 0, system_charset_info); + my_free(c); + } + + if (ip.length()) + { + char *c= (char *) ip.ptr(); + ip.set("", 0, system_charset_info); + my_free(c); } - my_free(ip); - ip= NULL; } @@ -3392,6 +3401,45 @@ bool Security_context::set_user(char *user_arg) return user == 0; } +String *Security_context::get_host() +{ + return (&host); +} + +String *Security_context::get_ip() +{ + return (&ip); +} + +String *Security_context::get_external_user() +{ + return (&external_user); +} + +void Security_context::set_host(const char *str) +{ + uint len= str ? strlen(str) : 0; + host.set(str, len, system_charset_info); +} + +void Security_context::set_ip(const char *str) +{ + uint len= str ? strlen(str) : 0; + ip.set(str, len, system_charset_info); +} + +void Security_context::set_external_user(const char *str) +{ + uint len= str ? strlen(str) : 0; + external_user.set(str, len, system_charset_info); +} + +void Security_context::set_host(const char * str, size_t len) +{ + host.set(str, len, system_charset_info); + host.c_ptr_quick(); +} + #ifndef NO_EMBEDDED_ACCESS_CHECKS /** Initialize this security context from the passed in credentials |