Blame SOURCES/shadow-4.6-home_mode-directive.patch

9f13c6
From a847899b521b0df0665e442845bcff23407d9ea0 Mon Sep 17 00:00:00 2001
9f13c6
From: Duncan Overbruck <mail@duncano.de>
9f13c6
Date: Sat, 11 Jan 2020 22:19:37 +0100
9f13c6
Subject: [PATCH] add new HOME_MODE login.defs(5) option
9f13c6
9f13c6
This option can be used to set a separate mode for useradd(8) and
9f13c6
newusers(8) to create the home directories with.
9f13c6
If this option is not set, the current behavior of using UMASK
9f13c6
or the default umask is preserved.
9f13c6
9f13c6
There are many distributions that set UMASK to 077 by default just
9f13c6
to create home directories not readable by others and use things like
9f13c6
/etc/profile, bashrc or sudo configuration files to set a less
9f13c6
restrictive
9f13c6
umask. This has always resulted in bug reports because it is hard
9f13c6
to follow as users tend to change files like bashrc and are not about
9f13c6
setting the umask to counteract the umask set in /etc/login.defs.
9f13c6
9f13c6
A recent change in sudo has also resulted in many bug reports about
9f13c6
this. sudo now tries to respect the umask set by pam modules and on
9f13c6
systems where pam does not set a umask, the login.defs UMASK value is
9f13c6
used.
9f13c6
---
9f13c6
 etc/login.defs             | 7 ++++++-
9f13c6
 lib/getdef.c               | 1 +
9f13c6
 man/login.defs.5.xml       | 4 ++++
9f13c6
 man/login.defs.d/UMASK.xml | 3 ++-
9f13c6
 src/newusers.c             | 6 +++---
9f13c6
 src/useradd.c              | 5 +++--
9f13c6
 6 files changed, 19 insertions(+), 7 deletions(-)
9f13c6
9f13c6
diff --git a/etc/login.defs b/etc/login.defs
9f13c6
index cd2597dc..a2f8cd50 100644
9f13c6
--- a/etc/login.defs
9f13c6
+++ b/etc/login.defs
9f13c6
@@ -195,12 +195,17 @@ KILLCHAR	025
9f13c6
 # Default initial "umask" value used by login(1) on non-PAM enabled systems.
9f13c6
 # Default "umask" value for pam_umask(8) on PAM enabled systems.
9f13c6
 # UMASK is also used by useradd(8) and newusers(8) to set the mode for new
9f13c6
-# home directories.
9f13c6
+# home directories if HOME_MODE is not set.
9f13c6
 # 022 is the default value, but 027, or even 077, could be considered
9f13c6
 # for increased privacy. There is no One True Answer here: each sysadmin
9f13c6
 # must make up their mind.
9f13c6
 UMASK		022
9f13c6
 
9f13c6
+# HOME_MODE is used by useradd(8) and newusers(8) to set the mode for new
9f13c6
+# home directories.
9f13c6
+# If HOME_MODE is not set, the value of UMASK is used to create the mode.
9f13c6
+HOME_MODE	0700
9f13c6
+
9f13c6
 #
9f13c6
 # Password aging controls:
9f13c6
 #
