summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <jimw@mysql.com>2005-07-18 17:00:37 -0700
committerunknown <jimw@mysql.com>2005-07-18 17:00:37 -0700
commit1f33538c2fd748259567a73c71ff72d7846e19fa (patch)
tree22b0ecf8f5e1180f7e27b02b6520bcbe8ea3e66c
parent21697831770104ad4ecea346947c5cddd36d080c (diff)
downloadmariadb-git-1f33538c2fd748259567a73c71ff72d7846e19fa.tar.gz
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().
-rw-r--r--sql/hostname.cc10
-rw-r--r--sql/sql_parse.cc30
2 files changed, 19 insertions, 21 deletions
diff --git a/sql/hostname.cc b/sql/hostname.cc
index 39223556024..12b69a97859 100644
--- a/sql/hostname.cc
+++ b/sql/hostname.cc
@@ -130,15 +130,23 @@ void reset_host_errors(struct in_addr *in)
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)
{
uint i;
host_entry *entry;
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 */
- *errors=0;
if (!(specialflag & SPECIAL_NO_HOST_CACHE))
{
VOID(pthread_mutex_lock(&hostname_cache->lock));
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 26f342eac54..6ddddfed1f9 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -775,29 +775,19 @@ static int check_connection(THD *thd)
return (ER_OUT_OF_RESOURCES);
thd->host_or_ip= thd->ip;
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"))
+ if (!(specialflag & SPECIAL_NO_RESOLVE))
{
- thd->host= (char*) my_localhost;
- thd->host_or_ip= my_localhost;
- }
- else
-#endif
- {
- if (!(specialflag & SPECIAL_NO_RESOLVE))
+ vio_in_addr(net->vio,&thd->remote.sin_addr);
+ thd->host=ip_to_hostname(&thd->remote.sin_addr,&connect_errors);
+ /* Cut very long hostnames to avoid possible overflows */
+ if (thd->host)
{
- vio_in_addr(net->vio,&thd->remote.sin_addr);
- thd->host=ip_to_hostname(&thd->remote.sin_addr,&connect_errors);
- /* Cut very long hostnames to avoid possible overflows */
- if (thd->host)
- {
- thd->host[min(strlen(thd->host), HOSTNAME_LENGTH)]= 0;
- thd->host_or_ip= thd->host;
- }
- if (connect_errors > max_connect_errors)
- return(ER_HOST_IS_BLOCKED);
+ if (thd->host != my_localhost)
+ thd->host[min(strlen(thd->host), HOSTNAME_LENGTH)]= 0;
+ thd->host_or_ip= thd->host;
}
+ if (connect_errors > max_connect_errors)
+ return(ER_HOST_IS_BLOCKED);
}
DBUG_PRINT("info",("Host: %s ip: %s",
thd->host ? thd->host : "unknown host",