1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

WL#7076: Backporting wl6715 to support both formats

in 5.5, 5.6, 5.7.
This commit is contained in:
Ashish Agarwal
2013-08-23 09:07:09 +05:30
17 changed files with 295 additions and 123 deletions

View File

@ -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));
}