make sure resolve_name() only returns valid IP addresses
authorAndrew Tridgell <tridge@samba.org>
Fri, 11 Jan 2002 00:23:29 +0000 (00:23 +0000)
committerAndrew Tridgell <tridge@samba.org>
Fri, 11 Jan 2002 00:23:29 +0000 (00:23 +0000)
this is actually a workaround for old broken nmbd daemons, especially
from Samba 2.0
(This used to be commit 12021a8de6a1dc2e43cc62f094a57c57283dfaf4)

source3/libsmb/namequery.c

index 6bf34c730cc9bb67b3adedd441ad313bedce5fec..d7e0af11df9d47bcf79632d325bc48ba284b2cd8 100644 (file)
@@ -954,10 +954,19 @@ BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
        struct in_addr *ip_list = NULL;
        int count = 0;
 
-       if(internal_resolve_name(name, name_type, &ip_list, &count)) {
-               *return_ip = ip_list[0];
-               SAFE_FREE(ip_list);
-               return True;
+       if (internal_resolve_name(name, name_type, &ip_list, &count)) {
+               int i;
+               /* only return valid addresses for TCP connections */
+               for (i=0; i<count; i++) {
+                       char *ip_str = inet_ntoa(ip_list[i]);
+                       if (ip_str &&
+                           strcmp(ip_str, "255.255.255.255") != 0 &&
+                           strcmp(ip_str, "0.0.0.0") != 0) {
+                               *return_ip = ip_list[i];
+                               SAFE_FREE(ip_list);
+                               return True;
+                       }
+               }
        }
        SAFE_FREE(ip_list);
        return False;