]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
useradd: create directories after the SELinux user
authorIker Pedrosa <ipedrosa@redhat.com>
Fri, 8 Oct 2021 11:09:59 +0000 (13:09 +0200)
committerIker Pedrosa <ipedrosa@redhat.com>
Mon, 25 Oct 2021 07:55:27 +0000 (09:55 +0200)
Create the home and mail folders after the SELinux user has been set for
the added user. This will allow the folders to be created with the
SELinux user label.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
src/useradd.c

index 6269c01c68e2706337e4b34a2029ca2bb86ec43e..b463a1708e209465a42f53c04dc559ab3059c3d5 100644 (file)
@@ -2670,27 +2670,12 @@ int main (int argc, char **argv)
 
        usr_update (subuid_count, subgid_count);
 
-       if (mflg) {
-               create_home ();
-               if (home_added) {
-                       copy_tree (def_template, prefix_user_home, false, false,
-                                  (uid_t)-1, user_id, (gid_t)-1, user_gid);
-               } else {
-                       fprintf (stderr,
-                                _("%s: warning: the home directory %s already exists.\n"
-                                  "%s: Not copying any file from skel directory into it.\n"),
-                                Prog, user_home, Prog);
-               }
-
-       }
-
-       /* Do not create mail directory for system accounts */
-       if (!rflg) {
-               create_mail ();
-       }
-
        close_files ();
 
+       nscd_flush_cache ("passwd");
+       nscd_flush_cache ("group");
+       sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
+
        /*
         * tallylog_reset needs to be able to lookup
         * a valid existing user name,
@@ -2716,15 +2701,30 @@ int main (int argc, char **argv)
        }
 #endif                         /* WITH_SELINUX */
 
+       if (mflg) {
+               create_home ();
+               if (home_added) {
+                       copy_tree (def_template, prefix_user_home, false, false,
+                                  (uid_t)-1, user_id, (gid_t)-1, user_gid);
+               } else {
+                       fprintf (stderr,
+                                _("%s: warning: the home directory %s already exists.\n"
+                                  "%s: Not copying any file from skel directory into it.\n"),
+                                Prog, user_home, Prog);
+               }
+
+       }
+
+       /* Do not create mail directory for system accounts */
+       if (!rflg) {
+               create_mail ();
+       }
+
        if (run_parts ("/etc/shadow-maint/useradd-post.d", (char*)user_name,
                        "useradd")) {
                exit(1);
        }
 
-       nscd_flush_cache ("passwd");
-       nscd_flush_cache ("group");
-       sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
-
        return E_SUCCESS;
 }