Add home directory creation mode to pw.conf(5) and be a bit

more specific about the effect of the current umask on -M.
This commit is contained in:
le 2007-03-30 11:23:10 +00:00
parent 2f93827b34
commit f17fbfd9be
6 changed files with 38 additions and 9 deletions

View File

@ -24,7 +24,7 @@
.\" .\"
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd March 27, 2007 .Dd March 30, 2007
.Dt PW 8 .Dt PW 8
.Os .Os
.Sh NAME .Sh NAME
@ -69,6 +69,7 @@
.Op Fl g Ar group .Op Fl g Ar group
.Op Fl G Ar grouplist .Op Fl G Ar grouplist
.Op Fl k Ar dir .Op Fl k Ar dir
.Op Fl M Ar mode
.Op Fl u Ar min , Ns Ar max .Op Fl u Ar min , Ns Ar max
.Op Fl i Ar min , Ns Ar max .Op Fl i Ar min , Ns Ar max
.Op Fl w Ar method .Op Fl w Ar method
@ -453,7 +454,9 @@ This can be overridden by the
option on the command line, if desired. option on the command line, if desired.
.It Fl M Ar mode .It Fl M Ar mode
Create the user's home directory with the specified Create the user's home directory with the specified
.Ar mode . .Ar mode ,
modified by the current
.Xr umask 2 .
If omitted, it is derived from the parent process' If omitted, it is derived from the parent process'
.Xr umask 2 . .Xr umask 2 .
This option is only useful in combination with the This option is only useful in combination with the

View File

@ -328,6 +328,7 @@ cmdhelp(int mode, int which)
"\t-G grp1,grp2 additional groups\n" "\t-G grp1,grp2 additional groups\n"
"\t-L class default user class\n" "\t-L class default user class\n"
"\t-k dir default home skeleton\n" "\t-k dir default home skeleton\n"
"\t-M mode home directory permissions\n"
"\t-u min,max set min,max uids\n" "\t-u min,max set min,max uids\n"
"\t-i min,max set min,max gids\n" "\t-i min,max set min,max gids\n"
"\t-w method set default password method\n" "\t-w method set default password method\n"

View File

@ -24,7 +24,7 @@
.\" .\"
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd December 9, 1996 .Dd March 30, 2007
.Dt PW.CONF 5 .Dt PW.CONF 5
.Os .Os
.Sh NAME .Sh NAME
@ -78,6 +78,8 @@ mail to send to new users
log user/group modifications to this file log user/group modifications to this file
.It home .It home
root directory for home directories root directory for home directories
.It homemode
permissions for home directory
.It shellpath .It shellpath
paths in which to locate shell programs paths in which to locate shell programs
.It shells .It shells
@ -204,6 +206,12 @@ This specifies the location of the directory in which all new user
home directories are created. home directories are created.
.Pp .Pp
The The
.Ar homemode
keyword is optional.
It specifies the creation mask of the user's home directory and is modified by
.Xr umask 2 .
.Pp
The
.Ar shellpath .Ar shellpath
keyword specifies a list of directories - separated by colons keyword specifies a list of directories - separated by colons
.Ql \&: .Ql \&:
@ -303,6 +311,7 @@ as comments.
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr passwd 1 , .Xr passwd 1 ,
.Xr umask 2 ,
.Xr group 5 , .Xr group 5 ,
.Xr login.conf 5 , .Xr login.conf 5 ,
.Xr passwd 5 , .Xr passwd 5 ,

View File

@ -81,6 +81,7 @@ struct userconf
char *newmail; /* Mail to send to new accounts */ char *newmail; /* Mail to send to new accounts */
char *logfile; /* Where to log changes */ char *logfile; /* Where to log changes */
char *home; /* Where to create home directory */ char *home; /* Where to create home directory */
mode_t homemode; /* Home directory permissions */
char *shelldir; /* Where shells are located */ char *shelldir; /* Where shells are located */
char **shells; /* List of shells */ char **shells; /* List of shells */
char *shell_default; /* Default shell */ char *shell_default; /* Default shell */

View File

