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

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
14 files changed:
lib/cleanup_user.c
lib/lockpw.c
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 e6a617a2943cef28cd087101c7d2cb99faf97c3f..16fa3f375c0c4bc09a81da026731c3f99ae48091 100644 (file)
@@ -117,7 +117,7 @@ void cleanup_unlock_passwd (MAYBE_UNUSED void *arg)
  */
 void cleanup_unlock_shadow (MAYBE_UNUSED void *arg)
 {
-       if (spw_unlock () == 0) {
+       if (spw_unlock (true) == 0) {
                fprintf (log_get_logfd(),
                         _("%s: failed to unlock %s\n"),
                         log_get_progname(), spw_dbname ());
index 04cbdf36f6b072191f0c565ff93af658ef778cbd..4f357b48b9704c4fc6859e43d7d60abe2d1eb7bd 100644 (file)
@@ -78,7 +78,7 @@ int ulckpwdf (void)
         * Unlock both files.
         */
 
-       return (pw_unlock (true) && spw_unlock ())? 0 : -1;
+       return (pw_unlock (true) && spw_unlock (true))? 0 : -1;
 }
 #else
 extern int ISO_C_forbids_an_empty_translation_unit;
index efa33b5bfba4756dc7d2eeeb79e725131bff7707..4d2bf3b7fb86fa67bccd8e9c2aee06ffd90da61b 100644 (file)
@@ -206,14 +206,14 @@ int spw_close (bool process_selinux)
        return retval;
 }
 
-int spw_unlock (void)
+int spw_unlock (bool process_selinux)
 {
 #ifdef WITH_TCB
        int retval = 0;
 
        if (!getdef_bool ("USE_TCB")) {
 #endif                         /* WITH_TCB */
-               return commonio_unlock (&shadow_db, true);
+               return commonio_unlock (&shadow_db, process_selinux);
 #ifdef WITH_TCB
        }
        if (shadowtcb_drop_priv () == SHADOWTCB_FAILURE) {
index e64d8d6022eb64ee77c49428151b938dbcff785b..be645d0e5e3104ac2159da6aec8c0767b44ddbdd 100644 (file)
@@ -23,7 +23,7 @@ extern /*@observer@*/ /*@null@*/const struct spwd *spw_next (void);
 extern int spw_open (int mode);
 extern int spw_remove (const char *name);
 extern int spw_rewind (void);
-extern int spw_unlock (void);
+extern int spw_unlock (bool process_selinux);
 extern int spw_update (const struct spwd *sp);
 extern int spw_sort (void);
 
index 09c8871e557ab5eee75dd92b5781c2538fefe7b5..6547a4eeb627d8404264cb932a31333b5d45bfaa 100644 (file)
@@ -94,7 +94,7 @@ static void
 fail_exit (int code)
 {
        if (spw_locked) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                        /* continue */
@@ -562,7 +562,7 @@ static void close_files (void)
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
                fail_exit (E_NOPERM);
        }
-       if (spw_unlock () == 0) {
+       if (spw_unlock (true) == 0) {
                fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                /* continue */
index 2ddfd08eef6428e08877945ec004270b540ac008..5eee5c2e990f54b62e86af6594cd590b5bb8c527 100644 (file)
@@ -91,7 +91,7 @@ static void fail_exit (int code)
        }
 
        if (spw_locked) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                        /* continue */
@@ -387,7 +387,7 @@ static void close_files (void)
                        SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
                        fail_exit (1);
                }
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                        /* continue */
index b931389506db2f856bbdcbaf6c2a2db1a590e521..961085a33f33d99f295a9bd3804e1ba57d9d53f2 100644 (file)
@@ -166,7 +166,7 @@ static void usage (int status)
 static void fail_exit (int code)
 {
        if (spw_locked) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                        /* continue */
@@ -960,7 +960,7 @@ static void close_files (void)
                        SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
                        fail_exit (EXIT_FAILURE);
                }
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr,
                                 _("%s: failed to unlock %s\n"),
                                 Prog, spw_dbname ());
index 342d77d1f5b45e7c8cd6025fd42f566ff4f0b5ad..0e8e8c47054b88f56b23d35cd9e31f1430133903 100644 (file)
@@ -491,7 +491,7 @@ fail_exit (int status)
        }
 
        if (spw_locked) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        (void) fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                        /* continue */
@@ -627,7 +627,7 @@ static void update_shadow (void)
                /* Try to update the password in /etc/passwd instead. */
                (void) spw_close (true);
                update_noshadow ();
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        (void) fprintf (stderr,
                                        _("%s: failed to unlock %s\n"),
                                        Prog, spw_dbname ());
@@ -688,7 +688,7 @@ static void update_shadow (void)
                SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
                fail_exit (E_FAILURE);
        }
