chiark / gitweb /
journal: fix parsing of facility in syslog messages
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 26 Jul 2013 16:57:33 +0000 (12:57 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 19 Aug 2013 15:14:14 +0000 (11:14 -0400)
In 49998b383 (journald: do not overwrite syslog facility when
parsing priority) journald started ignoring facility part when
reading service stderr to convert to syslog messages. In this
case it is fine, because only the priority is allowed.

But the same codepath is used for syslog messages, where the
facility should be used. Split the two codepaths by explicitly
specyfing whether the facility should be ignored or not.

https://bugzilla.redhat.com/show_bug.cgi?id=988814

src/journal/journald-stream.c
src/journal/journald-syslog.c
src/journal/journald-syslog.h

index e98fe94b46254559813e39f86f6202ef337acaf4..9c4efec9bcd4713f83285a0088ddbab259a149bb 100644 (file)
@@ -90,7 +90,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
         priority = s->priority;
 
         if (s->level_prefix)
         priority = s->priority;
 
         if (s->level_prefix)
-                syslog_parse_priority((char**) &p, &priority);
+                syslog_parse_priority((char**) &p, &priority, false);
 
         if (s->forward_to_syslog || s->server->forward_to_syslog)
                 server_forward_syslog(s->server, syslog_fixup_facility(priority), s->identifier, p, &s->ucred, NULL);
 
         if (s->forward_to_syslog || s->server->forward_to_syslog)
                 server_forward_syslog(s->server, syslog_fixup_facility(priority), s->identifier, p, &s->ucred, NULL);
index 7cbb34608b3579f3cf3ca2f490aaff92d5831186..c2770a53d0caf8791c4604cec44c7ad8cd1aa8f6 100644 (file)
@@ -236,7 +236,7 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
         return e;
 }
 
         return e;
 }
 
-void syslog_parse_priority(char **p, int *priority) {
+void syslog_parse_priority(char **p, int *priority, bool with_facility) {
         int a = 0, b = 0, c = 0;
         int k;
 
         int a = 0, b = 0, c = 0;
         int k;
 
@@ -265,10 +265,14 @@ void syslog_parse_priority(char **p, int *priority) {
         } else
                 return;
 
         } else
                 return;
 
-        if (a < 0 || b < 0 || c < 0)
+        if (a < 0 || b < 0 || c < 0 ||
+            (!with_facility && (a || b || c > 7)))
                 return;
 
                 return;
 
-        *priority = (*priority & LOG_FACMASK) | (a*100 + b*10 + c);
+        if (with_facility)
+                *priority = a*100 + b*10 + c;
+        else
+                *priority = (*priority & LOG_FACMASK) | c;
         *p += k;
 }
 
         *p += k;
 }
 
@@ -361,7 +365,7 @@ void server_process_syslog_message(
         assert(buf);
 
         orig = buf;
         assert(buf);
 
         orig = buf;
-        syslog_parse_priority((char**) &buf, &priority);
+        syslog_parse_priority((char**) &buf, &priority, true);
 
         if (s->forward_to_syslog)
                 forward_syslog_raw(s, priority, orig, ucred, tv);
 
         if (s->forward_to_syslog)
                 forward_syslog_raw(s, priority, orig, ucred, tv);
index 324b70eef08ddcd2b66a1885bc5a0cb39da7da65..8ccdb77a0928b0c07c59a7940ad971d86ffe361d 100644 (file)
@@ -25,7 +25,7 @@
 
 int syslog_fixup_facility(int priority) _const_;
 
 
 int syslog_fixup_facility(int priority) _const_;
 
-void syslog_parse_priority(char **p, int *priority);
+void syslog_parse_priority(char **p, int *priority, bool with_facility);
 size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid);
 
 void server_forward_syslog(Server *s, int priority, const char *identifier, const char *message, struct ucred *ucred, struct timeval *tv);
 size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid);
 
 void server_forward_syslog(Server *s, int priority, const char *identifier, const char *message, struct ucred *ucred, struct timeval *tv);