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