From 90467efb07e69aca52e912f065e31b13ec396d8e Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 22 Jul 2025 23:18:48 +0200 Subject: [PATCH] lib/, src/: Use strerrno() instead of its pattern Signed-off-by: Alejandro Colomar --- lib/addgrps.c | 3 ++- lib/commonio.c | 15 +++++++------ lib/copydir.c | 3 ++- lib/exit_if_null.h | 6 ++--- lib/find_new_gid.c | 4 +++- lib/find_new_uid.c | 3 ++- lib/get_pid.c | 5 +++-- lib/gettime.c | 3 ++- lib/idmapping.c | 7 +++--- lib/prefix_flag.c | 3 ++- lib/root_flag.c | 9 ++++---- lib/run_part.c | 11 ++++----- lib/selinux.c | 5 +++-- lib/spawn.c | 10 +++++---- lib/tcbfuncs.c | 56 +++++++++++++++++++++++----------------------- src/chage.c | 3 ++- src/chgpasswd.c | 3 ++- src/chpasswd.c | 3 ++- src/faillog.c | 7 +++--- src/gpasswd.c | 4 +++- src/groupadd.c | 9 ++++---- src/lastlog.c | 3 ++- src/login.c | 4 ++-- src/newgidmap.c | 18 ++++++--------- src/newgrp.c | 5 +++-- src/newuidmap.c | 5 +++-- src/newusers.c | 17 ++++++-------- src/passwd.c | 5 +++-- src/useradd.c | 23 +++++++++---------- src/userdel.c | 23 +++++++++---------- src/usermod.c | 19 ++++++++-------- src/vipw.c | 15 ++++++------- 32 files changed, 162 insertions(+), 147 deletions(-) diff --git a/lib/addgrps.c b/lib/addgrps.c index bdc4cf2f1..b79203205 100644 --- a/lib/addgrps.c +++ b/lib/addgrps.c @@ -24,6 +24,7 @@ #include "shadow/grp/agetgroups.h" #include "shadowlog.h" #include "string/strchr/strchrscnt.h" +#include "string/strerrno.h" /* @@ -65,7 +66,7 @@ add_groups(const char *list) free(dup); if (setgroups(n, gids) == -1) { - fprintf(shadow_logfd, "setgroups: %s\n", strerror(errno)); + fprintf(shadow_logfd, "setgroups: %s\n", strerrno()); goto free_gids; } diff --git a/lib/commonio.c b/lib/commonio.c index 039b01ea0..73afa6098 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -39,6 +39,7 @@ #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" +#include "string/strerrno.h" #include "string/strtok/stpsep.h" @@ -102,7 +103,7 @@ static int check_link_count (const char *file, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: %s file stat error: %s\n", - shadow_progname, file, strerror (errno)); + shadow_progname, file, strerrno()); } return 0; } @@ -133,7 +134,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: %s: %s\n", - shadow_progname, file, strerror (errno)); + shadow_progname, file, strerrno()); } return 0; } @@ -145,7 +146,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: %s file write error: %s\n", - shadow_progname, file, strerror (errno)); + shadow_progname, file, strerrno()); } (void) close (fd); unlink (file); @@ -155,7 +156,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: %s file sync error: %s\n", - shadow_progname, file, strerror (errno)); + shadow_progname, file, strerrno()); } (void) close (fd); unlink (file); @@ -174,7 +175,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: %s: %s\n", - shadow_progname, lock, strerror (errno)); + shadow_progname, lock, strerrno()); } unlink (file); errno = EINVAL; @@ -217,7 +218,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: cannot get lock %s: %s\n", - shadow_progname, lock, strerror (errno)); + shadow_progname, lock, strerrno()); } unlink (file); return 0; @@ -230,7 +231,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) if (log) { (void) fprintf (shadow_logfd, "%s: cannot get lock %s: %s\n", - shadow_progname, lock, strerror (errno)); + shadow_progname, lock, strerrno()); } } diff --git a/lib/copydir.c b/lib/copydir.c index 018d3be75..1933381ce 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -41,6 +41,7 @@ #include "string/sprintf/aprintf.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" +#include "string/strerrno.h" static /*@null@*/const char *src_orig; @@ -117,7 +118,7 @@ static void error_acl (MAYBE_UNUSED struct error_context *ctx, const char *fmt, if (vfprintf (shadow_logfd, fmt, ap) != 0) { (void) fputs (_(": "), shadow_logfd); } - (void) fprintf (shadow_logfd, "%s\n", strerror (errno)); + (void) fprintf(shadow_logfd, "%s\n", strerrno()); va_end (ap); } diff --git a/lib/exit_if_null.h b/lib/exit_if_null.h index 93b6e4756..708908b5b 100644 --- a/lib/exit_if_null.h +++ b/lib/exit_if_null.h @@ -8,13 +8,12 @@ #include "config.h" -#include #include #include #include -#include #include "shadowlog.h" +#include "string/strerrno.h" /* @@ -40,8 +39,7 @@ inline void exit_if_null_(void *p) { if (p == NULL) { - fprintf(log_get_logfd(), "%s: %s\n", - log_get_progname(), strerror(errno)); + fprintf(log_get_logfd(), "%s: %s\n", log_get_progname(), strerrno()); exit(13); } } diff --git a/lib/find_new_gid.c b/lib/find_new_gid.c index 5ee077abd..0d74945c1 100644 --- a/lib/find_new_gid.c +++ b/lib/find_new_gid.c @@ -18,6 +18,8 @@ #include "groupio.h" #include "getdef.h" #include "shadowlog.h" +#include "string/strerrno.h" + /* * get_ranges - Get the minimum and maximum ID ranges for the search @@ -237,7 +239,7 @@ int find_new_gid (bool sys_group, if (NULL == used_gids) { fprintf (log_get_logfd(), _("%s: failed to allocate memory: %s\n"), - log_get_progname(), strerror (errno)); + log_get_progname(), strerrno()); return -1; } diff --git a/lib/find_new_uid.c b/lib/find_new_uid.c index c9a460b02..4cce68131 100644 --- a/lib/find_new_uid.c +++ b/lib/find_new_uid.c @@ -18,6 +18,7 @@ #include "pwio.h" #include "getdef.h" #include "shadowlog.h" +#include "string/strerrno.h" /* * get_ranges - Get the minimum and maximum ID ranges for the search @@ -237,7 +238,7 @@ int find_new_uid(bool sys_user, if (NULL == used_uids) { fprintf (log_get_logfd(), _("%s: failed to allocate memory: %s\n"), - log_get_progname(), strerror (errno)); + log_get_progname(), strerrno()); return -1; } diff --git a/lib/get_pid.c b/lib/get_pid.c index eca73a9b7..7f80b1645 100644 --- a/lib/get_pid.c +++ b/lib/get_pid.c @@ -15,6 +15,7 @@ #include "defines.h" #include "prototypes.h" #include "string/sprintf/snprintf.h" +#include "string/strerrno.h" /* @@ -60,14 +61,14 @@ int open_pidfd(const char *pidstr) if (SNPRINTF(proc_dir_name, "/proc/%d/", target) == -1) { fprintf(stderr, "snprintf of proc path failed for %d: %s\n", - target, strerror(errno)); + target, strerrno()); return -EINVAL; } proc_dir_fd = open(proc_dir_name, O_DIRECTORY); if (proc_dir_fd < 0) { fprintf(stderr, _("Could not open proc directory for target %d: %s\n"), - target, strerror(errno)); + target, strerrno()); return -EINVAL; } return proc_dir_fd; diff --git a/lib/gettime.c b/lib/gettime.c index 8b6b6ddf6..0de0e7f78 100644 --- a/lib/gettime.c +++ b/lib/gettime.c @@ -15,6 +15,7 @@ #include "defines.h" #include "prototypes.h" #include "shadowlog.h" +#include "string/strerrno.h" /* @@ -40,7 +41,7 @@ gettime(void) if (a2i(time_t, &epoch, source_date_epoch, NULL, 10, 0, fallback) == -1) { fprintf(shadow_logfd, _("Environment variable $SOURCE_DATE_EPOCH: a2i(\"%s\"): %s"), - source_date_epoch, strerror(errno)); + source_date_epoch, strerrno()); return fallback; } return epoch; diff --git a/lib/idmapping.c b/lib/idmapping.c index 6f32c45e9..bd9dbd8a7 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -28,6 +28,7 @@ #include "sizeof.h" #include "string/sprintf/stpeprintf.h" #include "string/strcmp/streq.h" +#include "string/strerrno.h" struct map_range * @@ -196,17 +197,17 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings fd = openat(proc_dir_fd, map_file, O_WRONLY); if (fd < 0) { fprintf(log_get_logfd(), _("%s: open of %s failed: %s\n"), - log_get_progname(), map_file, strerror(errno)); + log_get_progname(), map_file, strerrno()); exit(EXIT_FAILURE); } if (write_full(fd, buf, pos - buf) == -1) { fprintf(log_get_logfd(), _("%s: write to %s failed: %s\n"), - log_get_progname(), map_file, strerror(errno)); + log_get_progname(), map_file, strerrno()); exit(EXIT_FAILURE); } if (close(fd) != 0 && errno != EINTR) { fprintf(log_get_logfd(), _("%s: closing %s failed: %s\n"), - log_get_progname(), map_file, strerror(errno)); + log_get_progname(), map_file, strerrno()); exit(EXIT_FAILURE); } free(buf); diff --git a/lib/prefix_flag.c b/lib/prefix_flag.c index d452d4c31..1f824a46e 100644 --- a/lib/prefix_flag.c +++ b/lib/prefix_flag.c @@ -34,6 +34,7 @@ #include "string/sprintf/aprintf.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" +#include "string/strerrno.h" static char *passwd_db_file = NULL; @@ -96,7 +97,7 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char ** || (setreuid (getuid (), getuid ()) != 0)) { fprintf (log_get_logfd(), _("%s: failed to drop privileges (%s)\n"), - log_get_progname(), strerror (errno)); + log_get_progname(), strerrno()); exit (EXIT_FAILURE); } diff --git a/lib/root_flag.c b/lib/root_flag.c index 09b466ad4..74ee98dd3 100644 --- a/lib/root_flag.c +++ b/lib/root_flag.c @@ -18,6 +18,7 @@ #include "shadowlog.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" +#include "string/strerrno.h" #include @@ -77,7 +78,7 @@ static void change_root (const char* newroot) if ( (setregid (getgid (), getgid ()) != 0) || (setreuid (getuid (), getuid ()) != 0)) { fprintf (log_get_logfd(), _("%s: failed to drop privileges (%s)\n"), - log_get_progname(), strerror (errno)); + log_get_progname(), strerrno()); exit (EXIT_FAILURE); } @@ -91,21 +92,21 @@ static void change_root (const char* newroot) if (access (newroot, F_OK) != 0) { fprintf(log_get_logfd(), _("%s: cannot access chroot directory %s: %s\n"), - log_get_progname(), newroot, strerror (errno)); + log_get_progname(), newroot, strerrno()); exit (E_BAD_ARG); } if (chroot (newroot) != 0) { fprintf(log_get_logfd(), _("%s: unable to chroot to directory %s: %s\n"), - log_get_progname(), newroot, strerror (errno)); + log_get_progname(), newroot, strerrno()); exit (E_BAD_ARG); } if (chdir ("/") != 0) { fprintf(log_get_logfd(), _("%s: cannot chdir in chroot directory %s: %s\n"), - log_get_progname(), newroot, strerror (errno)); + log_get_progname(), newroot, strerrno()); exit (E_BAD_ARG); } } diff --git a/lib/run_part.c b/lib/run_part.c index 996910947..fb32825b9 100644 --- a/lib/run_part.c +++ b/lib/run_part.c @@ -14,6 +14,7 @@ #include "run_part.h" #include "shadowlog_internal.h" #include "string/sprintf/aprintf.h" +#include "string/strerrno.h" static int run_part(char *script_path, const char *name, const char *action) @@ -25,14 +26,14 @@ static int run_part(char *script_path, const char *name, const char *action) pid=fork(); if (pid==-1) { - fprintf(shadow_logfd, "fork: %s\n", strerror(errno)); + fprintf(shadow_logfd, "fork: %s\n", strerrno()); return 1; } if (pid==0) { setenv("ACTION",action,1); setenv("SUBJECT",name,1); execv(script_path,args); - fprintf(shadow_logfd, "execv: %s\n", strerror(errno)); + fprintf(shadow_logfd, "execv: %s\n", strerrno()); _exit(1); } @@ -41,7 +42,7 @@ static int run_part(char *script_path, const char *name, const char *action) return (wait_status); } - fprintf(shadow_logfd, "waitpid: %s\n", strerror(errno)); + fprintf(shadow_logfd, "waitpid: %s\n", strerrno()); return (1); } @@ -63,7 +64,7 @@ int run_parts(const char *directory, const char *name, const char *action) s = aprintf("%s/%s", directory, namelist[n]->d_name); if (s == NULL) { - fprintf(shadow_logfd, "aprintf: %s\n", strerror(errno)); + fprintf(shadow_logfd, "aprintf: %s\n", strerrno()); for (; n #include #include + #include "exitcodes.h" #include "prototypes.h" - #include "shadowlog_internal.h" +#include "string/strerrno.h" + int run_command(const char *cmd, const char *argv[], @@ -38,11 +40,11 @@ run_command(const char *cmd, const char *argv[], _exit (E_CMD_NOTFOUND); } fprintf (shadow_logfd, "%s: cannot execute %s: %s\n", - shadow_progname, cmd, strerror (errno)); + shadow_progname, cmd, strerrno()); _exit (E_CMD_NOEXEC); } else if ((pid_t)-1 == pid) { fprintf (shadow_logfd, "%s: cannot execute %s: %s\n", - shadow_progname, cmd, strerror (errno)); + shadow_progname, cmd, strerrno()); return -1; } @@ -55,7 +57,7 @@ run_command(const char *cmd, const char *argv[], if ((pid_t)-1 == wpid) { fprintf (shadow_logfd, "%s: waitpid (status: %d): %s\n", - shadow_progname, *status, strerror (errno)); + shadow_progname, *status, strerrno()); return -1; } diff --git a/lib/tcbfuncs.c b/lib/tcbfuncs.c index 2041d66a4..7a99a60ca 100644 --- a/lib/tcbfuncs.c +++ b/lib/tcbfuncs.c @@ -26,6 +26,7 @@ #include "shadowlog_internal.h" #include "string/sprintf/aprintf.h" #include "string/strcmp/streq.h" +#include "string/strerrno.h" #define SHADOWTCB_HASH_BY 1000 @@ -102,7 +103,7 @@ static /*@null@*/ char *shadowtcb_path_rel_existing (const char *name) if (lstat (path, &st) != 0) { fprintf (shadow_logfd, _("%s: Cannot stat %s: %s\n"), - shadow_progname, path, strerror (errno)); + shadow_progname, path, strerrno()); free (path); return NULL; } @@ -125,7 +126,7 @@ static /*@null@*/ char *shadowtcb_path_rel_existing (const char *name) if (READLINKNUL(path, link) == -1) { fprintf (shadow_logfd, _("%s: Cannot read symbolic link %s: %s\n"), - shadow_progname, path, strerror (errno)); + shadow_progname, path, strerrno()); free (path); return NULL; } @@ -186,7 +187,7 @@ static shadowtcb_status mkdir_leading (const char *name, uid_t uid) if (stat (TCB_DIR, &st) != 0) { fprintf (shadow_logfd, _("%s: Cannot stat %s: %s\n"), - shadow_progname, TCB_DIR, strerror (errno)); + shadow_progname, TCB_DIR, strerrno()); goto out_free_path; } while (NULL != (ind = strchr(ptr, '/'))) { @@ -199,19 +200,19 @@ static shadowtcb_status mkdir_leading (const char *name, uid_t uid) if ((mkdir (dir, 0700) != 0) && (errno != EEXIST)) { fprintf (shadow_logfd, _("%s: Cannot create directory %s: %s\n"), - shadow_progname, dir, strerror (errno)); + shadow_progname, dir, strerrno()); goto out_free_dir; } if (chown (dir, 0, st.st_gid) != 0) { fprintf (shadow_logfd, _("%s: Cannot change owner of %s: %s\n"), - shadow_progname, dir, strerror (errno)); + shadow_progname, dir, strerrno()); goto out_free_dir; } if (chmod (dir, 0711) != 0) { fprintf (shadow_logfd, _("%s: Cannot change mode of %s: %s\n"), - shadow_progname, dir, strerror (errno)); + shadow_progname, dir, strerrno()); goto out_free_dir; } free (dir); @@ -242,7 +243,7 @@ static shadowtcb_status unlink_suffs (const char *user) if ((unlink (tmp) != 0) && (errno != ENOENT)) { fprintf (shadow_logfd, _("%s: unlink: %s: %s\n"), - shadow_progname, tmp, strerror (errno)); + shadow_progname, tmp, strerrno()); free (tmp); return SHADOWTCB_FAILURE; } @@ -268,7 +269,7 @@ static shadowtcb_status rmdir_leading (char *path) if (errno != ENOTEMPTY) { fprintf (shadow_logfd, _("%s: Cannot remove directory %s: %s\n"), - shadow_progname, dir, strerror (errno)); + shadow_progname, dir, strerrno()); ret = SHADOWTCB_FAILURE; } free (dir); @@ -298,7 +299,7 @@ static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid) if (stat (olddir, &oldmode) != 0) { fprintf (shadow_logfd, _("%s: Cannot stat %s: %s\n"), - shadow_progname, olddir, strerror (errno)); + shadow_progname, olddir, strerrno()); goto out_free; } old_uid = oldmode.st_uid; @@ -325,7 +326,7 @@ static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid) if (rename (real_old_dir, real_new_dir) != 0) { fprintf (shadow_logfd, _("%s: Cannot rename %s to %s: %s\n"), - shadow_progname, real_old_dir, real_new_dir, strerror (errno)); + shadow_progname, real_old_dir, real_new_dir, strerrno()); goto out_free; } if (rmdir_leading (real_old_dir_rel) == SHADOWTCB_FAILURE) { @@ -334,7 +335,7 @@ static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid) if ((unlink (olddir) != 0) && (errno != ENOENT)) { fprintf (shadow_logfd, _("%s: Cannot remove %s: %s\n"), - shadow_progname, olddir, strerror (errno)); + shadow_progname, olddir, strerrno()); goto out_free; } newdir = aprintf(TCB_DIR "/%s", user_newname); @@ -349,7 +350,7 @@ static shadowtcb_status move_dir (const char *user_newname, uid_t user_newid) && (symlink (real_new_dir_rel, newdir) != 0)) { fprintf (shadow_logfd, _("%s: Cannot create symbolic link %s: %s\n"), - shadow_progname, real_new_dir_rel, strerror (errno)); + shadow_progname, real_new_dir_rel, strerrno()); goto out_free; } ret = SHADOWTCB_SUCCESS; @@ -453,26 +454,26 @@ shadowtcb_status shadowtcb_move (/*@NULL@*/const char *user_newname, uid_t user_ if (stat (tcbdir, &dirmode) != 0) { fprintf (shadow_logfd, _("%s: Cannot stat %s: %s\n"), - shadow_progname, tcbdir, strerror (errno)); + shadow_progname, tcbdir, strerrno()); goto out_free; } if (chown (tcbdir, 0, 0) != 0) { fprintf (shadow_logfd, _("%s: Cannot change owners of %s: %s\n"), - shadow_progname, tcbdir, strerror (errno)); + shadow_progname, tcbdir, strerrno()); goto out_free; } if (chmod (tcbdir, 0700) != 0) { fprintf (shadow_logfd, _("%s: Cannot change mode of %s: %s\n"), - shadow_progname, tcbdir, strerror (errno)); + shadow_progname, tcbdir, strerrno()); goto out_free; } if (lstat (shadow, &filemode) != 0) { if (errno != ENOENT) { fprintf (shadow_logfd, _("%s: Cannot lstat %s: %s\n"), - shadow_progname, shadow, strerror (errno)); + shadow_progname, shadow, strerrno()); goto out_free; } fprintf (shadow_logfd, @@ -491,13 +492,13 @@ shadowtcb_status shadowtcb_move (/*@NULL@*/const char *user_newname, uid_t user_ if (chown (shadow, user_newid, filemode.st_gid) != 0) { fprintf (shadow_logfd, _("%s: Cannot change owner of %s: %s\n"), - shadow_progname, shadow, strerror (errno)); + shadow_progname, shadow, strerrno()); goto out_free; } if (chmod (shadow, filemode.st_mode & 07777) != 0) { fprintf (shadow_logfd, _("%s: Cannot change mode of %s: %s\n"), - shadow_progname, shadow, strerror (errno)); + shadow_progname, shadow, strerrno()); goto out_free; } } @@ -507,13 +508,13 @@ shadowtcb_status shadowtcb_move (/*@NULL@*/const char *user_newname, uid_t user_ if (chown (tcbdir, user_newid, dirmode.st_gid) != 0) { fprintf (shadow_logfd, _("%s: Cannot change owner of %s: %s\n"), - shadow_progname, tcbdir, strerror (errno)); + shadow_progname, tcbdir, strerrno()); goto out_free; } if (chmod (tcbdir, dirmode.st_mode & 07777) != 0) { fprintf (shadow_logfd, _("%s: Cannot change mode of %s: %s\n"), - shadow_progname, tcbdir, strerror (errno)); + shadow_progname, tcbdir, strerrno()); goto out_free; } ret = SHADOWTCB_SUCCESS; @@ -538,7 +539,7 @@ shadowtcb_status shadowtcb_create (const char *name, uid_t uid) if (stat (TCB_DIR, &tcbdir_stat) != 0) { fprintf (shadow_logfd, _("%s: Cannot stat %s: %s\n"), - shadow_progname, TCB_DIR, strerror (errno)); + shadow_progname, TCB_DIR, strerrno()); return SHADOWTCB_FAILURE; } shadowgid = tcbdir_stat.st_gid; @@ -562,39 +563,38 @@ shadowtcb_status shadowtcb_create (const char *name, uid_t uid) } if (mkdir (dir, 0700) != 0) { fprintf (shadow_logfd, - _("%s: mkdir: %s: %s\n"), - shadow_progname, dir, strerror (errno)); + _("%s: mkdir: %s: %s\n"), shadow_progname, dir, strerrno()); goto out_free; } fd = open (shadow, O_RDWR | O_CREAT | O_TRUNC, 0600); if (fd < 0) { fprintf (shadow_logfd, _("%s: Cannot open %s: %s\n"), - shadow_progname, shadow, strerror (errno)); + shadow_progname, shadow, strerrno()); goto out_free; } if (fchown (fd, 0, authgid) != 0) { fprintf (shadow_logfd, _("%s: Cannot change owner of %s: %s\n"), - shadow_progname, shadow, strerror (errno)); + shadow_progname, shadow, strerrno()); goto out_free; } if (fchmod (fd, (mode_t) ((authgid == shadowgid) ? 0600 : 0640)) != 0) { fprintf (shadow_logfd, _("%s: Cannot change mode of %s: %s\n"), - shadow_progname, shadow, strerror (errno)); + shadow_progname, shadow, strerrno()); goto out_free; } if (chown (dir, 0, authgid) != 0) { fprintf (shadow_logfd, _("%s: Cannot change owner of %s: %s\n"), - shadow_progname, dir, strerror (errno)); + shadow_progname, dir, strerrno()); goto out_free; } if (chmod (dir, (mode_t) ((authgid == shadowgid) ? 02700 : 02710)) != 0) { fprintf (shadow_logfd, _("%s: Cannot change mode of %s: %s\n"), - shadow_progname, dir, strerror (errno)); + shadow_progname, dir, strerrno()); goto out_free; } if ( (shadowtcb_set_user (name) == SHADOWTCB_FAILURE) diff --git a/src/chage.c b/src/chage.c index 693bad86c..1cc0c6824 100644 --- a/src/chage.c +++ b/src/chage.c @@ -33,6 +33,7 @@ #include "string/strcmp/streq.h" #include "string/strcpy/strtcpy.h" #include "string/strdup/strdup.h" +#include "string/strerrno.h" #include "string/strftime.h" #include "time/day_to_str.h" /*@-exitarg@*/ @@ -780,7 +781,7 @@ int main (int argc, char **argv) if (lflg && ( (setregid (rgid, rgid) != 0) || (setreuid (ruid, ruid) != 0))) { fprintf (stderr, _("%s: failed to drop privileges (%s)\n"), - Prog, strerror (errno)); + Prog, strerrno()); fail_exit (E_NOPERM, process_selinux); } diff --git a/src/chgpasswd.c b/src/chgpasswd.c index 52345d39c..577ae8b75 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -37,6 +37,7 @@ #include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "string/strcmp/streq.h" +#include "string/strerrno.h" #include "string/strtok/stpsep.h" /* @@ -536,7 +537,7 @@ int main (int argc, char **argv) if (NULL == cp) { fprintf (stderr, _("%s: failed to crypt password with salt '%s': %s\n"), - Prog, salt, strerror (errno)); + Prog, salt, strerrno()); fail_exit (1, process_selinux); } } diff --git a/src/chpasswd.c b/src/chpasswd.c index 91da42d0a..e1805e329 100644 --- a/src/chpasswd.c +++ b/src/chpasswd.c @@ -35,6 +35,7 @@ #include "exitcodes.h" #include "shadowlog.h" #include "string/strcmp/streq.h" +#include "string/strerrno.h" #include "string/strtok/stpsep.h" @@ -597,7 +598,7 @@ int main (int argc, char **argv) if (NULL == cp) { fprintf (stderr, _("%s: failed to crypt password with salt '%s': %s\n"), - Prog, salt, strerror (errno)); + Prog, salt, strerrno()); fail_exit (1, process_selinux); } } diff --git a/src/faillog.c b/src/faillog.c index 47ee26149..2800e93e3 100644 --- a/src/faillog.c +++ b/src/faillog.c @@ -27,6 +27,7 @@ #include "exitcodes.h" #include "shadowlog.h" #include "string/memset/memzero.h" +#include "string/strerrno.h" #include "string/strftime.h" @@ -638,7 +639,7 @@ int main (int argc, char **argv) if (NULL == fail) { fprintf (stderr, _("%s: Cannot open %s: %s\n"), - Prog, FAILLOG_FILE, strerror (errno)); + Prog, FAILLOG_FILE, strerrno()); exit (E_NOPERM); } @@ -646,7 +647,7 @@ int main (int argc, char **argv) if (fstat (fileno (fail), &statbuf) != 0) { fprintf (stderr, _("%s: Cannot get the size of %s: %s\n"), - Prog, FAILLOG_FILE, strerror (errno)); + Prog, FAILLOG_FILE, strerrno()); exit (E_NOPERM); } @@ -673,7 +674,7 @@ int main (int argc, char **argv) || (fclose (fail) != 0)) { fprintf (stderr, _("%s: Failed to write %s: %s\n"), - Prog, FAILLOG_FILE, strerror (errno)); + Prog, FAILLOG_FILE, strerrno()); (void) fclose (fail); errors = true; } diff --git a/src/gpasswd.c b/src/gpasswd.c index 4baa9a3aa..42ac0ff39 100644 --- a/src/gpasswd.c +++ b/src/gpasswd.c @@ -40,6 +40,8 @@ #include "string/strcmp/streq.h" #include "string/strcpy/strtcpy.h" #include "string/strdup/strdup.h" +#include "string/strerrno.h" + struct option_flags { bool chroot; @@ -852,7 +854,7 @@ static void change_passwd (struct group *gr) if (NULL == cp) { fprintf (stderr, _("%s: failed to crypt password with salt '%s': %s\n"), - Prog, salt, strerror (errno)); + Prog, salt, strerrno()); exit (1); } #ifdef SHADOWGRP diff --git a/src/groupadd.c b/src/groupadd.c index 0fe28ded3..af8109dff 100644 --- a/src/groupadd.c +++ b/src/groupadd.c @@ -40,6 +40,7 @@ #include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "string/memset/memzero.h" +#include "string/strerrno.h" #include "string/strtok/stpsep.h" @@ -374,8 +375,8 @@ static void open_files (struct option_flags *flags) /* And now open the databases */ if (gr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s: %s\n"), Prog, gr_dbname (), strerror(errno)); - SYSLOG ((LOG_WARN, "cannot open %s: %s", gr_dbname (), strerror(errno))); + fprintf(stderr, _("%s: cannot open %s: %s\n"), Prog, gr_dbname(), strerrno()); + SYSLOG((LOG_WARN, "cannot open %s: %s", gr_dbname(), strerrno())); fail_exit (E_GRP_UPDATE); } @@ -384,8 +385,8 @@ static void open_files (struct option_flags *flags) if (sgr_open (O_CREAT | O_RDWR) == 0) { fprintf (stderr, _("%s: cannot open %s: %s\n"), - Prog, sgr_dbname (), strerror(errno)); - SYSLOG ((LOG_WARN, "cannot open %s: %s", sgr_dbname (), strerror(errno))); + Prog, sgr_dbname(), strerrno()); + SYSLOG((LOG_WARN, "cannot open %s: %s", sgr_dbname(), strerrno())); fail_exit (E_GRP_UPDATE); } } diff --git a/src/lastlog.c b/src/lastlog.c index 0f8793c52..e513936c7 100644 --- a/src/lastlog.c +++ b/src/lastlog.c @@ -33,6 +33,7 @@ #include "shadowlog.h" #include "sizeof.h" #include "string/memset/memzero.h" +#include "string/strerrno.h" #include "string/strftime.h" @@ -436,7 +437,7 @@ int main (int argc, char **argv) if (fstat (fileno (lastlogfile), &statbuf) != 0) { fprintf (stderr, _("%s: Cannot get the size of %s: %s\n"), - Prog, _PATH_LASTLOG, strerror(errno)); + Prog, _PATH_LASTLOG, strerrno()); exit (EXIT_FAILURE); } diff --git a/src/login.c b/src/login.c index 8b5315346..9f193b004 100644 --- a/src/login.c +++ b/src/login.c @@ -46,6 +46,7 @@ #include "string/strcmp/strprefix.h" #include "string/strcpy/strtcpy.h" #include "string/strdup/strdup.h" +#include "string/strerrno.h" #include "string/strftime.h" @@ -1088,8 +1089,7 @@ int main (int argc, char **argv) child = fork (); if (child < 0) { /* error in fork() */ - fprintf (stderr, _("%s: failure forking: %s"), - Prog, strerror (errno)); + fprintf(stderr, _("%s: failure forking: %s"), Prog, strerrno()); PAM_END; exit (0); } else if (child != 0) { diff --git a/src/newgidmap.c b/src/newgidmap.c index a8fb630c3..9d130a7d3 100644 --- a/src/newgidmap.c +++ b/src/newgidmap.c @@ -20,6 +20,7 @@ #include "prototypes.h" #include "shadowlog.h" #include "string/strcmp/strprefix.h" +#include "string/strerrno.h" #include "subordinateio.h" @@ -103,8 +104,7 @@ static void write_setgroups(int proc_dir_fd, bool allow_setgroups) goto out; } fprintf(stderr, _("%s: couldn't open process setgroups: %s\n"), - Prog, - strerror(errno)); + Prog, strerrno()); exit(EXIT_FAILURE); } @@ -115,8 +115,7 @@ static void write_setgroups(int proc_dir_fd, bool allow_setgroups) */ if (read(setgroups_fd, policy_buffer, sizeof(policy_buffer)) < 0) { fprintf(stderr, _("%s: failed to read setgroups: %s\n"), - Prog, - strerror(errno)); + Prog, strerrno()); exit(EXIT_FAILURE); } if (strprefix(policy_buffer, policy)) @@ -125,15 +124,12 @@ static void write_setgroups(int proc_dir_fd, bool allow_setgroups) /* Write the policy. */ if (lseek(setgroups_fd, 0, SEEK_SET) < 0) { fprintf(stderr, _("%s: failed to seek setgroups: %s\n"), - Prog, - strerror(errno)); + Prog, strerrno()); exit(EXIT_FAILURE); } if (dprintf(setgroups_fd, "%s", policy) < 0) { fprintf(stderr, _("%s: failed to setgroups %s policy: %s\n"), - Prog, - policy, - strerror(errno)); + Prog, policy, strerrno()); exit(EXIT_FAILURE); } @@ -195,7 +191,7 @@ int main(int argc, char **argv) if (fstat(proc_dir_fd, &st) < 0) { fprintf(stderr, _("%s: Could not stat directory for target process: %s\n"), - Prog, strerror (errno)); + Prog, strerrno()); return EXIT_FAILURE; } @@ -217,7 +213,7 @@ int main(int argc, char **argv) if (want_subgid_file() && !sub_gid_open(O_RDONLY)) { fprintf (stderr, _("%s: cannot open %s: %s\n"), - Prog, sub_gid_dbname (), strerror (errno)); + Prog, sub_gid_dbname(), strerrno()); return EXIT_FAILURE; } diff --git a/src/newgrp.c b/src/newgrp.c index 123f1b285..66f4e9cba 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -36,6 +36,7 @@ #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" #include "string/strdup/strdup.h" +#include "string/strerrno.h" #include @@ -188,7 +189,7 @@ static void check_perms (const struct group *grp, if (NULL == cpasswd) { fprintf (stderr, _("%s: failed to crypt password with previous salt: %s\n"), - Prog, strerror (errno)); + Prog, strerrno()); SYSLOG ((LOG_INFO, "Failed to crypt password with previous salt of group '%s'", groupname)); @@ -295,7 +296,7 @@ static void syslog_sg (const char *name, const char *group) if ((pid_t)-1 == child) { /* error in fork() */ fprintf (stderr, _("%s: failure forking: %s\n"), - is_newgrp ? "newgrp" : "sg", strerror (errno)); + is_newgrp ? "newgrp" : "sg", strerrno()); #ifdef WITH_AUDIT if (group) { audit_logger_with_group(AUDIT_CHGRP_ID, "changing", NULL, diff --git a/src/newuidmap.c b/src/newuidmap.c index d9c3b4baf..43826b1d0 100644 --- a/src/newuidmap.c +++ b/src/newuidmap.c @@ -20,6 +20,7 @@ #include "prototypes.h" #include "shadowlog.h" #include "string/strcmp/strprefix.h" +#include "string/strerrno.h" #include "subordinateio.h" @@ -124,7 +125,7 @@ int main(int argc, char **argv) if (fstat(proc_dir_fd, &st) < 0) { fprintf(stderr, _("%s: Could not stat directory for target process: %s\n"), - Prog, strerror (errno)); + Prog, strerrno()); return EXIT_FAILURE; } @@ -146,7 +147,7 @@ int main(int argc, char **argv) if (want_subuid_file() && !sub_uid_open(O_RDONLY)) { fprintf (stderr, _("%s: cannot open %s: %s\n"), - Prog, sub_uid_dbname (), strerror (errno)); + Prog, sub_uid_dbname(), strerrno()); return EXIT_FAILURE; } diff --git a/src/newusers.c b/src/newusers.c index a7ab4a981..3f260584d 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -58,6 +58,7 @@ #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" #include "string/strdup/strdup.h" +#include "string/strerrno.h" #include "string/strtok/stpsep.h" #include "string/strtok/strsep2arr.h" @@ -467,7 +468,7 @@ static int update_passwd (struct passwd *pwd, const char *password) if (NULL == cp) { fprintf (stderr, _("%s: failed to crypt password with salt '%s': %s\n"), - Prog, salt, strerror (errno)); + Prog, salt, strerrno()); return 1; } pwd->pw_passwd = cp; @@ -545,7 +546,7 @@ static int add_passwd (struct passwd *pwd, const char *password) if (NULL == cp) { fprintf (stderr, _("%s: failed to crypt password with salt '%s': %s\n"), - Prog, salt, strerror (errno)); + Prog, salt, strerrno()); return 1; } spent.sp_pwdp = cp; @@ -595,7 +596,7 @@ static int add_passwd (struct passwd *pwd, const char *password) if (NULL == cp) { fprintf (stderr, _("%s: failed to crypt password with salt '%s': %s\n"), - Prog, salt, strerror (errno)); + Prog, salt, strerrno()); return 1; } spent.sp_pwdp = cp; @@ -1196,9 +1197,7 @@ int main (int argc, char **argv) usernames = REALLOCF(usernames, nusers, char *); passwords = REALLOCF(passwords, nusers, char *); if (lines == NULL || usernames == NULL || passwords == NULL) { - fprintf (stderr, - _("%s: line %jd: %s\n"), - Prog, line, strerror(errno)); + fprintf(stderr, _("%s: line %jd: %s\n"), Prog, line, strerrno()); fail_exit (EXIT_FAILURE, process_selinux); } lines[nusers-1] = line; @@ -1237,8 +1236,7 @@ int main (int argc, char **argv) if (mkdir (newpw.pw_dir, mode) != 0) { fprintf (stderr, _("%s: line %jd: mkdir %s failed: %s\n"), - Prog, line, newpw.pw_dir, - strerror (errno)); + Prog, line, newpw.pw_dir, strerrno()); if (errno != EEXIST) { fail_exit (EXIT_FAILURE, process_selinux); } @@ -1247,8 +1245,7 @@ int main (int argc, char **argv) { fprintf (stderr, _("%s: line %jd: chown %s failed: %s\n"), - Prog, line, newpw.pw_dir, - strerror (errno)); + Prog, line, newpw.pw_dir, strerrno()); fail_exit (EXIT_FAILURE, process_selinux); } } diff --git a/src/passwd.c b/src/passwd.c index a29f9640b..f51cf48d6 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -38,6 +38,7 @@ #include "string/strcmp/strprefix.h" #include "string/strcpy/strtcpy.h" #include "string/strdup/strdup.h" +#include "string/strerrno.h" #include "time/day_to_str.h" @@ -214,7 +215,7 @@ static int new_password (const struct passwd *pw) erase_pass (clear); fprintf (stderr, _("%s: failed to crypt password with previous salt: %s\n"), - Prog, strerror (errno)); + Prog, strerrno()); SYSLOG ((LOG_INFO, "Failed to crypt password with previous salt of user '%s'", pw->pw_name)); @@ -368,7 +369,7 @@ static int new_password (const struct passwd *pw) if (NULL == cp) { fprintf (stderr, _("%s: failed to crypt password with salt '%s': %s\n"), - Prog, salt, strerror (errno)); + Prog, salt, strerrno()); return -1; } diff --git a/src/useradd.c b/src/useradd.c index a4dd3638a..0d26a0bcb 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -74,6 +74,7 @@ #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" #include "string/strdup/strdup.h" +#include "string/strerrno.h" #include "string/strtok/stpsep.h" @@ -534,7 +535,7 @@ set_defaults(void) new_file = aprintf("%s%s%s", prefix, prefix[0]?"/":"", NEW_USER_FILE); if (new_file == NULL) { fprintf(stderr, _("%s: cannot create new defaults file: %s\n"), - Prog, strerror(errno)); + Prog, strerrno()); return -1; } @@ -543,7 +544,7 @@ set_defaults(void) if (default_file == NULL) { fprintf(stderr, _("%s: cannot create new defaults file: %s\n"), - Prog, strerror(errno)); + Prog, strerrno()); goto err_free_new; } } @@ -693,10 +694,9 @@ set_defaults(void) assert(SNPRINTF(buf, "%s-", default_file) != -1); unlink (buf); if ((link (default_file, buf) != 0) && (ENOENT != errno)) { - int err = errno; fprintf (stderr, _("%s: Cannot create backup file (%s): %s\n"), - Prog, buf, strerror (err)); + Prog, buf, strerrno()); unlink (new_file); goto err_free_def; } @@ -705,10 +705,9 @@ set_defaults(void) * Rename the new default file to its correct name. */ if (rename (new_file, default_file) != 0) { - int err = errno; fprintf (stderr, _("%s: rename: %s: %s\n"), - Prog, new_file, strerror (err)); + Prog, new_file, strerrno()); goto err_free_def; } #ifdef WITH_AUDIT @@ -1969,7 +1968,7 @@ static void faillog_reset (uid_t uid) if (-1 == fd) { fprintf (stderr, _("%s: failed to open the faillog file for UID %lu: %s\n"), - Prog, (unsigned long) uid, strerror (errno)); + Prog, (unsigned long) uid, strerrno()); SYSLOG ((LOG_WARN, "failed to open the faillog file for UID %lu", (unsigned long) uid)); return; } @@ -1978,13 +1977,13 @@ static void faillog_reset (uid_t uid) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to reset the faillog entry of UID %lu: %s\n"), - Prog, (unsigned long) uid, strerror (errno)); + Prog, (unsigned long) uid, strerrno()); SYSLOG ((LOG_WARN, "failed to reset the faillog entry of UID %lu", (unsigned long) uid)); } 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)); + Prog, (unsigned long) uid, strerrno()); SYSLOG ((LOG_WARN, "failed to close the faillog file for UID %lu", (unsigned long) uid)); } } @@ -2014,7 +2013,7 @@ static void lastlog_reset (uid_t uid) if (-1 == fd) { fprintf (stderr, _("%s: failed to open the lastlog file for UID %lu: %s\n"), - Prog, (unsigned long) uid, strerror (errno)); + Prog, (unsigned long) uid, strerrno()); SYSLOG ((LOG_WARN, "failed to open the lastlog file for UID %lu", (unsigned long) uid)); return; } @@ -2023,14 +2022,14 @@ static void lastlog_reset (uid_t uid) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to reset the lastlog entry of UID %lu: %s\n"), - Prog, (unsigned long) uid, strerror (errno)); + Prog, (unsigned long) uid, strerrno()); SYSLOG ((LOG_WARN, "failed to reset the lastlog entry of UID %lu", (unsigned long) uid)); /* continue */ } 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)); + Prog, (unsigned long) uid, strerrno()); SYSLOG ((LOG_WARN, "failed to close the lastlog file for UID %lu", (unsigned long) uid)); /* continue */ } diff --git a/src/userdel.c b/src/userdel.c index ae8cb61a3..474977247 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -56,6 +56,7 @@ #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" #include "string/strdup/strdup.h" +#include "string/strerrno.h" /* @@ -777,8 +778,8 @@ static bool remove_mailbox (void) } else { fprintf (stderr, _("%s: warning: can't remove %s: %s\n"), - Prog, mailfile, strerror (errno)); - SYSLOG ((LOG_ERR, "Cannot remove %s: %s", mailfile, strerror (errno))); + Prog, mailfile, strerrno()); + SYSLOG((LOG_ERR, "Cannot remove %s: %s", mailfile, strerrno())); #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, Prog, "delete-mail-file", @@ -793,8 +794,8 @@ static bool remove_mailbox (void) if (unlink (mailfile) != 0) { fprintf (stderr, _("%s: warning: can't remove %s: %s\n"), - Prog, mailfile, strerror (errno)); - SYSLOG ((LOG_ERR, "Cannot remove %s: %s", mailfile, strerror (errno))); + Prog, mailfile, strerrno()); + SYSLOG((LOG_ERR, "Cannot remove %s: %s", mailfile, strerrno())); #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, Prog, "delete-mail-file", @@ -819,9 +820,7 @@ static bool remove_mailbox (void) fprintf (stderr, _("%s: %s not owned by %s, not removing\n"), Prog, mailfile, user_name); - SYSLOG ((LOG_ERR, - "%s not owned by %s, not removed", - mailfile, strerror (errno))); + SYSLOG((LOG_ERR, "%s not owned by %s, not removed", mailfile, strerrno())); #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, Prog, "delete-mail-file", @@ -836,8 +835,8 @@ static bool remove_mailbox (void) if (unlink (mailfile) != 0) { fprintf (stderr, _("%s: warning: can't remove %s: %s\n"), - Prog, mailfile, strerror (errno)); - SYSLOG ((LOG_ERR, "Cannot remove %s: %s", mailfile, strerror (errno))); + Prog, mailfile, strerrno()); + SYSLOG((LOG_ERR, "Cannot remove %s: %s", mailfile, strerrno())); #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, Prog, "delete-mail-file", @@ -877,7 +876,7 @@ static int remove_tcbdir (const char *user_name, uid_t user_id) } if (shadowtcb_drop_priv () == SHADOWTCB_FAILURE) { fprintf (stderr, _("%s: Cannot drop privileges: %s\n"), - Prog, strerror (errno)); + Prog, strerrno()); shadowtcb_gain_priv (); free (buf); return 1; @@ -887,7 +886,7 @@ static int remove_tcbdir (const char *user_name, uid_t user_id) */ if (remove_tree (buf, false) != 0) { fprintf (stderr, _("%s: Cannot remove the content of %s: %s\n"), - Prog, buf, strerror (errno)); + Prog, buf, strerrno()); shadowtcb_gain_priv (); free (buf); return 1; @@ -896,7 +895,7 @@ static int remove_tcbdir (const char *user_name, uid_t user_id) free (buf); if (shadowtcb_remove (user_name) == SHADOWTCB_FAILURE) { fprintf (stderr, _("%s: Cannot remove tcb files for %s: %s\n"), - Prog, user_name, strerror (errno)); + Prog, user_name, strerrno()); ret = 1; } return ret; diff --git a/src/usermod.c b/src/usermod.c index 414ff7b56..fc1a8361e 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -68,6 +68,7 @@ #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" #include "string/strdup/strdup.h" +#include "string/strerrno.h" #include "time/day_to_str.h" #include "typetraits.h" @@ -368,7 +369,7 @@ prepend_range(const char *str, struct id_range_list_entry **head) if (!entry) { fprintf (stderr, _("%s: failed to allocate memory: %s\n"), - Prog, strerror (errno)); + Prog, strerrno()); return 0; } entry->next = *head; @@ -1917,7 +1918,7 @@ static void update_lastlog (void) if (-1 == fd) { fprintf (stderr, _("%s: failed to copy the lastlog entry of user %lu to user %lu: %s\n"), - Prog, (unsigned long) user_id, (unsigned long) user_newid, strerror (errno)); + Prog, (unsigned long) user_id, (unsigned long) user_newid, strerrno()); return; } @@ -1929,7 +1930,7 @@ static void update_lastlog (void) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to copy the lastlog entry of user %lu to user %lu: %s\n"), - Prog, (unsigned long) user_id, (unsigned long) user_newid, strerror (errno)); + Prog, (unsigned long) user_id, (unsigned long) user_newid, strerrno()); } } else { /* Assume lseek or read failed because there is @@ -1945,7 +1946,7 @@ static void update_lastlog (void) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to copy the lastlog entry of user %lu to user %lu: %s\n"), - Prog, (unsigned long) user_id, (unsigned long) user_newid, strerror (errno)); + Prog, (unsigned long) user_id, (unsigned long) user_newid, strerrno()); } } } @@ -1953,7 +1954,7 @@ static void update_lastlog (void) 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)); + Prog, (uintmax_t) user_id, (uintmax_t) user_newid, strerrno()); } } #endif /* ENABLE_LASTLOG */ @@ -1981,7 +1982,7 @@ static void update_faillog (void) if (-1 == fd) { fprintf (stderr, _("%s: failed to copy the faillog entry of user %lu to user %lu: %s\n"), - Prog, (unsigned long) user_id, (unsigned long) user_newid, strerror (errno)); + Prog, (unsigned long) user_id, (unsigned long) user_newid, strerrno()); return; } @@ -1993,7 +1994,7 @@ static void update_faillog (void) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to copy the faillog entry of user %lu to user %lu: %s\n"), - Prog, (unsigned long) user_id, (unsigned long) user_newid, strerror (errno)); + Prog, (unsigned long) user_id, (unsigned long) user_newid, strerrno()); } } else { /* Assume lseek or read failed because there is @@ -2009,7 +2010,7 @@ static void update_faillog (void) { fprintf (stderr, _("%s: failed to copy the faillog entry of user %lu to user %lu: %s\n"), - Prog, (unsigned long) user_id, (unsigned long) user_newid, strerror (errno)); + Prog, (unsigned long) user_id, (unsigned long) user_newid, strerrno()); } } } @@ -2017,7 +2018,7 @@ static void update_faillog (void) 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)); + Prog, (uintmax_t) user_id, (uintmax_t) user_newid, strerrno()); } } diff --git a/src/vipw.c b/src/vipw.c index 29fa55a87..83ff3d92b 100644 --- a/src/vipw.c +++ b/src/vipw.c @@ -46,6 +46,7 @@ #include "string/sprintf/aprintf.h" #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" +#include "string/strerrno.h" #define MSG_WARN_EDIT_OTHER_FILE _( \ @@ -310,8 +311,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) status = system (buf); if (-1 == status) { - fprintf (stderr, _("%s: %s: %s\n"), Prog, editor, - strerror (errno)); + fprintf(stderr, _("%s: %s: %s\n"), Prog, editor, strerrno()); exit (1); } else if ( WIFEXITED (status) && (WEXITSTATUS (status) != 0)) { @@ -350,11 +350,11 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) editor_pgrp = tcgetpgrp(STDIN_FILENO); if (editor_pgrp == -1) { fprintf (stderr, "%s: %s: %s", Prog, - "tcgetpgrp", strerror (errno)); + "tcgetpgrp", strerrno()); } if (tcsetpgrp(STDIN_FILENO, orig_pgrp) == -1) { fprintf (stderr, "%s: %s: %s", Prog, - "tcsetpgrp", strerror (errno)); + "tcsetpgrp", strerrno()); } } kill (getpid (), SIGSTOP); @@ -362,7 +362,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) if (editor_pgrp != -1) { if (tcsetpgrp(STDIN_FILENO, editor_pgrp) == -1) { fprintf (stderr, "%s: %s: %s", Prog, - "tcsetpgrp", strerror (errno)); + "tcsetpgrp", strerrno()); } } killpg (pid, SIGCONT); @@ -374,8 +374,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) if (orig_pgrp != -1) { /* Restore terminal pgrp after editing. */ if (tcsetpgrp(STDIN_FILENO, orig_pgrp) == -1) { - fprintf(stderr, "%s: %s: %s", Prog, - "tcsetpgrp", strerror(errno)); + fprintf(stderr, "%s: %s: %s", Prog, "tcsetpgrp", strerrno()); } sigprocmask(SIG_SETMASK, &omask, NULL); } @@ -447,7 +446,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool)) if (rename (to_rename, file) == -1) { fprintf (stderr, _("%s: can't restore %s: %s (your changes are in %s)\n"), - Prog, file, strerror (errno), to_rename); + Prog, file, strerrno(), to_rename); #ifdef WITH_TCB if (tcb_mode) { free(to_rename); -- 2.47.3