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_connect.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_connect.cc')
-rw-r--r-- | sql/sql_connect.cc | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 14a1acdef5e..a948a508d12 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -38,6 +38,7 @@ #include "sql_acl.h" // acl_getroot, NO_ACCESS, SUPER_ACL #include "sql_callback.h" + #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) /* Without SSL the handshake consists of one packet. This packet @@ -490,7 +491,7 @@ static int check_connection(THD *thd) thd->set_active_vio(net->vio); #endif - if (!thd->main_security_ctx.host) // If TCP/IP connection + if (!thd->main_security_ctx.get_host()->length()) // If TCP/IP connection { char ip[NI_MAXHOST]; @@ -512,25 +513,30 @@ static int check_connection(THD *thd) };); /* END : DEBUG */ - if (!(thd->main_security_ctx.ip= my_strdup(ip,MYF(MY_WME)))) + thd->main_security_ctx.set_ip(my_strdup(ip, MYF(MY_WME))); + if (!(thd->main_security_ctx.get_ip()->length())) return 1; /* The error is set by my_strdup(). */ - thd->main_security_ctx.host_or_ip= thd->main_security_ctx.ip; + thd->main_security_ctx.host_or_ip= thd->main_security_ctx.get_ip()->ptr(); if (!(specialflag & SPECIAL_NO_RESOLVE)) { - if (ip_to_hostname(&net->vio->remote, thd->main_security_ctx.ip, - &thd->main_security_ctx.host, &connect_errors)) + char *host= (char *) thd->main_security_ctx.get_host()->ptr(); + if (ip_to_hostname(&net->vio->remote, + thd->main_security_ctx.get_ip()->ptr(), + &host, &connect_errors)) { my_error(ER_BAD_HOST_ERROR, MYF(0)); return 1; } - + thd->main_security_ctx.set_host(host); /* Cut very long hostnames to avoid possible overflows */ - if (thd->main_security_ctx.host) + if (thd->main_security_ctx.get_host()->length()) { - if (thd->main_security_ctx.host != my_localhost) - thd->main_security_ctx.host[min(strlen(thd->main_security_ctx.host), - HOSTNAME_LENGTH)]= 0; - thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host; + if (thd->main_security_ctx.get_host()->ptr() != my_localhost) + thd->main_security_ctx.set_host(thd->main_security_ctx.get_host()->ptr(), + min(thd->main_security_ctx.get_host()->length(), + HOSTNAME_LENGTH)); + thd->main_security_ctx.host_or_ip= + thd->main_security_ctx.get_host()->ptr(); } if (connect_errors > max_connect_errors) { @@ -539,11 +545,14 @@ static int check_connection(THD *thd) } } DBUG_PRINT("info",("Host: %s ip: %s", - (thd->main_security_ctx.host ? - thd->main_security_ctx.host : "unknown host"), - (thd->main_security_ctx.ip ? - thd->main_security_ctx.ip : "unknown ip"))); - if (acl_check_host(thd->main_security_ctx.host, thd->main_security_ctx.ip)) + (thd->main_security_ctx.get_host()->length() ? + thd->main_security_ctx.get_host()->ptr() : + "unknown host"), + (thd->main_security_ctx.get_ip()->length() ? + thd->main_security_ctx.get_ip()->ptr() + : "unknown ip"))); + if (acl_check_host(thd->main_security_ctx.get_host()->ptr(), + thd->main_security_ctx.get_ip()->ptr())) { my_error(ER_HOST_NOT_PRIVILEGED, MYF(0), thd->main_security_ctx.host_or_ip); @@ -552,9 +561,9 @@ static int check_connection(THD *thd) } else /* Hostname given means that the connection was on a socket */ { - DBUG_PRINT("info",("Host: %s", thd->main_security_ctx.host)); - thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host; - thd->main_security_ctx.ip= 0; + DBUG_PRINT("info",("Host: %s", thd->main_security_ctx.get_host()->ptr())); + thd->main_security_ctx.host_or_ip= thd->main_security_ctx.get_host()->ptr(); + thd->main_security_ctx.set_ip(""); /* Reset sin_addr */ bzero((char*) &net->vio->remote, sizeof(net->vio->remote)); } |