In article <20021105174502.GA26028@pegasys.ws> (at Tue, 5 Nov 2002
09:45:02 -0800), jw schultz <jw@pegasys.ws> says:
> > I think there really have been no commits since then:
> >
> > http://cvs.samba.org/cgi-bin/cvsweb/rsync/?sortby=date#dirlist
> >
> > We are all slackers and/or overworked. :-(
> >
> > I did see your Stratus (sp?) patch, and it looks harmless and useful.
> > I have a lot on at the moment but I don't mind merging it when I
or
> > somebody else gets a chance.
>
> This might be a good time for tagging 2.5.6 perhaps. A fair
> number of bugfixes have gone in, popt updates, and a few new
> features. It has been stable for about 2 months. Unless
Please apply my IPv6 ACL patch.
This is very important for ipv6-enabled environment.
Index: access.c
==================================================================RCS file:
/cvsroot/apps/rsync/access.c,v
retrieving revision 1.1.1.1
retrieving revision 1.4
diff -u -r1.1.1.1 -r1.4
--- access.c 2002/09/06 04:49:10 1.1.1.1
+++ access.c 2002/09/20 13:14:13 1.4
@@ -30,54 +30,163 @@
return (fnmatch(tok, host, 0) == 0);
}
+static int match_binary(char *b1, char *b2, char *mask, int addrlen)
+{
+ int i;
+
+ for (i=0; i<addrlen; i++) {
+ if ((b1[i]^b2[i])&mask[i]) {
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+static void make_mask(char *mask, int plen, int addrlen) {
+ int w, b;
+ w = plen >> 3;
+ b = plen & 0x7;
+
+ if (w)
+ memset(mask, 0xff, w);
+ mask[w] = 0xff & (0xff<<(8-b));
+ if (w+1 < addrlen)
+ memset(mask+w+1, 0, addrlen-w-1);
+
+ return;
+}
+
static int match_address(char *addr, char *tok)
{
char *p;
- unsigned long a, t, mask = (unsigned long)~0;
+ struct addrinfo hints, *resa, *rest;
+ int gai;
+ int ret = 0;
+ int addrlen = 0;
+#ifdef HAVE_STRTOL
+ long int bits;
+#else
+ int bits;
+#endif
+ char mask[16];
+ char *a = NULL, *t = NULL;
if (!addr || !*addr) return 0;
- if (!isdigit(tok[0])) return 0;
-
p = strchr(tok,'/');
if (p) *p = 0;
-
- a = inet_addr(addr);
- t = inet_addr(tok);
- if (p) {
- *p = '/';
- }
-
- if (t == INADDR_NONE) {
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_NUMERICHOST;
+
+ gai = getaddrinfo(addr, NULL, &hints, &resa);
+ if (gai) return 0;
+
+ gai = getaddrinfo(tok, NULL, &hints, &rest);
+ if (p)
+ *p++ = '/';
+ if (gai) {
rprintf(FERROR,"malformed address %s\n", tok);
+ freeaddrinfo(resa);
return 0;
}
+
+ if (rest->ai_family != resa->ai_family) {
+ ret = 0;
+ goto out;
+ }
- a = ntohl(a);
- t = ntohl(t);
+ switch(resa->ai_family) {
+ case PF_INET:
+ a = (char *)&((struct sockaddr_in *)resa->ai_addr)->sin_addr;
+ t = (char *)&((struct sockaddr_in *)rest->ai_addr)->sin_addr;
+ addrlen = 4;
+
+ break;
+
+#ifdef INET6
+ case PF_INET6:
+ {
+ struct sockaddr_in6 *sin6a, *sin6t;
+
+ sin6a = (struct sockaddr_in6 *)resa->ai_addr;
+ sin6t = (struct sockaddr_in6 *)rest->ai_addr;
+
+ a = (char *)&sin6a->sin6_addr;
+ t = (char *)&sin6t->sin6_addr;
+
+ if (sin6t->sin6_scope_id &&
+ sin6a->sin6_scope_id != sin6t->sin6_scope_id) {
+ ret = 0;
+ goto out;
+ }
+ a = (char *)&sin6a->sin6_addr;
+ t = (char *)&sin6t->sin6_addr;
+ addrlen = 16;
+
+ break;
+ }
+#endif
+ default:
+ rprintf(FERROR,"unknown family %u\n", rest->ai_family);
+ ret = 0;
+ goto out;
+ }
+
+ bits = -1;
if (p) {
- if (strchr(p+1,'.')) {
- mask = inet_addr(p+1);
- if (mask == INADDR_NONE) {
+ if (inet_pton(resa->ai_addr->sa_family, p, mask) <= 0) {
+#ifdef HAVE_STRTOL
+ char *ep = NULL;
+#else
+ unsigned char *pp;
+#endif
+
+#ifdef HAVE_STRTOL
+ bits = strtol(p, &ep, 10);
+ if (!*p || *ep) {
rprintf(FERROR,"malformed mask in %s\n", tok);
- return 0;
+ ret = 0;
+ goto out;
+ }
+#else
+ for (pp = (unsigned char *)p; *pp; pp++) {
+ if (!isascii(*pp) || !isdigit(*pp)) {
+ rprintf(FERROR,"malformed mask in %s\n", tok);
+ ret = 0;
+ goto out;
+ }
+ }
+ bits = atoi(p);
+#endif
+ if (bits == 0) {
+ ret = 1;
+ goto out;
}
- mask = ntohl(mask);
- } else {
- int bits = atoi(p+1);
- if (bits == 0) return 1;
- if (bits <= 0 || bits > 32) {
+ if (bits < 0 || bits > (addrlen << 3)) {
rprintf(FERROR,"malformed mask in %s\n", tok);
- return 0;
+ ret = 0;
+ goto out;
}
- mask &= (mask << (32-bits));
}
+ } else {
+ bits = 128;
}
+
+ if (bits >= 0)
+ make_mask(mask, bits, addrlen);
+
+ ret = match_binary(a, t, mask, addrlen);
- return ((a&mask) == (t&mask));
+out:
+ freeaddrinfo(resa);
+ freeaddrinfo(rest);
+ return ret;
}
static int access_match(char *list, char *addr, char *host)
Index: acconfig.h
==================================================================RCS file:
/cvsroot/apps/rsync/acconfig.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- acconfig.h 2002/09/06 04:49:10 1.1.1.1
+++ acconfig.h 2002/09/20 14:13:10 1.2
@@ -7,4 +7,5 @@
#undef HAVE_GETTIMEOFDAY_TZ
#undef ENABLE_IPV6
#undef HAVE_SOCKADDR_LEN
+#undef HAVE_SOCKADDR_IN6_SCOPE_ID
#undef HAVE_SOCKETPAIR
Index: clientname.c
==================================================================RCS file:
/cvsroot/apps/rsync/clientname.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- clientname.c 2002/09/06 04:49:10 1.1.1.1
+++ clientname.c 2002/09/20 14:13:10 1.2
@@ -108,6 +108,9 @@
struct sockaddr_storage *ss,
socklen_t *ss_len)
{
+#if defined(__linux__) || defined(HAVE_SOCKADDR_IN6_SOCPE_ID)
+ memset(ss, 0, sizeof(*ss));
+#endif
if (getpeername(fd, (struct sockaddr *) ss, ss_len)) {
/* FIXME: Can we really not continue? */
rprintf(FERROR, RSYNC_NAME ": getpeername on fd%d failed: %s\n",
@@ -209,9 +212,23 @@
sin1 = (const struct sockaddr_in6 *) ss;
sin2 = (const struct sockaddr_in6 *) ai->ai_addr;
-
- return memcmp(&sin1->sin6_addr, &sin2->sin6_addr,
- sizeof sin1->sin6_addr);
+
+ if (ai->ai_addrlen < sizeof(struct sockaddr_in6)) {
+ rprintf(FERROR,
+ "%s: too short sockaddr_in6; length=%d\n",
+ fn, ai->ai_addrlen);
+ return 1;
+ }
+
+ if (memcmp(&sin1->sin6_addr, &sin2->sin6_addr,
+ sizeof sin1->sin6_addr))
+ return 1;
+
+#ifdef HAVE_SOCKADDR_IN6_SCOPE_ID
+ if (sin1->sin6_scope_id != sin2->sin6_scope_id)
+ return 1;
+#endif
+ return 0;
}
#endif /* INET6 */
else {
Index: config.h.in
==================================================================RCS file:
/cvsroot/apps/rsync/config.h.in,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- config.h.in 2002/09/06 04:49:10 1.1.1.1
+++ config.h.in 2002/09/20 14:13:10 1.3
@@ -8,6 +8,7 @@
#undef HAVE_GETTIMEOFDAY_TZ
#undef ENABLE_IPV6
#undef HAVE_SOCKADDR_LEN
+#undef HAVE_SOCKADDR_IN6_SCOPE_ID
#undef HAVE_SOCKETPAIR
/* Define to the type of elements in the array set by `getgroups'. Usually
@@ -214,6 +215,9 @@
/* Define if you have the `strpbrk' function. */
#undef HAVE_STRPBRK
+
+/* Define if you have the `strtol' function. */
+#undef HAVE_STRTOL
/* Define if `st_rdev' is member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_RDEV
Index: configure
==================================================================RCS file:
/cvsroot/apps/rsync/configure,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- configure 2002/09/06 04:49:10 1.1.1.1
+++ configure 2002/09/20 14:13:10 1.3
@@ -7514,6 +7514,66 @@
fi
rm -f conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: checking for struct sockaddr_in6.sin6_scope_id"
>&5
+echo $ECHO_N "checking for struct sockaddr_in6.sin6_scope_id...
$ECHO_C" >&6
+if test "${ac_cv_member_struct_sockaddr_in6_sin6_scope_id+set}" =
set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+
+#ifdef F77_DUMMY_MAIN
+# ifdef __cplusplus
+ extern "C"
+# endif
+ int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+static struct sockaddr_in6 ac_aggr;
+if (ac_aggr.sin6_scope_id)
+return 0;
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"")
>&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_member_struct_sockaddr_in6_sin6_scope_id=yes
+else
+ echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+ac_cv_member_struct_sockaddr_in6_sin6_scope_id=no
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result:
$ac_cv_member_struct_sockaddr_in6_sin6_scope_id" >&5
+echo "${ECHO_T}$ac_cv_member_struct_sockaddr_in6_sin6_scope_id"
>&6
+if test $ac_cv_member_struct_sockaddr_in6_sin6_scope_id = yes; then
+ cat >>confdefs.h <<\_ACEOF
+#define HAVE_SOCKADDR_IN6_SCOPE_ID 1
+_ACEOF
+
+fi
+
+
# if we can't find strcasecmp, look in -lresolv (for Unixware at least)
#
@@ -7981,8 +8041,9 @@
+
-for ac_func in strlcat strlcpy mtrace mallinfo setgroups
+for ac_func in strlcat strlcpy strtol mtrace mallinfo setgroups
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
Index: configure.in
==================================================================RCS file:
/cvsroot/apps/rsync/configure.in,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- configure.in 2002/09/06 04:49:10 1.1.1.1
+++ configure.in 2002/09/20 14:13:10 1.3
@@ -346,6 +346,15 @@
[Define if you have strct sockaddr_storage.] ),
AC_MSG_RESULT(no))
+AC_CHECK_MEMBER([struct sockaddr_in6.sin6_scope_id],
+ [ AC_DEFINE(HAVE_SOCKADDR_IN6_SCOPE_ID) ],
+ [],
+ [
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+])
+
# if we can't find strcasecmp, look in -lresolv (for Unixware at least)
#
AC_CHECK_FUNCS(strcasecmp)
@@ -362,7 +371,7 @@
AC_CHECK_FUNCS(waitpid wait4 getcwd strdup strerror chown chmod mknod)
AC_CHECK_FUNCS(fchmod fstat strchr readlink link utime utimes strftime)
AC_CHECK_FUNCS(memmove lchown vsnprintf snprintf asprintf setsid glob strpbrk)
-AC_CHECK_FUNCS(strlcat strlcpy mtrace mallinfo setgroups)
+AC_CHECK_FUNCS(strlcat strlcpy strtol mtrace mallinfo setgroups)
AC_CACHE_CHECK([for working socketpair],rsync_cv_HAVE_SOCKETPAIR,[
AC_TRY_RUN([
--
Hideaki YOSHIFUJI @ USAGI Project <yoshfuji@linux-ipv6.org>
GPG FP: 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA