]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Use SYSLOGE() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Wed, 23 Jul 2025 16:14:32 +0000 (18:14 +0200)
committerSerge Hallyn <serge@hallyn.com>
Fri, 17 Jul 2026 13:48:04 +0000 (08:48 -0500)
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 <alx@kernel.org>
lib/chowntty.c
lib/getdef.c
lib/selinux.c
lib/setugid.c
src/groupadd.c
src/login_nopam.c
src/newusers.c
src/suauth.c
src/useradd.c
src/userdel.c
src/usermod.c

index dc29203eedcba20e2faf77a382c1303b2af8d6bf..eb0f9e3835c92573d020aa4dd4701d28b6f2cea1 100644 (file)
@@ -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);
index e85e0a4460a02cdf4669bcb2318fb159695693ba..ae6bbeb2b975969fe43fe52c015b72c604864a22 100644 (file)
@@ -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);
        }
 
index a434d0e774f9f71cdd9dd451d4d8035d3f74827f..66bb3c12ecafe1436a53d4e122e6f98062f76611 100644 (file)
 #include <selinux/label.h>
 
 #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);
        }
 
index d8a3588bdf41fcdfb2bf1d2474479a1ff5ec9509..cbff8ac2c7d11efe4a9e359813f4078a151fb887 100644 (file)
 #include <stdio.h>
 #include <grp.h>
 #include <errno.h>
-#include "prototypes.h"
-#include "defines.h"
 #include <pwd.h>
+
+#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;
        }
index f29ff83fe9ece696a21d9bb8caa9a13e780e28d9..ff1219a294c02ddd51f8f1b360581ec8c8249993 100644 (file)
@@ -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);
                }
        }
index 7b5356ee278381e0014561456f65ee491ddc2dcd..ef78143bf2ea1d93d0724717614b6217a2d7a45a 100644 (file)
@@ -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;
 }
index 7b544fe89015bc4a8ad3802bd366c5cbc203c881..957930b0533d7482a3dbfdffb0022d4ffb8635d4 100644 (file)
@@ -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) {
index 5d55484ce95458b2e818e1fdbc29fcc2fa75cd01..453f9a4dfa8e6ac21115d1d0c34cbcbff20c7840 100644 (file)
@@ -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;
        }
 
index 643a029d687a57ee58f8aac6fdbcedfd73b65043..1dce5eefceaddc0e55ad199655600864936c898b 100644 (file)
@@ -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);
                }
        }
index ad36a97d00e234e51bc07cf9aa485fd442bdd8f5..3e1efa3ec37eb309c9ecde338822c62c50ba1c37 100644 (file)
@@ -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",
index e2ec58bbef4adc651e25db2d96749af8958ffbe9..d6692260d4f71ae3ad140d557af9e803ba37265f 100644 (file)
@@ -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);
                }
        }