Unhelpful error message when matching hosts in access list [PATCH]

Wayne Davison wayned at samba.org
Tue Jul 8 04:43:02 EST 2003


On Mon, Jul 07, 2003 at 06:29:58PM +0200, Thorild Selen wrote:
> It's not enough just checking the last char to see whether something
> is an address: [...]

Yeah, good point.  I've checked in an improved version of the test based
on your suggestions (which I finally got around to looking at in depth).

> (What to do when rsync is configured for IPv4 only, but we are given
> an IPv6 address to match against? Just considering it a failed match
> would perhaps do.)

My patch leaves out the IPv6 logic if INET6 is not configured into rsync.

> Also, please consider introducing the other change in my patch; [...]
> This gives a more descriptive error message when
> getaddrinfo fails, instead of just telling us that it failed.

Yes, my only concern was with the portability of gai_strerror(), but
when I had a chance to finally look into this, I noticed that we already
supply a compatibility function for gai_strerror() -- thus, I was
concerned over nothing.

I've checked-in the appended patch.  See if you like it.

..wayne..
-------------- next part --------------
--- access.c	5 Jul 2003 07:39:57 -0000
+++ access.c	7 Jul 2003 18:37:38 -0000
@@ -73,16 +73,24 @@
 #endif
 	char mask[16];
 	char *a = NULL, *t = NULL;
+	unsigned int len;
 
 	if (!addr || !*addr) return 0;
 
 	p = strchr(tok,'/');
-	if (p) *p = 0;
-
-	/* skip if last char is not a digit (i.e. not an address) */
-	/* (don't check first char - might be 11.22.33.44.an.isp) */
-	if (!*tok) return 0;	/* nothing to check */
-	if (!isdigit(*(unsigned char*)tok+strlen(tok)-1)) return 0;
+	if (p) {
+		*p = '\0';
+		len = p - tok;
+	}
+	else
+		len = strlen(tok);
+
+	/* Fail quietly if tok is a hostname (not an address) */
+	if (strspn(tok, "./0123456789") != len
+#ifdef INET6
+	 && !strchr(tok, ':')
+#endif
+		) return 0;
 
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = PF_UNSPEC;
@@ -98,7 +106,10 @@
 	if (p)
 		*p++ = '/';
 	if (gai) {
-		rprintf(FERROR,"malformed address %s\n", tok);
+		rprintf(FERROR,
+			"error matching address %s: %s\n",
+			tok,
+			gai_strerror(gai));
 		freeaddrinfo(resa);
 		return 0;
 	}


More information about the rsync mailing list