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