diff options
author | bapt <bapt@FreeBSD.org> | 2015-07-12 20:29:51 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-07-12 20:29:51 +0000 |
commit | 8621997ee99ee7487f32e3f5c0c45b8dc9c21d5a (patch) | |
tree | 473edb252332496a7902109f52368a7f025499d7 /usr.sbin/pw/pw_user.c | |
parent | 93f91db3aac7ffbe93771407ae5d86292b916cff (diff) | |
download | FreeBSD-src-8621997ee99ee7487f32e3f5c0c45b8dc9c21d5a.zip FreeBSD-src-8621997ee99ee7487f32e3f5c0c45b8dc9c21d5a.tar.gz |
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 'usr.sbin/pw/pw_user.c')
-rw-r--r-- | usr.sbin/pw/pw_user.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index 16b2ac8..afc163f 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/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); } |