Blame SOURCES/shadow-4.9-move-create-home.patch

9746fa
From 09c752f00f9dfc610f66d68be38c9e5be8ca7f15 Mon Sep 17 00:00:00 2001
9746fa
From: Iker Pedrosa <ipedrosa@redhat.com>
9746fa
Date: Fri, 8 Oct 2021 13:09:59 +0200
9746fa
Subject: [PATCH] useradd: create directories after the SELinux user
9746fa
9746fa
Create the home and mail folders after the SELinux user has been set for
9746fa
the added user. This will allow the folders to be created with the
9746fa
SELinux user label.
9746fa
9746fa
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
9746fa
---
9746fa
 src/useradd.c | 46 +++++++++++++++++++++++-----------------------
9746fa
 1 file changed, 23 insertions(+), 23 deletions(-)
9746fa
b8f1b8
diff --git a/src/useradd.c b/src/useradd.c
9746fa
index 6269c01c..b463a170 100644
b8f1b8
--- a/src/useradd.c
b8f1b8
+++ b/src/useradd.c
9746fa
@@ -2670,27 +2670,12 @@ int main (int argc, char **argv)
b8f1b8
 
b8f1b8
 	usr_update ();
b8f1b8
 
b8f1b8
-	if (mflg) {
b8f1b8
-		create_home ();
b8f1b8
-		if (home_added) {
b8f1b8
-			copy_tree (def_template, prefix_user_home, false, false,
b8f1b8
-			           (uid_t)-1, user_id, (gid_t)-1, user_gid);
b8f1b8
-		} else {
b8f1b8
-			fprintf (stderr,
b8f1b8
-			         _("%s: warning: the home directory %s already exists.\n"
b8f1b8
-			           "%s: Not copying any file from skel directory into it.\n"),
b8f1b8
-			         Prog, user_home, Prog);
b8f1b8
-		}
b8f1b8
-
b8f1b8
-	}
b8f1b8
-
b8f1b8
-	/* Do not create mail directory for system accounts */
b8f1b8
-	if (!rflg) {
b8f1b8
-		create_mail ();
b8f1b8
-	}
b8f1b8
-
b8f1b8
 	close_files ();
b8f1b8
 
b8f1b8
+	nscd_flush_cache ("passwd");
b8f1b8
+	nscd_flush_cache ("group");
b8f1b8
+	sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
b8f1b8
+
b8f1b8
 	/*
b8f1b8
 	 * tallylog_reset needs to be able to lookup
b8f1b8
 	 * a valid existing user name,
9746fa
@@ -2716,15 +2701,30 @@ int main (int argc, char **argv)
b8f1b8
 	}
9746fa
 #endif				/* WITH_SELINUX */
b8f1b8
 
b8f1b8
+	if (mflg) {
b8f1b8
+		create_home ();
b8f1b8
+		if (home_added) {
9746fa
+			copy_tree (def_template, prefix_user_home, false, false,
b8f1b8
+			           (uid_t)-1, user_id, (gid_t)-1, user_gid);
b8f1b8
+		} else {
b8f1b8
+			fprintf (stderr,
b8f1b8
+			         _("%s: warning: the home directory %s already exists.\n"
b8f1b8
+			           "%s: Not copying any file from skel directory into it.\n"),
b8f1b8
+			         Prog, user_home, Prog);
b8f1b8
+		}
b8f1b8
+
b8f1b8
+	}
b8f1b8
+
b8f1b8
+	/* Do not create mail directory for system accounts */
b8f1b8
+	if (!rflg) {
b8f1b8
+		create_mail ();
b8f1b8
+	}
9746fa
+
9746fa
 	if (run_parts ("/etc/shadow-maint/useradd-post.d", (char*)user_name,
9746fa
 			"useradd")) {
9746fa
 		exit(1);
9746fa
 	}
b8f1b8
 
9746fa
-	nscd_flush_cache ("passwd");
9746fa
-	nscd_flush_cache ("group");
9746fa
-	sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
9746fa
-
b8f1b8
 	return E_SUCCESS;
b8f1b8
 }
9746fa
 
9746fa
-- 
9746fa
2.31.1
9746fa