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

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
12 files changed:
lib/shadowio.c
lib/shadowio.h
src/chage.c
src/chpasswd.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 89c94dd612f29522e2ee63b5d273c4cddf66f3a0..903dcf38fea43b88b51ee04da10bba6ceb455f2d 100644 (file)
@@ -187,7 +187,7 @@ int spw_rewind (void)
        return commonio_next (&shadow_db);
 }
 
-int spw_close (void)
+int spw_close (bool process_selinux)
 {
        int retval = 0;
 #ifdef WITH_TCB
@@ -197,7 +197,7 @@ int spw_close (void)
                return 0;
        }
 #endif                         /* WITH_TCB */
-       retval = commonio_close (&shadow_db, true);
+       retval = commonio_close (&shadow_db, process_selinux);
 #ifdef WITH_TCB
        if (use_tcb && (shadowtcb_gain_priv () == SHADOWTCB_FAILURE)) {
                return 0;
index 4dbeb6d64fe72ef4a553e38f342916ad909ca6e8..e64d8d6022eb64ee77c49428151b938dbcff785b 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "defines.h"
 
-extern int spw_close (void);
+extern int spw_close (bool process_selinux);
 extern bool spw_file_present (void);
 extern /*@observer@*/ /*@null@*/const struct spwd *spw_locate (const char *name);
 extern int spw_lock (void);
index b5c9ac701b484509981b55c2abba899ba0ba4dfe..be45af17516026121bf88722af3d86e27c4871a1 100644 (file)
@@ -546,7 +546,7 @@ static void close_files (void)
         * Now close the shadow password file, which will cause all of the
         * entries to be re-written.
         */
-       if (spw_close () == 0) {
+       if (spw_close (true) == 0) {
                fprintf (stderr,
                         _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ());
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
index 391deb888fdccc06ab516d9be09834c1e788e5f4..ba1a3b0ddf1e7e519cba503d2d0529e2e8b4affb 100644 (file)
@@ -380,7 +380,7 @@ static void open_files (void)
 static void close_files (void)
 {
        if (is_shadow_pwd) {
-               if (spw_close () == 0) {
+               if (spw_close (true) == 0) {
                        fprintf (stderr,
                                 _("%s: failure while writing changes to %s\n"),
                                 Prog, spw_dbname ());
index 2e8f112c05edf9c44e9130166337b89eb02faf6b..ebe467441bed9431581a144a36f256fefa4c1f0c 100644 (file)
@@ -953,7 +953,7 @@ static void close_files (void)
        pw_locked = false;
 
        if (is_shadow) {
-               if (spw_close () == 0) {
+               if (spw_close (true) == 0) {
                        fprintf (stderr,
                                 _("%s: failure while writing changes to %s\n"),
                                 Prog, spw_dbname ());
index 4bc23e59795f92035260471044e74e4744b5c112..b1a3e612934baf66597a1753cf0a4f93abb687a1 100644 (file)
@@ -625,7 +625,7 @@ static void update_shadow (void)
        sp = spw_locate (name);
        if (NULL == sp) {
                /* Try to update the password in /etc/passwd instead. */
-               (void) spw_close ();
+               (void) spw_close (true);
                update_noshadow ();
                if (spw_unlock () == 0) {
                        (void) fprintf (stderr,
@@ -681,7 +681,7 @@ static void update_shadow (void)
                                Prog, spw_dbname (), nsp->sp_namp);
                fail_exit (E_FAILURE);
        }
-       if (spw_close () == 0) {
+       if (spw_close (true) == 0) {
                (void) fprintf (stderr,
                                _("%s: failure while writing changes to %s\n"),
                                Prog, spw_dbname ());
index 6e22923ebb6ef45f942819349c36ef90066e3852..9d30b7d3b3705d68c3379a7087904ad349c7da3e 100644 (file)
@@ -320,7 +320,7 @@ static void close_files (bool changed)
                        }
                        fail_exit (E_CANTUPDATE);
                }
-               if (spw_opened && (spw_close () == 0)) {
+               if (spw_opened && (spw_close (true) == 0)) {
                        fprintf (stderr,
                                 _("%s: failure while writing changes to %s\n"),
                                 Prog, spw_dbname ());
@@ -657,7 +657,7 @@ static void check_pw_file (bool *errors, bool *changed)
                }
 #ifdef WITH_TCB
                if (getdef_bool ("USE_TCB") && spw_locked) {
-                       if (spw_opened && (spw_close () == 0)) {
+                       if (spw_opened && (spw_close (true) == 0)) {
                                fprintf (stderr,
                                         _("%s: failure while writing changes to %s\n"),
                                         Prog, spw_dbname ());
index 1f3b412462fd0039beed1fbb3c4143695136ebf5..75eb8d07bce5bfe328e40349eee4b2bf388f2ebf 100644 (file)
@@ -274,7 +274,7 @@ int main (int argc, char **argv)
                }
        }
 
-       if (spw_close () == 0) {
+       if (spw_close (true) == 0) {
                fprintf (stderr,
                         _("%s: failure while writing changes to %s\n"),
                         Prog, spw_dbname ());
index 4321c6837a7595ae9cb6cc7ae1eb06f5a0ff551d..83d3516cd95a693e8f6c942077fac1e965f6a182 100644 (file)
@@ -205,7 +205,7 @@ int main (int argc, char **argv)
                }
        }
 
-       (void) spw_close (); /* was only open O_RDONLY */
+       (void) spw_close (true); /* was only open O_RDONLY */
 
        if (pw_close (true) == 0) {
                fprintf (stderr,
index ce24ea8e2cb48c6c156bb90088296774f06c1d16..55444c811fee1eb67bd87aea8d5b2b086d09dae0 100644 (file)
@@ -1567,7 +1567,7 @@ static void close_files (void)
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
                fail_exit (E_PW_UPDATE);
        }
-       if (is_shadow_pwd && (spw_close () == 0)) {
+       if (is_shadow_pwd && (spw_close (true) == 0)) {
                fprintf (stderr,
                         _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ());
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
index 7bb29aa1f993904f32a07b6e9dac92533c0ada9c..d60c974b3abdb0fd1aab9e7ed4a105f1194f5ca5 100644 (file)
@@ -404,7 +404,7 @@ static void close_files (void)
        pw_locked = false;
 
        if (is_shadow_pwd) {
-               if (spw_close () == 0) {
+               if (spw_close (true) == 0) {
                        fprintf (stderr,
                                 _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
index 043591cdc3a03a18e79c0f6ff2baf6fe076787b9..f392ed58bd101ae0a31213c63137d5057e7b6bad 100644 (file)
@@ -1479,7 +1479,7 @@ static void close_files (void)
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
                fail_exit (E_PW_UPDATE);
        }
-       if (is_shadow_pwd && (spw_close () == 0)) {
+       if (is_shadow_pwd && (spw_close (true) == 0)) {
                fprintf (stderr,
                         _("%s: failure while writing changes to %s\n"),
                         Prog, spw_dbname ());