@ -47,6 +47,7 @@ enum {
_UC_NEWMAIL, _UC_NEWMAIL,
_UC_LOGFILE, _UC_LOGFILE,
_UC_HOMEROOT, _UC_HOMEROOT,
_UC_HOMEMODE,
_UC_SHELLPATH, _UC_SHELLPATH,
_UC_SHELLS, _UC_SHELLS,
_UC_DEFAULTSHELL, _UC_DEFAULTSHELL,
@ -90,6 +91,7 @@ static struct userconf config =
NULL, /* Mail to send to new accounts */ NULL, /* Mail to send to new accounts */
"/var/log/userlog", /* Where to log changes */ "/var/log/userlog", /* Where to log changes */
"/home", /* Where to create home directory */ "/home", /* Where to create home directory */
0777, /* Home directory perms, modified by umask */
"/bin", /* Where shells are located */ "/bin", /* Where shells are located */
system_shells, /* List of shells (first is default) */ system_shells, /* List of shells (first is default) */
bourne_shell, /* Default shell */ bourne_shell, /* Default shell */
@ -114,6 +116,7 @@ static char const *comments[_UC_FIELDS] =
"\n# Mail this file to new user (/etc/newuser.msg or no)\n", "\n# Mail this file to new user (/etc/newuser.msg or no)\n",
"\n# Log add/change/remove information in this file\n", "\n# Log add/change/remove information in this file\n",
"\n# Root directory in which $HOME directory is created\n", "\n# Root directory in which $HOME directory is created\n",
"\n# Mode for the new $HOME directory, will be modified by umask\n",
"\n# Colon separated list of directories containing valid shells\n", "\n# Colon separated list of directories containing valid shells\n",
"\n# Comma separated list of available shells (without paths)\n", "\n# Comma separated list of available shells (without paths)\n",
"\n# Default shell (without path)\n", "\n# Default shell (without path)\n",
@ -139,6 +142,7 @@ static char const *kwds[] =
"newmail", "newmail",
"logfile", "logfile",
"home", "home",
"homemode",
"shellpath", "shellpath",
"shells", "shells",
"defaultshell", "defaultshell",
@ -255,6 +259,7 @@ read_userconfig(char const * file)
static char const toks[] = " \t\r\n,="; static char const toks[] = " \t\r\n,=";
char *q = strtok(NULL, toks); char *q = strtok(NULL, toks);
int i = 0; int i = 0;
mode_t *modeset;
while (i < _UC_FIELDS && strcmp(p, kwds[i]) != 0) while (i < _UC_FIELDS && strcmp(p, kwds[i]) != 0)
++i; ++i;
@ -294,6 +299,12 @@ read_userconfig(char const * file)
config.home = (q == NULL || !boolean_val(q, 1)) config.home = (q == NULL || !boolean_val(q, 1))
? "/home" : newstr(q); ? "/home" : newstr(q);
break; break;
case _UC_HOMEMODE:
modeset = setmode(q);
config.homemode = (q == NULL || !boolean_val(q, 1))
? 0777 : getmode(modeset, 0777);
free(modeset);
break;
case _UC_SHELLPATH: case _UC_SHELLPATH:
config.shelldir = (q == NULL || !boolean_val(q, 1)) config.shelldir = (q == NULL || !boolean_val(q, 1))
? "/bin" : newstr(q); ? "/bin" : newstr(q);
@ -413,6 +424,10 @@ write_userconfig(char const * file)
case _UC_HOMEROOT: case _UC_HOMEROOT:
val = config.home; val = config.home;
break; break;
case _UC_HOMEMODE:
sprintf(buf, "%04o", config.homemode);
quote = 0;
break;
case _UC_SHELLPATH: case _UC_SHELLPATH:
val = config.shelldir; val = config.shelldir;
break; break;

View File

@ -166,8 +166,8 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
dmode_c); dmode_c);
dmode = getmode(set, S_IRWXU | S_IRWXG | S_IRWXO); dmode = getmode(set, S_IRWXU | S_IRWXG | S_IRWXO);
free(set); free(set);
} else cnf->homemode = dmode;
dmode = S_IRWXU | S_IRWXG | S_IRWXO; }
/* /*
* If we'll need to use it or we're updating it, * If we'll need to use it or we're updating it,
@ -194,7 +194,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
if (strchr(cnf->home+1, '/') == NULL) { if (strchr(cnf->home+1, '/') == NULL) {
strcpy(dbuf, "/usr"); strcpy(dbuf, "/usr");
strncat(dbuf, cnf->home, MAXPATHLEN-5); strncat(dbuf, cnf->home, MAXPATHLEN-5);
if (mkdir(dbuf, dmode) != -1 || errno == EEXIST) { if (mkdir(dbuf, cnf->homemode) != -1 || errno == EEXIST) {
chown(dbuf, 0, 0); chown(dbuf, 0, 0);
/* /*
* Skip first "/" and create symlink: * Skip first "/" and create symlink:
@ -210,7 +210,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
while ((p = strchr(++p, '/')) != NULL) { while ((p = strchr(++p, '/')) != NULL) {
*p = '\0'; *p = '\0';
if (stat(dbuf, &st) == -1) { if (stat(dbuf, &st) == -1) {
if (mkdir(dbuf, dmode) == -1) if (mkdir(dbuf, cnf->homemode) == -1)
goto direrr; goto direrr;
chown(dbuf, 0, 0); chown(dbuf, 0, 0);
} else if (!S_ISDIR(st.st_mode)) } else if (!S_ISDIR(st.st_mode))
@ -219,7 +219,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
} }
} }
if (stat(dbuf, &st) == -1) { if (stat(dbuf, &st) == -1) {
if (mkdir(dbuf, dmode) == -1) { if (mkdir(dbuf, cnf->homemode) == -1) {
direrr: err(EX_OSFILE, "mkdir '%s'", dbuf); direrr: err(EX_OSFILE, "mkdir '%s'", dbuf);
} }
chown(dbuf, 0, 0); chown(dbuf, 0, 0);
@ -776,7 +776,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
* existing files will *not* be overwritten. * existing files will *not* be overwritten.
*/ */
if (!PWALTDIR() && getarg(args, 'm') != NULL && pwd->pw_dir && *pwd->pw_dir == '/' && pwd->pw_dir[1]) { if (!PWALTDIR() && getarg(args, 'm') != NULL && pwd->pw_dir && *pwd->pw_dir == '/' && pwd->pw_dir[1]) {
copymkdir(pwd->pw_dir, cnf->dotdir, dmode, pwd->pw_uid, pwd->pw_gid); 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", pw_log(cnf, mode, W_USER, "%s(%ld) home %s made",
pwd->pw_name, (long) pwd->pw_uid, pwd->pw_dir); pwd->pw_name, (long) pwd->pw_uid, pwd->pw_dir);
} }