]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - pw/pw_user.c
Rework the home directory creation and copy or the skel content to use *at
[pw-darwin.git] / pw / pw_user.c
index 315af39ed47e0181ce29dd4cfc3d07742e8bc819..afc163fc916c7a812de57c754faf4758a0ed6b33 100644 (file)
@@ -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);
 }
@@ -874,11 +873,8 @@ pw_gidpolicy(struct cargs * args, char *nam, gid_t prefer)
            (grp->gr_mem == NULL || grp->gr_mem[0] == NULL)) {
                gid = grp->gr_gid;  /* Already created? Use it anyway... */
        } else {
-               struct cargs    grpargs;
                gid_t           grid = -1;
 
-               LIST_INIT(&grpargs);
-
                /*
                 * We need to auto-create a group with the user's name. We
                 * can send all the appropriate output to our sister routine
@@ -893,7 +889,7 @@ pw_gidpolicy(struct cargs * args, char *nam, gid_t prefer)
                if (conf.dryrun) {
                        gid = pw_groupnext(cnf, true);
                } else {
-                       pw_group(M_ADD, nam, grid, &grpargs);
+                       pw_group(M_ADD, nam, grid, NULL);
                        if ((grp = GETGRNAM(nam)) != NULL)
                                gid = grp->gr_gid;
                }