summaryrefslogtreecommitdiffstats
path: root/pw/pw_user.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-07-12 22:08:58 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-07-12 22:08:58 +0000
commit2d773bd7573e856c732b3fc1b827b288ea3beebf (patch)
tree723dadc5d4de30a840b02c51a174b5f11b03bdbb /pw/pw_user.c
parentd6d7189c26aa1c3f1bb8ac622e5daf43b8485c30 (diff)
downloadpw-darwin-2d773bd7573e856c732b3fc1b827b288ea3beebf.tar.gz
pw-darwin-2d773bd7573e856c732b3fc1b827b288ea3beebf.tar.zst
pw-darwin-2d773bd7573e856c732b3fc1b827b288ea3beebf.zip
Ensure skeldir is abolute path (relatively to the rootdir)
Diffstat (limited to 'pw/pw_user.c')
-rw-r--r--pw/pw_user.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c
index fd2c80a..8ba2807 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -74,8 +74,9 @@ create_and_populate_homedir(struct passwd *pwd)
skeldir = cnf->dotdir;
if (skeldir != NULL && *skeldir != '\0') {
- skelfd = openat(conf.rootfd, cnf->dotdir,
- O_DIRECTORY|O_CLOEXEC);
+ if (*skeldir == '/')
+ skeldir++;
+ skelfd = openat(conf.rootfd, skeldir, O_DIRECTORY|O_CLOEXEC);
}
copymkdir(conf.rootfd, pwd->pw_dir, skelfd, cnf->homemode, pwd->pw_uid,
@@ -449,8 +450,13 @@ pw_user(int mode, char *name, long id, struct cargs * args)
}
if ((arg = getarg(args, 'k')) != NULL) {
- if (stat(cnf->dotdir = arg->val, &st) == -1 || !S_ISDIR(st.st_mode))
- errx(EX_OSFILE, "skeleton `%s' is not a directory or does not exist", cnf->dotdir);
+ char *tmp = cnf->dotdir = arg->val;
+ if (*tmp == '/')
+ tmp++;
+ if ((fstatat(conf.rootfd, tmp, &st, 0) == -1) ||
+ !S_ISDIR(st.st_mode))
+ errx(EX_OSFILE, "skeleton `%s' is not a directory or "
+ "does not exist", cnf->dotdir);
}
if ((arg = getarg(args, 's')) != NULL)