Harald Hoyer fe20ad
From 376cb2b4d456d50167756ec49176bf6cffd052a7 Mon Sep 17 00:00:00 2001
Harald Hoyer fe20ad
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Harald Hoyer fe20ad
Date: Fri, 26 Jul 2013 12:57:33 -0400
Harald Hoyer fe20ad
Subject: [PATCH] journal: fix parsing of facility in syslog messages
Harald Hoyer fe20ad
Harald Hoyer fe20ad
In 49998b383 (journald: do not overwrite syslog facility when
Harald Hoyer fe20ad
parsing priority) journald started ignoring facility part when
Harald Hoyer fe20ad
reading service stderr to convert to syslog messages. In this
Harald Hoyer fe20ad
case it is fine, because only the priority is allowed.
Harald Hoyer fe20ad
Harald Hoyer fe20ad
But the same codepath is used for syslog messages, where the
Harald Hoyer fe20ad
facility should be used. Split the two codepaths by explicitly
Harald Hoyer fe20ad
specyfing whether the facility should be ignored or not.
Harald Hoyer fe20ad
Harald Hoyer fe20ad
https://bugzilla.redhat.com/show_bug.cgi?id=988814
Harald Hoyer fe20ad
---
Harald Hoyer fe20ad
 src/journal/journald-stream.c |  2 +-
Harald Hoyer fe20ad
 src/journal/journald-syslog.c | 12 ++++++++----
Harald Hoyer fe20ad
 src/journal/journald-syslog.h |  2 +-
Harald Hoyer fe20ad
 3 files changed, 10 insertions(+), 6 deletions(-)
Harald Hoyer fe20ad
Harald Hoyer fe20ad
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
Harald Hoyer fe20ad
index e98fe94..9c4efec 100644
Harald Hoyer fe20ad
--- a/src/journal/journald-stream.c
Harald Hoyer fe20ad
+++ b/src/journal/journald-stream.c
Harald Hoyer fe20ad
@@ -90,7 +90,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
Harald Hoyer fe20ad
         priority = s->priority;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
         if (s->level_prefix)
Harald Hoyer fe20ad
-                syslog_parse_priority((char**) &p, &priority);
Harald Hoyer fe20ad
+                syslog_parse_priority((char**) &p, &priority, false);
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
         if (s->forward_to_syslog || s->server->forward_to_syslog)
Harald Hoyer fe20ad
                 server_forward_syslog(s->server, syslog_fixup_facility(priority), s->identifier, p, &s->ucred, NULL);
Harald Hoyer fe20ad
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
Harald Hoyer fe20ad
index 7cbb346..c2770a5 100644
Harald Hoyer fe20ad
--- a/src/journal/journald-syslog.c
Harald Hoyer fe20ad
+++ b/src/journal/journald-syslog.c
Harald Hoyer fe20ad
@@ -236,7 +236,7 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
Harald Hoyer fe20ad
         return e;
Harald Hoyer fe20ad
 }
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-void syslog_parse_priority(char **p, int *priority) {
Harald Hoyer fe20ad
+void syslog_parse_priority(char **p, int *priority, bool with_facility) {
Harald Hoyer fe20ad
         int a = 0, b = 0, c = 0;
Harald Hoyer fe20ad
         int k;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
@@ -265,10 +265,14 @@ void syslog_parse_priority(char **p, int *priority) {
Harald Hoyer fe20ad
         } else
Harald Hoyer fe20ad
                 return;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-        if (a < 0 || b < 0 || c < 0)
Harald Hoyer fe20ad
+        if (a < 0 || b < 0 || c < 0 ||
Harald Hoyer fe20ad
+            (!with_facility && (a || b || c > 7)))
Harald Hoyer fe20ad
                 return;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-        *priority = (*priority & LOG_FACMASK) | (a*100 + b*10 + c);
Harald Hoyer fe20ad
+        if (with_facility)
Harald Hoyer fe20ad
+                *priority = a*100 + b*10 + c;
Harald Hoyer fe20ad
+        else
Harald Hoyer fe20ad
+                *priority = (*priority & LOG_FACMASK) | c;
Harald Hoyer fe20ad
         *p += k;
Harald Hoyer fe20ad
 }
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
@@ -361,7 +365,7 @@ void server_process_syslog_message(
Harald Hoyer fe20ad
         assert(buf);
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
         orig = buf;
Harald Hoyer fe20ad
-        syslog_parse_priority((char**) &buf, &priority);
Harald Hoyer fe20ad
+        syslog_parse_priority((char**) &buf, &priority, true);
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
         if (s->forward_to_syslog)
Harald Hoyer fe20ad
                 forward_syslog_raw(s, priority, orig, ucred, tv);
Harald Hoyer fe20ad
diff --git a/src/journal/journald-syslog.h b/src/journal/journald-syslog.h
Harald Hoyer fe20ad
index 324b70e..8ccdb77 100644
Harald Hoyer fe20ad
--- a/src/journal/journald-syslog.h
Harald Hoyer fe20ad
+++ b/src/journal/journald-syslog.h
Harald Hoyer fe20ad
@@ -25,7 +25,7 @@
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
 int syslog_fixup_facility(int priority) _const_;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-void syslog_parse_priority(char **p, int *priority);
Harald Hoyer fe20ad
+void syslog_parse_priority(char **p, int *priority, bool with_facility);
Harald Hoyer fe20ad
 size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid);
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
 void server_forward_syslog(Server *s, int priority, const char *identifier, const char *message, struct ucred *ucred, struct timeval *tv);