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

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
lib/commonio.c
lib/commonio.h
lib/groupio.c
lib/pwio.c
lib/sgroupio.c
lib/shadowio.c
lib/subordinateio.c

index ce5f17b4ef1cbf53421a5ec751a2f3d5f8d5439c..01127980149dea0f00050b457363af4e8171864a 100644 (file)
@@ -473,7 +473,7 @@ int commonio_unlock (struct commonio_db *db)
 
        if (db->isopen) {
                db->readonly = true;
-               if (commonio_close (db) == 0) {
+               if (commonio_close (db, true) == 0) {
                        if (db->locked) {
                                dec_lock_count ();
                        }
@@ -885,7 +885,7 @@ static int write_all (const struct commonio_db *db)
 }
 
 
-int commonio_close (struct commonio_db *db)
+int commonio_close (struct commonio_db *db, bool process_selinux)
 {
        bool         errors = false;
        char         buf[1024];
@@ -927,7 +927,8 @@ int commonio_close (struct commonio_db *db)
                }
 
 #ifdef WITH_SELINUX
-               if (set_selinux_file_context (db->filename, S_IFREG) != 0) {
+               if (process_selinux
+                   && set_selinux_file_context (db->filename, S_IFREG) != 0) {
                        errors = true;
                }
 #endif
@@ -942,7 +943,8 @@ int commonio_close (struct commonio_db *db)
                db->fp = NULL;
 
 #ifdef WITH_SELINUX
-               if (reset_selinux_file_context () != 0) {
+               if (process_selinux
+                   && reset_selinux_file_context () != 0) {
                        errors = true;
                }
 #endif
@@ -961,7 +963,8 @@ int commonio_close (struct commonio_db *db)
                goto fail;
 
 #ifdef WITH_SELINUX
-       if (set_selinux_file_context (db->filename, S_IFREG) != 0) {
+       if (process_selinux
+           && set_selinux_file_context (db->filename, S_IFREG) != 0) {
                errors = true;
        }
 #endif
@@ -999,7 +1002,8 @@ int commonio_close (struct commonio_db *db)
        }
 
 #ifdef WITH_SELINUX
-       if (reset_selinux_file_context () != 0) {
+       if (process_selinux
+           && reset_selinux_file_context () != 0) {
                goto fail;
        }
 #endif
index fedbefa3d9159644ba5eb9f43366dcdc1ef8f762..dadc05008d99d87814232391fa0d80b17d2dfd31 100644 (file)
@@ -138,7 +138,7 @@ extern int commonio_append (struct commonio_db *, const void *);
 extern int commonio_remove (struct commonio_db *, const char *);
 extern int commonio_rewind (struct commonio_db *);
 extern /*@observer@*/ /*@null@*/const void *commonio_next (struct commonio_db *);
-extern int commonio_close (struct commonio_db *);
+extern int commonio_close (struct commonio_db *, bool);
 extern int commonio_unlock (struct commonio_db *);
 extern void commonio_del_entry (struct commonio_db *,
                                 const struct commonio_entry *);
index 0af395a957ad01bd9dc704b9ee2faee4c49f57f7..0bce549fdabc5749f0a257755d0072188ec5b8fa 100644 (file)
@@ -187,7 +187,7 @@ int gr_rewind (void)
 
 int gr_close (void)
 {
-       return commonio_close (&group_db);
+       return commonio_close (&group_db, true);
 }
 
 int gr_unlock (void)
index 463f8378c8ceb7d7d1eba3be808977a8578f5b77..f834354a4fabfac51456f3647f01eec6fe4f2067 100644 (file)
@@ -160,7 +160,7 @@ int pw_rewind (void)
 
 int pw_close (void)
 {
-       return commonio_close (&passwd_db);
+       return commonio_close (&passwd_db, true);
 }
 
 int pw_unlock (void)
index 5c109657983034ab0e5ee0060bc6a80308e2b427..2cf509bc1156b2cf6ec730ef3d6da77455467e5a 100644 (file)
@@ -282,7 +282,7 @@ int sgr_rewind (void)
 
 int sgr_close (void)
 {
-       return commonio_close (&gshadow_db);
+       return commonio_close (&gshadow_db, true);
 }
 
 int sgr_unlock (void)
index bf71817519850f593e7aac4422a20ce35a2f5133..89c94dd612f29522e2ee63b5d273c4cddf66f3a0 100644 (file)
@@ -197,7 +197,7 @@ int spw_close (void)
                return 0;
        }
 #endif                         /* WITH_TCB */
-       retval = commonio_close (&shadow_db);
+       retval = commonio_close (&shadow_db, true);
 #ifdef WITH_TCB
        if (use_tcb && (shadowtcb_gain_priv () == SHADOWTCB_FAILURE)) {
                return 0;
index 9fc53f004f85507f5bdf9cae772c71c657b8032e..1a9bbbfa271f6548e2e33416a83401c79107027d 100644 (file)
@@ -671,7 +671,7 @@ int sub_uid_remove (const char *owner, uid_t start, unsigned long count)
 
 int sub_uid_close (void)
 {
-       return commonio_close (&subordinate_uid_db);
+       return commonio_close (&subordinate_uid_db, true);
 }
 
 int sub_uid_unlock (void)
@@ -809,7 +809,7 @@ int sub_gid_remove (const char *owner, gid_t start, unsigned long count)
 
 int sub_gid_close (void)
 {
-       return commonio_close (&subordinate_gid_db);
+       return commonio_close (&subordinate_gid_db, true);
 }
 
 int sub_gid_unlock (void)