From 5176a0b2af1bb16e530412faaa2f36108f312a03 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Mar 2011 12:11:02 -0700 Subject: Fix is_myname_or_ipaddr() to be robust against strange DNS setups. If IPv6 DNS names are turned on, but Samba isn't configured to listen on an IPv6 interface, then is_myname_or_ipaddr() can return false on a valid DNS name that it should detect is our own. If the IPv6 addr is returned by preference, then looking at the first addr only causes is_myname_or_ipaddr() to fail. We need to look at all the addresses returned by the DNS lookup and check all of them against our interface list. This is an order N^2 lookup, but there shouldn't be enough addresses to make this a practical problem. Jeremy. --- source3/lib/util_sock.c | 86 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index eea153ad91..0c7db2e134 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1577,6 +1577,40 @@ const char *get_mydnsfullname(void) return (const char *)tmp.data; } +/************************************************************ + Is this my ip address ? +************************************************************/ + +static bool is_my_ipaddr(const char *ipaddr_str) +{ + struct sockaddr_storage ss; + struct iface_struct *nics; + int i, n; + + if (!interpret_string_addr(&ss, ipaddr_str, AI_NUMERICHOST)) { + return false; + } + + if (ismyaddr((struct sockaddr *)&ss)) { + return true; + } + + if (is_zero_addr(&ss) || + is_loopback_addr((struct sockaddr *)&ss)) { + return false; + } + + n = get_interfaces(talloc_tos(), &nics); + for (i=0; iai_next) { + char addr[INET6_ADDRSTRLEN]; + struct sockaddr_storage ss; + + ZERO_STRUCT(ss); + memcpy(&ss, p->ai_addr, p->ai_addrlen); + print_sockaddr(addr, + sizeof(addr), + &ss); + if (is_my_ipaddr(addr)) { + freeaddrinfo(res); return true; } } - TALLOC_FREE(nics); + freeaddrinfo(res); } /* No match */ -- cgit