Add FreeBSD facilities: LOG_NTP, LOG_SECURITY, LOG_CONSOLE, ...
This patch is a major refactor of the priority and facility parsing in syslogd. The "new" facilities are taken from FreeBSD and are de facto interpretations of facilities otherwise "reserved for system use", as GLIBC syslog.h puts it. ___ ... and LOG_CRON_SOL, but only for completness. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
ff4f2cdb31
commit
4066a1e9bf
4
TODO.org
4
TODO.org
@ -2,13 +2,13 @@
|
|||||||
* sysklogd v2.0
|
* sysklogd v2.0
|
||||||
|
|
||||||
** TODO Document, and add examle of, how to use libsyslog
|
** TODO Document, and add examle of, how to use libsyslog
|
||||||
|
** TODO Check for memory/descriptor leaks, valgrind
|
||||||
** DONE Separate libsylog.{a,so} and syslog/syslog.h with NetBSD API
|
** DONE Separate libsylog.{a,so} and syslog/syslog.h with NetBSD API
|
||||||
** DONE Add syslogp() and vsyslogp() to libsyslog
|
** DONE Add syslogp() and vsyslogp() to libsyslog
|
||||||
** DONE Add support for =/etc/syslog.d/*.conf= to syslogd
|
** DONE Add support for =/etc/syslog.d/*.conf= to syslogd
|
||||||
** DONE Test support of =/etc/syslog.d/*.conf= to syslogd
|
** DONE Test support of =/etc/syslog.d/*.conf= to syslogd
|
||||||
** Test SIGHUP of syslogd
|
** Test SIGHUP of syslogd
|
||||||
** Check for memory/descriptor leaks, valgrind
|
** DONE Custom facilities!
|
||||||
** Custom facilities!
|
|
||||||
** Fix option parsing in syslog.conf, e.g. ;RFC5424 and log rotation
|
** Fix option parsing in syslog.conf, e.g. ;RFC5424 and log rotation
|
||||||
** Test with/without openlog()
|
** Test with/without openlog()
|
||||||
** Test custom facilities
|
** Test custom facilities
|
||||||
|
14
src/syslog.h
14
src/syslog.h
@ -76,8 +76,10 @@
|
|||||||
#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
|
#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
|
||||||
|
|
||||||
#ifdef SYSLOG_NAMES
|
#ifdef SYSLOG_NAMES
|
||||||
|
#define INTERNAL_INVPRI 0x00 /* Value to indicate no priority in f_pmask */
|
||||||
#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
|
#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
|
||||||
/* mark "facility" */
|
/* mark "facility" */
|
||||||
|
#define INTERNAL_ALLPRI 0xFF /* Value to indicate all priorities in f_pmask */
|
||||||
#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0)
|
#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0)
|
||||||
typedef struct _code {
|
typedef struct _code {
|
||||||
const char *c_name;
|
const char *c_name;
|
||||||
@ -97,6 +99,7 @@ CODE prioritynames[] = {
|
|||||||
{ "panic", LOG_EMERG }, /* DEPRECATED */
|
{ "panic", LOG_EMERG }, /* DEPRECATED */
|
||||||
{ "warn", LOG_WARNING }, /* DEPRECATED */
|
{ "warn", LOG_WARNING }, /* DEPRECATED */
|
||||||
{ "warning", LOG_WARNING },
|
{ "warning", LOG_WARNING },
|
||||||
|
{ "*", INTERNAL_ALLPRI }, /* INTERNAL */
|
||||||
{ NULL, -1 }
|
{ NULL, -1 }
|
||||||
};
|
};
|
||||||
#endif /* SYSLOG_NAMES */
|
#endif /* SYSLOG_NAMES */
|
||||||
@ -114,8 +117,10 @@ CODE prioritynames[] = {
|
|||||||
#define LOG_CRON (9<<3) /* clock daemon */
|
#define LOG_CRON (9<<3) /* clock daemon */
|
||||||
#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */
|
#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */
|
||||||
#define LOG_FTP (11<<3) /* ftp daemon */
|
#define LOG_FTP (11<<3) /* ftp daemon */
|
||||||
|
#define LOG_NTP (12<<3) /* NTP subsystem */
|
||||||
/* other codes through 15 reserved for system use */
|
#define LOG_SECURITY (13<<3) /* Log audit, for audit trails */
|
||||||
|
#define LOG_CONSOLE (14<<3) /* Log alert */
|
||||||
|
#define LOG_CRON_SOL (15<<3) /* clock daemon (Solaris) */
|
||||||
#define LOG_LOCAL0 (16<<3) /* reserved for local use */
|
#define LOG_LOCAL0 (16<<3) /* reserved for local use */
|
||||||
#define LOG_LOCAL1 (17<<3) /* reserved for local use */
|
#define LOG_LOCAL1 (17<<3) /* reserved for local use */
|
||||||
#define LOG_LOCAL2 (18<<3) /* reserved for local use */
|
#define LOG_LOCAL2 (18<<3) /* reserved for local use */
|
||||||
@ -134,7 +139,9 @@ CODE prioritynames[] = {
|
|||||||
CODE facilitynames[] = {
|
CODE facilitynames[] = {
|
||||||
{ "auth", LOG_AUTH },
|
{ "auth", LOG_AUTH },
|
||||||
{ "authpriv", LOG_AUTHPRIV },
|
{ "authpriv", LOG_AUTHPRIV },
|
||||||
|
{ "console", LOG_CONSOLE },
|
||||||
{ "cron", LOG_CRON },
|
{ "cron", LOG_CRON },
|
||||||
|
{ "cron_sol", LOG_CRON_SOL }, /* Solaris cron */
|
||||||
{ "daemon", LOG_DAEMON },
|
{ "daemon", LOG_DAEMON },
|
||||||
{ "ftp", LOG_FTP },
|
{ "ftp", LOG_FTP },
|
||||||
{ "kern", LOG_KERN },
|
{ "kern", LOG_KERN },
|
||||||
@ -142,7 +149,8 @@ CODE facilitynames[] = {
|
|||||||
{ "mail", LOG_MAIL },
|
{ "mail", LOG_MAIL },
|
||||||
{ "mark", INTERNAL_MARK }, /* INTERNAL */
|
{ "mark", INTERNAL_MARK }, /* INTERNAL */
|
||||||
{ "news", LOG_NEWS },
|
{ "news", LOG_NEWS },
|
||||||
{ "security", LOG_AUTH }, /* DEPRECATED */
|
{ "ntp", LOG_NTP },
|
||||||
|
{ "security", LOG_SECURITY },
|
||||||
{ "syslog", LOG_SYSLOG },
|
{ "syslog", LOG_SYSLOG },
|
||||||
{ "user", LOG_USER },
|
{ "user", LOG_USER },
|
||||||
{ "uucp", LOG_UUCP },
|
{ "uucp", LOG_UUCP },
|
||||||
|
105
src/syslogd.c
105
src/syslogd.c
@ -73,7 +73,6 @@ static char sccsid[] __attribute__((unused)) =
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <utmp.h>
|
#include <utmp.h>
|
||||||
|
|
||||||
#define SYSLOG_NAMES
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -96,6 +95,7 @@ static char sccsid[] __attribute__((unused)) =
|
|||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
|
|
||||||
|
#define SYSLOG_NAMES
|
||||||
#include "syslogd.h"
|
#include "syslogd.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
|
||||||
@ -216,56 +216,6 @@ char *TypeNames[] = {
|
|||||||
static SIMPLEQ_HEAD(files, filed) fhead = SIMPLEQ_HEAD_INITIALIZER(fhead);
|
static SIMPLEQ_HEAD(files, filed) fhead = SIMPLEQ_HEAD_INITIALIZER(fhead);
|
||||||
struct filed consfile;
|
struct filed consfile;
|
||||||
|
|
||||||
struct code {
|
|
||||||
char *c_name;
|
|
||||||
int c_val;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct code PriNames[] = {
|
|
||||||
{ "alert", LOG_ALERT },
|
|
||||||
{ "crit", LOG_CRIT },
|
|
||||||
{ "debug", LOG_DEBUG },
|
|
||||||
{ "emerg", LOG_EMERG },
|
|
||||||
{ "err", LOG_ERR },
|
|
||||||
{ "error", LOG_ERR }, /* DEPRECATED */
|
|
||||||
{ "info", LOG_INFO },
|
|
||||||
{ "none", INTERNAL_NOPRI }, /* INTERNAL */
|
|
||||||
{ "notice", LOG_NOTICE },
|
|
||||||
{ "panic", LOG_EMERG }, /* DEPRECATED */
|
|
||||||
{ "warn", LOG_WARNING }, /* DEPRECATED */
|
|
||||||
{ "warning", LOG_WARNING },
|
|
||||||
{ "*", TABLE_ALLPRI },
|
|
||||||
{ NULL, -1 }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct code FacNames[] = {
|
|
||||||
{ "auth", LOG_AUTH },
|
|
||||||
{ "authpriv", LOG_AUTHPRIV },
|
|
||||||
{ "cron", LOG_CRON },
|
|
||||||
{ "daemon", LOG_DAEMON },
|
|
||||||
{ "kern", LOG_KERN },
|
|
||||||
{ "lpr", LOG_LPR },
|
|
||||||
{ "mail", LOG_MAIL },
|
|
||||||
{ "mark", LOG_MARK }, /* INTERNAL */
|
|
||||||
{ "news", LOG_NEWS },
|
|
||||||
{ "security", LOG_AUTH }, /* DEPRECATED */
|
|
||||||
{ "syslog", LOG_SYSLOG },
|
|
||||||
{ "user", LOG_USER },
|
|
||||||
{ "uucp", LOG_UUCP },
|
|
||||||
#if defined(LOG_FTP)
|
|
||||||
{ "ftp", LOG_FTP },
|
|
||||||
#endif
|
|
||||||
{ "local0", LOG_LOCAL0 },
|
|
||||||
{ "local1", LOG_LOCAL1 },
|
|
||||||
{ "local2", LOG_LOCAL2 },
|
|
||||||
{ "local3", LOG_LOCAL3 },
|
|
||||||
{ "local4", LOG_LOCAL4 },
|
|
||||||
{ "local5", LOG_LOCAL5 },
|
|
||||||
{ "local6", LOG_LOCAL6 },
|
|
||||||
{ "local7", LOG_LOCAL7 },
|
|
||||||
{ NULL, -1 },
|
|
||||||
};
|
|
||||||
|
|
||||||
static int Debug; /* debug flag */
|
static int Debug; /* debug flag */
|
||||||
static int Foreground = 0; /* don't fork - don't run in daemon mode */
|
static int Foreground = 0; /* don't fork - don't run in daemon mode */
|
||||||
static char LocalHostName[MAXHOSTNAMELEN + 1]; /* our hostname */
|
static char LocalHostName[MAXHOSTNAMELEN + 1]; /* our hostname */
|
||||||
@ -317,7 +267,7 @@ void doexit(int sig);
|
|||||||
void init();
|
void init();
|
||||||
static int strtobytes(char *arg);
|
static int strtobytes(char *arg);
|
||||||
static int cfparse(FILE *fp, struct files *newf);
|
static int cfparse(FILE *fp, struct files *newf);
|
||||||
int decode(char *name, struct code *codetab);
|
int decode(char *name, struct _code *codetab);
|
||||||
static void logit(char *, ...);
|
static void logit(char *, ...);
|
||||||
void sighup_handler(int);
|
void sighup_handler(int);
|
||||||
static int create_unix_socket(const char *path);
|
static int create_unix_socket(const char *path);
|
||||||
@ -1433,7 +1383,7 @@ static void logmsg(struct buf_msg *buffer)
|
|||||||
|
|
||||||
SIMPLEQ_FOREACH(f, &fhead, f_link) {
|
SIMPLEQ_FOREACH(f, &fhead, f_link) {
|
||||||
/* skip messages that are incorrect priority */
|
/* skip messages that are incorrect priority */
|
||||||
if ((f->f_pmask[fac] == TABLE_NOPRI) ||
|
if ((f->f_pmask[fac] == INTERNAL_INVPRI) ||
|
||||||
((f->f_pmask[fac] & (1 << prilev)) == 0))
|
((f->f_pmask[fac] & (1 << prilev)) == 0))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -2126,7 +2076,7 @@ static void flog(int pri, char *fmt, ...)
|
|||||||
buffer.proc_id = proc_id;
|
buffer.proc_id = proc_id;
|
||||||
buffer.pri = pri;
|
buffer.pri = pri;
|
||||||
buffer.msg = buf;
|
buffer.msg = buf;
|
||||||
if (pri & LOG_MARK)
|
if (pri & INTERNAL_MARK)
|
||||||
buffer.flags = MARK;
|
buffer.flags = MARK;
|
||||||
|
|
||||||
logmsg(&buffer);
|
logmsg(&buffer);
|
||||||
@ -2140,7 +2090,7 @@ void domark(int signo)
|
|||||||
now = time(0);
|
now = time(0);
|
||||||
MarkSeq += LastAlarm;
|
MarkSeq += LastAlarm;
|
||||||
if (MarkSeq >= MarkInterval) {
|
if (MarkSeq >= MarkInterval) {
|
||||||
flog(LOG_MARK | LOG_INFO, "-- MARK --");
|
flog(INTERNAL_MARK | LOG_INFO, "-- MARK --");
|
||||||
MarkSeq -= MarkInterval;
|
MarkSeq -= MarkInterval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2447,7 +2397,7 @@ void init(void)
|
|||||||
SIMPLEQ_FOREACH(f, &fhead, f_link) {
|
SIMPLEQ_FOREACH(f, &fhead, f_link) {
|
||||||
if (f->f_type != F_UNUSED) {
|
if (f->f_type != F_UNUSED) {
|
||||||
for (i = 0; i <= LOG_NFACILITIES; i++)
|
for (i = 0; i <= LOG_NFACILITIES; i++)
|
||||||
if (f->f_pmask[i] == TABLE_NOPRI)
|
if (f->f_pmask[i] == INTERNAL_INVPRI)
|
||||||
printf(" X ");
|
printf(" X ");
|
||||||
else
|
else
|
||||||
printf("%2X ", f->f_pmask[i]);
|
printf("%2X ", f->f_pmask[i]);
|
||||||
@ -2542,10 +2492,10 @@ static struct filed *cfline(char *line)
|
|||||||
}
|
}
|
||||||
if (*buf == '=') {
|
if (*buf == '=') {
|
||||||
singlpri = 1;
|
singlpri = 1;
|
||||||
pri = decode(&buf[1], PriNames);
|
pri = decode(&buf[1], prioritynames);
|
||||||
} else {
|
} else {
|
||||||
singlpri = 0;
|
singlpri = 0;
|
||||||
pri = decode(buf, PriNames);
|
pri = decode(buf, prioritynames);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pri < 0) {
|
if (pri < 0) {
|
||||||
@ -2565,20 +2515,20 @@ static struct filed *cfline(char *line)
|
|||||||
for (i = 0; i <= LOG_NFACILITIES; i++) {
|
for (i = 0; i <= LOG_NFACILITIES; i++) {
|
||||||
if (pri == INTERNAL_NOPRI) {
|
if (pri == INTERNAL_NOPRI) {
|
||||||
if (ignorepri)
|
if (ignorepri)
|
||||||
f->f_pmask[i] = TABLE_ALLPRI;
|
f->f_pmask[i] = INTERNAL_ALLPRI;
|
||||||
else
|
else
|
||||||
f->f_pmask[i] = TABLE_NOPRI;
|
f->f_pmask[i] = INTERNAL_INVPRI;
|
||||||
} else if (singlpri) {
|
} else if (singlpri) {
|
||||||
if (ignorepri)
|
if (ignorepri)
|
||||||
f->f_pmask[i] &= ~(1 << pri);
|
f->f_pmask[i] &= ~(1 << pri);
|
||||||
else
|
else
|
||||||
f->f_pmask[i] |= (1 << pri);
|
f->f_pmask[i] |= (1 << pri);
|
||||||
} else {
|
} else {
|
||||||
if (pri == TABLE_ALLPRI) {
|
if (pri == INTERNAL_ALLPRI) {
|
||||||
if (ignorepri)
|
if (ignorepri)
|
||||||
f->f_pmask[i] = TABLE_NOPRI;
|
f->f_pmask[i] = INTERNAL_INVPRI;
|
||||||
else
|
else
|
||||||
f->f_pmask[i] = TABLE_ALLPRI;
|
f->f_pmask[i] = INTERNAL_ALLPRI;
|
||||||
} else {
|
} else {
|
||||||
if (ignorepri)
|
if (ignorepri)
|
||||||
for (i2 = 0; i2 <= pri; ++i2)
|
for (i2 = 0; i2 <= pri; ++i2)
|
||||||
@ -2590,7 +2540,7 @@ static struct filed *cfline(char *line)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
i = decode(buf, FacNames);
|
i = decode(buf, facilitynames);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
(void)snprintf(xbuf, sizeof(xbuf), "unknown facility name \"%s\"", buf);
|
(void)snprintf(xbuf, sizeof(xbuf), "unknown facility name \"%s\"", buf);
|
||||||
logerror(xbuf);
|
logerror(xbuf);
|
||||||
@ -2601,20 +2551,20 @@ static struct filed *cfline(char *line)
|
|||||||
|
|
||||||
if (pri == INTERNAL_NOPRI) {
|
if (pri == INTERNAL_NOPRI) {
|
||||||
if (ignorepri)
|
if (ignorepri)
|
||||||
f->f_pmask[i >> 3] = TABLE_ALLPRI;
|
f->f_pmask[i >> 3] = INTERNAL_ALLPRI;
|
||||||
else
|
else
|
||||||
f->f_pmask[i >> 3] = TABLE_NOPRI;
|
f->f_pmask[i >> 3] = INTERNAL_INVPRI;
|
||||||
} else if (singlpri) {
|
} else if (singlpri) {
|
||||||
if (ignorepri)
|
if (ignorepri)
|
||||||
f->f_pmask[i >> 3] &= ~(1 << pri);
|
f->f_pmask[i >> 3] &= ~(1 << pri);
|
||||||
else
|
else
|
||||||
f->f_pmask[i >> 3] |= (1 << pri);
|
f->f_pmask[i >> 3] |= (1 << pri);
|
||||||
} else {
|
} else {
|
||||||
if (pri == TABLE_ALLPRI) {
|
if (pri == INTERNAL_ALLPRI) {
|
||||||
if (ignorepri)
|
if (ignorepri)
|
||||||
f->f_pmask[i >> 3] = TABLE_NOPRI;
|
f->f_pmask[i >> 3] = INTERNAL_INVPRI;
|
||||||
else
|
else
|
||||||
f->f_pmask[i >> 3] = TABLE_ALLPRI;
|
f->f_pmask[i >> 3] = INTERNAL_ALLPRI;
|
||||||
} else {
|
} else {
|
||||||
if (ignorepri)
|
if (ignorepri)
|
||||||
for (i2 = 0; i2 <= pri; ++i2)
|
for (i2 = 0; i2 <= pri; ++i2)
|
||||||
@ -2843,10 +2793,10 @@ static int cfparse(FILE *fp, struct files *newf)
|
|||||||
/*
|
/*
|
||||||
* Decode a symbolic name to a numeric value
|
* Decode a symbolic name to a numeric value
|
||||||
*/
|
*/
|
||||||
int decode(char *name, struct code *codetab)
|
int decode(char *name, struct _code *codetab)
|
||||||
{
|
{
|
||||||
struct code *c;
|
struct _code *c;
|
||||||
char * p;
|
char *p;
|
||||||
char buf[80];
|
char buf[80];
|
||||||
|
|
||||||
logit("symbolic name: %s", name);
|
logit("symbolic name: %s", name);
|
||||||
@ -2854,15 +2804,20 @@ int decode(char *name, struct code *codetab)
|
|||||||
logit("\n");
|
logit("\n");
|
||||||
return atoi(name);
|
return atoi(name);
|
||||||
}
|
}
|
||||||
(void)strncpy(buf, name, 79);
|
|
||||||
for (p = buf; *p; p++)
|
strlcpy(buf, name, sizeof(buf));
|
||||||
|
for (p = buf; *p; p++) {
|
||||||
if (isupper(*p))
|
if (isupper(*p))
|
||||||
*p = tolower(*p);
|
*p = tolower(*p);
|
||||||
for (c = codetab; c->c_name; c++)
|
}
|
||||||
|
|
||||||
|
for (c = codetab; c->c_name; c++) {
|
||||||
if (!strcmp(buf, c->c_name)) {
|
if (!strcmp(buf, c->c_name)) {
|
||||||
logit(" ==> %d\n", c->c_val);
|
logit(" ==> %d\n", c->c_val);
|
||||||
return c->c_val;
|
return c->c_val;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,13 +43,6 @@
|
|||||||
#define MAXUNAMES 20 /* maximum number of user names */
|
#define MAXUNAMES 20 /* maximum number of user names */
|
||||||
#define MAXFNAME 200 /* max file pathname length */
|
#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. */
|
/* Traditional syslog timestamp format. */
|
||||||
#define RFC3164_DATELEN 15
|
#define RFC3164_DATELEN 15
|
||||||
#define RFC3164_DATEFMT "%b %e %H:%M:%S"
|
#define RFC3164_DATEFMT "%b %e %H:%M:%S"
|
||||||
|
Loading…
Reference in New Issue
Block a user