The branch, master has been updated
       via  7577d9ebf06fcdb630b2cdaab8772a6da9e37b70 (commit)
       via  fe36fe8c3e76e3dd7c66ecdf7254dc01c5d065c0 (commit)
       via  d1bc7e56d0584ef4f1051e39cd1a81182d63f096 (commit)
       via  d6a5476ee7af464a381bbeeec576ee58f3650a43 (commit)
       via  55fd6b125c3e5ac135d124c291f5ae6102fcbb2f (commit)
      from  27c4cf4e7b2ba042b4caace7bab19f9e37510d86 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 7577d9ebf06fcdb630b2cdaab8772a6da9e37b70
Merge: fe36fe8c3e76e3dd7c66ecdf7254dc01c5d065c0 
27c4cf4e7b2ba042b4caace7bab19f9e37510d86
Author: Jelmer Vernooij <[EMAIL PROTECTED]>
Date:   Thu Oct 23 20:42:30 2008 +0200

    Merge branch 'master' of ssh://git.samba.org/data/git/samba

commit fe36fe8c3e76e3dd7c66ecdf7254dc01c5d065c0
Author: Jelmer Vernooij <[EMAIL PROTECTED]>
Date:   Thu Oct 23 20:41:15 2008 +0200

    Use common net utility code (address and sockaddr manipulation).

commit d1bc7e56d0584ef4f1051e39cd1a81182d63f096
Author: Jelmer Vernooij <[EMAIL PROTECTED]>
Date:   Thu Oct 23 19:56:09 2008 +0200

    Rename same_net to same_net_v4 for consistency with Samba 3.

commit d6a5476ee7af464a381bbeeec576ee58f3650a43
Author: Jelmer Vernooij <[EMAIL PROTECTED]>
Date:   Thu Oct 23 19:53:15 2008 +0200

    Use sockaddr_storage only where we rely on the size, use sockaddr
    otherwise (to clarify we can also pass in structs smaller than
    sockaddr_storage, such as sockaddr_in).

commit 55fd6b125c3e5ac135d124c291f5ae6102fcbb2f
Author: Jelmer Vernooij <[EMAIL PROTECTED]>
Date:   Thu Oct 23 18:56:37 2008 +0200

    Remove support for obsolete data type "ipv4address"

-----------------------------------------------------------------------

Summary of changes:
 lib/util/talloc_stack.c             |    2 +-
 lib/util/util.h                     |    6 +-
 lib/util/util_net.c                 |  367 ++++++++++++++++++++++++++----
 source3/Makefile.in                 |    2 +-
 source3/auth/auth_server.c          |    2 +-
 source3/include/proto.h             |   32 ++--
 source3/lib/access.c                |    2 +-
 source3/lib/interface.c             |   41 ++--
 source3/lib/util_sock.c             |  428 ++---------------------------------
 source3/lib/wins_srv.c              |    4 +-
 source3/libads/kerberos.c           |    9 +-
 source3/libsmb/cliconnect.c         |    2 +-
 source3/libsmb/dsgetdcname.c        |    2 +-
 source3/libsmb/namequery.c          |   36 ++--
 source3/libsmb/namequery_dc.c       |    2 +-
 source3/nmbd/nmbd.c                 |    4 +-
 source3/nmbd/nmbd_mynames.c         |    3 +-
 source3/nmbd/nmbd_packets.c         |    2 +-
 source3/nmbd/nmbd_processlogon.c    |    2 +-
 source3/nmbd/nmbd_sendannounce.c    |    4 +-
 source3/nmbd/nmbd_subnetdb.c        |    2 +-
 source3/nmbd/nmbd_winsserver.c      |   16 +-
 source3/rpc_server/srv_spoolss_nt.c |    4 +-
 source3/utils/net_util.c            |    4 +-
 source3/utils/nmblookup.c           |    2 +-
 source3/utils/smbcontrol.c          |    2 +-
 source3/winbindd/winbindd_cm.c      |    2 +-
 source4/client/smbmount.c           |    2 +-
 source4/lib/socket/interface.c      |    8 +-
 source4/lib/tdr/tdr.c               |   34 ---
 30 files changed, 445 insertions(+), 583 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/talloc_stack.c b/lib/util/talloc_stack.c
