]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Update close(2) checking
authorChristian Göttsche <cgzones@googlemail.com>
Mon, 11 Dec 2023 16:32:13 +0000 (17:32 +0100)
committerSerge Hallyn <serge@hallyn.com>
Thu, 14 Dec 2023 13:40:40 +0000 (07:40 -0600)
Check for close(2) failure at more places closing a file descriptor
written to.

Also ignore failures with errno set to EINTR (see man:close(2) for
details).

lib/copydir.c
lib/idmapping.c
src/useradd.c
src/usermod.c

index c485088baa4613d3f9a91ef869dc1c564aafdeff..d61902524841f8d6bcdf034e90ed462f4ffd6a02 100644 (file)
@@ -814,7 +814,7 @@ static int copy_file (const struct path_info *src, const struct path_info *dst,
        }
 
        (void) close (ifd);
-       if (close (ofd) != 0) {
+       if (close (ofd) != 0 && errno != EINTR) {
                return -1;
        }
 
index 3fcad8d3c67ababe91a043c616212f7e251adab9..83ab745bf94a17a8b0abb5e9e3e6f202a717d96f 100644 (file)
@@ -222,6 +222,10 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings
                        log_get_progname(), map_file, strerror(errno));
                exit(EXIT_FAILURE);
        }
-       close(fd);
+       if (close(fd) != 0 && errno != EINTR) {
+               fprintf(log_get_logfd(), _("%s: closing %s failed: %s\n"),
+                       log_get_progname(), map_file, strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        free(buf);
 }
index 3b20e56ff0bdadf43ca22c4e8ccd3381be030c3f..9a7037f95267d51359a98a8e60c3fec06f5ad37c 100644 (file)
@@ -2041,7 +2041,7 @@ static void faillog_reset (uid_t uid)
                         Prog, (unsigned long) uid, strerror (errno));
                SYSLOG ((LOG_WARN, "failed to reset the faillog entry of UID %lu", (unsigned long) uid));
        }
-       if (close (fd) != 0) {
+       if (close (fd) != 0 && errno != EINTR) {
                fprintf (stderr,
                         _("%s: failed to close the faillog file for UID %lu: %s\n"),
                         Prog, (unsigned long) uid, strerror (errno));
@@ -2087,7 +2087,7 @@ static void lastlog_reset (uid_t uid)
                SYSLOG ((LOG_WARN, "failed to reset the lastlog entry of UID %lu", (unsigned long) uid));
                /* continue */
        }
-       if (close (fd) != 0) {
+       if (close (fd) != 0 && errno != EINTR) {
                fprintf (stderr,
                         _("%s: failed to close the lastlog file for UID %lu: %s\n"),
                         Prog, (unsigned long) uid, strerror (errno));
@@ -2442,8 +2442,12 @@ static void create_mail (void)
                perror(_("Setting mailbox file permissions"));
        }
 
-       fsync(fd);
-       close(fd);
+       if (fsync(fd) != 0) {
+               perror (_("Synchronize mailbox file"));
+       }
+       if (close(fd) != 0 && errno != EINTR) {
+               perror (_("Closing mailbox file"));
+       }
 #ifdef WITH_SELINUX
        /* Reset SELinux to create files with default contexts */
        if (reset_selinux_file_context() != 0) {
index 9cbc504c2674d4c1d6616f3a6ac7b6f8a10419c9..285c2636db3b954ea0f5378c6f9f775defc4d69c 100644 (file)
@@ -1963,7 +1963,11 @@ static void update_lastlog (void)
                }
        }
 
-       (void) close (fd);
+       if (close (fd) != 0 && errno != EINTR) {
+               fprintf (stderr,
+                        _("%s: failed to copy the lastlog entry of user %ju to user %ju: %s\n"),
+                        Prog, (uintmax_t) user_id, (uintmax_t) user_newid, strerror (errno));
+       }
 }
 #endif /* ENABLE_LASTLOG */
 
@@ -2023,7 +2027,11 @@ static void update_faillog (void)
                }
        }
 
-       (void) close (fd);
+       if (close (fd) != 0 && errno != EINTR) {
+               fprintf (stderr,
+                        _("%s: failed to copy the faillog entry of user %ju to user %ju: %s\n"),
+                        Prog, (uintmax_t) user_id, (uintmax_t) user_newid, strerror (errno));
+       }
 }
 
 #ifndef NO_MOVE_MAILBOX