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
commitc1e7bb989dbd01e5ed534b0db64aa19b97f2262c (patch)
tree40d748945f4c5728dae581732e62a84353ef7a9d /pw/pw_user.c
parenta5020ce2c4306656996725b75203311f5ebf8e91 (diff)
downloadpw-darwin-c1e7bb989dbd01e5ed534b0db64aa19b97f2262c.tar.gz
pw-darwin-c1e7bb989dbd01e5ed534b0db64aa19b97f2262c.tar.zst
pw-darwin-c1e7bb989dbd01e5ed534b0db64aa19b97f2262c.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)