diff options
author | Ashish Agarwal <ashish.y.agarwal@oracle.com> | 2013-08-23 09:07:09 +0530 |
---|---|---|
committer | Ashish Agarwal <ashish.y.agarwal@oracle.com> | 2013-08-23 09:07:09 +0530 |
commit | 292aa926c15f31936ee14bf11dd791847fd7b74d (patch) | |
tree | 01a2e2f69168201021668f8d6144a6aa701c61ad /sql/sql_class.cc | |
parent | 6613734b1abd5b6572963c14034bb64c6d923894 (diff) | |
parent | e879caf845f3f1209eb2065fc4463a293ad9518c (diff) | |
download | mariadb-git-292aa926c15f31936ee14bf11dd791847fd7b74d.tar.gz |
WL#7076: Backporting wl6715 to support both formats
in 5.5, 5.6, 5.7.
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 94a6baf9f92..93f1d8eb3bb 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) @@ -3342,7 +3342,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; @@ -3351,29 +3354,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 && user != delayed_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; } @@ -3393,6 +3402,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 |