From: Alejandro Colomar Date: Tue, 22 Jul 2025 23:41:11 +0000 (+0200) Subject: lib/: Move wrappers to "io/syslog.h" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=956efba215adda90515c3fe104f747b43019473e;p=thirdparty%2Fshadow.git lib/: Move wrappers to "io/syslog.h" Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index 6a9a16443..72a57ad94 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 \ diff --git a/lib/defines.h b/lib/defines.h index e7da7cc6f..6e7f43177 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -62,60 +62,7 @@ #define MAXHOSTNAMELEN 64 #endif -#include - -#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 #define STTY(fd, termio) tcsetattr(fd, TCSANOW, termio) diff --git a/lib/io/syslog.c b/lib/io/syslog.c new file mode 100644 index 000000000..d7e3493fb --- /dev/null +++ b/lib/io/syslog.c @@ -0,0 +1,7 @@ +// SPDX-FileCopyrightText: 2025, Alejandro Colomar +// 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 index 000000000..a2089dad8 --- /dev/null +++ b/lib/io/syslog.h @@ -0,0 +1,72 @@ +// SPDX-FileCopyrightText: 2025, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_IO_SYSLOG_H_ +#define SHADOW_INCLUDE_LIB_IO_SYSLOG_H_ + + +#include "config.h" + +#include +#include +#include +#include +#include + + +#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