[SCM] Samba Shared Repository branch, v3-2-test,
updated. initial-v3-2-unstable-13-g169c585
Jeremy Allison
jra at samba.org
Thu Oct 11 01:58:03 GMT 2007
The branch, v3-2-test has been updated
via 169c5857b7e7922fe3fffef997ced0e014e925a8 (commit)
via 3f6bd0e1ec5cc6670f3d08f76fc2cd94c9cd1a08 (commit)
from 3f1ac564c0ab6d498a47da84b4b5744d8d376f3b (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 169c5857b7e7922fe3fffef997ced0e014e925a8
Author: Jeremy Allison <jra at samba.org>
Date: Wed Oct 10 18:47:41 2007 -0700
Added missing is_ipaddress is_ipaddress_v4 not in initial
port from old svn code.
Jeremy.
commit 3f6bd0e1ec5cc6670f3d08f76fc2cd94c9cd1a08
Author: Jeremy Allison <jra at samba.org>
Date: Wed Oct 10 18:25:16 2007 -0700
Add start of IPv6 implementation. Currently most of this is avoiding
IPv6 in winbindd, but moves most of the socket functions that were
wrongly in lib/util.c into lib/util_sock.c and provides generic
IPv4/6 independent versions of most things. Still lots of work
to do, but now I can see how I'll fix the access check code.
Nasty part that remains is the name resolution code which is
used to returning arrays of in_addr structs.
Jeremy.
-----------------------------------------------------------------------
Summary of changes:
source/auth/auth_server.c | 2 +-
source/client/client.c | 4 +-
source/include/interfaces.h | 19 +-
source/include/smb.h | 8 +-
source/lib/access.c | 2 +-
source/lib/interface.c | 644 +++++++++++++++++++++++++----------
source/lib/interfaces.c | 258 ++++++++++-----
source/lib/util.c | 189 ----------
source/lib/util_sock.c | 515 +++++++++++++++++++++++++---
source/lib/wins_srv.c | 10 +-
source/librpc/ndr/ndr_basic.c | 2 +-
source/libsmb/cliconnect.c | 8 +-
source/libsmb/clidfs.c | 4 +-
source/libsmb/dsgetdcname.c | 2 +-
source/libsmb/libsmbclient.c | 10 +-
source/libsmb/namequery.c | 35 ++-
source/libsmb/namequery_dc.c | 6 +-
source/nmbd/nmbd.c | 55 +++-
source/nmbd/nmbd_become_dmb.c | 20 +-
source/nmbd/nmbd_browsesync.c | 8 +-
source/nmbd/nmbd_incomingrequests.c | 6 +-
source/nmbd/nmbd_lmhosts.c | 2 +-
source/nmbd/nmbd_logonnames.c | 2 -
source/nmbd/nmbd_namequery.c | 2 +-
source/nmbd/nmbd_packets.c | 54 ++--
source/nmbd/nmbd_processlogon.c | 21 +-
source/nmbd/nmbd_subnetdb.c | 50 ++-
source/nmbd/nmbd_synclists.c | 2 +-
source/nmbd/nmbd_winsproxy.c | 2 +-
source/nmbd/nmbd_winsserver.c | 4 +-
source/nmbd/nmbd_workgroupdb.c | 2 +-
source/nsswitch/wins.c | 5 +-
source/rpc_server/srv_spoolss_nt.c | 4 +-
source/smbd/server.c | 13 +-
source/torture/locktest.c | 4 +-
source/torture/masktest.c | 4 +-
source/torture/torture.c | 2 +-
source/utils/net.c | 11 +-
source/utils/net_dns.c | 3 +-
source/utils/netlookup.c | 3 +-
source/utils/nmblookup.c | 7 +-
source/utils/smbcacls.c | 2 +-
source/utils/smbcquotas.c | 2 +-
source/web/diagnose.c | 8 +-
source/winbindd/winbindd_cm.c | 4 +-
source/winbindd/winbindd_misc.c | 2 +-
source/winbindd/winbindd_wins.c | 5 +-
47 files changed, 1364 insertions(+), 663 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source/auth/auth_server.c b/source/auth/auth_server.c
index b7669e9..44f36dc 100644
--- a/source/auth/auth_server.c
+++ b/source/auth/auth_server.c
@@ -59,7 +59,7 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
continue;
}
- if (ismyip(dest_ip)) {
+ if (ismyip_v4(dest_ip)) {
DEBUG(1,("Password server loop - disabling password server %s\n",desthost));
continue;
}
diff --git a/source/client/client.c b/source/client/client.c
index 171d413..4e916f6 100644
--- a/source/client/client.c
+++ b/source/client/client.c
@@ -3853,7 +3853,7 @@ static int do_message_op(void)
snprintf(name_type_hex, sizeof(name_type_hex), "#%X", name_type);
fstrcat(server_name, name_type_hex);
- zero_ip(&ip);
+ zero_ip_v4(&ip);
if (have_ip)
ip = dest_ip;
@@ -3994,7 +3994,7 @@ static int do_message_op(void)
case 'I':
{
dest_ip = *interpret_addr2(poptGetOptArg(pc));
- if (is_zero_ip(dest_ip))
+ if (is_zero_ip_v4(dest_ip))
exit(1);
have_ip = True;
diff --git a/source/include/interfaces.h b/source/include/interfaces.h
index 371f642..66ea151 100644
--- a/source/include/interfaces.h
+++ b/source/include/interfaces.h
@@ -1,4 +1,4 @@
-/*
+/*
This structure is used by lib/interfaces.c to return the list of network
interfaces on the machine
*/
@@ -7,17 +7,8 @@
struct iface_struct {
char name[16];
- sa_family_t sa_family;
- union {
- struct in_addr ip;
-#ifdef AF_INET6
- struct in6_addr ip6;
-#endif
- } iface_addr;
- union {
- struct in_addr netmask;
-#ifdef AF_INET6
- struct in6_addr netmask6;
-#endif
- } iface_netmask;
+ int flags;
+ struct sockaddr_storage ip;
+ struct sockaddr_storage netmask;
+ struct sockaddr_storage bcast;
};
diff --git a/source/include/smb.h b/source/include/smb.h
index 75ec436..7386613 100644
--- a/source/include/smb.h
+++ b/source/include/smb.h
@@ -726,9 +726,11 @@ struct server_info_struct {
/* used for network interfaces */
struct interface {
struct interface *next, *prev;
- struct in_addr ip;
- struct in_addr bcast;
- struct in_addr nmask;
+ char *name;
+ int flags;
+ struct sockaddr_storage ip;
+ struct sockaddr_storage netmask;
+ struct sockaddr_storage bcast;
};
/* Internal message queue for deferred opens. */
diff --git a/source/lib/access.c b/source/lib/access.c
index 303e3ed..17f4c36 100644
--- a/source/lib/access.c
+++ b/source/lib/access.c
@@ -279,7 +279,7 @@ static BOOL only_ipaddrs_in_list(const char** list)
continue;
}
- if (!is_ipaddress(*list)) {
+ if (!is_ipaddress_v4(*list)) {
/*
* if we failed, make sure that it was not because the token
* was a network/netmask pair. Only network/netmask pairs
diff --git a/source/lib/interface.c b/source/lib/interface.c
index 5982d82..1471a06 100644
--- a/source/lib/interface.c
+++ b/source/lib/interface.c
@@ -2,6 +2,7 @@
Unix SMB/CIFS implementation.
multiple interface handling
Copyright (C) Andrew Tridgell 1992-1998
+ Copyright (C) Jeremy Allison 2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,66 +23,404 @@
static struct iface_struct *probed_ifaces;
static int total_probed;
-struct in_addr allones_ip;
-struct in_addr loopback_ip;
-
static struct interface *local_interfaces;
-#define ALLONES ((uint32)0xFFFFFFFF)
-#define MKBCADDR(_IP, _NM) ((_IP & _NM) | (_NM ^ ALLONES))
-#define MKNETADDR(_IP, _NM) (_IP & _NM)
+/****************************************************************************
+ Check if an IP is one of mine.
+**************************************************************************/
+
+bool ismyaddr(const struct sockaddr_storage *ip)
+{
+ struct interface *i;
+ for (i=local_interfaces;i;i=i->next) {
+ if (addr_equal(&i->ip,ip)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool ismyip_v4(struct in_addr ip)
+{
+ struct sockaddr_storage ss;
+ in_addr_to_sockaddr_storage(&ss, ip);
+ return ismyaddr(&ss);
+}
/****************************************************************************
Try and find an interface that matches an ip. If we cannot, return NULL.
**************************************************************************/
-static struct interface *iface_find(struct in_addr ip, BOOL CheckMask)
+static struct interface *iface_find(const struct sockaddr_storage *ip,
+ bool check_mask)
{
struct interface *i;
- if (is_zero_ip(ip)) return local_interfaces;
- for (i=local_interfaces;i;i=i->next)
- if (CheckMask) {
- if (same_net(i->ip,ip,i->nmask)) return i;
- } else if ((i->ip).s_addr == ip.s_addr) return i;
+ if (is_address_any(ip)) {
+ return local_interfaces;
+ }
+
+ for (i=local_interfaces;i;i=i->next) {
+ if (check_mask) {
+ if (same_net(ip, &i->ip, &i->netmask)) {
+ return i;
+ }
+ } else if (addr_equal(&i->ip, ip)) {
+ return i;
+ }
+ }
return NULL;
}
/****************************************************************************
+ Check if a packet is from a local (known) net.
+**************************************************************************/
+
+bool is_local_net(const struct sockaddr_storage *from)
+{
+ struct interface *i;
+ for (i=local_interfaces;i;i=i->next) {
+ if (same_net(from, &i->ip, &i->netmask)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/****************************************************************************
+ Check if a packet is from a local (known) net.
+**************************************************************************/
+
+bool is_local_net_v4(struct in_addr from)
+{
+ struct sockaddr_storage ss;
+
+ in_addr_to_sockaddr_storage(&ss, from);
+ return is_local_net(&ss);
+}
+
+/****************************************************************************
+ How many interfaces do we have ?
+**************************************************************************/
+
+int iface_count(void)
+{
+ int ret = 0;
+ struct interface *i;
+
+ for (i=local_interfaces;i;i=i->next) {
+ ret++;
+ }
+ return ret;
+}
+
+/****************************************************************************
+ How many interfaces do we have (v4 only) ?
+**************************************************************************/
+
+int iface_count_v4(void)
+{
+ int ret = 0;
+ struct interface *i;
+
+ for (i=local_interfaces;i;i=i->next) {
+ if (i->ip.ss_family == AF_INET) {
+ ret++;
+ }
+ }
+ return ret;
+}
+
+/****************************************************************************
+ Return a pointer to the in_addr of the first IPv4 interface.
+**************************************************************************/
+
+const struct in_addr *first_ipv4_iface(void)
+{
+ struct interface *i;
+
+ for (i=local_interfaces;i ;i=i->next) {
+ if (i->ip.ss_family == AF_INET) {
+ break;
+ }
+ }
+
+ if (!i) {
+ return NULL;
+ }
+ return &((const struct sockaddr_in *)&i->ip)->sin_addr;
+}
+
+/****************************************************************************
+ Return the Nth interface.
+**************************************************************************/
+
+struct interface *get_interface(int n)
+{
+ struct interface *i;
+
+ for (i=local_interfaces;i && n;i=i->next) {
+ n--;
+ }
+
+ if (i) {
+ return i;
+ }
+ return NULL;
+}
+
+/****************************************************************************
+ Return IP sockaddr_storage of the Nth interface.
+**************************************************************************/
+
+const struct sockaddr_storage *iface_n_sockaddr_storage(int n)
+{
+ struct interface *i;
+
+ for (i=local_interfaces;i && n;i=i->next) {
+ n--;
+ }
+
+ if (i) {
+ return &i->ip;
+ }
+ return NULL;
+}
+
+/****************************************************************************
+ Return IPv4 of the Nth interface (if a v4 address). NULL otherwise.
+**************************************************************************/
+
+const struct in_addr *iface_n_ip_v4(int n)
+{
+ struct interface *i;
+
+ for (i=local_interfaces;i && n;i=i->next) {
+ n--;
+ }
+
+ if (i && i->ip.ss_family == AF_INET) {
+ return &((const struct sockaddr_in *)&i->ip)->sin_addr;
+ }
+ return NULL;
+}
+
+/****************************************************************************
+ Return IPv4 bcast of the Nth interface (if a v4 address). NULL otherwise.
+**************************************************************************/
+
+const struct in_addr *iface_n_bcast_v4(int n)
+{
+ struct interface *i;
+
+ for (i=local_interfaces;i && n;i=i->next) {
+ n--;
+ }
+
+ if (i && i->ip.ss_family == AF_INET) {
+ return &((const struct sockaddr_in *)&i->bcast)->sin_addr;
+ }
+ return NULL;
+}
+
+/****************************************************************************
+ Return bcast of the Nth interface.
+**************************************************************************/
+
+const struct sockaddr_storage *iface_n_bcast(int n)
+{
+ struct interface *i;
+
+ for (i=local_interfaces;i && n;i=i->next) {
+ n--;
+ }
+
+ if (i) {
+ return &i->bcast;
+ }
+ return NULL;
+}
+
+/* these 3 functions return the ip/bcast/nmask for the interface
+ most appropriate for the given ip address. If they can't find
+ an appropriate interface they return the requested field of the
+ first known interface. */
+
+const struct sockaddr_storage *iface_ip(const struct sockaddr_storage *ip)
+{
+ struct interface *i = iface_find(ip, true);
+ if (i) {
+ return &i->ip;
+ }
+
+ /* Search for the first interface with
+ * matching address family. */
+
+ for (i=local_interfaces;i;i=i->next) {
+ if (i->ip.ss_family == ip->ss_family) {
+ return &i->ip;
+ }
+ }
+ return NULL;
+}
+
+/*
+ return True if a IP is directly reachable on one of our interfaces
+*/
+
+bool iface_local(struct sockaddr_storage *ip)
+{
+ return iface_find(ip, True) ? true : false;
+}
+
+/****************************************************************************
Add an interface to the linked list of interfaces.
****************************************************************************/
-static void add_interface(struct in_addr ip, struct in_addr nmask)
+static void add_interface(const struct iface_struct *ifs)
{
+ char addr[INET6_ADDRSTRLEN];
struct interface *iface;
- if (iface_find(ip, False)) {
- DEBUG(3,("not adding duplicate interface %s\n",inet_ntoa(ip)));
+
+ if (iface_find(&ifs->ip, False)) {
+ DEBUG(3,("add_interface: not adding duplicate interface %s\n",
+ print_sockaddr(addr, sizeof(addr),
+ &ifs->ip, sizeof(struct sockaddr_storage)) ));
return;
}
-#if !defined(__s390__)
- if (ip_equal(nmask, allones_ip)) {
+ if (!(ifs->flags & IFF_BROADCAST)) {
DEBUG(3,("not adding non-broadcast interface %s\n",
- inet_ntoa(ip)));
+ ifs->name ));
return;
}
-#endif
iface = SMB_MALLOC_P(struct interface);
- if (!iface) return;
+ if (!iface) {
+ return;
+ }
ZERO_STRUCTPN(iface);
- iface->ip = ip;
- iface->nmask = nmask;
- iface->bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr);
+ iface->name = SMB_STRDUP(ifs->name);
+ if (!iface->name) {
+ SAFE_FREE(iface);
+ return;
+ }
+ iface->flags = ifs->flags;
+ iface->ip = ifs->ip;
+ iface->netmask = ifs->netmask;
+ iface->bcast = ifs->bcast;
DLIST_ADD(local_interfaces, iface);
- DEBUG(2,("added interface ip=%s ",inet_ntoa(iface->ip)));
- DEBUG(2,("bcast=%s ",inet_ntoa(iface->bcast)));
- DEBUG(2,("nmask=%s\n",inet_ntoa(iface->nmask)));
+ DEBUG(2,("added interface %s ip=%s ",
+ iface->name,
+ print_sockaddr(addr, sizeof(addr),
+ &iface->ip, sizeof(struct sockaddr_storage)) ));
+ DEBUG(2,("bcast=%s ",
+ print_sockaddr(addr, sizeof(addr),
+ &iface->bcast,
+ sizeof(struct sockaddr_storage)) ));
+ DEBUG(2,("netmask=%s\n",
+ print_sockaddr(addr, sizeof(addr),
+ &iface->netmask,
+ sizeof(struct sockaddr_storage)) ));
+}
+
+/****************************************************************************
+ Create a struct sockaddr_storage with the netmask bits set to 1.
+****************************************************************************/
+
+static bool make_netmask(struct sockaddr_storage *pss_out,
+ const struct sockaddr_storage *pss_in,
+ unsigned long masklen)
+{
+ *pss_out = *pss_in;
+ /* Now apply masklen bits of mask. */
+#if defined(AF_INET6)
+ if (pss_in->ss_family == AF_INET6) {
+ char *p = (char *)&((struct sockaddr_in6 *)pss_out)->sin6_addr;
+ unsigned int i;
+
+ if (masklen > 128) {
+ return false;
+ }
+ for (i = 0; masklen >= 8; masklen -= 8, i++) {
+ *p++ = 0xff;
+ }
+ /* Deal with the partial byte. */
+ *p++ &= (0xff & ~(0xff>>masklen));
+ i++;
+ for (;i < sizeof(struct in6_addr); i++) {
+ *p++ = '\0';
+ }
+ return true;
+ }
+#endif
+ if (pss_in->ss_family == AF_INET) {
+ if (masklen > 32) {
+ return false;
+ }
+ ((struct sockaddr_in *)pss_out)->sin_addr.s_addr =
+ htonl(((0xFFFFFFFFL >> masklen) ^ 0xFFFFFFFFL));
+ return true;
+ }
+ return false;
+}
+
+/****************************************************************************
+ Create a struct sockaddr_storage set to the broadcast or network adress from
+ an incoming sockaddr_storage.
+****************************************************************************/
+
+static void make_bcast_or_net(struct sockaddr_storage *pss_out,
+ const struct sockaddr_storage *pss_in,
+ const struct sockaddr_storage *nmask,
+ bool make_bcast)
+{
+ unsigned int i = 0, len = 0;
+ char *pmask = NULL;
--
Samba Shared Repository
More information about the samba-cvs
mailing list