]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: add SELinux control flag in pw_close()
authorIker Pedrosa <ipedrosa@redhat.com>
Fri, 25 Apr 2025 13:19:29 +0000 (15:19 +0200)
committerIker Pedrosa <ipedrosa@redhat.com>
Tue, 7 Oct 2025 09:03:48 +0000 (11:03 +0200)
Expand pw_close() interface to add a control flag for SELinux file
context processing.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
15 files changed:
lib/pwio.c
lib/pwio.h
src/chage.c
src/chfn.c
src/chpasswd.c
src/chsh.c
src/groupmod.c
src/newusers.c
src/passwd.c
src/pwck.c
src/pwconv.c
src/pwunconv.c
src/useradd.c
src/userdel.c
src/usermod.c

index f834354a4fabfac51456f3647f01eec6fe4f2067..cda2a21caf1d5fd85867bc574e87a44739436851 100644 (file)
@@ -158,9 +158,9 @@ int pw_rewind (void)
        return commonio_next (&passwd_db);
 }
 
-int pw_close (void)
+int pw_close (bool process_selinux)
 {
-       return commonio_close (&passwd_db, true);
+       return commonio_close (&passwd_db, process_selinux);
 }
 
 int pw_unlock (void)
index 882a7c7a49d012b058bc642d6bc0342c2f6271d0..b051a7e7551ed5cd8a27c729e6b555c756998af7 100644 (file)
@@ -14,8 +14,9 @@
 
 #include <sys/types.h>
 #include <pwd.h>
+#include <stdbool.h>
 
-extern int pw_close (void);
+extern int pw_close (bool process_selinux);
 extern /*@observer@*/ /*@null@*/const struct passwd *pw_locate (const char *name);
 extern /*@observer@*/ /*@null@*/const struct passwd *pw_locate_uid (uid_t uid);
 extern int pw_lock (void);
index 3a9461aca1f1d1b0c19088bdbcb4216fec798817..b5c9ac701b484509981b55c2abba899ba0ba4dfe 100644 (file)
@@ -557,7 +557,7 @@ static void close_files (void)
         * Close the password file. If any entries were modified, the file
         * will be re-written.
         */
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
                fail_exit (E_NOPERM);
index d92c23a840bc9b3c7b814189fa6e78e7c457d618..f80d2f3dbad8f6ae7d1ad6da55d9c848b276c974 100644 (file)
@@ -453,7 +453,7 @@ static void update_gecos (const char *user, char *gecos)
        /*
         * Changes have all been made, so commit them and unlock the file.
         */
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
                fail_exit (E_NOPERM);
index fe3e6e9c23eb2fb365777a14498fb5140962bc5b..391deb888fdccc06ab516d9be09834c1e788e5f4 100644 (file)
@@ -395,7 +395,7 @@ static void close_files (void)
                spw_locked = false;
        }
 
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                fprintf (stderr,
                         _("%s: failure while writing changes to %s\n"),
                         Prog, pw_dbname ());
index e5575ac6da98558959e354e6aa0eebeaeb94fcac..87ad64d169c32162adcaeb1061892bf8a95985e1 100644 (file)
@@ -428,7 +428,7 @@ static void update_shell (const char *user, char *newshell)
        /*
         * Changes have all been made, so commit them and unlock the file.
         */
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
                fail_exit (1);
