diff options
Diffstat (limited to 'sql/sql_connect.cc')
-rw-r--r-- | sql/sql_connect.cc | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 14a1acdef5e..666d6e7d5e0 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; } /* 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)); } |