xref: /freebsd/usr.sbin/syslogd/syslogd.h (revision 2567168dc49869475db79176bf5f6ae9761bc75a)
196468787SJake Freeland /*-
296468787SJake Freeland  * SPDX-License-Identifier: BSD-3-Clause
396468787SJake Freeland  *
496468787SJake Freeland  * Copyright (c) 1983, 1988, 1993, 1994
596468787SJake Freeland  *	The Regents of the University of California.  All rights reserved.
696468787SJake Freeland  *
796468787SJake Freeland  * Redistribution and use in source and binary forms, with or without
896468787SJake Freeland  * modification, are permitted provided that the following conditions
996468787SJake Freeland  * are met:
1096468787SJake Freeland  * 1. Redistributions of source code must retain the above copyright
1196468787SJake Freeland  *    notice, this list of conditions and the following disclaimer.
1296468787SJake Freeland  * 2. Redistributions in binary form must reproduce the above copyright
1396468787SJake Freeland  *    notice, this list of conditions and the following disclaimer in the
1496468787SJake Freeland  *    documentation and/or other materials provided with the distribution.
1596468787SJake Freeland  * 3. Neither the name of the University nor the names of its contributors
1696468787SJake Freeland  *    may be used to endorse or promote products derived from this software
1796468787SJake Freeland  *    without specific prior written permission.
1896468787SJake Freeland  *
1996468787SJake Freeland  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2096468787SJake Freeland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2196468787SJake Freeland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2296468787SJake Freeland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2396468787SJake Freeland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2496468787SJake Freeland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2596468787SJake Freeland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2696468787SJake Freeland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2796468787SJake Freeland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2896468787SJake Freeland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2996468787SJake Freeland  * SUCH DAMAGE.
3096468787SJake Freeland  */
3196468787SJake Freeland /*-
3296468787SJake Freeland  * SPDX-License-Identifier: BSD-2-Clause
3396468787SJake Freeland  *
3496468787SJake Freeland  * Copyright (c) 2018 Prodrive Technologies, https://prodrive-technologies.com/
3596468787SJake Freeland  * Author: Ed Schouten <ed@FreeBSD.org>
3696468787SJake Freeland  * Copyright (c) 2023 The FreeBSD Foundation
3796468787SJake Freeland  *
3896468787SJake Freeland  * This software was developed by Jake Freeland <jfree@FreeBSD.org>
3996468787SJake Freeland  * under sponsorship from the FreeBSD Foundation.
4096468787SJake Freeland  *
4196468787SJake Freeland  * Redistribution and use in source and binary forms, with or without
4296468787SJake Freeland  * modification, are permitted provided that the following conditions
4396468787SJake Freeland  * are met:
4496468787SJake Freeland  * 1. Redistributions of source code must retain the above copyright
4596468787SJake Freeland  *    notice, this list of conditions and the following disclaimer.
4696468787SJake Freeland  * 2. Redistributions in binary form must reproduce the above copyright
4796468787SJake Freeland  *    notice, this list of conditions and the following disclaimer in the
4896468787SJake Freeland  *    documentation and/or other materials provided with the distribution.
4996468787SJake Freeland  *
5096468787SJake Freeland  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
5196468787SJake Freeland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5296468787SJake Freeland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5396468787SJake Freeland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
5496468787SJake Freeland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5596468787SJake Freeland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5696468787SJake Freeland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5796468787SJake Freeland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5896468787SJake Freeland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5996468787SJake Freeland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6096468787SJake Freeland  * SUCH DAMAGE.
6196468787SJake Freeland  */
6296468787SJake Freeland 
6396468787SJake Freeland #ifndef _SYSLOGD_H_
6496468787SJake Freeland #define _SYSLOGD_H_
6596468787SJake Freeland 
6696468787SJake Freeland #include <sys/param.h>
67*2567168dSJake Freeland #include <sys/nv.h>
6896468787SJake Freeland #include <sys/queue.h>
6996468787SJake Freeland #include <sys/time.h>
7096468787SJake Freeland 
7196468787SJake Freeland #define SYSLOG_NAMES
7296468787SJake Freeland #include <sys/syslog.h>
7396468787SJake Freeland 
7496468787SJake Freeland #include <regex.h>
75*2567168dSJake Freeland #include <stdbool.h>
76*2567168dSJake Freeland #include <stdio.h>
7796468787SJake Freeland 
7896468787SJake Freeland #define	MAXLINE		8192		/* maximum line length */
7996468787SJake Freeland #define	MAXSVLINE	MAXLINE		/* maximum saved line length */
8096468787SJake Freeland #define	MAXUNAMES	20		/* maximum number of user names */
8196468787SJake Freeland 
8296468787SJake Freeland /* Timestamps of log entries. */
8396468787SJake Freeland struct logtime {
8496468787SJake Freeland 	struct tm	tm;
8596468787SJake Freeland 	suseconds_t	usec;
8696468787SJake Freeland };
8796468787SJake Freeland 
8896468787SJake Freeland enum filt_proptype {
8996468787SJake Freeland 	FILT_PROP_NOOP,
9096468787SJake Freeland 	FILT_PROP_MSG,
9196468787SJake Freeland 	FILT_PROP_HOSTNAME,
9296468787SJake Freeland 	FILT_PROP_PROGNAME,
9396468787SJake Freeland };
9496468787SJake Freeland 
9596468787SJake Freeland enum filt_cmptype {
9696468787SJake Freeland 	FILT_CMP_CONTAINS,
9796468787SJake Freeland 	FILT_CMP_EQUAL,
9896468787SJake Freeland 	FILT_CMP_STARTS,
9996468787SJake Freeland 	FILT_CMP_REGEX,
10096468787SJake Freeland };
10196468787SJake Freeland 
10296468787SJake Freeland /*
10396468787SJake Freeland  * This structure holds a property-based filter
10496468787SJake Freeland  */
10596468787SJake Freeland struct prop_filter {
10696468787SJake Freeland 	enum filt_proptype prop_type;
10796468787SJake Freeland 	enum filt_cmptype cmp_type;
10896468787SJake Freeland 	uint8_t cmp_flags;
10996468787SJake Freeland #define	FILT_FLAG_EXCLUDE	(1 << 0)
11096468787SJake Freeland #define	FILT_FLAG_EXTENDED	(1 << 1)
11196468787SJake Freeland #define	FILT_FLAG_ICASE		(1 << 2)
11296468787SJake Freeland 	char *pflt_strval;
11396468787SJake Freeland 	regex_t *pflt_re;
11496468787SJake Freeland };
11596468787SJake Freeland 
11696468787SJake Freeland enum f_type {
11796468787SJake Freeland 	F_UNUSED,	/* unused entry */
11896468787SJake Freeland 	F_FILE,		/* regular file */
11996468787SJake Freeland 	F_TTY,		/* terminal */
12096468787SJake Freeland 	F_CONSOLE,	/* console terminal */
12196468787SJake Freeland 	F_FORW,		/* remote machine */
12296468787SJake Freeland 	F_USERS,	/* list of users */
12396468787SJake Freeland 	F_WALL,		/* everyone logged on */
12496468787SJake Freeland 	F_PIPE,		/* pipe to program */
12596468787SJake Freeland };
12696468787SJake Freeland 
12796468787SJake Freeland /*
12896468787SJake Freeland  * This structure represents the files that will have log
12996468787SJake Freeland  * copies printed.
13096468787SJake Freeland  * We require f_file to be valid if f_type is F_FILE, F_CONSOLE, F_TTY
13196468787SJake Freeland  * or if f_type is F_PIPE and f_pid > 0.
13296468787SJake Freeland  */
13396468787SJake Freeland struct filed {
13496468787SJake Freeland 	enum f_type f_type;
13596468787SJake Freeland 
13696468787SJake Freeland 	/* Used for filtering. */
137*2567168dSJake Freeland 	char	f_host[MAXHOSTNAMELEN];		/* host from which to recd. */
138*2567168dSJake Freeland 	char	f_program[MAXPATHLEN];		/* program this applies to */
13996468787SJake Freeland 	struct prop_filter *f_prop_filter;	/* property-based filter */
14096468787SJake Freeland 	u_char	f_pmask[LOG_NFACILITIES+1];	/* priority mask */
14196468787SJake Freeland 	u_char	f_pcmp[LOG_NFACILITIES+1];	/* compare priority */
14296468787SJake Freeland #define PRI_LT	0x1
14396468787SJake Freeland #define PRI_EQ	0x2
14496468787SJake Freeland #define PRI_GT	0x4
14596468787SJake Freeland 
14696468787SJake Freeland 	/* Logging destinations. */
14796468787SJake Freeland 	int	f_file;				/* file descriptor */
14896468787SJake Freeland 	int	f_flags;			/* file-specific flags */
14996468787SJake Freeland #define	FFLAG_SYNC	0x01
15096468787SJake Freeland #define	FFLAG_NEEDSYNC	0x02
15196468787SJake Freeland 	union {
15296468787SJake Freeland 		char	f_uname[MAXUNAMES][MAXLOGNAME];	/* F_WALL, F_USERS */
15396468787SJake Freeland 		char	f_fname[MAXPATHLEN];	/* F_FILE, F_CONSOLE, F_TTY */
15496468787SJake Freeland 		struct {
15596468787SJake Freeland 			char	f_hname[MAXHOSTNAMELEN];
15696468787SJake Freeland 			struct addrinfo *f_addr;
157ad607893SJake Freeland 		};				/* F_FORW */
15896468787SJake Freeland 		struct {
15996468787SJake Freeland 			char	f_pname[MAXPATHLEN];
16096468787SJake Freeland 			int	f_procdesc;
161ad607893SJake Freeland 		};				/* F_PIPE */
162ad607893SJake Freeland 	};
16396468787SJake Freeland 
16496468787SJake Freeland 	/* Book-keeping. */
16596468787SJake Freeland 	char	f_prevline[MAXSVLINE];		/* last message logged */
16696468787SJake Freeland 	time_t	f_time;				/* time this was last written */
16796468787SJake Freeland 	struct logtime f_lasttime;		/* time of last occurrence */
16896468787SJake Freeland 	int	f_prevpri;			/* pri of f_prevline */
16996468787SJake Freeland 	size_t	f_prevlen;			/* length of f_prevline */
17096468787SJake Freeland 	int	f_prevcount;			/* repetition cnt of prevline */
17196468787SJake Freeland 	u_int	f_repeatcount;			/* number of "repeated" msgs */
17296468787SJake Freeland 	STAILQ_ENTRY(filed) next;		/* next in linked list */
17396468787SJake Freeland };
17496468787SJake Freeland 
175*2567168dSJake Freeland extern const char *ConfFile;
176*2567168dSJake Freeland extern char LocalHostName[MAXHOSTNAMELEN];
177*2567168dSJake Freeland 
178*2567168dSJake Freeland void closelogfiles(void);
179*2567168dSJake Freeland void logerror(const char *);
180*2567168dSJake Freeland nvlist_t *readconfigfile(const char *);
181*2567168dSJake Freeland 
18296468787SJake Freeland #endif /* !_SYSLOGD_H_ */
183