syslogd: Accept pre-RFC3164 formatted messages from remote hosts

This patch makes us wire-compatible with older versions of ourself, and
current versions set up to use default remote format.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-11-13 16:09:20 +01:00
parent 06b26aae7b
commit 12fa1f6682

View File

@ -945,12 +945,13 @@ parsemsg_rfc3164(const char *from, int pri, char *msg)
buffer.pri = pri; buffer.pri = pri;
buffer.msg = line; buffer.msg = line;
/* Parse the timestamp provided by the remote side. */ /*
if (strptime(msg, RFC3164_DATEFMT, &tm_parsed) != * Parse the TIMESTAMP provided by the remote side. If none is
msg + RFC3164_DATELEN || msg[RFC3164_DATELEN] != ' ') { * found, assume this is not an RFC 3164 formatted message,
logit("Failed to parse TIMESTAMP from %s: %s\n", from, msg); * only containing a TAG and a MSG.
return; */
} if (strptime(msg, RFC3164_DATEFMT, &tm_parsed) ==
msg + RFC3164_DATELEN && msg[RFC3164_DATELEN] == ' ') {
msg += RFC3164_DATELEN + 1; msg += RFC3164_DATELEN + 1;
if (!RemoteAddDate) { if (!RemoteAddDate) {
@ -959,15 +960,16 @@ parsemsg_rfc3164(const char *from, int pri, char *msg)
int year; int year;
/* /*
* As the timestamp does not contain the year number, * As the timestamp does not contain the year
* daylight saving time information, nor a time zone, * number, daylight saving time information, nor
* attempt to infer it. Due to clock skews, the * a time zone, attempt to infer it. Due to
* timestamp may even be part of the next year. Use the * clock skews, the timestamp may even be part
* last year for which the timestamp is at most one week * of the next year. Use the last year for which
* in the future. * the timestamp is at most one week in the
* future.
* *
* This loop can only run for at most three iterations * This loop can only run for at most three
* before terminating. * iterations before terminating.
*/ */
t_now = time(NULL); t_now = time(NULL);
localtime_r(&t_now, &tm_now); localtime_r(&t_now, &tm_now);
@ -983,6 +985,7 @@ parsemsg_rfc3164(const char *from, int pri, char *msg)
} }
buffer.timestamp = timestamp_remote; buffer.timestamp = timestamp_remote;
} }
}
/* /*
* A single space character MUST also follow the HOSTNAME field. * A single space character MUST also follow the HOSTNAME field.