add new HOME_MODE login.defs(5) option
This option can be used to set a separate mode for useradd(8) and newusers(8) to create the home directories with. If this option is not set, the current behavior of using UMASK or the default umask is preserved. There are many distributions that set UMASK to 077 by default just to create home directories not readable by others and use things like /etc/profile, bashrc or sudo configuration files to set a less restrictive umask. This has always resulted in bug reports because it is hard to follow as users tend to change files like bashrc and are not about setting the umask to counteract the umask set in /etc/login.defs. A recent change in sudo has also resulted in many bug reports about this. sudo now tries to respect the umask set by pam modules and on systems where pam does not set a umask, the login.defs UMASK value is used.
This commit is contained in:
@@ -1216,9 +1216,9 @@ int main (int argc, char **argv)
|
||||
if ( ('\0' != fields[5][0])
|
||||
&& (access (newpw.pw_dir, F_OK) != 0)) {
|
||||
/* FIXME: should check for directory */
|
||||
mode_t msk = 0777 & ~getdef_num ("UMASK",
|
||||
GETDEF_DEFAULT_UMASK);
|
||||
if (mkdir (newpw.pw_dir, msk) != 0) {
|
||||
mode_t mode = getdef_num ("HOME_MODE",
|
||||
0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
|
||||
if (mkdir (newpw.pw_dir, mode) != 0) {
|
||||
fprintf (stderr,
|
||||
_("%s: line %d: mkdir %s failed: %s\n"),
|
||||
Prog, line, newpw.pw_dir,
|
||||
|
||||
@@ -2152,8 +2152,9 @@ static void create_home (void)
|
||||
}
|
||||
|
||||
(void) chown (prefix_user_home, user_id, user_gid);
|
||||
chmod (prefix_user_home,
|
||||
0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
|
||||
mode_t mode = getdef_num ("HOME_MODE",
|
||||
0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
|
||||
chmod (prefix_user_home, mode);
|
||||
home_added = true;
|
||||
#ifdef WITH_AUDIT
|
||||
audit_logger (AUDIT_ADD_USER, Prog,
|
||||
|
||||
Reference in New Issue
Block a user