Sync with FreeBSD syslogd to get full RFC5424 support
This massive patch brings support for parsing incoming syslog messages, remote or local, to determine if format is RFC5424 or the older RFC3164. For logging syslogd currently defaults to RFC3164 for local files and supports RFC5424 for sending to remote servers. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
4f45f3c22f
commit
ee2d0ce106
37
src/syslog.h
37
src/syslog.h
@ -34,10 +34,28 @@
|
||||
#ifndef _SYS_SYSLOG_H_ /* From NetBSD, for co-existance with C-library header */
|
||||
#define _SYS_SYSLOG_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <features.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define _PATH_LOG "/var/run/log"
|
||||
/*
|
||||
* Default on *BSD is /var/run/log, but on Linux systems with
|
||||
* systemd/journald this is reserved and may already exist as
|
||||
* a directory. For compatibility with GLIBC syslog API, for
|
||||
* those who opt not to use this replacement API, we use the
|
||||
* default/traditional Linux path /dev/log. In case we're in
|
||||
* unit TESTING mode we usr /tmp/log.sock
|
||||
*/
|
||||
#ifndef TESTING
|
||||
# ifndef __linux__
|
||||
# define _PATH_LOG "/var/run/log"
|
||||
# else
|
||||
# define _PATH_LOG "/dev/log"
|
||||
# endif
|
||||
#else
|
||||
# define _PATH_LOG "/tmp/log.sock"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* priorities/facilities are encoded into a single 32-bit quantity, where the
|
||||
@ -161,14 +179,15 @@ CODE facilitynames[] = {
|
||||
* LOG_ODELAY no longer does anything.
|
||||
* LOG_NDELAY is the inverse of what it used to be.
|
||||
*/
|
||||
#define LOG_PID 0x01 /* log the pid with each message */
|
||||
#define LOG_CONS 0x02 /* log on the console if errors in sending */
|
||||
#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */
|
||||
#define LOG_NDELAY 0x08 /* don't delay open */
|
||||
#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
|
||||
#define LOG_PERROR 0x20 /* log to stderr as well */
|
||||
#define LOG_PTRIM 0x40 /* trim tag and pid from messages to stderr */
|
||||
#define LOG_NLOG 0x80 /* don't write to the system log */
|
||||
#define LOG_PID 0x001 /* log the pid with each message */
|
||||
#define LOG_CONS 0x002 /* log on the console if errors in sending */
|
||||
#define LOG_ODELAY 0x004 /* delay open until first syslog() (default) */
|
||||
#define LOG_NDELAY 0x008 /* don't delay open */
|
||||
#define LOG_NOWAIT 0x010 /* don't wait for console forks: DEPRECATED */
|
||||
#define LOG_PERROR 0x020 /* log to stderr as well */
|
||||
#define LOG_PTRIM 0x040 /* trim tag and pid from messages to stderr */
|
||||
#define LOG_NLOG 0x080 /* don't write to the system log */
|
||||
#define LOG_STDOUT 0x100 /* like nlog, for debugging syslogp() API */
|
||||
|
||||
#ifndef __KERNEL__
|
||||
|
||||
|
1096
src/syslogd.c
1096
src/syslogd.c
File diff suppressed because it is too large
Load Diff
118
src/syslogd.h
Normal file
118
src/syslogd.h
Normal file
@ -0,0 +1,118 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 1983, 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef SYSKLOGD_SYSLOGD_H_
|
||||
#define SYSKLOGD_SYSLOGD_H_
|
||||
|
||||
#include "syslog.h"
|
||||
|
||||
#ifdef UT_NAMESIZE
|
||||
#define UNAMESZ UT_NAMESIZE /* length of a login name */
|
||||
#else
|
||||
#define UNAMESZ 8 /* length of a login name */
|
||||
#endif
|
||||
#define MAXUNAMES 20 /* maximum number of user names */
|
||||
#define MAXFNAME 200 /* max file pathname length */
|
||||
|
||||
#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
|
||||
#define TABLE_NOPRI 0 /* Value to indicate no priority in f_pmask */
|
||||
#define TABLE_ALLPRI 0xFF /* Value to indicate all priorities in f_pmask */
|
||||
#define LOG_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) /* mark "facility" */
|
||||
|
||||
#define MAX_PRI 191 /* Maximum Priority per RFC 3164 */
|
||||
|
||||
/* Traditional syslog timestamp format. */
|
||||
#define RFC3164_DATELEN 15
|
||||
#define RFC3164_DATEFMT "%b %e %H:%M:%S"
|
||||
|
||||
/* From The Practice of Programming, by Kernighan and Pike */
|
||||
#ifndef NELEMS
|
||||
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
|
||||
#endif
|
||||
|
||||
/* Timestamps of log entries. */
|
||||
struct logtime {
|
||||
struct tm tm;
|
||||
suseconds_t usec;
|
||||
};
|
||||
|
||||
/* message buffer container used for processing, formatting, and queueing */
|
||||
struct buf_msg {
|
||||
int pri;
|
||||
char pribuf[7];
|
||||
int flags;
|
||||
struct logtime timestamp;
|
||||
char timebuf[33];
|
||||
char *recvhost;
|
||||
char *hostname;
|
||||
char *app_name;
|
||||
char *proc_id;
|
||||
char *msgid;
|
||||
char *sd; /* structured data */
|
||||
char *msg; /* message content */
|
||||
};
|
||||
|
||||
/*
|
||||
* This structure represents the files that will have log
|
||||
* copies printed.
|
||||
* We require f_file to be valid if f_type is F_FILE, F_CONSOLE, F_TTY
|
||||
* or if f_type is F_PIPE and f_pid > 0.
|
||||
*/
|
||||
|
||||
struct filed {
|
||||
struct filed *f_next; /* next in linked list */
|
||||
|
||||
short f_type; /* entry type, see below */
|
||||
short f_file; /* file descriptor */
|
||||
time_t f_time; /* time this was last written */
|
||||
char *f_host; /* host from which to recd. */
|
||||
u_char f_pmask[LOG_NFACILITIES + 1]; /* priority mask */
|
||||
union {
|
||||
char f_uname[MAXUNAMES][UNAMESZ + 1];
|
||||
struct {
|
||||
char f_hname[MAXHOSTNAMELEN + 1];
|
||||
struct addrinfo *f_addr;
|
||||
} f_forw; /* forwarding address */
|
||||
char f_fname[MAXFNAME];
|
||||
} f_un;
|
||||
char f_prevline[MAXSVLINE]; /* last message logged */
|
||||
struct logtime f_lasttime; /* time of last occurrence */
|
||||
char f_prevhost[MAXHOSTNAMELEN + 1]; /* host from which recd. */
|
||||
int f_prevpri; /* pri of f_prevline */
|
||||
size_t f_prevlen; /* length of f_prevline */
|
||||
int f_prevcount; /* repetition cnt of prevline */
|
||||
size_t f_repeatcount; /* number of "repeated" msgs */
|
||||
int f_flags; /* store some additional flags */
|
||||
int f_rotatecount;
|
||||
int f_rotatesz;
|
||||
};
|
||||
|
||||
#endif /* SYSKLOGD_SYSLOGD_H_ */
|
Loading…
Reference in New Issue
Block a user