diff options
author | bapt <bapt@FreeBSD.org> | 2015-07-12 22:08:58 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-07-12 22:08:58 +0000 |
commit | e657e72f8d38371e7179defecc39ca3ab89fc233 (patch) | |
tree | 6019fc74314eaadbfb606fe912b6ada0de0473ec /usr.sbin/pw/pw_user.c | |
parent | 16b27ac1cfeeb4676dfc24ad1be02d253f418ac3 (diff) | |
download | FreeBSD-src-e657e72f8d38371e7179defecc39ca3ab89fc233.zip FreeBSD-src-e657e72f8d38371e7179defecc39ca3ab89fc233.tar.gz |
Ensure skeldir is abolute path (relatively to the rootdir)
Diffstat (limited to 'usr.sbin/pw/pw_user.c')
-rw-r--r-- | usr.sbin/pw/pw_user.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index fd2c80a..8ba2807 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/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) |