Commit 1f33538c authored by unknown's avatar unknown

Handle systems where 127.0.0.1 doesn't always map to 'localhost'

first. (Bug #11822)


sql/hostname.cc:
  Short-circuit ip_to_hostname() lookup for INADDR_LOOPBACK to
  always return 'localhost'.
sql/sql_parse.cc:
  Push special handling of 127.0.0.1 into ip_to_hostname().
parent 21697831
...@@ -130,15 +130,23 @@ void reset_host_errors(struct in_addr *in) ...@@ -130,15 +130,23 @@ void reset_host_errors(struct in_addr *in)
VOID(pthread_mutex_unlock(&hostname_cache->lock)); VOID(pthread_mutex_unlock(&hostname_cache->lock));
} }
/* Deal with systems that don't defined INADDR_LOOPBACK */
#ifndef INADDR_LOOPBACK
#define INADDR_LOOPBACK 0x7f000001UL
#endif
my_string ip_to_hostname(struct in_addr *in, uint *errors) my_string ip_to_hostname(struct in_addr *in, uint *errors)
{ {
uint i; uint i;
host_entry *entry; host_entry *entry;
DBUG_ENTER("ip_to_hostname"); DBUG_ENTER("ip_to_hostname");
*errors=0;
/* We always treat the loopback address as "localhost". */
if (in->s_addr == INADDR_LOOPBACK)
return (char *)my_localhost;
/* Check first if we have name in cache */ /* Check first if we have name in cache */
*errors=0;
if (!(specialflag & SPECIAL_NO_HOST_CACHE)) if (!(specialflag & SPECIAL_NO_HOST_CACHE))
{ {
VOID(pthread_mutex_lock(&hostname_cache->lock)); VOID(pthread_mutex_lock(&hostname_cache->lock));
......
...@@ -775,16 +775,6 @@ static int check_connection(THD *thd) ...@@ -775,16 +775,6 @@ static int check_connection(THD *thd)
return (ER_OUT_OF_RESOURCES); return (ER_OUT_OF_RESOURCES);
thd->host_or_ip= thd->ip; thd->host_or_ip= thd->ip;
vio_in_addr(net->vio,&thd->remote.sin_addr); vio_in_addr(net->vio,&thd->remote.sin_addr);
#if !defined(HAVE_SYS_UN_H) || defined(HAVE_mit_thread)
/* Fast local hostname resolve for Win32 */
if (!strcmp(thd->ip,"127.0.0.1"))
{
thd->host= (char*) my_localhost;
thd->host_or_ip= my_localhost;
}
else
#endif
{
if (!(specialflag & SPECIAL_NO_RESOLVE)) if (!(specialflag & SPECIAL_NO_RESOLVE))
{ {
vio_in_addr(net->vio,&thd->remote.sin_addr); vio_in_addr(net->vio,&thd->remote.sin_addr);
...@@ -792,13 +782,13 @@ static int check_connection(THD *thd) ...@@ -792,13 +782,13 @@ static int check_connection(THD *thd)
/* Cut very long hostnames to avoid possible overflows */ /* Cut very long hostnames to avoid possible overflows */
if (thd->host) if (thd->host)
{ {
if (thd->host != my_localhost)
thd->host[min(strlen(thd->host), HOSTNAME_LENGTH)]= 0; thd->host[min(strlen(thd->host), HOSTNAME_LENGTH)]= 0;
thd->host_or_ip= thd->host; thd->host_or_ip= thd->host;
} }
if (connect_errors > max_connect_errors) if (connect_errors > max_connect_errors)
return(ER_HOST_IS_BLOCKED); return(ER_HOST_IS_BLOCKED);
} }
}
DBUG_PRINT("info",("Host: %s ip: %s", DBUG_PRINT("info",("Host: %s ip: %s",
thd->host ? thd->host : "unknown host", thd->host ? thd->host : "unknown host",
thd->ip ? thd->ip : "unknown ip")); thd->ip ? thd->ip : "unknown ip"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment