]> arthur.barton.de Git - netatalk.git/commitdiff
getvolbypath returns incorrect volume, bug #563
authorRalph Boehme <rb@sernet.de>
Wed, 21 May 2014 14:42:58 +0000 (16:42 +0200)
committerRalph Boehme <rb@sernet.de>
Wed, 21 May 2014 14:48:36 +0000 (16:48 +0200)
getvolbypath() would match a given path "/foo/barbaz" with an existing
volume path of "/foo/bar" because the strings where compared with
strnlen() where n is the length of "/foo/bar", ie we did a substring
match.

I faintly remember there was a reason for this, but I couldn't come up
with any sensible configuration of usage of dbd that would not also
work by simply using strcmp() instead of strmcmp().

Of course, in order for dbd to work with paths that included a
trailing slash, there's a need to adding some slash stripping code,
because our code (somehow) ensures (hopefully!) that in struct
vol.v_path is always stored with trailinsh slashes stripped.

Signed-off-by: Ralph Boehme <rb@sernet.de>
NEWS
libatalk/util/netatalk_conf.c

diff --git a/NEWS b/NEWS
index 7e85ab8f2ec11fd496ce28b11c751efe1156a031..6ed64ee6c5d3e96efd5c7e41cf690f4fc7c7d2b1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Changes in 3.1.2
 * FIX: xattrs on *BSD, bug #562
 * NEW: afpd: support for using $u username variable in AFP volume
        definitions. FR#90.
+* FIX: getvolbypath returns incorrect volume, bug #563
 
 Changes in 3.1.1
 ================
index 482aa7776420cd4330a4b8faa59c867a70bcba7b..01e1f16704df4dc66f7570fc2a5aa1ce3dc9243f 100644 (file)
@@ -1606,6 +1606,7 @@ struct vol *getvolbypath(AFPObj *obj, const char *path)
     const char *secname, *basedir, *p = NULL, *subpath = NULL, *subpathconfig;
     char *user = NULL, *prw;
     regmatch_t match[1];
+    size_t abspath_len;
 
     LOG(log_debug, logtype_afpd, "getvolbypath(\"%s\")", path);
 
@@ -1615,13 +1616,28 @@ struct vol *getvolbypath(AFPObj *obj, const char *path)
         strlcat(abspath, "/", MAXPATHLEN);
         strlcat(abspath, path, MAXPATHLEN);
         path = abspath;
+    } else {
+        strlcpy(abspath, path, MAXPATHLEN);
+        path = abspath;
     }
+    /* path now points to a copy of path in the abspath buffer */
 
+    /*
+     * Strip trailing slashes
+     */
+    abspath_len = strlen(abspath);
+    while (abspath[abspath_len - 1] == '/') {
+        abspath[abspath_len - 1] = 0;
+        abspath_len--;
+    }
 
     for (tmp = Volumes; tmp; tmp = tmp->v_next) { /* (1) */
-        if (strncmp(path, tmp->v_path, strlen(tmp->v_path)) == 0) {
+        if (strcmp(path, tmp->v_path) == 0) {
+            LOG(log_debug, logtype_afpd, "getvolbypath: path(\"%s\") == volume(\"%s\")", path, tmp->v_path);
             vol = tmp;
             goto EC_CLEANUP;
+        } else {
+            LOG(log_debug, logtype_afpd, "getvolbypath: path(\"%s\") != volume(\"%s\")", path, tmp->v_path);
         }
     }