Skip to content

Commit

Permalink
User homes directory names
Browse files Browse the repository at this point in the history
Fix an issue with user homes when user home directory has not the
same name as the username.

Fixes bug #497.
  • Loading branch information
slowfranklin committed Feb 15, 2013
1 parent 636cc94 commit 726e33c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Changes in 3.0.3
* UPD: RedHat sysvinit: rm graceful, reimplement reload, add condrestart
* FIX: Couldn't create folders on FreeBSD 9.1 ZFS fileystems.
Fixed bug #491.
* FIX: Fix an issue with user homes when user home directory has not the
same name as the username.
Fixes bug #497.

Changes in 3.0.2
================
Expand Down
61 changes: 61 additions & 0 deletions libatalk/util/netatalk_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,56 @@ struct vol *getvolbyvid(const uint16_t vid )
return( vol );
}

/*
* get username by path
*
* getvolbypath() assumes that the user home directory has the same name as the username.
* If that is not true, getuserbypath() is called and tries to retrieve the username
* from the directory owner, checking its validity.
*
* @param path (r) absolute volume path
* @returns NULL if no match is found, pointer to username if successfull
*
*/
static char *getuserbypath(const char *path)
{
EC_INIT;
struct stat sbuf;
struct passwd *pwd;
char *hdir = NULL;

LOG(log_debug, logtype_afpd, "getuserbypath(\"%s\")", path);

/* does folder exists? */
if (stat(path, &sbuf) != 0)
EC_FAIL;

/* get uid of dir owner */
if ((pwd = getpwuid(sbuf.st_uid)) == NULL)
EC_FAIL;

/* does user home directory exists? */
if (stat(pwd->pw_dir, &sbuf) != 0)
EC_FAIL;

/* resolve and remove symlinks */
if ((hdir = realpath_safe(pwd->pw_dir)) == NULL)
EC_FAIL;

/* handle subdirectories, path = */
if (strncmp(path, hdir, strlen(hdir)) != 0)
EC_FAIL;

LOG(log_debug, logtype_afpd, "getuserbypath: match user: %s, home: %s, realhome: %s",
pwd->pw_name, pwd->pw_dir, hdir);

EC_CLEANUP:
if (hdir)
free(hdir);
if (ret != 0)
return NULL;
return pwd->pw_name;
}
/*!
* Search volume by path, creating user home vols as necessary
*
Expand All @@ -1447,6 +1497,9 @@ struct vol *getvolbyvid(const uint16_t vid )
* (3) If there is, match "path" with "basedir regex" to get the user home parent dir
* (4) Built user home path by appending the basedir matched in (3) and appending the username
* (5) The next path element then is the username
* (5b) getvolbypath() assumes that the user home directory has the same name as the username.
* If that is not true, getuserbypath() is called and tries to retrieve the username
* from the directory owner, checking its validity
* (6) Append [Homes]->path subdirectory if defined
* (7) Create volume
*
Expand Down Expand Up @@ -1539,6 +1592,14 @@ struct vol *getvolbypath(AFPObj *obj, const char *path)
subpath = prw;

strlcat(tmpbuf, user, MAXPATHLEN);
if (getpwnam(user) == NULL) {
/* (5b) */
char *tuser;
if ((tuser = getuserbypath(tmpbuf)) != NULL) {
free(user);
user = strdup(tuser);
}
}
strlcpy(obj->username, user, MAXUSERLEN);
strlcat(tmpbuf, "/", MAXPATHLEN);

Expand Down

0 comments on commit 726e33c

Please sign in to comment.