Blame SOURCES/oddjob-home-mode-support.patch

673046
From c51b28adf66a4597ff1c0cb0e0754b2968a337e2 Mon Sep 17 00:00:00 2001
673046
From: Alexander Bokovoy <abokovoy@redhat.com>
673046
Date: Thu, 8 Oct 2020 13:37:32 +0300
673046
Subject: [PATCH] Read HOME_MODE and UMASK from /etc/login.defs
673046
673046
shadow-utils changed behavior of UMASK to only apply to runtime
673046
processes. For home directories, HOME_MODE variable was introduced
673046
instead.
673046
673046
Read HOME_MODE and fall back to UMASK if that does not exist.
673046
673046
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
673046
---
673046
 src/mkhomedir.c                 | 13 +++++++++----
673046
 src/oddjobd-mkhomedir.conf.5.in |  3 ++-
673046
 src/pam_oddjob_mkhomedir.8.in   |  5 +++--
673046
 3 files changed, 14 insertions(+), 7 deletions(-)
673046
673046
diff --git a/src/mkhomedir.c b/src/mkhomedir.c
673046
index 1c0d8e4..be85959 100644
673046
--- a/src/mkhomedir.c
673046
+++ b/src/mkhomedir.c
673046
@@ -264,12 +264,13 @@ mkhomedir(const char *user, int flags)
673046
 }
673046
 
673046
 static mode_t
673046
-get_umask(int *configured)
673046
+get_umask(int *configured, const char *variable)
673046
 {
673046
 	FILE *fp;
673046
 	char buf[BUFSIZ], *p, *end;
673046
 	mode_t mask = umask(0777);
673046
 	long tmp;
673046
+	size_t vlen = strlen(variable);
673046
 
673046
 	fp = fopen("/etc/login.defs", "r");
673046
 	if (fp != NULL) {
673046
@@ -279,10 +280,10 @@ get_umask(int *configured)
673046
 			}
673046
 			buf[strcspn(buf, "\r\n")] = '\0';
673046
 			p = buf + strspn(buf, " \t");
673046
-			if (strncmp(p, "UMASK", 5) != 0) {
673046
+			if (strncmp(p, variable, vlen) != 0) {
673046
 				continue;
673046
 			}
673046
-			p += 5;
673046
+			p += vlen;
673046
 			if (strspn(p, " \t") == 0) {
673046
 				continue;
673046
 			}
673046
@@ -308,7 +309,11 @@ main(int argc, char **argv)
673046
 	int i, configured_umask = 0, flags = FLAG_POPULATE;
673046
 
673046
 	openlog(PACKAGE "-mkhomedir", LOG_PID, LOG_DAEMON);
673046
-	override_umask = get_umask(&configured_umask);
673046
+	/* Unlike UMASK, HOME_MODE is the file mode, so needs to be reverted */
673046
+	override_umask = 0777 & ~get_umask(&configured_umask, "HOME_MODE");
673046
+	if (configured_umask == 0) {
673046
+		override_umask = get_umask(&configured_umask, "UMASK");
673046
+	}
673046
 	umask(override_umask);
673046
 	skel_dir = "/etc/skel";
673046
 
673046
diff --git a/src/oddjobd-mkhomedir.conf.5.in b/src/oddjobd-mkhomedir.conf.5.in
673046
index b0cd934..d7a2429 100644
673046
--- a/src/oddjobd-mkhomedir.conf.5.in
673046
+++ b/src/oddjobd-mkhomedir.conf.5.in
673046
@@ -24,7 +24,8 @@ Override the location of the skeleton directory (by default: \fI/etc/skel\fR).
673046
 -u
673046
 Specify a umask whose bits are masked off of contents of the skeleton directory
673046
 while they are copied to the user's new home directory.  The default is read
673046
-from \fB/etc/login.defs\fR.
673046
+from \fB/etc/login.defs\fR by taking \fBHOME_MODE\fR and \fBUMASK\fR values, in
673046
+this order.  First found value persists.
673046
 
673046
 .SH SEE ALSO
673046
 \fBoddjob.conf\fR(5)
673046
diff --git a/src/pam_oddjob_mkhomedir.8.in b/src/pam_oddjob_mkhomedir.8.in
673046
index 3793764..2fb16bc 100644
673046
--- a/src/pam_oddjob_mkhomedir.8.in
673046
+++ b/src/pam_oddjob_mkhomedir.8.in
673046
@@ -14,8 +14,9 @@ if the module is running with superuser privileges.  Otherwise, it invokes the
673046
 \fImkmyhomedir\fR method.
673046
 
673046
 The location of the skeleton directory and the default umask are determined by
673046
-the configuration for the corresponding service in \fBoddjobd-mkhomedir.conf\fR,
673046
-so they can not be specified as arguments to this module.
673046
+the values of \fBHOME_MODE\fR or \fBUMASK\fR (as a fallback) variables in
673046
+\fI/etc/login.defs\fR, so they can not be specified as arguments to this
673046
+module.
673046
 
673046
 If \fID-Bus\fR has not been configured to allow the calling application to
673046
 invoke these methods provided as part of the \fI@NAMESPACE@.oddjob_mkhomedir\fR
673046
-- 
673046
2.28.0
673046