summaryrefslogtreecommitdiffstats
path: root/pw/pw_user.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-07-12 20:29:51 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-07-12 20:29:51 +0000
commit82e3411026949c74f9a726bb418b3fdcbc4e9fd0 (patch)
tree220b3c93097f3a69a4282486b48c4b4ae65d1110 /pw/pw_user.c
parent36810b94302ed35424caa32ae205ee0f1d4f7185 (diff)
downloadpw-darwin-82e3411026949c74f9a726bb418b3fdcbc4e9fd0.tar.gz
pw-darwin-82e3411026949c74f9a726bb418b3fdcbc4e9fd0.tar.zst
pw-darwin-82e3411026949c74f9a726bb418b3fdcbc4e9fd0.zip
Rework the home directory creation and copy or the skel content to use *at
functions This allows to simplify the code a bit for -R by not having to keep modifying path and also prepare the code to improve support -R in userdel While here, add regression tests for the functionality
Diffstat (limited to 'pw/pw_user.c')
-rw-r--r--pw/pw_user.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c
index 16b2ac8..afc163f 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -67,20 +67,19 @@ static void rmopie(char const * name);
static void
create_and_populate_homedir(struct passwd *pwd)
{
- char *homedir, *dotdir;
struct userconf *cnf = conf.userconf;
+ const char *skeldir;
+ int skelfd = -1;
- homedir = dotdir = NULL;
+ skeldir = cnf->dotdir;
- if (conf.rootdir[0] != '\0') {
- asprintf(&homedir, "%s/%s", conf.rootdir, pwd->pw_dir);
- if (homedir == NULL)
- errx(EX_OSERR, "out of memory");
- asprintf(&dotdir, "%s/%s", conf.rootdir, cnf->dotdir);
+ if (skeldir != NULL && *skeldir != '\0') {
+ skelfd = openat(conf.rootfd, cnf->dotdir,
+ O_DIRECTORY|O_CLOEXEC);
}
- copymkdir(homedir ? homedir : pwd->pw_dir, dotdir ? dotdir: cnf->dotdir,
- cnf->homemode, pwd->pw_uid, pwd->pw_gid);
+ copymkdir(conf.rootfd, pwd->pw_dir, skelfd, cnf->homemode, pwd->pw_uid,
+ pwd->pw_gid, 0);
pw_log(cnf, M_ADD, W_USER, "%s(%u) home %s made", pwd->pw_name,
pwd->pw_uid, pwd->pw_dir);
}