diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-07-12 20:29:51 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-07-12 20:29:51 +0000 |
commit | f6975773c5ebf939f9e3f22b2b600d2c821604bc (patch) | |
tree | 8ae8db36682640068427bbf00fdaed91decb822d /pw/pw_user.c | |
parent | 5c8793faf0c3ceee6ca534d0f69b417a3759f7af (diff) | |
download | pw-darwin-f6975773c5ebf939f9e3f22b2b600d2c821604bc.tar.gz pw-darwin-f6975773c5ebf939f9e3f22b2b600d2c821604bc.tar.zst pw-darwin-f6975773c5ebf939f9e3f22b2b600d2c821604bc.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.c | 17 |
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); } |