9f13c6
diff --git a/lib/getdef.c b/lib/getdef.c
9f13c6
index bbb273f4..00f6abfe 100644
9f13c6
--- a/lib/getdef.c
9f13c6
+++ b/lib/getdef.c
9f13c6
@@ -93,6 +93,7 @@ static struct itemdef def_table[] = {
9f13c6
 	{"FAKE_SHELL", NULL},
9f13c6
 	{"GID_MAX", NULL},
9f13c6
 	{"GID_MIN", NULL},
9f13c6
+	{"HOME_MODE", NULL},
9f13c6
 	{"HUSHLOGIN_FILE", NULL},
9f13c6
 	{"KILLCHAR", NULL},
9f13c6
 	{"LOGIN_RETRIES", NULL},
9f13c6
diff --git a/man/login.defs.5.xml b/man/login.defs.5.xml
9f13c6
index ebf60ba3..9e95da20 100644
9f13c6
--- a/man/login.defs.5.xml
9f13c6
+++ b/man/login.defs.5.xml
9f13c6
@@ -50,6 +50,7 @@
9f13c6
 
9f13c6
 
9f13c6
 
9f13c6
+
9f13c6
 
9f13c6
 
9f13c6
 
9f13c6
@@ -185,6 +186,7 @@
9f13c6
       &FAKE_SHELL;
9f13c6
       &FTMP_FILE;
9f13c6
       &GID_MAX; 
9f13c6
+      &HOME_MODE;
9f13c6
       &HUSHLOGIN_FILE;
9f13c6
       &ISSUE_FILE;
9f13c6
       &KILLCHAR;
9f13c6
@@ -401,6 +403,7 @@
9f13c6
 	    ENCRYPT_METHOD
9f13c6
 	    GID_MAX GID_MIN
9f13c6
 	    MAX_MEMBERS_PER_GROUP MD5_CRYPT_ENAB
9f13c6
+	    HOME_MODE
9f13c6
 	    PASS_MAX_DAYS PASS_MIN_DAYS PASS_WARN_AGE
9f13c6
 	    <phrase condition="sha_crypt">SHA_CRYPT_MAX_ROUNDS
9f13c6
 	    SHA_CRYPT_MIN_ROUNDS</phrase>
9f13c6
@@ -481,6 +484,7 @@
9f13c6
 	  <para>
9f13c6
 	    CREATE_HOME
9f13c6
 	    GID_MAX GID_MIN
9f13c6
+	    HOME_MODE
9f13c6
 	    MAIL_DIR MAX_MEMBERS_PER_GROUP
9f13c6
 	    PASS_MAX_DAYS PASS_MIN_DAYS PASS_WARN_AGE
9f13c6
	    SUB_GID_COUNT SUB_GID_MAX SUB_GID_MIN
9f13c6
diff --git a/man/login.defs.d/HOME_MODE.xml b/man/login.defs.d/HOME_MODE.xml
9f13c6
new file mode 100644
9f13c6
index 00000000..21aa55f7
9f13c6
--- /dev/null
9f13c6
+++ b/man/login.defs.d/HOME_MODE.xml
9f13c6
@@ -0,0 +1,43 @@
9f13c6
+
9f13c6
+   Copyright (c) 1991 - 1993, Julianne Frances Haugh
9f13c6
+   Copyright (c) 1991 - 1993, Chip Rosenthal
9f13c6
+   Copyright (c) 2007 - 2009, Nicolas François
9f13c6
+   All rights reserved.
9f13c6
+  
9f13c6
+   Redistribution and use in source and binary forms, with or without
9f13c6
+   modification, are permitted provided that the following conditions
9f13c6
+   are met:
9f13c6
+   1. Redistributions of source code must retain the above copyright
9f13c6
+      notice, this list of conditions and the following disclaimer.
9f13c6
+   2. Redistributions in binary form must reproduce the above copyright
9f13c6
+      notice, this list of conditions and the following disclaimer in the
9f13c6
+      documentation and/or other materials provided with the distribution.
9f13c6
+   3. The name of the copyright holders or contributors may not be used to
9f13c6
+      endorse or promote products derived from this software without
9f13c6
+      specific prior written permission.
9f13c6
+  
9f13c6
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9f13c6
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
9f13c6
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
9f13c6
+   PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
9f13c6
+   HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9f13c6
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9f13c6
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
9f13c6
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
9f13c6
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9f13c6
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
9f13c6
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9f13c6
+-->
9f13c6
+<varlistentry>
9f13c6
+  <term><option>HOME_MODE</option> (number)</term>
9f13c6
+  <listitem>
9f13c6
+    <para>
9f13c6
+      The mode for new home directories. If not specified,
9f13c6
+      the <option>UMASK</option> is used to create the mode.
9f13c6
+    </para>
9f13c6
+    <para>
9f13c6
+      <command>useradd</command> and <command>newusers</command> use this
9f13c6
+      to set the mode of the home directory they create.
9f13c6
+    </para>
9f13c6
+  </listitem>
9f13c6
+</varlistentry>
9f13c6
diff --git a/man/login.defs.d/UMASK.xml b/man/login.defs.d/UMASK.xml
9f13c6
index d7b71a5e..0f061dbb 100644
9f13c6
--- a/man/login.defs.d/UMASK.xml
9f13c6
+++ b/man/login.defs.d/UMASK.xml
9f13c6
@@ -37,7 +37,8 @@
9f13c6
     </para>
9f13c6
     <para>
9f13c6
       <command>useradd</command> and <command>newusers</command> use this
9f13c6
-      mask to set the mode of the home directory they create
9f13c6
+      mask to set the mode of the home directory they create if
9f13c6
+      <option>HOME_MODE</option> is not set.
9f13c6
     </para>
9f13c6
     <para condition="no_pam">
9f13c6
       It is also used by <command>login</command> to define users' initial
9f13c6
diff --git a/src/newusers.c b/src/newusers.c
9f13c6
index 99c69f78..e9fe0e27 100644
9f13c6
--- a/src/newusers.c
9f13c6
+++ b/src/newusers.c
9f13c6
@@ -1216,9 +1216,9 @@ int main (int argc, char **argv)
9f13c6
 		if (   ('\0' != fields[5][0])
9f13c6
 		    && (access (newpw.pw_dir, F_OK) != 0)) {
9f13c6
 /* FIXME: should check for directory */
9f13c6
-			mode_t msk = 0777 & ~getdef_num ("UMASK",
9f13c6
-			                                 GETDEF_DEFAULT_UMASK);
9f13c6
-			if (mkdir (newpw.pw_dir, msk) != 0) {
9f13c6
+			mode_t mode = getdef_num ("HOME_MODE",
9f13c6
+			                          0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
9f13c6
+			if (mkdir (newpw.pw_dir, mode) != 0) {
9f13c6
 				fprintf (stderr,
9f13c6
 				         _("%s: line %d: mkdir %s failed: %s\n"),
9f13c6
 				         Prog, line, newpw.pw_dir,
9f13c6
diff --git a/src/useradd.c b/src/useradd.c
9f13c6
index 4af0f7c6..8b453e3c 100644
9f13c6
--- a/src/useradd.c
9f13c6
+++ b/src/useradd.c
9f13c6
@@ -2152,8 +2152,9 @@ static void create_home (void)
9f13c6
 			fail_exit (E_HOMEDIR);
9f13c6
 		}
9f13c6
 		(void) chown (prefix_user_home, user_id, user_gid);
9f13c6
-		chmod (prefix_user_home,
9f13c6
-		       0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
9f13c6
+		mode_t mode = getdef_num ("HOME_MODE",
9f13c6
+		                          0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
9f13c6
+		chmod (prefix_user_home, mode);
9f13c6
 		home_added = true;
9f13c6
 #ifdef WITH_AUDIT
9f13c6
 		audit_logger (AUDIT_USER_MGMT, Prog,
9f13c6
-- 
9f13c6
2.25.2
9f13c6