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

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