-       if (spw_unlock () == 0) {
+       if (spw_unlock (true) == 0) {
                (void) fprintf (stderr,
                                _("%s: failed to unlock %s\n"),
                                Prog, spw_dbname ());
index c827b5ca01b6d0ce3e2a78f3ad87c8bd8387cc1b..4e55dd707a09ce816326cb3b318ab4a76715f32c 100644 (file)
@@ -85,7 +85,7 @@ extern int allow_bad_names;
 static void fail_exit (int code)
 {
        if (spw_locked) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        if (use_system_spw_file) {
                                SYSLOG ((LOG_ERR, "failed to unlock %s",
@@ -338,7 +338,7 @@ static void close_files (bool changed)
         * Don't be anti-social - unlock the files when you're done.
         */
        if (spw_locked) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr,
                                 _("%s: failed to unlock %s\n"),
                                 Prog, spw_dbname ());
@@ -581,7 +581,7 @@ static void check_pw_file (bool *errors, bool *changed)
                                                 _("%s: cannot open %s\n"),
                                                 Prog, spw_dbname ());
                                        *errors = true;
-                                       if (spw_unlock () == 0) {
+                                       if (spw_unlock (true) == 0) {
                                                fprintf (stderr,
                                                         _("%s: failed to unlock %s\n"),
                                                         Prog, spw_dbname ());
@@ -669,7 +669,7 @@ static void check_pw_file (bool *errors, bool *changed)
                        } else {
                                spw_opened = false;
                        }
-                       if (spw_unlock () == 0) {
+                       if (spw_unlock (true) == 0) {
                                fprintf (stderr,
                                         _("%s: failed to unlock %s\n"),
                                         Prog, spw_dbname ());
index 6bef9be50a1ff449379ed9e4da0de7ab920fb417..acefb0e27845f43afbb04fa5c347085e473aeb51 100644 (file)
@@ -91,7 +91,7 @@ static void fail_exit (int status)
        }
 
        if (spw_locked) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                        /* continue */
@@ -305,7 +305,7 @@ int main (int argc, char **argv)
                /* continue */
        }
 
-       if (spw_unlock () == 0) {
+       if (spw_unlock (true) == 0) {
                fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                /* continue */
index 2ce174ebe583b016248d188a1f0db0c712e5c8c8..ddbc8105254362ad8a9d7093ee016a3a1de70544 100644 (file)
@@ -47,7 +47,7 @@ static void process_flags (int argc, char **argv);
 static void fail_exit (int status)
 {
        if (spw_locked) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                        /* continue */
@@ -222,7 +222,7 @@ int main (int argc, char **argv)
                fail_exit (3);
        }
 
-       if (spw_unlock () == 0) {
+       if (spw_unlock (true) == 0) {
                fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                /* continue */
index 0af295ce5d07dc2d1e24729e500b2cefa5bdde3d..66f4ca66efc7b1b0be529fc56f6bced9f7f4ef69 100644 (file)
@@ -263,7 +263,7 @@ static void fail_exit (int code)
                SYSLOG((LOG_ERR, "failed to remove %s", prefix_user_home));
        }
 
-       if (spw_locked && spw_unlock() == 0) {
+       if (spw_locked && spw_unlock(true) == 0) {
                fprintf(stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname());
                SYSLOG((LOG_ERR, "failed to unlock %s", spw_dbname()));
                /* continue */
@@ -1591,7 +1591,7 @@ static void close_files (void)
        }
 #endif                         /* ENABLE_SUBIDS */
        if (is_shadow_pwd) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
 #ifdef WITH_AUDIT
index fa1de98853fa280df3893480a7167d68486f00d3..a74eea662ed74032cf60331f16086c160fc0d215 100644 (file)
@@ -410,7 +410,7 @@ static void close_files (void)
                        SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
                        fail_exit (E_PW_UPDATE);
                }
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                        /* continue */
@@ -499,7 +499,7 @@ static void fail_exit (int code)
                }
        }
        if (spw_locked) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                        /* continue */
index 12cd13926bc75160eee8046e32ed4c9cb7cc66ce..15c0f26dcf5555bda1c610c8eba00da691aae381 100644 (file)
@@ -651,7 +651,7 @@ fail_exit (int code)
        }
 #endif
        if (spw_locked) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
                        SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
                        /* continue */
@@ -1537,7 +1537,7 @@ static void close_files (void)
        }
 
        if (is_shadow_pwd) {
-               if (spw_unlock () == 0) {
+               if (spw_unlock (true) == 0) {
                        fprintf (stderr,
                                 _("%s: failed to unlock %s\n"),
                                 Prog, spw_dbname ());