pw not creating home directories with -V +patch

Ivan Voras ivoras at
Wed Aug 22 15:03:01 PDT 2007


I've just found out that pw(8) isn't creating home directories when -V 
(alternate /etc directory) is specified. I realize this was probably 
made to avoid foot-shooting but I also think there should be a way to 
enable this feature. I've created the following patch:

--- pw_user.c.old       2007-08-22 04:00:24.000000000 +0200
+++ pw_user.c   2007-08-22 04:10:30.000000000 +0200
@@ -775,7 +775,7 @@
          * that this also `works' for editing users if -m is used, but
          * existing files will *not* be overwritten.
-       if (!PWALTDIR() && getarg(args, 'm') != NULL && pwd->pw_dir && 
*pwd->pw_dir == '/' && pwd->pw_dir[1]) {
+       if ((!PWALTDIR() | (PWALTDIR() && getarg(args, 'd') != NULL)) && 
getarg(args, 'm') != NULL && pwd->pw_dir && *pwd->pw_dir == '/' && 
pwd->pw_dir[1]) {
                 copymkdir(pwd->pw_dir, cnf->dotdir, cnf->homemode, 
pwd->pw_uid, pwd->pw_gid);
                 pw_log(cnf, mode, W_USER, "%s(%ld) home %s made",
                        pwd->pw_name, (long) pwd->pw_uid, pwd->pw_dir);

This will enable pw to create user's home directory only if the 
directory name was explicitly specified on the command line (the -d 
switch), which I think is in the spirit of the -V switch.

If someone's available, I'd like this to get committed as soon as possible.

(If you need an example of why this behavior is useful, think of 
creating users for a jail from outside the jail, installers, etc.)

More information about the freebsd-hackers mailing list