index 20c063058a366844f4d79c255ede727c166753cc..66559432200dae249265f8eb43d642cbe238a87a 100644 (file)
@@ -536,7 +536,7 @@ static void close_files (void)
 #endif                         /* SHADOWGRP */
 
        if (gflg) {
-               if (pw_close () == 0) {
+               if (pw_close (true) == 0) {
                        fprintf (stderr,
                                 _("%s: failure while writing changes to %s\n"),
                                 Prog, pw_dbname ());
index a4c374da1cf8a9a21f5b4335c55cd4c2baf6fe00..2e8f112c05edf9c44e9130166337b89eb02faf6b 100644 (file)
@@ -940,7 +940,7 @@ static void open_files (void)
  */
 static void close_files (void)
 {
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
                fail_exit (EXIT_FAILURE);
index 8057af88e5eef31e6c86a26b992ca16016209624..4bc23e59795f92035260471044e74e4744b5c112 100644 (file)
@@ -586,7 +586,7 @@ static void update_noshadow (void)
                                Prog, pw_dbname (), npw->pw_name);
                fail_exit (E_FAILURE);
        }
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                (void) fprintf (stderr,
                                _("%s: failure while writing changes to %s\n"),
                                Prog, pw_dbname ());
index aa7f437bff0d0330fe8c5bbd22fb6230df81c6a2..6e22923ebb6ef45f942819349c36ef90066e3852 100644 (file)
@@ -309,7 +309,7 @@ static void close_files (bool changed)
         * changes to the files.
         */
        if (changed) {
-               if (pw_close () == 0) {
+               if (pw_close (true) == 0) {
                        fprintf (stderr,
                                 _("%s: failure while writing changes to %s\n"),
                                 Prog, pw_dbname ());
index 69f5634913902182485b6da2333f27831cb3dadc..1f3b412462fd0039beed1fbb3c4143695136ebf5 100644 (file)
@@ -281,7 +281,7 @@ int main (int argc, char **argv)
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
                fail_exit (E_FAILURE);
        }
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                fprintf (stderr,
                         _("%s: failure while writing changes to %s\n"),
                         Prog, pw_dbname ());
index b0516cbe6a34a7899fb430fdc1d5ca6bc26568d1..4321c6837a7595ae9cb6cc7ae1eb06f5a0ff551d 100644 (file)
@@ -207,7 +207,7 @@ int main (int argc, char **argv)
 
        (void) spw_close (); /* was only open O_RDONLY */
 
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                fprintf (stderr,
                         _("%s: failure while writing changes to %s\n"),
                         Prog, pw_dbname ());
index 586333a355a47f3340de7c6116af6f28d1a9eab1..ce24ea8e2cb48c6c156bb90088296774f06c1d16 100644 (file)
@@ -1562,7 +1562,7 @@ static void process_flags (int argc, char **argv)
  */
 static void close_files (void)
 {
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
                fail_exit (E_PW_UPDATE);
index 3e5b5b5825a11534ef85bd65952c6bd72aac5c87..7bb29aa1f993904f32a07b6e9dac92533c0ada9c 100644 (file)
@@ -391,7 +391,7 @@ static void remove_usergroup (void)
  */
 static void close_files (void)
 {
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
                fail_exit (E_PW_UPDATE);
@@ -1047,7 +1047,7 @@ int main (int argc, char **argv)
                pw_open(O_RDONLY);
                pwd = pw_locate (user_name); /* we care only about local users */
                if (NULL == pwd) {
-                       pw_close();
+                       pw_close(true);
                        fprintf (stderr, _("%s: user '%s' does not exist\n"),
                                 Prog, user_name);
 #ifdef WITH_AUDIT
@@ -1066,7 +1066,7 @@ int main (int argc, char **argv)
                } else {
                        user_home = xstrdup(pwd->pw_dir);
                }
-               pw_close();
+               pw_close(true);
        }
 #ifdef WITH_TCB
        if (shadowtcb_set_user (user_name) == SHADOWTCB_FAILURE) {
index 17288d07b331e2abde34ecf0d319c3449a7c1682..043591cdc3a03a18e79c0f6ff2baf6fe076787b9 100644 (file)
@@ -1472,7 +1472,7 @@ process_flags(int argc, char **argv)
  */
 static void close_files (void)
 {
-       if (pw_close () == 0) {
+       if (pw_close (true) == 0) {
                fprintf (stderr,
                         _("%s: failure while writing changes to %s\n"),
                         Prog, pw_dbname ());