Allow syslogd to select messages based on the originating host in
a similar way to the way it can select messages from a given program. Lines beginning with "+hostname" or "#+hostname" select messaes from that hostname and lines beginning with "-hostname" or "#-hostname" match messages not from that hostname. There are some significant style issues left in the original program selection code and the man page. This should be cleared up in some later commits. Reviewed by: sheldonh Based on an original patch by: Bernd Walter <ticso@cicely8.cicely.de> Man page stylist: sheldonh
This commit is contained in:
parent
c146223678
commit
a144588d15
@ -49,6 +49,8 @@ program.
|
||||
It consists of
|
||||
blocks of lines separated by
|
||||
.Em program
|
||||
and
|
||||
.Em hostname
|
||||
specifications,
|
||||
with each line containing two fields: the
|
||||
.Em selector
|
||||
@ -136,19 +138,71 @@ values specified to the
|
||||
.Xr syslog 3
|
||||
library routine.
|
||||
.Pp
|
||||
Each block of lines is separated from the previous block by a tag.
|
||||
The tag
|
||||
is a line beginning with
|
||||
.Em #!prog
|
||||
Each block of lines is separated from the previous block by a
|
||||
.Em program
|
||||
or
|
||||
.Em !prog
|
||||
.Em hostname
|
||||
specification.
|
||||
A block will only log messages corresponding to the most recent
|
||||
.Em program
|
||||
and
|
||||
.Em hostname
|
||||
specifications given.
|
||||
Thus, a block which selects
|
||||
.Ql ppp
|
||||
as the
|
||||
.Em program ,
|
||||
directly followed by a block that selects messages from the
|
||||
.Em hostname
|
||||
.Ql dialhost ,
|
||||
then the second block will only log messages
|
||||
from the
|
||||
.Xr ppp 8
|
||||
program on dialhost.
|
||||
.Pp
|
||||
A
|
||||
.Em program
|
||||
specification is a line beginning with
|
||||
.Ql #!prog
|
||||
or
|
||||
.Ql !prog
|
||||
(the former is for compatibility with the previous syslogd, if one is sharing
|
||||
.Pa syslog.conf
|
||||
files, for example)
|
||||
and each block will be associated with calls to syslog from that specific
|
||||
program.
|
||||
A tag for ``foo'' will also match any message logged by the kernel
|
||||
with the prefix ``foo: ''.
|
||||
and the following blocks will be associated with calls to
|
||||
.Xr syslog 3
|
||||
from that specific program.
|
||||
A
|
||||
.Em program
|
||||
specification for
|
||||
.Ql foo
|
||||
will also match any message logged by the kernel with the prefix
|
||||
.Ql "foo: " .
|
||||
A
|
||||
.Em hostname
|
||||
specification of the form
|
||||
.Ql #+hostname
|
||||
or
|
||||
.Ql +hostname
|
||||
and the following blocks will be applied to messages
|
||||
received from the specified hostname.
|
||||
Alternatively, a
|
||||
.Em hostname
|
||||
specification
|
||||
.Ql #-hostname
|
||||
or
|
||||
.Ql -hostname
|
||||
causes the following blocks to be applied to messages
|
||||
from any host but the one specified.
|
||||
If the hostname is given as
|
||||
.Ql @ ,
|
||||
the local hostname will be used.
|
||||
A
|
||||
.Em program
|
||||
or
|
||||
.Em hostname
|
||||
specification may be reset by giving the program or hostname as
|
||||
.Ql * .
|
||||
.Pp
|
||||
See
|
||||
.Xr syslog 3
|
||||
|
@ -147,6 +147,7 @@ struct filed {
|
||||
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 */
|
||||
u_char f_pcmp[LOG_NFACILITIES+1]; /* compare priority */
|
||||
#define PRI_LT 0x1
|
||||
@ -269,7 +270,7 @@ int LogFacPri = 0; /* Put facility and priority in log message: */
|
||||
/* 0=no, 1=numeric, 2=names */
|
||||
|
||||
int allowaddr __P((char *));
|
||||
void cfline __P((char *, struct filed *, char *));
|
||||
void cfline __P((char *, struct filed *, char *, char *));
|
||||
char *cvthname __P((struct sockaddr_in *));
|
||||
void deadq_enter __P((pid_t, const char *));
|
||||
int deadq_remove __P((pid_t));
|
||||
@ -752,6 +753,19 @@ logmsg(pri, msg, from, flags)
|
||||
)
|
||||
|| f->f_pmask[fac] == INTERNAL_NOPRI)
|
||||
continue;
|
||||
/* skip messages with the incorrect hostname */
|
||||
if (f->f_host)
|
||||
switch (f->f_host[0]) {
|
||||
case '+':
|
||||
if((strcmp(from, f->f_host + 1) != 0) )
|
||||
continue;
|
||||
break;
|
||||
case '-':
|
||||
if((strcmp(from, f->f_host + 1) == 0) )
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
/* skip messages with the incorrect program name */
|
||||
if(f->f_program)
|
||||
if(strcmp(prog, f->f_program) != 0)
|
||||
@ -1242,6 +1256,7 @@ init(signo)
|
||||
char *p;
|
||||
char cline[LINE_MAX];
|
||||
char prog[NAME_MAX+1];
|
||||
char host[MAXHOSTNAMELEN+1];
|
||||
|
||||
dprintf("init\n");
|
||||
|
||||
@ -1271,6 +1286,7 @@ init(signo)
|
||||
}
|
||||
next = f->f_next;
|
||||
if(f->f_program) free(f->f_program);
|
||||
if (f->f_host) free(f->f_host);
|
||||
free((char *)f);
|
||||
}
|
||||
Files = NULL;
|
||||
@ -1280,9 +1296,9 @@ init(signo)
|
||||
if ((cf = fopen(ConfFile, "r")) == NULL) {
|
||||
dprintf("cannot open %s\n", ConfFile);
|
||||
*nextp = (struct filed *)calloc(1, sizeof(*f));
|
||||
cfline("*.ERR\t/dev/console", *nextp, "*");
|
||||
cfline("*.ERR\t/dev/console", *nextp, "*", "*");
|
||||
(*nextp)->f_next = (struct filed *)calloc(1, sizeof(*f));
|
||||
cfline("*.PANIC\t*", (*nextp)->f_next, "*");
|
||||
cfline("*.PANIC\t*", (*nextp)->f_next, "*", "*");
|
||||
Initialized = 1;
|
||||
return;
|
||||
}
|
||||
@ -1291,6 +1307,7 @@ init(signo)
|
||||
* Foreach line in the conf table, open that file.
|
||||
*/
|
||||
f = NULL;
|
||||
strcpy(host, "*");
|
||||
strcpy(prog, "*");
|
||||
while (fgets(cline, sizeof(cline), cf) != NULL) {
|
||||
/*
|
||||
@ -1304,9 +1321,26 @@ init(signo)
|
||||
continue;
|
||||
if(*p == '#') {
|
||||
p++;
|
||||
if(*p!='!')
|
||||
if (*p != '!' && *p != '+' && *p != '-')
|
||||
continue;
|
||||
}
|
||||
if (*p == '+' || *p == '-') {
|
||||
host[0] = *p++;
|
||||
while (isspace(*p)) p++;
|
||||
if ((!*p) || (*p == '*')) {
|
||||
strcpy(host, "*");
|
||||
continue;
|
||||
}
|
||||
if (*p == '@')
|
||||
p = LocalHostName;
|
||||
for (i = 1; i < MAXHOSTNAMELEN; i++) {
|
||||
if (!isalnum(*p) && *p != '.' && *p != '-')
|
||||
break;
|
||||
host[i] = *p++;
|
||||
}
|
||||
host[i] = '\0';
|
||||
continue;
|
||||
}
|
||||
if(*p=='!') {
|
||||
p++;
|
||||
while(isspace(*p)) p++;
|
||||
@ -1328,7 +1362,7 @@ init(signo)
|
||||
f = (struct filed *)calloc(1, sizeof(*f));
|
||||
*nextp = f;
|
||||
nextp = &f->f_next;
|
||||
cfline(cline, f, prog);
|
||||
cfline(cline, f, prog, host);
|
||||
}
|
||||
|
||||
/* close the configuration file */
|
||||
@ -1382,17 +1416,18 @@ init(signo)
|
||||
* Crack a configuration file line
|
||||
*/
|
||||
void
|
||||
cfline(line, f, prog)
|
||||
cfline(line, f, prog, host)
|
||||
char *line;
|
||||
struct filed *f;
|
||||
char *prog;
|
||||
char *host;
|
||||
{
|
||||
struct hostent *hp;
|
||||
int i, pri;
|
||||
char *bp, *p, *q;
|
||||
char buf[MAXLINE], ebuf[100];
|
||||
|
||||
dprintf("cfline(\"%s\", f, \"%s\")\n", line, prog);
|
||||
dprintf("cfline(\"%s\", f, \"%s\", \"%s\")\n", line, prog, host);
|
||||
|
||||
errno = 0; /* keep strerror() stuff out of logerror messages */
|
||||
|
||||
@ -1401,6 +1436,15 @@ cfline(line, f, prog)
|
||||
for (i = 0; i <= LOG_NFACILITIES; i++)
|
||||
f->f_pmask[i] = INTERNAL_NOPRI;
|
||||
|
||||
/* save hostname if any */
|
||||
if (host && *host == '*') host = NULL;
|
||||
if (host) {
|
||||
f->f_host = calloc(1, strlen(host)+1);
|
||||
if (f->f_host) {
|
||||
strcpy(f->f_host, host);
|
||||
}
|
||||
}
|
||||
|
||||
/* save program name if any */
|
||||
if(prog && *prog=='*') prog = NULL;
|
||||
if(prog) {
|
||||
|
Loading…
Reference in New Issue
Block a user