From: Ralph Boehme Date: Wed, 21 May 2014 14:42:58 +0000 (+0200) Subject: getvolbypath returns incorrect volume, bug #563 X-Git-Url: https://arthur.ath.cx/gitweb/?a=commitdiff_plain;h=c74e410eeb03f8fe2fc31a2a4093a1ad5b65c6db;p=netatalk.git getvolbypath returns incorrect volume, bug #563 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 --- diff --git a/NEWS b/NEWS index 7e85ab8f..6ed64ee6 100644 --- 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 ================ diff --git a/libatalk/util/netatalk_conf.c b/libatalk/util/netatalk_conf.c index 482aa777..01e1f167 100644 --- a/libatalk/util/netatalk_conf.c +++ b/libatalk/util/netatalk_conf.c @@ -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); } }