Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/syslogd/syslogd.c
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
* extensive changes by Ralph Campbell | * extensive changes by Ralph Campbell | ||||
* more extensive changes by Eric Allman (again) | * more extensive changes by Eric Allman (again) | ||||
* Extension to log by program name as well as facility and priority | * Extension to log by program name as well as facility and priority | ||||
* by Peter da Silva. | * by Peter da Silva. | ||||
* -u and -v by Harlan Stenn. | * -u and -v by Harlan Stenn. | ||||
* Priority comparison code by Harlan Stenn. | * Priority comparison code by Harlan Stenn. | ||||
*/ | */ | ||||
/* Maximum number of characters in time of last occurrence */ | #define MAXLINE 8192 /* maximum line length */ | ||||
#define MAXLINE 2048 /* maximum line length */ | |||||
#define MAXSVLINE MAXLINE /* maximum saved line length */ | #define MAXSVLINE MAXLINE /* maximum saved line length */ | ||||
#define DEFUPRI (LOG_USER|LOG_NOTICE) | #define DEFUPRI (LOG_USER|LOG_NOTICE) | ||||
#define DEFSPRI (LOG_KERN|LOG_CRIT) | #define DEFSPRI (LOG_KERN|LOG_CRIT) | ||||
#define TIMERINTVL 30 /* interval for checking flush, mark */ | #define TIMERINTVL 30 /* interval for checking flush, mark */ | ||||
#define TTYMSGTIME 1 /* timeout passed to ttymsg */ | #define TTYMSGTIME 1 /* timeout passed to ttymsg */ | ||||
#define RCVBUF_MINSIZE (80 * 1024) /* minimum size of dgram rcv buffer */ | #define RCVBUF_MINSIZE (80 * 1024) /* minimum size of dgram rcv buffer */ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | |||||
static int resolve = 1; /* resolve hostname */ | static int resolve = 1; /* resolve hostname */ | ||||
static char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */ | static char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */ | ||||
static const char *LocalDomain; /* our local domain name */ | static const char *LocalDomain; /* our local domain name */ | ||||
static int Initialized; /* set when we have initialized ourselves */ | static int Initialized; /* set when we have initialized ourselves */ | ||||
static int MarkInterval = 20 * 60; /* interval between marks in seconds */ | static int MarkInterval = 20 * 60; /* interval between marks in seconds */ | ||||
static int MarkSeq; /* mark sequence number */ | static int MarkSeq; /* mark sequence number */ | ||||
static int NoBind; /* don't bind() as suggested by RFC 3164 */ | static int NoBind; /* don't bind() as suggested by RFC 3164 */ | ||||
static int SecureMode; /* when true, receive only unix domain socks */ | static int SecureMode; /* when true, receive only unix domain socks */ | ||||
static int MaxForwardLen = 1024; /* max length of forwared message */ | |||||
#ifdef INET6 | #ifdef INET6 | ||||
static int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */ | static int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */ | ||||
#else | #else | ||||
static int family = PF_INET; /* protocol family (IPv4 only) */ | static int family = PF_INET; /* protocol family (IPv4 only) */ | ||||
#endif | #endif | ||||
static int mask_C1 = 1; /* mask characters from 0x80 - 0x9F */ | static int mask_C1 = 1; /* mask characters from 0x80 - 0x9F */ | ||||
static int send_to_all; /* send message to all IPv4/IPv6 addresses */ | static int send_to_all; /* send message to all IPv4/IPv6 addresses */ | ||||
static int use_bootfile; /* log entire bootfile for every kern msg */ | static int use_bootfile; /* log entire bootfile for every kern msg */ | ||||
static int no_compress; /* don't compress messages (1=pipes, 2=all) */ | static int no_compress; /* don't compress messages (1=pipes, 2=all) */ | ||||
static int logflags = O_WRONLY|O_APPEND; /* flags used to open log files */ | static int logflags = O_WRONLY|O_APPEND; /* flags used to open log files */ | ||||
static char bootfile[MAXLINE+1]; /* booted kernel file */ | static char bootfile[MAXPATHLEN]; /* booted kernel file */ | ||||
0mp: Is this desired? MAXPATHLEN is not mentioned in the description of the change. | |||||
Not Done Inline ActionsReplaced bootfile[] size for MAXPATHLEN used in getbootfile(3) as a returned value. Using (MAXLINE+1) as a size for bootfile[] is excessive. dmitry.wagin_ya.ru: Replaced bootfile[] size for MAXPATHLEN used in getbootfile(3) as a returned value. Using… | |||||
static int RemoteAddDate; /* Always set the date on remote messages */ | static int RemoteAddDate; /* Always set the date on remote messages */ | ||||
static int RemoteHostname; /* Log remote hostname from the message */ | static int RemoteHostname; /* Log remote hostname from the message */ | ||||
static int UniquePriority; /* Only log specified priority? */ | static int UniquePriority; /* Only log specified priority? */ | ||||
static int LogFacPri; /* Put facility and priority in log message: */ | static int LogFacPri; /* Put facility and priority in log message: */ | ||||
/* 0=no, 1=numeric, 2=names */ | /* 0=no, 1=numeric, 2=names */ | ||||
static int KeepKernFac; /* Keep remotely logged kernel facility */ | static int KeepKernFac; /* Keep remotely logged kernel facility */ | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | main(int argc, char *argv[]) | ||||
struct peer *pe; | struct peer *pe; | ||||
struct socklist *sl; | struct socklist *sl; | ||||
pid_t ppid = 1, spid; | pid_t ppid = 1, spid; | ||||
char *p; | char *p; | ||||
if (madvise(NULL, 0, MADV_PROTECT) != 0) | if (madvise(NULL, 0, MADV_PROTECT) != 0) | ||||
dprintf("madvise() failed: %s\n", strerror(errno)); | dprintf("madvise() failed: %s\n", strerror(errno)); | ||||
while ((ch = getopt(argc, argv, "468Aa:b:cCdf:FHkl:m:nNoO:p:P:sS:Tuv")) | while ((ch = getopt(argc, argv, "468Aa:b:cCdf:FHkl:M:m:nNoO:p:P:sS:Tuv")) | ||||
!= -1) | != -1) | ||||
switch (ch) { | switch (ch) { | ||||
#ifdef INET | #ifdef INET | ||||
case '4': | case '4': | ||||
family = PF_INET; | family = PF_INET; | ||||
break; | break; | ||||
#endif | #endif | ||||
#ifdef INET6 | #ifdef INET6 | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | case 'S': | ||||
errx(1, "invalid filename %s, exiting", | errx(1, "invalid filename %s, exiting", | ||||
optarg); | optarg); | ||||
addpeer(&(struct peer){ | addpeer(&(struct peer){ | ||||
.pe_name = name, | .pe_name = name, | ||||
.pe_mode = mode | .pe_mode = mode | ||||
}); | }); | ||||
break; | break; | ||||
} | } | ||||
case 'M': /* max length of forwarded message */ | |||||
MaxForwardLen = atoi(optarg); | |||||
if (MaxForwardLen < 480) | |||||
errx(1, "minimum length limit of forwarded " | |||||
"messages is 480 bytes"); | |||||
Not Done Inline ActionsI suggest "minimum maximum length of forwarded messages is 480 bytes". markj: I suggest "minimum maximum length of forwarded messages is 480 bytes". | |||||
Done Inline ActionsMaybe better "minimum length limit of forwarded messages is 480 bytes"? dmitry.wagin_ya.ru: Maybe better "minimum length limit of forwarded messages is 480 bytes"? | |||||
Not Done Inline ActionsThat's better, thanks. markj: That's better, thanks. | |||||
break; | |||||
case 'm': /* mark interval */ | case 'm': /* mark interval */ | ||||
MarkInterval = atoi(optarg) * 60; | MarkInterval = atoi(optarg) * 60; | ||||
break; | break; | ||||
case 'N': | case 'N': | ||||
NoBind = 1; | NoBind = 1; | ||||
SecureMode = 1; | SecureMode = 1; | ||||
break; | break; | ||||
case 'n': | case 'n': | ||||
Show All 28 Lines | case 'v': /* log facility and priority */ | ||||
LogFacPri++; | LogFacPri++; | ||||
break; | break; | ||||
default: | default: | ||||
usage(); | usage(); | ||||
} | } | ||||
if ((argc -= optind) != 0) | if ((argc -= optind) != 0) | ||||
usage(); | usage(); | ||||
if (RFC3164OutputFormat && MaxForwardLen > 1024) | |||||
errx(1, "RFC 3164 messages may not exceed 1024 bytes"); | |||||
Done Inline ActionsI would write it a bit shorter, e.g., "RFC 3164 messages may not exceed 1024 bytes" markj: I would write it a bit shorter, e.g., "RFC 3164 messages may not exceed 1024 bytes" | |||||
/* Pipe to catch a signal during select(). */ | /* Pipe to catch a signal during select(). */ | ||||
s = pipe2(sigpipe, O_CLOEXEC); | s = pipe2(sigpipe, O_CLOEXEC); | ||||
if (s < 0) { | if (s < 0) { | ||||
err(1, "cannot open a pipe for signals"); | err(1, "cannot open a pipe for signals"); | ||||
} else { | } else { | ||||
addsock(NULL, &(struct socklist){ | addsock(NULL, &(struct socklist){ | ||||
.sl_socket = sigpipe[0], | .sl_socket = sigpipe[0], | ||||
.sl_recv = socklist_recv_signal | .sl_recv = socklist_recv_signal | ||||
▲ Show 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"usage: syslogd [-468ACcdFHknosTuv] [-a allowed_peer]\n" | "usage: syslogd [-468ACcdFHknosTuv] [-a allowed_peer]\n" | ||||
" [-b bind_address] [-f config_file]\n" | " [-b bind_address] [-f config_file]\n" | ||||
" [-l [mode:]path] [-m mark_interval]\n" | " [-l [mode:]path] [-M fwd_length]\n" | ||||
" [-O format] [-P pid_file] [-p log_socket]\n" | " [-m mark_interval] [-O format] [-P pid_file]\n" | ||||
" [-S logpriv_socket]\n"); | " [-p log_socket] [-S logpriv_socket]\n"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
/* | /* | ||||
* Removes characters from log messages that are unsafe to display. | * Removes characters from log messages that are unsafe to display. | ||||
* TODO: Permit UTF-8 strings that include a BOM per RFC 5424? | * TODO: Permit UTF-8 strings that include a BOM per RFC 5424? | ||||
*/ | */ | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 873 Lines • ▼ Show 20 Lines | fprintlog_write(struct filed *f, struct iovlist *il, int flags) | ||||
struct msghdr msghdr; | struct msghdr msghdr; | ||||
struct addrinfo *r; | struct addrinfo *r; | ||||
struct socklist *sl; | struct socklist *sl; | ||||
const char *msgret; | const char *msgret; | ||||
ssize_t lsent; | ssize_t lsent; | ||||
switch (f->f_type) { | switch (f->f_type) { | ||||
case F_FORW: | case F_FORW: | ||||
/* Truncate messages to RFC 5426 recommended size. */ | |||||
dprintf(" %s", f->fu_forw_hname); | dprintf(" %s", f->fu_forw_hname); | ||||
switch (f->fu_forw_addr->ai_family) { | switch (f->fu_forw_addr->ai_family) { | ||||
#ifdef INET | #ifdef INET | ||||
case AF_INET: | case AF_INET: | ||||
dprintf(":%d\n", | dprintf(":%d\n", | ||||
ntohs(satosin(f->fu_forw_addr->ai_addr)->sin_port)); | ntohs(satosin(f->fu_forw_addr->ai_addr)->sin_port)); | ||||
iovlist_truncate(il, 480); | |||||
break; | break; | ||||
#endif | #endif | ||||
#ifdef INET6 | #ifdef INET6 | ||||
case AF_INET6: | case AF_INET6: | ||||
dprintf(":%d\n", | dprintf(":%d\n", | ||||
ntohs(satosin6(f->fu_forw_addr->ai_addr)->sin6_port)); | ntohs(satosin6(f->fu_forw_addr->ai_addr)->sin6_port)); | ||||
iovlist_truncate(il, 1180); | |||||
break; | break; | ||||
#endif | #endif | ||||
default: | default: | ||||
dprintf("\n"); | dprintf("\n"); | ||||
} | } | ||||
/* Truncate messages to maximum forward length. */ | |||||
iovlist_truncate(il, MaxForwardLen); | |||||
lsent = 0; | lsent = 0; | ||||
for (r = f->fu_forw_addr; r; r = r->ai_next) { | for (r = f->fu_forw_addr; r; r = r->ai_next) { | ||||
memset(&msghdr, 0, sizeof(msghdr)); | memset(&msghdr, 0, sizeof(msghdr)); | ||||
msghdr.msg_name = r->ai_addr; | msghdr.msg_name = r->ai_addr; | ||||
msghdr.msg_namelen = r->ai_addrlen; | msghdr.msg_namelen = r->ai_addrlen; | ||||
msghdr.msg_iov = il->iov; | msghdr.msg_iov = il->iov; | ||||
msghdr.msg_iovlen = il->iovcnt; | msghdr.msg_iovlen = il->iovcnt; | ||||
STAILQ_FOREACH(sl, &shead, next) { | STAILQ_FOREACH(sl, &shead, next) { | ||||
▲ Show 20 Lines • Show All 676 Lines • ▼ Show 20 Lines | |||||
init(int signo) | init(int signo) | ||||
{ | { | ||||
int i; | int i; | ||||
FILE *cf; | FILE *cf; | ||||
struct filed *f; | struct filed *f; | ||||
char *p; | char *p; | ||||
char oldLocalHostName[MAXHOSTNAMELEN]; | char oldLocalHostName[MAXHOSTNAMELEN]; | ||||
char hostMsg[2*MAXHOSTNAMELEN+40]; | char hostMsg[2*MAXHOSTNAMELEN+40]; | ||||
char bootfileMsg[LINE_MAX]; | char bootfileMsg[MAXLINE + 1]; | ||||
dprintf("init\n"); | dprintf("init\n"); | ||||
WantInitialize = 0; | WantInitialize = 0; | ||||
/* | /* | ||||
* Load hostname (may have changed). | * Load hostname (may have changed). | ||||
*/ | */ | ||||
if (signo != 0) | if (signo != 0) | ||||
▲ Show 20 Lines • Show All 330 Lines • ▼ Show 20 Lines | |||||
cfline(const char *line, const char *prog, const char *host, | cfline(const char *line, const char *prog, const char *host, | ||||
const char *pfilter) | const char *pfilter) | ||||
{ | { | ||||
struct filed *f; | struct filed *f; | ||||
struct addrinfo hints, *res; | struct addrinfo hints, *res; | ||||
int error, i, pri, syncfile; | int error, i, pri, syncfile; | ||||
const char *p, *q; | const char *p, *q; | ||||
char *bp, *pfilter_dup; | char *bp, *pfilter_dup; | ||||
char buf[MAXLINE], ebuf[100]; | char buf[LINE_MAX], ebuf[100]; | ||||
dprintf("cfline(\"%s\", f, \"%s\", \"%s\", \"%s\")\n", line, prog, | dprintf("cfline(\"%s\", f, \"%s\", \"%s\", \"%s\")\n", line, prog, | ||||
host, pfilter); | host, pfilter); | ||||
f = calloc(1, sizeof(*f)); | f = calloc(1, sizeof(*f)); | ||||
if (f == NULL) { | if (f == NULL) { | ||||
logerror("malloc"); | logerror("malloc"); | ||||
exit(1); | exit(1); | ||||
▲ Show 20 Lines • Show All 1,045 Lines • Show Last 20 Lines |
Is this desired? MAXPATHLEN is not mentioned in the description of the change.