xref: /freebsd/usr.sbin/syslogd/syslogd.h (revision 964687879a38034d3f0221d3c73b9add6cadb567)
1*96468787SJake Freeland /*-
2*96468787SJake Freeland  * SPDX-License-Identifier: BSD-3-Clause
3*96468787SJake Freeland  *
4*96468787SJake Freeland  * Copyright (c) 1983, 1988, 1993, 1994
5*96468787SJake Freeland  *	The Regents of the University of California.  All rights reserved.
6*96468787SJake Freeland  *
7*96468787SJake Freeland  * Redistribution and use in source and binary forms, with or without
8*96468787SJake Freeland  * modification, are permitted provided that the following conditions
9*96468787SJake Freeland  * are met:
10*96468787SJake Freeland  * 1. Redistributions of source code must retain the above copyright
11*96468787SJake Freeland  *    notice, this list of conditions and the following disclaimer.
12*96468787SJake Freeland  * 2. Redistributions in binary form must reproduce the above copyright
13*96468787SJake Freeland  *    notice, this list of conditions and the following disclaimer in the
14*96468787SJake Freeland  *    documentation and/or other materials provided with the distribution.
15*96468787SJake Freeland  * 3. Neither the name of the University nor the names of its contributors
16*96468787SJake Freeland  *    may be used to endorse or promote products derived from this software
17*96468787SJake Freeland  *    without specific prior written permission.
18*96468787SJake Freeland  *
19*96468787SJake Freeland  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*96468787SJake Freeland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*96468787SJake Freeland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*96468787SJake Freeland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*96468787SJake Freeland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*96468787SJake Freeland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*96468787SJake Freeland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*96468787SJake Freeland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*96468787SJake Freeland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*96468787SJake Freeland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*96468787SJake Freeland  * SUCH DAMAGE.
30*96468787SJake Freeland  */
31*96468787SJake Freeland /*-
32*96468787SJake Freeland  * SPDX-License-Identifier: BSD-2-Clause
33*96468787SJake Freeland  *
34*96468787SJake Freeland  * Copyright (c) 2018 Prodrive Technologies, https://prodrive-technologies.com/
35*96468787SJake Freeland  * Author: Ed Schouten <ed@FreeBSD.org>
36*96468787SJake Freeland  * Copyright (c) 2023 The FreeBSD Foundation
37*96468787SJake Freeland  *
38*96468787SJake Freeland  * This software was developed by Jake Freeland <jfree@FreeBSD.org>
39*96468787SJake Freeland  * under sponsorship from the FreeBSD Foundation.
40*96468787SJake Freeland  *
41*96468787SJake Freeland  * Redistribution and use in source and binary forms, with or without
42*96468787SJake Freeland  * modification, are permitted provided that the following conditions
43*96468787SJake Freeland  * are met:
44*96468787SJake Freeland  * 1. Redistributions of source code must retain the above copyright
45*96468787SJake Freeland  *    notice, this list of conditions and the following disclaimer.
46*96468787SJake Freeland  * 2. Redistributions in binary form must reproduce the above copyright
47*96468787SJake Freeland  *    notice, this list of conditions and the following disclaimer in the
48*96468787SJake Freeland  *    documentation and/or other materials provided with the distribution.
49*96468787SJake Freeland  *
50*96468787SJake Freeland  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
51*96468787SJake Freeland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52*96468787SJake Freeland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53*96468787SJake Freeland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
54*96468787SJake Freeland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55*96468787SJake Freeland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56*96468787SJake Freeland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57*96468787SJake Freeland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58*96468787SJake Freeland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59*96468787SJake Freeland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60*96468787SJake Freeland  * SUCH DAMAGE.
61*96468787SJake Freeland  */
62*96468787SJake Freeland 
63*96468787SJake Freeland #ifndef _SYSLOGD_H_
64*96468787SJake Freeland #define _SYSLOGD_H_
65*96468787SJake Freeland 
66*96468787SJake Freeland #include <sys/param.h>
67*96468787SJake Freeland #include <sys/queue.h>
68*96468787SJake Freeland #include <sys/time.h>
69*96468787SJake Freeland 
70*96468787SJake Freeland #define SYSLOG_NAMES
71*96468787SJake Freeland #include <sys/syslog.h>
72*96468787SJake Freeland 
73*96468787SJake Freeland #include <regex.h>
74*96468787SJake Freeland 
75*96468787SJake Freeland #define	MAXLINE		8192		/* maximum line length */
76*96468787SJake Freeland #define	MAXSVLINE	MAXLINE		/* maximum saved line length */
77*96468787SJake Freeland #define	MAXUNAMES	20		/* maximum number of user names */
78*96468787SJake Freeland 
79*96468787SJake Freeland /* Timestamps of log entries. */
80*96468787SJake Freeland struct logtime {
81*96468787SJake Freeland 	struct tm	tm;
82*96468787SJake Freeland 	suseconds_t	usec;
83*96468787SJake Freeland };
84*96468787SJake Freeland 
85*96468787SJake Freeland enum filt_proptype {
86*96468787SJake Freeland 	FILT_PROP_NOOP,
87*96468787SJake Freeland 	FILT_PROP_MSG,
88*96468787SJake Freeland 	FILT_PROP_HOSTNAME,
89*96468787SJake Freeland 	FILT_PROP_PROGNAME,
90*96468787SJake Freeland };
91*96468787SJake Freeland 
92*96468787SJake Freeland enum filt_cmptype {
93*96468787SJake Freeland 	FILT_CMP_CONTAINS,
94*96468787SJake Freeland 	FILT_CMP_EQUAL,
95*96468787SJake Freeland 	FILT_CMP_STARTS,
96*96468787SJake Freeland 	FILT_CMP_REGEX,
97*96468787SJake Freeland };
98*96468787SJake Freeland 
99*96468787SJake Freeland /*
100*96468787SJake Freeland  * This structure holds a property-based filter
101*96468787SJake Freeland  */
102*96468787SJake Freeland struct prop_filter {
103*96468787SJake Freeland 	enum filt_proptype prop_type;
104*96468787SJake Freeland 	enum filt_cmptype cmp_type;
105*96468787SJake Freeland 	uint8_t cmp_flags;
106*96468787SJake Freeland #define	FILT_FLAG_EXCLUDE	(1 << 0)
107*96468787SJake Freeland #define	FILT_FLAG_EXTENDED	(1 << 1)
108*96468787SJake Freeland #define	FILT_FLAG_ICASE		(1 << 2)
109*96468787SJake Freeland 	char *pflt_strval;
110*96468787SJake Freeland 	size_t	pflt_strlen;
111*96468787SJake Freeland 	regex_t *pflt_re;
112*96468787SJake Freeland };
113*96468787SJake Freeland 
114*96468787SJake Freeland enum f_type {
115*96468787SJake Freeland 	F_UNUSED,	/* unused entry */
116*96468787SJake Freeland 	F_FILE,		/* regular file */
117*96468787SJake Freeland 	F_TTY,		/* terminal */
118*96468787SJake Freeland 	F_CONSOLE,	/* console terminal */
119*96468787SJake Freeland 	F_FORW,		/* remote machine */
120*96468787SJake Freeland 	F_USERS,	/* list of users */
121*96468787SJake Freeland 	F_WALL,		/* everyone logged on */
122*96468787SJake Freeland 	F_PIPE,		/* pipe to program */
123*96468787SJake Freeland };
124*96468787SJake Freeland 
125*96468787SJake Freeland /*
126*96468787SJake Freeland  * This structure represents the files that will have log
127*96468787SJake Freeland  * copies printed.
128*96468787SJake Freeland  * We require f_file to be valid if f_type is F_FILE, F_CONSOLE, F_TTY
129*96468787SJake Freeland  * or if f_type is F_PIPE and f_pid > 0.
130*96468787SJake Freeland  */
131*96468787SJake Freeland struct filed {
132*96468787SJake Freeland 	enum f_type f_type;
133*96468787SJake Freeland 
134*96468787SJake Freeland 	/* Used for filtering. */
135*96468787SJake Freeland 	char	*f_host;			/* host from which to recd. */
136*96468787SJake Freeland 	char	*f_program;			/* program this applies to */
137*96468787SJake Freeland 	struct prop_filter *f_prop_filter;	/* property-based filter */
138*96468787SJake Freeland 	u_char	f_pmask[LOG_NFACILITIES+1];	/* priority mask */
139*96468787SJake Freeland 	u_char	f_pcmp[LOG_NFACILITIES+1];	/* compare priority */
140*96468787SJake Freeland #define PRI_LT	0x1
141*96468787SJake Freeland #define PRI_EQ	0x2
142*96468787SJake Freeland #define PRI_GT	0x4
143*96468787SJake Freeland 
144*96468787SJake Freeland 	/* Logging destinations. */
145*96468787SJake Freeland 	int	f_file;				/* file descriptor */
146*96468787SJake Freeland 	int	f_flags;			/* file-specific flags */
147*96468787SJake Freeland #define	FFLAG_SYNC	0x01
148*96468787SJake Freeland #define	FFLAG_NEEDSYNC	0x02
149*96468787SJake Freeland 	union {
150*96468787SJake Freeland 		char	f_uname[MAXUNAMES][MAXLOGNAME];	/* F_WALL, F_USERS */
151*96468787SJake Freeland 		char	f_fname[MAXPATHLEN];	/* F_FILE, F_CONSOLE, F_TTY */
152*96468787SJake Freeland 		struct {
153*96468787SJake Freeland 			char	f_hname[MAXHOSTNAMELEN];
154*96468787SJake Freeland 			struct addrinfo *f_addr;
155*96468787SJake Freeland 		} f_forw;			/* F_FORW */
156*96468787SJake Freeland 		struct {
157*96468787SJake Freeland 			char	f_pname[MAXPATHLEN];
158*96468787SJake Freeland 			int	f_procdesc;
159*96468787SJake Freeland 		} f_pipe;			/* F_PIPE */
160*96468787SJake Freeland 	} f_un;
161*96468787SJake Freeland #define	fu_uname	f_un.f_uname
162*96468787SJake Freeland #define	fu_fname	f_un.f_fname
163*96468787SJake Freeland #define	fu_forw_hname	f_un.f_forw.f_hname
164*96468787SJake Freeland #define	fu_forw_addr	f_un.f_forw.f_addr
165*96468787SJake Freeland #define	fu_pipe_pname	f_un.f_pipe.f_pname
166*96468787SJake Freeland #define	fu_pipe_pd	f_un.f_pipe.f_procdesc
167*96468787SJake Freeland 
168*96468787SJake Freeland 	/* Book-keeping. */
169*96468787SJake Freeland 	char	f_prevline[MAXSVLINE];		/* last message logged */
170*96468787SJake Freeland 	time_t	f_time;				/* time this was last written */
171*96468787SJake Freeland 	struct logtime f_lasttime;		/* time of last occurrence */
172*96468787SJake Freeland 	int	f_prevpri;			/* pri of f_prevline */
173*96468787SJake Freeland 	size_t	f_prevlen;			/* length of f_prevline */
174*96468787SJake Freeland 	int	f_prevcount;			/* repetition cnt of prevline */
175*96468787SJake Freeland 	u_int	f_repeatcount;			/* number of "repeated" msgs */
176*96468787SJake Freeland 	STAILQ_ENTRY(filed) next;		/* next in linked list */
177*96468787SJake Freeland };
178*96468787SJake Freeland 
179*96468787SJake Freeland #endif /* !_SYSLOGD_H_ */
180