index 2722fb9..2f3ea11 100644
--- a/lib/util/talloc_stack.c
+++ b/lib/util/talloc_stack.c
@@ -69,7 +69,7 @@ static TALLOC_CTX *talloc_stackframe_internal(size_t poolsize)
        TALLOC_CTX **tmp, *top, *parent;
 
        if (talloc_stack_arraysize < talloc_stacksize + 1) {
-               tmp = TALLOC_REALLOC_ARRAY(NULL, talloc_stack, TALLOC_CTX *,
+               tmp = talloc_realloc(NULL, talloc_stack, TALLOC_CTX *,
                                           talloc_stacksize + 1);
                if (tmp == NULL) {
                        goto fail;
diff --git a/lib/util/util.h b/lib/util/util.h
index e72df02..c2407ae 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -541,12 +541,14 @@ _PUBLIC_ struct in_addr interpret_addr2(const char *str);
 /**
  Check if an IP is the 0.0.0.0.
 **/
-_PUBLIC_ bool is_zero_ip(struct in_addr ip);
+_PUBLIC_ bool is_zero_ip_v4(struct in_addr ip);
 
 /**
  Are two IPs on the same subnet?
 **/
-_PUBLIC_ bool same_net(struct in_addr ip1,struct in_addr ip2,struct in_addr 
mask);
+_PUBLIC_ bool same_net_v4(struct in_addr ip1,struct in_addr ip2,struct in_addr 
mask);
+
+_PUBLIC_ bool is_ipaddress_v4(const char *str);
 
 /**
  Check if a process exists. Does this work on all unixes?
diff --git a/lib/util/util_net.c b/lib/util/util_net.c
index ee57e9d..eb5e225 100644
--- a/lib/util/util_net.c
+++ b/lib/util/util_net.c
@@ -3,7 +3,7 @@
    Samba utility functions
    Copyright (C) Jelmer Vernooij <[EMAIL PROTECTED]> 2008
    Copyright (C) Andrew Tridgell 1992-1998
-   Copyright (C) Jeremy Allison 2001-2002
+   Copyright (C) Jeremy Allison 2001-2007
    Copyright (C) Simo Sorce 2001
    Copyright (C) Jim McDonough ([EMAIL PROTECTED])  2003.
    Copyright (C) James J Myers 2003
@@ -26,50 +26,105 @@
 #include "system/network.h"
 #include "system/locale.h"
 #include "system/filesys.h"
+#undef strcasecmp
 
 /**
- Interpret an internet address or name into an IP address in 4 byte form.
-**/
-_PUBLIC_ uint32_t interpret_addr(const char *str)
+ * Wrap getaddrinfo...
+ */
+bool interpret_string_addr_internal(struct addrinfo **ppres,
+                                       const char *str, int flags)
 {
-       struct hostent *hp;
-       uint32_t res;
+       int ret;
+       struct addrinfo hints;
 
-       if (str == NULL || *str == 0 ||
-           strcmp(str,"0.0.0.0") == 0) {
-               return 0;
-       }
-       if (strcmp(str,"255.255.255.255") == 0) {
-               return 0xFFFFFFFF;
-       }
-       /* recognise 'localhost' as a special name. This fixes problems with
-          some hosts that don't have localhost in /etc/hosts */
-       if (strcasecmp(str,"localhost") == 0) {
-               str = "127.0.0.1";
+       memset(&hints, '\0', sizeof(hints));
+       /* By default make sure it supports TCP. */
+       hints.ai_socktype = SOCK_STREAM;
+       hints.ai_flags = flags;
+
+       /* Linux man page on getaddinfo() says port will be
+          uninitialized when service string in NULL */
+
+       ret = getaddrinfo(str, NULL,
+                       &hints,
+                       ppres);
+
+       if (ret) {
+               DEBUG(3,("interpret_string_addr_internal: getaddrinfo failed "
+                       "for name %s [%s]\n",
+                       str,
+                       gai_strerror(ret) ));
+               return false;
        }
+       return true;
+}
+
+/**
+ * Interpret an internet address or name into an IP address in 4 byte form.
+ * RETURNS IN NETWORK BYTE ORDER (big endian).
+ */
+
+uint32_t interpret_addr(const char *str)
+{
+       uint32_t ret;
 
-       /* if it's in the form of an IP address then get the lib to interpret 
it */
-       if (is_ipaddress(str)) {
-               res = inet_addr(str);
+       /* If it's in the form of an IP address then
+        * get the lib to interpret it */
+       if (is_ipaddress_v4(str)) {
+               struct in_addr dest;
+
+               if (inet_pton(AF_INET, str, &dest) <= 0) {
+                       /* Error - this shouldn't happen ! */
+                       DEBUG(0,("interpret_addr: inet_pton failed "
+                               "host %s\n",
+                               str));
+                       return 0;
+               }
+               ret = dest.s_addr; /* NETWORK BYTE ORDER ! */
        } else {
-               /* otherwise assume it's a network name of some sort and use 
-                       sys_gethostbyname */
-               if ((hp = sys_gethostbyname(str)) == 0) {
-                       DEBUG(3,("sys_gethostbyname: Unknown host. %s\n",str));
+               /* Otherwise assume it's a network name of some sort and use
+                       getadddrinfo. */
+               struct addrinfo *res = NULL;
+               struct addrinfo *res_list = NULL;
+               if (!interpret_string_addr_internal(&res_list,
+                                       str,
+                                       AI_ADDRCONFIG)) {
+                       DEBUG(3,("interpret_addr: Unknown host. %s\n",str));
                        return 0;
                }
 
-               if(hp->h_addr == NULL) {
-                       DEBUG(3,("sys_gethostbyname: host address is invalid 
for host %s\n",str));
+               /* Find the first IPv4 address. */
+               for (res = res_list; res; res = res->ai_next) {
+                       if (res->ai_family != AF_INET) {
+                               continue;
+                       }
+                       if (res->ai_addr == NULL) {
+                               continue;
+                       }
+                       break;
+               }
+               if(res == NULL) {
+                       DEBUG(3,("interpret_addr: host address is "
+                               "invalid for host %s\n",str));
+                       if (res_list) {
+                               freeaddrinfo(res_list);
+                       }
                        return 0;
                }
-               memcpy((char *)&res,(char *)hp->h_addr, 4);
+               memcpy((char *)&ret,
+                       &((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr,
+                       sizeof(ret));
+               if (res_list) {
+                       freeaddrinfo(res_list);
+               }
        }
 
-       if (res == (uint32_t)-1)
-               return(0);
+       /* This is so bogus - all callers need fixing... JRA. */
+       if (ret == (uint32_t)-1) {
+               return 0;
+       }
 
-       return(res);
+       return ret;
 }
 
 /**
@@ -87,7 +142,7 @@ _PUBLIC_ struct in_addr interpret_addr2(const char *str)
  Check if an IP is the 0.0.0.0.
 **/
 
-_PUBLIC_ bool is_zero_ip(struct in_addr ip)
+_PUBLIC_ bool is_zero_ip_v4(struct in_addr ip)
 {
        return ip.s_addr == 0;
 }
@@ -96,7 +151,7 @@ _PUBLIC_ bool is_zero_ip(struct in_addr ip)
  Are two IPs on the same subnet?
 **/
 
-_PUBLIC_ bool same_net(struct in_addr ip1, struct in_addr ip2, struct in_addr 
mask)
+_PUBLIC_ bool same_net_v4(struct in_addr ip1, struct in_addr ip2, struct 
in_addr mask)
 {
        uint32_t net1,net2,nmask;
 
@@ -108,24 +163,248 @@ _PUBLIC_ bool same_net(struct in_addr ip1, struct 
in_addr ip2, struct in_addr ma
 }
 
 /**
- Return true if a string could be a pure IP address.
-**/
+ * Return true if a string could be an IPv4 address.
+ */
+
+bool is_ipaddress_v4(const char *str)
+{
+       int ret = -1;
+       struct in_addr dest;
+
+       ret = inet_pton(AF_INET, str, &dest);
+       if (ret > 0) {
+               return true;
+       }
+       return false;
+}
+
+/**
+ * Return true if a string could be an IPv4 or IPv6 address.
+ */
+
+bool is_ipaddress(const char *str)
+{
+#if defined(HAVE_IPV6)
+       int ret = -1;
+
+       if (strchr_m(str, ':')) {
+               char addr[INET6_ADDRSTRLEN];
+               struct in6_addr dest6;
+               const char *sp = str;
+               char *p = strchr_m(str, '%');
+
+               /*
+                * Cope with link-local.
+                * This is IP:v6:addr%ifname.
+                */
+
+               if (p && (p > str) && (if_nametoindex(p+1) != 0)) {
+                       strlcpy(addr, str,
+                               MIN(PTR_DIFF(p,str)+1,
+                                       sizeof(addr)));
+                       sp = addr;
+               }
+               ret = inet_pton(AF_INET6, sp, &dest6);
+               if (ret > 0) {
+                       return true;
+               }
+       }
+#endif
+       return is_ipaddress_v4(str);
+}
+
+/**
+ * Is a sockaddr a broadcast address ?
+ */
+
+bool is_broadcast_addr(const struct sockaddr *pss)
+{
+#if defined(HAVE_IPV6)
+       if (pss->sa_family == AF_INET6) {
+               const struct in6_addr *sin6 =
+                       &((const struct sockaddr_in6 *)pss)->sin6_addr;
+               return IN6_IS_ADDR_MULTICAST(sin6);
+       }
+#endif
+       if (pss->sa_family == AF_INET) {
+               uint32_t addr =
+               ntohl(((const struct sockaddr_in *)pss)->sin_addr.s_addr);
+               return addr == INADDR_BROADCAST;
+       }
+       return false;
+}
+
+/**
+ * Check if an IPv7 is 127.0.0.1
+ */
+bool is_loopback_ip_v4(struct in_addr ip)
+{
+       struct in_addr a;
+       a.s_addr = htonl(INADDR_LOOPBACK);
+       return(ip.s_addr == a.s_addr);
+}
 
-_PUBLIC_ bool is_ipaddress(const char *str)
+/**
+ * Check if a struct sockaddr is the loopback address.
+ */
+bool is_loopback_addr(const struct sockaddr *pss)
 {
-       bool pure_address = true;
-       int i;
+#if defined(HAVE_IPV6)
+       if (pss->sa_family == AF_INET6) {
+               const struct in6_addr *pin6 =
+                       &((const struct sockaddr_in6 *)pss)->sin6_addr;
+               return IN6_IS_ADDR_LOOPBACK(pin6);
+       }
+#endif
+       if (pss->sa_family == AF_INET) {
+               const struct in_addr *pin = &((const struct sockaddr_in 
*)pss)->sin_addr;
+               return is_loopback_ip_v4(*pin);
+       }
+       return false;
+}
 
-       if (str == NULL) return false;
+/**
+ * Check if a struct sockaddr has an unspecified address.
+ */
+bool is_zero_addr(const struct sockaddr *pss)
+{
+#if defined(HAVE_IPV6)
+       if (pss->sa_family == AF_INET6) {
+               const struct in6_addr *pin6 =
+                       &((const struct sockaddr_in6 *)pss)->sin6_addr;
+               return IN6_IS_ADDR_UNSPECIFIED(pin6);
+       }
+#endif
+       if (pss->sa_family == AF_INET) {
+               const struct in_addr *pin = &((const struct sockaddr_in 
*)pss)->sin_addr;
+               return is_zero_ip_v4(*pin);
+       }
+       return false;
+}
 
-       for (i=0; pure_address && str[i]; i++)
-               if (!(isdigit((int)str[i]) || str[i] == '.'))
-                       pure_address = false;
+/**
+ * Set an IP to 0.0.0.0.
+ */
+void zero_ip_v4(struct in_addr *ip)
+{
+       memset(ip, '\0', sizeof(struct in_addr));
+}
 
-       /* Check that a pure number is not misinterpreted as an IP */
-       pure_address = pure_address && (strchr(str, '.') != NULL);
+/**
+ * Convert an IPv4 struct in_addr to a struct sockaddr_storage.
+ */
+void in_addr_to_sockaddr_storage(struct sockaddr_storage *ss,
+               struct in_addr ip)
+{
+       struct sockaddr_in *sa = (struct sockaddr_in *)ss;
+       memset(ss, '\0', sizeof(*ss));
+       sa->sin_family = AF_INET;
+       sa->sin_addr = ip;
+}
 
-       return pure_address;
+#if defined(HAVE_IPV6)
+/**
+ * Convert an IPv6 struct in_addr to a struct sockaddr_storage.
+ */
+void in6_addr_to_sockaddr_storage(struct sockaddr_storage *ss,
+               struct in6_addr ip)
+{
+       struct sockaddr_in6 *sa = (struct sockaddr_in6 *)ss;
+       memset(ss, '\0', sizeof(*ss));
+       sa->sin6_family = AF_INET6;
+       sa->sin6_addr = ip;
 }
+#endif
 
+/**
+ * Are two IPs on the same subnet?
+ */
+bool same_net(const struct sockaddr *ip1,
+               const struct sockaddr *ip2,
+               const struct sockaddr *mask)
+{
+       if (ip1->sa_family != ip2->sa_family) {
+               /* Never on the same net. */
+               return false;
+       }
 
+#if defined(HAVE_IPV6)
+       if (ip1->sa_family == AF_INET6) {
+               struct sockaddr_in6 ip1_6 = *(const struct sockaddr_in6 *)ip1;
+               struct sockaddr_in6 ip2_6 = *(const struct sockaddr_in6 *)ip2;
+               struct sockaddr_in6 mask_6 = *(const struct sockaddr_in6 *)mask;
+               char *p1 = (char *)&ip1_6.sin6_addr;
+               char *p2 = (char *)&ip2_6.sin6_addr;
+               char *m = (char *)&mask_6.sin6_addr;
+               int i;
+
+               for (i = 0; i < sizeof(struct in6_addr); i++) {
+                       *p1++ &= *m;
+                       *p2++ &= *m;
+                       m++;
+               }
+               return (memcmp(&ip1_6.sin6_addr,
+                               &ip2_6.sin6_addr,
+                               sizeof(struct in6_addr)) == 0);
+       }
+#endif
+       if (ip1->sa_family == AF_INET) {
+               return same_net_v4(((const struct sockaddr_in *)ip1)->sin_addr,
+                               ((const struct sockaddr_in *)ip2)->sin_addr,
+                               ((const struct sockaddr_in *)mask)->sin_addr);
+       }
+       return false;
+}
+
+/**
+ * Are two sockaddr 's the same family and address ? Ignore port etc.
+ */
+
+bool addr_equal(const struct sockaddr *ip1,
+               const struct sockaddr *ip2)
+{
+       if (ip1->sa_family != ip2->sa_family) {
+               /* Never the same. */
+               return false;
+       }
+
+#if defined(HAVE_IPV6)
+       if (ip1->sa_family == AF_INET6) {
+               return (memcmp(&((const struct sockaddr_in6 *)ip1)->sin6_addr,
+                               &((const struct sockaddr_in6 *)ip2)->sin6_addr,
+                               sizeof(struct in6_addr)) == 0);
+       }
+#endif
+       if (ip1->sa_family == AF_INET) {
+               return (memcmp(&((const struct sockaddr_in *)ip1)->sin_addr,
+                               &((const struct sockaddr_in *)ip2)->sin_addr,
+                               sizeof(struct in_addr)) == 0);
+       }
+       return false;
+}
+
+/**
+ * Is an IP address the INADDR_ANY or in6addr_any value ?
+ */
+bool is_address_any(const struct sockaddr *psa)
+{
+#if defined(HAVE_IPV6)
+       if (psa->sa_family == AF_INET6) {
+               const struct sockaddr_in6 *si6 = (const struct sockaddr_in6 
*)psa;
+               if (memcmp(&in6addr_any,
+                               &si6->sin6_addr,
+                               sizeof(in6addr_any)) == 0) {
+                       return true;
+               }
+               return false;
+       }
+#endif
+       if (psa->sa_family == AF_INET) {
+               const struct sockaddr_in *si = (const struct sockaddr_in *)psa;
+               if (si->sin_addr.s_addr == INADDR_ANY) {
+                       return true;
+               }
+               return false;
+       }
+       return false;
+}
diff --git a/source3/Makefile.in b/source3/Makefile.in
index dad046f..01ea90a 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -321,7 +321,7 @@ UTIL_OBJ = ../lib/util/rbtree.o ../lib/util/signal.o 
../lib/util/time.o \
                   ../lib/util/util_file.o ../lib/util/data_blob.o \
                   ../lib/util/util.o ../lib/util/fsusage.o \
                   ../lib/util/params.o ../lib/util/talloc_stack.o \
-                  ../lib/util/genrand.o 
+                  ../lib/util/genrand.o ../lib/util/util_net.o
 
 CRYPTO_OBJ = ../lib/crypto/crc32.o ../lib/crypto/md5.o \
                         ../lib/crypto/hmacmd5.o ../lib/crypto/arcfour.o \
diff --git a/source3/auth/auth_server.c b/source3/auth/auth_server.c
index 696b426..e74e3f5 100644
--- a/source3/auth/auth_server.c
+++ b/source3/auth/auth_server.c
@@ -65,7 +65,7 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
                        continue;
                }
 
-               if (ismyaddr(&dest_ss)) {
+               if (ismyaddr((struct sockaddr *)&dest_ss)) {
                        DEBUG(1,("Password server loop - disabling password 
server %s\n",desthost));
                        continue;
                }
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 37f934a..61f864d 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -591,10 +591,10 @@ int smb_iconv_close (smb_iconv_t cd);
 
 /* The following definitions come from lib/interface.c  */
 
-bool ismyaddr(const struct sockaddr_storage *ip);
+bool ismyaddr(const struct sockaddr *ip);
 bool ismyip_v4(struct in_addr ip);
-bool is_local_net(const struct sockaddr_storage *from);
-void setup_linklocal_scope_id(struct sockaddr_storage *pss);


-- 
Samba Shared Repository

Reply via email to