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> 672567168dSJake Freeland #include <sys/nv.h> 6896468787SJake Freeland #include <sys/queue.h> 6996468787SJake Freeland #include <sys/time.h> 7061a29ecaSJake Freeland #include <sys/uio.h> 7196468787SJake Freeland 7296468787SJake Freeland #define SYSLOG_NAMES 7396468787SJake Freeland #include <sys/syslog.h> 7496468787SJake Freeland 7596468787SJake Freeland #include <regex.h> 762567168dSJake Freeland #include <stdbool.h> 772567168dSJake Freeland #include <stdio.h> 7896468787SJake Freeland 7961a29ecaSJake Freeland #include "ttymsg.h" 8061a29ecaSJake Freeland 8196468787SJake Freeland #define MAXLINE 8192 /* maximum line length */ 8296468787SJake Freeland #define MAXSVLINE MAXLINE /* maximum saved line length */ 8396468787SJake Freeland #define MAXUNAMES 20 /* maximum number of user names */ 8496468787SJake Freeland 8596468787SJake Freeland /* Timestamps of log entries. */ 8696468787SJake Freeland struct logtime { 8796468787SJake Freeland struct tm tm; 8896468787SJake Freeland suseconds_t usec; 8996468787SJake Freeland }; 9096468787SJake Freeland 9196468787SJake Freeland enum filt_proptype { 9296468787SJake Freeland FILT_PROP_NOOP, 9396468787SJake Freeland FILT_PROP_MSG, 9496468787SJake Freeland FILT_PROP_HOSTNAME, 9596468787SJake Freeland FILT_PROP_PROGNAME, 9696468787SJake Freeland }; 9796468787SJake Freeland 9896468787SJake Freeland enum filt_cmptype { 9996468787SJake Freeland FILT_CMP_CONTAINS, 10096468787SJake Freeland FILT_CMP_EQUAL, 10196468787SJake Freeland FILT_CMP_STARTS, 10296468787SJake Freeland FILT_CMP_REGEX, 10396468787SJake Freeland }; 10496468787SJake Freeland 10596468787SJake Freeland /* 10696468787SJake Freeland * This structure holds a property-based filter 10796468787SJake Freeland */ 10896468787SJake Freeland struct prop_filter { 10996468787SJake Freeland enum filt_proptype prop_type; 11096468787SJake Freeland enum filt_cmptype cmp_type; 11196468787SJake Freeland uint8_t cmp_flags; 11296468787SJake Freeland #define FILT_FLAG_EXCLUDE (1 << 0) 11396468787SJake Freeland #define FILT_FLAG_EXTENDED (1 << 1) 11496468787SJake Freeland #define FILT_FLAG_ICASE (1 << 2) 11596468787SJake Freeland char *pflt_strval; 11696468787SJake Freeland regex_t *pflt_re; 11796468787SJake Freeland }; 11896468787SJake Freeland 11996468787SJake Freeland enum f_type { 12096468787SJake Freeland F_UNUSED, /* unused entry */ 12196468787SJake Freeland F_FILE, /* regular file */ 12296468787SJake Freeland F_TTY, /* terminal */ 12396468787SJake Freeland F_CONSOLE, /* console terminal */ 12496468787SJake Freeland F_FORW, /* remote machine */ 12596468787SJake Freeland F_USERS, /* list of users */ 12696468787SJake Freeland F_WALL, /* everyone logged on */ 12796468787SJake Freeland F_PIPE, /* pipe to program */ 12896468787SJake Freeland }; 12996468787SJake Freeland 130*ae4f708fSMark Johnston struct forw_addr { 131*ae4f708fSMark Johnston struct sockaddr_storage laddr; 132*ae4f708fSMark Johnston struct sockaddr_storage raddr; 133*ae4f708fSMark Johnston }; 134*ae4f708fSMark Johnston 13596468787SJake Freeland /* 13696468787SJake Freeland * This structure represents the files that will have log 13796468787SJake Freeland * copies printed. 13896468787SJake Freeland * We require f_file to be valid if f_type is F_FILE, F_CONSOLE, F_TTY 13996468787SJake Freeland * or if f_type is F_PIPE and f_pid > 0. 14096468787SJake Freeland */ 14196468787SJake Freeland struct filed { 14296468787SJake Freeland enum f_type f_type; 14396468787SJake Freeland 14496468787SJake Freeland /* Used for filtering. */ 1452567168dSJake Freeland char f_host[MAXHOSTNAMELEN]; /* host from which to recd. */ 1462567168dSJake Freeland char f_program[MAXPATHLEN]; /* program this applies to */ 14796468787SJake Freeland struct prop_filter *f_prop_filter; /* property-based filter */ 14896468787SJake Freeland u_char f_pmask[LOG_NFACILITIES+1]; /* priority mask */ 14996468787SJake Freeland u_char f_pcmp[LOG_NFACILITIES+1]; /* compare priority */ 15096468787SJake Freeland #define PRI_LT 0x1 15196468787SJake Freeland #define PRI_EQ 0x2 15296468787SJake Freeland #define PRI_GT 0x4 15396468787SJake Freeland 15496468787SJake Freeland /* Logging destinations. */ 15596468787SJake Freeland int f_file; /* file descriptor */ 15696468787SJake Freeland int f_flags; /* file-specific flags */ 15796468787SJake Freeland #define FFLAG_SYNC 0x01 15896468787SJake Freeland #define FFLAG_NEEDSYNC 0x02 15996468787SJake Freeland union { 16096468787SJake Freeland char f_uname[MAXUNAMES][MAXLOGNAME]; /* F_WALL, F_USERS */ 16196468787SJake Freeland char f_fname[MAXPATHLEN]; /* F_FILE, F_CONSOLE, F_TTY */ 16296468787SJake Freeland struct { 16396468787SJake Freeland char f_hname[MAXHOSTNAMELEN]; 1644ecbee27SJake Freeland int *f_addr_fds; 1654ecbee27SJake Freeland size_t f_num_addr_fds; 166*ae4f708fSMark Johnston struct forw_addr *f_addrs; 167ad607893SJake Freeland }; /* F_FORW */ 16896468787SJake Freeland struct { 16996468787SJake Freeland char f_pname[MAXPATHLEN]; 17096468787SJake Freeland int f_procdesc; 171d2d180fbSJake Freeland struct deadq_entry *f_dq; 172ad607893SJake Freeland }; /* F_PIPE */ 173ad607893SJake Freeland }; 17496468787SJake Freeland 17596468787SJake Freeland /* Book-keeping. */ 17696468787SJake Freeland char f_prevline[MAXSVLINE]; /* last message logged */ 17796468787SJake Freeland time_t f_time; /* time this was last written */ 17896468787SJake Freeland struct logtime f_lasttime; /* time of last occurrence */ 17996468787SJake Freeland int f_prevpri; /* pri of f_prevline */ 18096468787SJake Freeland size_t f_prevlen; /* length of f_prevline */ 18196468787SJake Freeland int f_prevcount; /* repetition cnt of prevline */ 18296468787SJake Freeland u_int f_repeatcount; /* number of "repeated" msgs */ 18396468787SJake Freeland STAILQ_ENTRY(filed) next; /* next in linked list */ 18496468787SJake Freeland }; 18596468787SJake Freeland 18661a29ecaSJake Freeland /* 18761a29ecaSJake Freeland * List of iovecs to which entries can be appended. 18861a29ecaSJake Freeland * Used for constructing the message to be logged. 18961a29ecaSJake Freeland */ 19061a29ecaSJake Freeland struct iovlist { 19161a29ecaSJake Freeland struct iovec iov[TTYMSG_IOV_MAX]; 19261a29ecaSJake Freeland size_t iovcnt; 19361a29ecaSJake Freeland size_t totalsize; 19461a29ecaSJake Freeland }; 19561a29ecaSJake Freeland 1962567168dSJake Freeland extern const char *ConfFile; 1972567168dSJake Freeland extern char LocalHostName[MAXHOSTNAMELEN]; 1982567168dSJake Freeland 1992567168dSJake Freeland void closelogfiles(void); 2002567168dSJake Freeland void logerror(const char *); 20161a29ecaSJake Freeland int p_open(const char *, pid_t *); 2022567168dSJake Freeland nvlist_t *readconfigfile(const char *); 20361a29ecaSJake Freeland void wallmsg(const struct filed *, struct iovec *, const int); 2042567168dSJake Freeland 20596468787SJake Freeland #endif /* !_SYSLOGD_H_ */ 206