Ensure skeldir is abolute path (relatively to the rootdir)
This commit is contained in:
parent
ee8c5d1451
commit
28b2f1294f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=285434
@ -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)
|
||||
|
@ -268,7 +268,7 @@ user_add_skel_body() {
|
||||
echo "c" > ${HOME}/skel/c/d/dot.c
|
||||
mkdir ${HOME}/home
|
||||
ln -sf /nonexistent ${HOME}/skel/c/foo
|
||||
atf_check -s exit:0 ${RPW} useradd foo -k skel -m
|
||||
atf_check -s exit:0 ${RPW} useradd foo -k /skel -m
|
||||
test -d ${HOME}/home/foo || atf_fail "Directory not created"
|
||||
test -f ${HOME}/home/foo/.a || atf_fail "File not created"
|
||||
atf_check -o file:${HOME}/skel/.a -s exit:0 cat ${HOME}/home/foo/.a
|
||||
|
@ -40,7 +40,7 @@ delete_files_body() {
|
||||
mkdir -p ${HOME}/home
|
||||
mkdir -p ${HOME}/var/mail
|
||||
echo "foo wedontcare" > ${HOME}/etc/opiekeys
|
||||
atf_check -s exit:0 ${RPW} useradd foo -k skel -m
|
||||
atf_check -s exit:0 ${RPW} useradd foo -k /skel -m
|
||||
test -d ${HOME}/home || atf_fail "Fail to create home directory"
|
||||
test -f ${HOME}/var/mail/foo || atf_fail "Mail file not created"
|
||||
atf_check -s exit:0 ${RPW} userdel foo -r
|
||||
|
Loading…
Reference in New Issue
Block a user