From: Alejandro Colomar Date: Wed, 23 Jul 2025 16:14:32 +0000 (+0200) Subject: lib/, src/: Use SYSLOGE() instead of its pattern X-Git-Tag: 4.20.0-rc3~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e61cb1e94e621598036124d7f619ba364fd7f2e1;p=thirdparty%2Fshadow.git lib/, src/: Use SYSLOGE() instead of its pattern Having such long and complex format strings and variadic arguments is error-prone, as can be seen in the previous commit, which fixes a bug of this kind. Signed-off-by: Alejandro Colomar --- diff --git a/lib/chowntty.c b/lib/chowntty.c index dc29203ee..eb0f9e383 100644 --- a/lib/chowntty.c +++ b/lib/chowntty.c @@ -21,6 +21,7 @@ #include "defines.h" #include "getdef.h" #include "io/fprintf.h" +#include "io/syslog.h" #include "prototypes.h" #include "shadowlog.h" @@ -57,9 +58,9 @@ void chown_tty (const struct passwd *info) int err = errno; fprinte(log_get_logfd(), _("Unable to change owner or mode of tty stdin")); - SYSLOG(LOG_WARN, - "unable to change owner or mode of tty stdin for user `%s': %s\n", - info->pw_name, strerror(err)); + SYSLOGE(LOG_WARN, + "unable to change owner or mode of tty stdin for user `%s'", + info->pw_name); if (EROFS != err) { closelog (); exit (EXIT_FAILURE); diff --git a/lib/getdef.c b/lib/getdef.c index e85e0a446..ae6bbeb2b 100644 --- a/lib/getdef.c +++ b/lib/getdef.c @@ -26,6 +26,7 @@ #include "defines.h" #include "getdef.h" #include "io/fgets/fgets.h" +#include "io/syslog.h" #include "prototypes.h" #include "shadowlog.h" #include "sizeof.h" @@ -549,9 +550,7 @@ static void def_load (void) if (errno == ENOENT) return; - int err = errno; - SYSLOG(LOG_CRIT, "cannot open login definitions %s [%s]", - def_fname, strerror(err)); + SYSLOGE(LOG_CRIT, "cannot open login definitions %s", def_fname); exit (EXIT_FAILURE); } @@ -590,9 +589,7 @@ static void def_load (void) } if (ferror (fp) != 0) { - int err = errno; - SYSLOG(LOG_CRIT, "cannot read login definitions %s [%s]", - def_fname, strerror(err)); + SYSLOGE(LOG_CRIT, "cannot read login definitions %s", def_fname); exit (EXIT_FAILURE); } diff --git a/lib/selinux.c b/lib/selinux.c index a434d0e77..66bb3c12e 100644 --- a/lib/selinux.c +++ b/lib/selinux.c @@ -15,10 +15,10 @@ #include #include "io/fprintf.h" +#include "io/syslog.h" #include "prototypes.h" #include "shadowlog.h" #include "string/sprintf/aprintf.h" -#include "string/strerrno.h" static bool selinux_checked = false; @@ -194,9 +194,7 @@ int check_selinux_permit (const char *perm_name) if (getprevcon_raw (&user_context_raw) != 0) { fprinte(log_get_logfd(), _("%s: can not get previous SELinux process context"), log_get_progname()); - SYSLOG(LOG_WARN, - "can not get previous SELinux process context: %s", - strerrno()); + SYSLOGE(LOG_WARN, "can not get previous SELinux process context"); return (security_getenforce () != 0); } diff --git a/lib/setugid.c b/lib/setugid.c index d8a3588bd..cbff8ac2c 100644 --- a/lib/setugid.c +++ b/lib/setugid.c @@ -18,10 +18,13 @@ #include #include #include -#include "prototypes.h" -#include "defines.h" #include + +#include "defines.h" #include "getdef.h" +#include "io/syslog.h" +#include "prototypes.h" + /* * setup_groups - set the group credentials @@ -40,10 +43,9 @@ int setup_groups (const struct passwd *info) * file. */ if (setgid (info->pw_gid) == -1) { - int err = errno; perror ("setgid"); - SYSLOG(LOG_ERR, "bad group ID `%d' for user `%s': %s\n", - info->pw_gid, info->pw_name, strerror(err)); + SYSLOGE(LOG_ERR, "bad group ID `%d' for user `%s'", + info->pw_gid, info->pw_name); closelog (); return -1; } @@ -53,10 +55,8 @@ int setup_groups (const struct passwd *info) * the group set from the /etc/group file. */ if (initgroups (info->pw_name, info->pw_gid) == -1) { - int err = errno; perror ("initgroups"); - SYSLOG(LOG_ERR, "initgroups failed for user `%s': %s\n", - info->pw_name, strerror(err)); + SYSLOGE(LOG_ERR, "initgroups failed for user `%s'", info->pw_name); closelog (); return -1; } @@ -75,10 +75,9 @@ int change_uid (const struct passwd *info) * Set the real UID to the UID value in the password file. */ if (setuid (info->pw_uid) != 0) { - int err = errno; perror ("setuid"); - SYSLOG(LOG_ERR, "bad user ID `%d' for user `%s': %s\n", - (int) info->pw_uid, info->pw_name, strerror(err)); + SYSLOGE(LOG_ERR, "bad user ID `%d' for user `%s'", + (int) info->pw_uid, info->pw_name); closelog (); return -1; } diff --git a/src/groupadd.c b/src/groupadd.c index f29ff83fe..ff1219a29 100644 --- a/src/groupadd.c +++ b/src/groupadd.c @@ -25,6 +25,7 @@ #include "getdef.h" #include "groupio.h" #include "io/fprintf.h" +#include "io/syslog.h" #include "nscd.h" #include "sssd.h" #include "prototypes.h" @@ -36,7 +37,6 @@ #include "shadowlog.h" #include "string/memset/memzero.h" #include "string/strcmp/streq.h" -#include "string/strerrno.h" #include "string/strtok/stpsep.h" @@ -372,7 +372,7 @@ static void open_files(const struct option_flags *flags) /* And now open the databases */ if (gr_open (O_CREAT | O_RDWR) == 0) { fprinte(stderr, _("%s: cannot open %s"), Prog, gr_dbname()); - SYSLOG(LOG_WARN, "cannot open %s: %s", gr_dbname(), strerrno()); + SYSLOGE(LOG_WARN, "cannot open %s", gr_dbname()); fail_exit (E_GRP_UPDATE); } @@ -380,7 +380,7 @@ static void open_files(const struct option_flags *flags) if (is_shadow_grp) { if (sgr_open (O_CREAT | O_RDWR) == 0) { fprinte(stderr, _("%s: cannot open %s"), Prog, sgr_dbname()); - SYSLOG(LOG_WARN, "cannot open %s: %s", sgr_dbname(), strerrno()); + SYSLOGE(LOG_WARN, "cannot open %s", sgr_dbname()); fail_exit (E_GRP_UPDATE); } } diff --git a/src/login_nopam.c b/src/login_nopam.c index 7b5356ee2..ef78143bf 100644 --- a/src/login_nopam.c +++ b/src/login_nopam.c @@ -59,6 +59,7 @@ #include "defines.h" #include "io/fgets/fgets.h" +#include "io/syslog.h" #include "prototypes.h" #include "sizeof.h" #include "string/strcmp/strcaseeq.h" @@ -139,8 +140,7 @@ login_access(const char *user, const char *from) } (void) fclose (fp); } else if (errno != ENOENT) { - int err = errno; - SYSLOG(LOG_ERR, "cannot open %s: %s", TABLE, strerror(err)); + SYSLOGE(LOG_ERR, "cannot open %s", TABLE); } return (!match || strprefix(line, "+"))?1:0; } diff --git a/src/newusers.c b/src/newusers.c index 7b544fe89..957930b05 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -42,6 +42,7 @@ #include "groupio.h" #include "io/fgets/fgets.h" #include "io/fprintf.h" +#include "io/syslog.h" #include "nscd.h" #include "prototypes.h" #include "pwio.h" @@ -1183,8 +1184,7 @@ int main (int argc, char **argv) fprinte(stderr, _("%s: can't find subordinate user range"), Prog); - SYSLOG(LOG_WARN, "can't find subordinate user range: %s\n", - strerrno()); + SYSLOGE(LOG_WARN, "can't find subordinate user range"); fail_exit (EXIT_FAILURE, process_selinux); } if (sub_uid_add(fields[0], sub_uid_start, sub_uid_count) == 0) @@ -1206,8 +1206,7 @@ int main (int argc, char **argv) fprinte(stderr, _("%s: can't find subordinate group range"), Prog); - SYSLOG(LOG_WARN, "can't find subordinate group range: %s\n", - strerrno()); + SYSLOGE(LOG_WARN, "can't find subordinate group range"); fail_exit (EXIT_FAILURE, process_selinux); } if (sub_gid_add(fields[0], sub_gid_start, sub_gid_count) == 0) { diff --git a/src/suauth.c b/src/suauth.c index 5d55484ce..453f9a4df 100644 --- a/src/suauth.c +++ b/src/suauth.c @@ -19,6 +19,7 @@ #include "defines.h" #include "io/fgets/fgets.h" +#include "io/syslog.h" #include "prototypes.h" #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" @@ -68,8 +69,7 @@ check_su_auth(const char *actual_id, const char *wanted_id, bool su_to_root) if (ENOENT == err) { return NOACTION; } - SYSLOG(LOG_ERR, "could not open/read config file '%s': %s\n", - SUAUTHFILE, strerror(err)); + SYSLOGE(LOG_ERR, "could not open/read config file '%s'", SUAUTHFILE); return DENY; } diff --git a/src/useradd.c b/src/useradd.c index 643a029d6..1dce5eefc 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -43,6 +43,7 @@ #include "groupio.h" #include "io/fgets/fgets.h" #include "io/fprintf.h" +#include "io/syslog.h" #include "nscd.h" #include "prototypes.h" #include "pwauth.h" @@ -2651,8 +2652,7 @@ int main (int argc, char **argv) fprinte(stderr, _("%s: can't create subordinate user IDs"), Prog); - SYSLOG(LOG_WARN, "can't create subordinate user IDs: %s\n", - strerrno()); + SYSLOGE(LOG_WARN, "can't create subordinate user IDs"); fail_exit(E_SUB_UID_UPDATE, process_selinux); } } @@ -2661,8 +2661,7 @@ int main (int argc, char **argv) fprinte(stderr, _("%s: can't create subordinate group IDs"), Prog); - SYSLOG(LOG_WARN, "can't create subordinate group IDs: %s\n", - strerrno()); + SYSLOGE(LOG_WARN, "can't create subordinate group IDs"); fail_exit(E_SUB_GID_UPDATE, process_selinux); } } diff --git a/src/userdel.c b/src/userdel.c index ad36a97d0..3e1efa3ec 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -25,6 +25,7 @@ #include "getdef.h" #include "groupio.h" #include "io/fprintf.h" +#include "io/syslog.h" #include "nscd.h" #include "sssd.h" #include "prototypes.h" @@ -53,7 +54,6 @@ #include "string/strcmp/streq.h" #include "string/strcmp/strprefix.h" #include "string/strdup/strdup.h" -#include "string/strerrno.h" /* @@ -772,7 +772,7 @@ static bool remove_mailbox (void) return 0; } else { fprinte(stderr, _("%s: warning: can't remove %s"), Prog, mailfile); - SYSLOG(LOG_ERR, "Cannot remove %s: %s", mailfile, strerrno()); + SYSLOGE(LOG_ERR, "Cannot remove %s", mailfile); #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, "delete-mail-file", @@ -786,7 +786,7 @@ static bool remove_mailbox (void) if (fflg) { if (unlink (mailfile) != 0) { fprinte(stderr, _("%s: warning: can't remove %s"), Prog, mailfile); - SYSLOG(LOG_ERR, "Cannot remove %s: %s", mailfile, strerrno()); + SYSLOGE(LOG_ERR, "Cannot remove %s", mailfile); #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, "delete-mail-file", @@ -825,7 +825,7 @@ static bool remove_mailbox (void) } if (unlink (mailfile) != 0) { fprinte(stderr, _("%s: warning: can't remove %s"), Prog, mailfile); - SYSLOG(LOG_ERR, "Cannot remove %s: %s", mailfile, strerrno()); + SYSLOGE(LOG_ERR, "Cannot remove %s", mailfile); #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, "delete-mail-file", diff --git a/src/usermod.c b/src/usermod.c index e2ec58bbe..d6692260d 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -39,6 +39,7 @@ #include "getdef.h" #include "groupio.h" #include "io/fprintf.h" +#include "io/syslog.h" #include "nscd.h" #include "prototypes.h" #include "pwauth.h" @@ -2243,16 +2244,14 @@ int main (int argc, char **argv) fprinte(stderr, _("%s: unable to find new subordinate uid range"), Prog); - SYSLOG(LOG_WARN, "unable to find new subordinate uid range: %s\n", - strerrno()); + SYSLOGE(LOG_WARN, "unable to find new subordinate uid range"); fail_exit (E_SUB_UID_UPDATE, process_selinux); } if (find_range (&add_sub_gids, user_id, find_new_sub_gids) == 0) { fprinte(stderr, _("%s: unable to find new subordinate gid range"), Prog); - SYSLOG(LOG_WARN, "unable to find new subordinate gid range: %s\n", - strerrno()); + SYSLOGE(LOG_WARN, "unable to find new subordinate gid range"); fail_exit (E_SUB_GID_UPDATE, process_selinux); } }