From 94afc9de97f2118bd28f6971bdec009e4e380b7a Mon Sep 17 00:00:00 2001 From: HAT Date: Wed, 3 Oct 2012 23:23:55 +0900 Subject: [PATCH] fix: basedir regex symlink problem --- NEWS | 2 ++ libatalk/util/netatalk_conf.c | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 81863591..e203bd41 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ Changes in 3.0.2 ================ * FIX: "path" parameter value may contain symlink. +* FIX: "basedir regex" was never able to treat symlink. + If /home -> /usr/home, set "basedir regex = /usr/home". Changes in 3.0.1 ================ diff --git a/libatalk/util/netatalk_conf.c b/libatalk/util/netatalk_conf.c index cd550be0..6d252e83 100644 --- a/libatalk/util/netatalk_conf.c +++ b/libatalk/util/netatalk_conf.c @@ -989,6 +989,7 @@ static int readvolfile(AFPObj *obj, const struct passwd *pwent) EC_INIT; static int regexerr = -1; static regex_t reg; + char *realpw_dir; char *realvolpath; char volname[AFPVOL_U8MNAMELEN + 1]; char tmp[MAXPATHLEN + 1], tmp2[MAXPATHLEN + 1]; @@ -1022,6 +1023,8 @@ static int readvolfile(AFPObj *obj, const struct passwd *pwent) if (pwent->pw_dir == NULL || STRCMP("", ==, pwent->pw_dir)) /* no user home */ continue; + if ((realpw_dir = realpath_safe(pwent->pw_dir)) == NULL) + continue; /* check if user home matches our "basedir regex" */ if ((basedir = iniparser_getstring(obj->iniconfig, INISEC_HOMES, "basedir regex", NULL)) == NULL) { @@ -1036,13 +1039,13 @@ static int readvolfile(AFPObj *obj, const struct passwd *pwent) LOG(log_debug, logtype_default, "readvolfile: bad basedir regex: %s", errbuf); } - if (regexec(®, pwent->pw_dir, 1, match, 0) == REG_NOMATCH) { + if (regexec(®, realpw_dir, 1, match, 0) == REG_NOMATCH) { LOG(log_debug, logtype_default, "readvolfile: user home \"%s\" doesn't match basedir regex \"%s\"", - pwent->pw_dir, basedir); + realpw_dir, basedir); continue; } - strlcpy(tmp, pwent->pw_dir, MAXPATHLEN); + strlcpy(tmp, realpw_dir, MAXPATHLEN); strlcat(tmp, "/", MAXPATHLEN); if (p = iniparser_getstring(obj->iniconfig, INISEC_HOMES, "path", NULL)) strlcat(tmp, p, MAXPATHLEN); -- 2.39.2