]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/: Move <syslog.h> wrappers to "io/syslog.h"
authorAlejandro Colomar <alx@kernel.org>
Tue, 22 Jul 2025 23:41:11 +0000 (01:41 +0200)
committerSerge Hallyn <serge@hallyn.com>
Fri, 6 Mar 2026 01:44:32 +0000 (19:44 -0600)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/defines.h
lib/io/syslog.c [new file with mode: 0644]
lib/io/syslog.h [new file with mode: 0644]

index 6a9a1644339aa6bd2ba549ccdf546ac1fb82e1fd..72a57ad94b7e11cbc19a0128c6e24576122451a4 100644 (file)
@@ -103,6 +103,8 @@ libshadow_la_SOURCES = \
        hushed.c \
        idmapping.h \
        idmapping.c \
+       io/syslog.c \
+       io/syslog.h \
        isexpired.c \
        limits.c \
        list.c \
index e7da7cc6fa1d700a6f6ca4739692c7434739b732..6e7f43177e6c7999e625a1e96378f8df21aab0b2 100644 (file)
 #define MAXHOSTNAMELEN 64
 #endif
 
-#include <syslog.h>
-
-#ifndef LOG_WARN
-#define LOG_WARN LOG_WARNING
-#endif
-
-/* LOG_AUTH is deprecated, use LOG_AUTHPRIV instead */
-#ifndef LOG_AUTHPRIV
-#define LOG_AUTHPRIV LOG_AUTH
-#endif
-
-/* cleaner than lots of #ifdefs everywhere - use this as follows:
-   SYSLOG(LOG_CRIT, "user %s cracked root", user); */
-#ifdef ENABLE_NLS
-/* Temporarily set LC_TIME to "C" to avoid strange dates in syslog.
-   This is a workaround for a more general syslog(d) design problem -
-   syslogd should log the current system time for each event, and not
-   trust the formatted time received from the unix domain (or worse,
-   UDP) socket.  -MM */
-/* Avoid translated PAM error messages: set LC_ALL to "C".
- * --Nekral */
-#define SYSLOG(...)                                                    \
-       do {                                                            \
-               char *old_locale = setlocale (LC_ALL, NULL);            \
-               char *saved_locale = NULL;                              \
-               if (NULL != old_locale) {                               \
-                       saved_locale = strdup (old_locale);             \
-               }                                                       \
-               if (NULL != saved_locale) {                             \
-                       (void) setlocale (LC_ALL, "C");                 \
-               }                                                       \
-               syslog(__VA_ARGS__);                                    \
-               if (NULL != saved_locale) {                             \
-                       (void) setlocale (LC_ALL, saved_locale);        \
-                       free (saved_locale);                            \
-               }                                                       \
-       } while (false)
-#else                          /* !ENABLE_NLS */
-#define SYSLOG(...)  syslog(__VA_ARGS__)
-#endif                         /* !ENABLE_NLS */
-
-/* The default syslog settings can now be changed here,
-   in just one place.  */
-
-#ifndef SYSLOG_OPTIONS
-/* #define SYSLOG_OPTIONS (LOG_PID | LOG_CONS) */
-#define SYSLOG_OPTIONS (LOG_PID)
-#endif
-
-#ifndef SYSLOG_FACILITY
-#define SYSLOG_FACILITY LOG_AUTHPRIV
-#endif
-
-#define OPENLOG(progname) openlog(progname, SYSLOG_OPTIONS, SYSLOG_FACILITY)
+#include "io/syslog.h"
 
 #include <termios.h>
 #define STTY(fd, termio) tcsetattr(fd, TCSANOW, termio)
diff --git a/lib/io/syslog.c b/lib/io/syslog.c
new file mode 100644 (file)
index 0000000..d7e3493
--- /dev/null
@@ -0,0 +1,7 @@
+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include "config.h"
+
+#include "io/syslog.h"
diff --git a/lib/io/syslog.h b/lib/io/syslog.h
new file mode 100644 (file)
index 0000000..a2089da
--- /dev/null
@@ -0,0 +1,72 @@
+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_IO_SYSLOG_H_
+#define SHADOW_INCLUDE_LIB_IO_SYSLOG_H_
+
+
+#include "config.h"
+
+#include <locale.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+
+
+#ifndef LOG_WARN
+#define LOG_WARN LOG_WARNING
+#endif
+
+/* LOG_AUTH is deprecated, use LOG_AUTHPRIV instead */
+#ifndef LOG_AUTHPRIV
+#define LOG_AUTHPRIV LOG_AUTH
+#endif
+
+/* cleaner than lots of #ifdefs everywhere - use this as follows:
+   SYSLOG(LOG_CRIT, "user %s cracked root", user); */
+#ifdef ENABLE_NLS
+/* Temporarily set LC_TIME to "C" to avoid strange dates in syslog.
+   This is a workaround for a more general syslog(d) design problem -
+   syslogd should log the current system time for each event, and not
+   trust the formatted time received from the unix domain (or worse,
+   UDP) socket.  -MM */
+/* Avoid translated PAM error messages: set LC_ALL to "C".
+ * --Nekral */
+#define SYSLOG(...)                                                    \
+       do {                                                            \
+               char *old_locale = setlocale (LC_ALL, NULL);            \
+               char *saved_locale = NULL;                              \
+               if (NULL != old_locale) {                               \
+                       saved_locale = strdup (old_locale);             \
+               }                                                       \
+               if (NULL != saved_locale) {                             \
+                       (void) setlocale (LC_ALL, "C");                 \
+               }                                                       \
+               syslog(__VA_ARGS__);                                    \
+               if (NULL != saved_locale) {                             \
+                       (void) setlocale (LC_ALL, saved_locale);        \
+                       free (saved_locale);                            \
+               }                                                       \
+       } while (false)
+#else                          /* !ENABLE_NLS */
+#define SYSLOG(...)  syslog(__VA_ARGS__)
+#endif                         /* !ENABLE_NLS */
+
+/* The default syslog settings can now be changed here,
+   in just one place.  */
+
+#ifndef SYSLOG_OPTIONS
+/* #define SYSLOG_OPTIONS (LOG_PID | LOG_CONS) */
+#define SYSLOG_OPTIONS (LOG_PID)
+#endif
+
+#ifndef SYSLOG_FACILITY
+#define SYSLOG_FACILITY LOG_AUTHPRIV
+#endif
+
+#define OPENLOG(progname) openlog(progname, SYSLOG_OPTIONS, SYSLOG_FACILITY)
+
+
+#endif  // include guard