From f95f228d39dcc0204a71c8afe9187188de313dfb Mon Sep 17 00:00:00 2001
From: Mats Erik Andersson <gnu@gisladisker.se>
Date: Thu, 8 Oct 2015 19:04:43 +0200
Subject: [PATCH 12/60] syslogd: Redefine faulty macro LOG_MAKEPRI.

Old versions of Glibc cause remotely logged kernel
messages to be rewritten for facility `uucp', not
the intended facility `user'.
---
 ChangeLog     | 15 +++++++++++++++
 src/logprio.h | 12 ++++++++++++
 src/syslogd.c | 13 +++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 03bb8a78..113e5246 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2015-10-08  Mats Erik Andersson  <gnu@gisladisker.se>
+
+	syslogd: Redefine faulty macro LOG_MAKEPRI whenever needed.
+	Systems with Glibc header file <syslog.h> prior to 2.17,
+	are not correctly defining the helper macro LOG_MAKEPRI.
+	This effects our syslog service whenever it receives kernel
+	messages from a remote host.  The issue was mentioned in
+	Debian's BTS as report #729666.
+
+	* src/logprio.h [LOG_MAKEPRI]: Check that the macro does
+	not shift the first argument.  If it does, undefine it and
+	apply our corrected definition.
+	* src/syslogd.c [LOG_MAKEPRI]: Likewise.  Display a precompiler
+	warning to the effect that we have diagnosed an issue.
+
 2015-08-15  Mats Erik Andersson  <gnu@gisladisker.se>
 
 	telnetd: Premature connection closure.
diff --git a/src/logprio.h b/src/logprio.h
index 79072e02..315ad052 100644
--- a/src/logprio.h
+++ b/src/logprio.h
@@ -66,6 +66,18 @@ typedef struct _code {
 #  define LOG_PRI(p)	((p) & LOG_PRIMASK)
 #endif
 
+/* Glibc prior to 2.17 included a definition of LOG_MAKEPRI
+ * that evaluated LOG_MAKEPRI(LOG_USER, 0) to (1 << 9).
+ * The first argument was shifted three bits, ignoring
+ * the definition LOG_USER = (1 << 3).  Avoid this
+ * harmful mistake.
+ */
+#ifdef LOG_MAKEPRI
+# if LOG_MAKEPRI (1, 0) > LOG_PRIMASK
+#  undef LOG_MAKEPRI
+# endif
+#endif /* LOG_MAKEPRI */
+
 #ifndef LOG_MAKEPRI
 #  define LOG_MAKEPRI(fac, p)	((fac) | (p))
 #endif
diff --git a/src/syslogd.c b/src/syslogd.c
index 0fa41945..352a5bd0 100644
--- a/src/syslogd.c
+++ b/src/syslogd.c
@@ -116,6 +116,19 @@
 # include "logprio.h"
 #endif
 
+/* Glibc prior to 2.17 included a definition of LOG_MAKEPRI
+ * that evaluated LOG_MAKEPRI(LOG_USER, 0) to (1 << 9).
+ * The first argument was shifted three bits, ignoring
+ * the definition LOG_USER = (1 << 3).  Avoid this
+ * harmful mistake.
+ */
+#ifdef LOG_MAKEPRI
+# if LOG_MAKEPRI (1, 0) > LOG_PRIMASK
+#  warning Discarding faulty LOG_MAKEPRI defined in system header file.
+#  undef LOG_MAKEPRI
+# endif
+#endif /* LOG_MAKEPRI */
+
 #ifndef LOG_MAKEPRI
 #  define LOG_MAKEPRI(fac, p)	((fac) | (p))
 #endif
-- 
2.26.0.292.g33ef6b2f38

