If there is no lchown(), don't try to set the user & group of a symlink.
[rsync/rsync.git] / access.c
index 4cbd9a1..cba3cc5 100644 (file)
--- a/access.c
+++ b/access.c
@@ -27,7 +27,7 @@
 static int match_hostname(char *host, char *tok)
 {
        if (!host || !*host) return 0;
-       return (fnmatch(tok, host, 0) == 0);
+       return wildmatch(tok, host);
 }
 
 static int match_binary(char *b1, char *b2, char *mask, int addrlen)
@@ -73,16 +73,28 @@ static int match_address(char *addr, char *tok)
 #endif
        char mask[16];
        char *a = NULL, *t = NULL;
+       unsigned int len;
 
        if (!addr || !*addr) return 0;
 
        p = strchr(tok,'/');
-       if (p) *p = 0;
+       if (p) {
+               *p = '\0';
+               len = p - tok;
+       }
+       else
+               len = strlen(tok);
 
-       /* 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;
+       /* Fail quietly if tok is a hostname (not an address) */
+       if (strspn(tok, ".0123456789") != len
+#ifdef INET6
+           && strchr(tok, ':') == NULL
+#endif
+       ) {
+               if (p)
+                       *p = '/';
+               return 0;
+       }
 
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = PF_UNSPEC;
@@ -91,14 +103,18 @@ static int match_address(char *addr, char *tok)
        hints.ai_flags = AI_NUMERICHOST;
 #endif
 
-       gai = getaddrinfo(addr, NULL, &hints, &resa);
-       if (gai) return 0;
+       if (getaddrinfo(addr, NULL, &hints, &resa) != 0) {
+               if (p)
+                       *p = '/';
+               return 0;
+       }
 
        gai = getaddrinfo(tok, NULL, &hints, &rest);
        if (p)
                *p++ = '/';
-       if (gai) {
-               rprintf(FERROR,"malformed address %s\n", tok);
+       if (gai != 0) {
+               rprintf(FLOG, "error matching address %s: %s\n",
+                       tok, gai_strerror(gai));
                freeaddrinfo(resa);
                return 0;
        }
@@ -141,7 +157,7 @@ static int match_address(char *addr, char *tok)
            }
 #endif
        default:
-           rprintf(FERROR,"unknown family %u\n", rest->ai_family);
+           rprintf(FLOG, "unknown family %u\n", rest->ai_family);
            ret = 0;
            goto out;
        }
@@ -158,14 +174,14 @@ static int match_address(char *addr, char *tok)
 #ifdef HAVE_STRTOL
                        bits = strtol(p, &ep, 10);
                        if (!*p || *ep) {
-                               rprintf(FERROR,"malformed mask in %s\n", tok);
+                               rprintf(FLOG, "malformed mask in %s\n", tok);
                                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);
+                                       rprintf(FLOG, "malformed mask in %s\n", tok);
                                        ret = 0;
                                        goto out;
                                }
@@ -177,7 +193,7 @@ static int match_address(char *addr, char *tok)
                                goto out;
                        }
                        if (bits < 0 || bits > (addrlen << 3)) {
-                               rprintf(FERROR,"malformed mask in %s\n", tok);
+                               rprintf(FLOG, "malformed mask in %s\n", tok);
                                ret = 0;
                                goto out;
                        }