Index: usr.sbin/syslogd/syslogd.c =================================================================== --- usr.sbin/syslogd/syslogd.c +++ usr.sbin/syslogd/syslogd.c @@ -1011,7 +1011,11 @@ omsg = msg; IF_NOT_NILVALUE(timestamp) { - /* Parse RFC 3339-like timestamp. */ + if (RemoteAddDate) { + PARSE_CHAR("TIMESTAMP", ' '); + timestamp = NULL; + } else { + /* Parse RFC 3339-like timestamp. */ #define PARSE_NUMBER(dest, length, min, max) do { \ int i, v; \ \ @@ -1023,53 +1027,54 @@ FAIL_IF("TIMESTAMP", v < min || v > max); \ dest = v; \ } while (0) - /* Date and time. */ - memset(×tamp_remote, 0, sizeof(timestamp_remote)); - PARSE_NUMBER(timestamp_remote.tm.tm_year, 4, 0, 9999); - timestamp_remote.tm.tm_year -= 1900; - PARSE_CHAR("TIMESTAMP", '-'); - PARSE_NUMBER(timestamp_remote.tm.tm_mon, 2, 1, 12); - --timestamp_remote.tm.tm_mon; - PARSE_CHAR("TIMESTAMP", '-'); - PARSE_NUMBER(timestamp_remote.tm.tm_mday, 2, 1, 31); - PARSE_CHAR("TIMESTAMP", 'T'); - PARSE_NUMBER(timestamp_remote.tm.tm_hour, 2, 0, 23); - PARSE_CHAR("TIMESTAMP", ':'); - PARSE_NUMBER(timestamp_remote.tm.tm_min, 2, 0, 59); - PARSE_CHAR("TIMESTAMP", ':'); - PARSE_NUMBER(timestamp_remote.tm.tm_sec, 2, 0, 59); - /* Perform normalization. */ - timegm(×tamp_remote.tm); - /* Optional: fractional seconds. */ - if (msg[0] == '.' && msg[1] >= '0' && msg[1] <= '9') { - int i; + /* Date and time. */ + memset(×tamp_remote, 0, sizeof(timestamp_remote)); + PARSE_NUMBER(timestamp_remote.tm.tm_year, 4, 0, 9999); + timestamp_remote.tm.tm_year -= 1900; + PARSE_CHAR("TIMESTAMP", '-'); + PARSE_NUMBER(timestamp_remote.tm.tm_mon, 2, 1, 12); + --timestamp_remote.tm.tm_mon; + PARSE_CHAR("TIMESTAMP", '-'); + PARSE_NUMBER(timestamp_remote.tm.tm_mday, 2, 1, 31); + PARSE_CHAR("TIMESTAMP", 'T'); + PARSE_NUMBER(timestamp_remote.tm.tm_hour, 2, 0, 23); + PARSE_CHAR("TIMESTAMP", ':'); + PARSE_NUMBER(timestamp_remote.tm.tm_min, 2, 0, 59); + PARSE_CHAR("TIMESTAMP", ':'); + PARSE_NUMBER(timestamp_remote.tm.tm_sec, 2, 0, 59); + /* Perform normalization. */ + timegm(×tamp_remote.tm); + /* Optional: fractional seconds. */ + if (msg[0] == '.' && msg[1] >= '0' && msg[1] <= '9') { + int i; - ++msg; - for (i = 100000; i != 0; i /= 10) { - if (*msg < '0' || *msg > '9') - break; - timestamp_remote.usec += (*msg++ - '0') * i; + ++msg; + for (i = 100000; i != 0; i /= 10) { + if (*msg < '0' || *msg > '9') + break; + timestamp_remote.usec += (*msg++ - '0') * i; + } } - } - /* Timezone. */ - if (*msg == 'Z') { - /* UTC. */ - ++msg; - } else { - int sign, tz_hour, tz_min; + /* Timezone. */ + if (*msg == 'Z') { + /* UTC. */ + ++msg; + } else { + int sign, tz_hour, tz_min; - /* Local time zone offset. */ - FAIL_IF("TIMESTAMP", *msg != '-' && *msg != '+'); - sign = *msg++ == '-' ? -1 : 1; - PARSE_NUMBER(tz_hour, 2, 0, 23); - PARSE_CHAR("TIMESTAMP", ':'); - PARSE_NUMBER(tz_min, 2, 0, 59); - timestamp_remote.tm.tm_gmtoff = - sign * (tz_hour * 3600 + tz_min * 60); + /* Local time zone offset. */ + FAIL_IF("TIMESTAMP", *msg != '-' && *msg != '+'); + sign = *msg++ == '-' ? -1 : 1; + PARSE_NUMBER(tz_hour, 2, 0, 23); + PARSE_CHAR("TIMESTAMP", ':'); + PARSE_NUMBER(tz_min, 2, 0, 59); + timestamp_remote.tm.tm_gmtoff = + sign * (tz_hour * 3600 + tz_min * 60); + } + PARSE_CHAR("TIMESTAMP", ' '); + timestamp = ×tamp_remote; +#undef PARSE_NUMBER } -#undef PARSE_NUMBER - PARSE_CHAR("TIMESTAMP", ' '); - timestamp = RemoteAddDate ? NULL : ×tamp_remote; } /* String fields part of the HEADER. */ @@ -2226,7 +2231,9 @@ hl = strlen(hname); if (hl > 0 && hname[hl-1] == '.') hname[--hl] = '\0'; - trimdomain(hname, hl); + /* RFC 5424 prefers logging FQDNs. */ + if (RFC3164OutputFormat) + trimdomain(hname, hl); return (hname); } @@ -2853,7 +2860,9 @@ hl = strlen(f->f_host); if (hl > 0 && f->f_host[hl-1] == '.') f->f_host[--hl] = '\0'; - trimdomain(f->f_host, hl); + /* RFC 5424 prefers logging FQDNs. */ + if (RFC3164OutputFormat) + trimdomain(f->f_host, hl); } /* save program name if any */