syslogd.h revision 1.1 1 1.1 christos /* $NetBSD: syslogd.h,v 1.1 2008/10/31 16:12:19 christos Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.1 christos * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.1 christos * by Martin Schtte.
9 1.1 christos *
10 1.1 christos * Redistribution and use in source and binary forms, with or without
11 1.1 christos * modification, are permitted provided that the following conditions
12 1.1 christos * are met:
13 1.1 christos * 1. Redistributions of source code must retain the above copyright
14 1.1 christos * notice, this list of conditions and the following disclaimer.
15 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 christos * notice, this list of conditions and the following disclaimer in the
17 1.1 christos * documentation and/or other materials provided with the distribution.
18 1.1 christos * 3. All advertising materials mentioning features or use of this software
19 1.1 christos * must display the following acknowledgement:
20 1.1 christos * This product includes software developed by the NetBSD
21 1.1 christos * Foundation, Inc. and its contributors.
22 1.1 christos * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 christos * contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
37 1.1 christos */
38 1.1 christos #ifndef SYSLOGD_H_
39 1.1 christos #define SYSLOGD_H_
40 1.1 christos /*
41 1.1 christos * hold common data structures and prototypes
42 1.1 christos * for syslogd.c and tls.c
43 1.1 christos *
44 1.1 christos */
45 1.1 christos
46 1.1 christos #include <sys/cdefs.h>
47 1.1 christos #define MAXLINE 1024 /* maximum line length */
48 1.1 christos #define MAXSVLINE 120 /* maximum saved line length */
49 1.1 christos #define DEFUPRI (LOG_USER|LOG_NOTICE)
50 1.1 christos #define DEFSPRI (LOG_KERN|LOG_NOTICE)
51 1.1 christos #define TIMERINTVL 30 /* interval for checking flush, mark */
52 1.1 christos #define TTYMSGTIME 1 /* timeout passed to ttymsg */
53 1.1 christos
54 1.1 christos #include <sys/param.h>
55 1.1 christos #include <sys/socket.h>
56 1.1 christos #include <sys/sysctl.h>
57 1.1 christos #include <sys/types.h>
58 1.1 christos #include <sys/un.h>
59 1.1 christos #include <sys/wait.h>
60 1.1 christos #include <sys/queue.h>
61 1.1 christos #include <netinet/in.h>
62 1.1 christos #include <sys/event.h>
63 1.1 christos #include <event.h>
64 1.1 christos
65 1.1 christos #include <assert.h>
66 1.1 christos #include <ctype.h>
67 1.1 christos #include <errno.h>
68 1.1 christos #include <fcntl.h>
69 1.1 christos #include <grp.h>
70 1.1 christos #include <locale.h>
71 1.1 christos #include <netdb.h>
72 1.1 christos #include <pwd.h>
73 1.1 christos #include <signal.h>
74 1.1 christos #include <stdarg.h>
75 1.1 christos #include <stdio.h>
76 1.1 christos #include <stdlib.h>
77 1.1 christos #include <string.h>
78 1.1 christos #include <unistd.h>
79 1.1 christos #include <stdbool.h>
80 1.1 christos #include <utmp.h>
81 1.1 christos #ifdef __NetBSD_Version__
82 1.1 christos #include <util.h>
83 1.1 christos #include "utmpentry.h"
84 1.1 christos #endif /* __NetBSD_Version__ */
85 1.1 christos #ifdef __FreeBSD_version
86 1.1 christos #include <libutil.h>
87 1.1 christos #include <sys/stat.h>
88 1.1 christos #include <sys/uio.h>
89 1.1 christos #include <limits.h>
90 1.1 christos #endif /* __FreeBSD_version */
91 1.1 christos
92 1.1 christos #ifndef DISABLE_TLS
93 1.1 christos #include <netinet/tcp.h>
94 1.1 christos #include <openssl/ssl.h>
95 1.1 christos #endif /* !DISABLE_TLS */
96 1.1 christos
97 1.1 christos #include <sys/stdint.h>
98 1.1 christos #include <sys/resource.h>
99 1.1 christos
100 1.1 christos /* additional queue macros copied from FreeBSD */
101 1.1 christos #ifndef SLIST_FOREACH_SAFE
102 1.1 christos #define SLIST_FOREACH_SAFE(var, head, field, tvar) \
103 1.1 christos for ((var) = SLIST_FIRST((head)); \
104 1.1 christos (var) && ((tvar) = SLIST_NEXT((var), field), 1); \
105 1.1 christos (var) = (tvar))
106 1.1 christos #endif /* !SLIST_FOREACH_SAFE */
107 1.1 christos #ifndef STAILQ_FOREACH_SAFE
108 1.1 christos #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
109 1.1 christos for ((var) = STAILQ_FIRST((head)); \
110 1.1 christos (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
111 1.1 christos (var) = (tvar))
112 1.1 christos #endif /* !STAILQ_FOREACH_SAFE */
113 1.1 christos #ifndef STAILQ_LAST
114 1.1 christos #define STAILQ_LAST(head, type, field) \
115 1.1 christos (STAILQ_EMPTY((head)) ? \
116 1.1 christos NULL : \
117 1.1 christos ((struct type *) \
118 1.1 christos ((char *)((head)->stqh_last) - offsetof(struct type, field))))
119 1.1 christos #endif /* !STAILQ_LAST */
120 1.1 christos #ifndef STAILQ_CONCAT
121 1.1 christos #define STAILQ_CONCAT(head1, head2) do { \
122 1.1 christos if (!STAILQ_EMPTY((head2))) { \
123 1.1 christos *(head1)->stqh_last = (head2)->stqh_first; \
124 1.1 christos (head1)->stqh_last = (head2)->stqh_last; \
125 1.1 christos STAILQ_INIT((head2)); \
126 1.1 christos } \
127 1.1 christos } while (0)
128 1.1 christos #endif /* !STAILQ_CONCAT */
129 1.1 christos #ifndef TAILQ_CONCAT
130 1.1 christos #define TAILQ_CONCAT(head1, head2, field) do { \
131 1.1 christos if (!TAILQ_EMPTY(head2)) { \
132 1.1 christos *(head1)->tqh_last = (head2)->tqh_first; \
133 1.1 christos (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
134 1.1 christos (head1)->tqh_last = (head2)->tqh_last; \
135 1.1 christos TAILQ_INIT((head2)); \
136 1.1 christos } \
137 1.1 christos } while (0)
138 1.1 christos #endif /* !TAILQ_CONCAT */
139 1.1 christos
140 1.1 christos #include "pathnames.h"
141 1.1 christos #include <sys/syslog.h>
142 1.1 christos
143 1.1 christos /* some differences between the BSDs */
144 1.1 christos #ifdef __FreeBSD_version
145 1.1 christos #undef _PATH_UNIX
146 1.1 christos #define _PATH_UNIX "kernel"
147 1.1 christos #define HAVE_STRNDUP 0
148 1.1 christos #endif /* __FreeBSD_version */
149 1.1 christos
150 1.1 christos #ifdef __NetBSD_Version__
151 1.1 christos #define HAVE_STRNDUP 1
152 1.1 christos #define HAVE_DEHUMANIZE_NUMBER 1
153 1.1 christos #endif /* __NetBSD_Version__ */
154 1.1 christos
155 1.1 christos #ifndef HAVE_DEHUMANIZE_NUMBER /* not in my 4.0-STABLE yet */
156 1.1 christos extern int dehumanize_number(const char *str, int64_t *size);
157 1.1 christos #endif /* !HAVE_DEHUMANIZE_NUMBER */
158 1.1 christos
159 1.1 christos #if !HAVE_STRNDUP
160 1.1 christos char *strndup(const char *str, size_t n);
161 1.1 christos #endif /* !HAVE_STRNDUP */
162 1.1 christos
163 1.1 christos #ifdef LIBWRAP
164 1.1 christos #include <tcpd.h>
165 1.1 christos #endif
166 1.1 christos
167 1.1 christos #define FDMASK(fd) (1 << (fd))
168 1.1 christos
169 1.1 christos #define A_CNT(x) (sizeof((x)) / sizeof((x)[0]))
170 1.1 christos
171 1.1 christos /* debug messages with categories */
172 1.1 christos #define D_NONE 0
173 1.1 christos #define D_CALL 1 /* function calls */
174 1.1 christos #define D_DATA 2 /* syslog message reading/formatting */
175 1.1 christos #define D_NET 4 /* sockets/network */
176 1.1 christos #define D_FILE 8 /* local files */
177 1.1 christos #define D_TLS 16 /* TLS */
178 1.1 christos #define D_PARSE 32 /* configuration/parsing */
179 1.1 christos #define D_EVENT 64 /* libevent */
180 1.1 christos #define D_BUFFER 128 /* message queues */
181 1.1 christos #define D_MEM 256 /* malloc/free */
182 1.1 christos #define D_MEM2 1024 /* every single malloc/free */
183 1.1 christos #define D_SIGN 2048 /* -sign */
184 1.1 christos #define D_MISC 4096 /* everything else */
185 1.1 christos #define D_ALL (D_CALL | D_DATA | D_NET | D_FILE | D_TLS | D_PARSE | \
186 1.1 christos D_EVENT | D_BUFFER | D_MEM | D_MEM2 | D_SIGN | D_MISC)
187 1.1 christos #define D_DEFAULT (D_CALL | D_NET | D_FILE | D_TLS | D_MISC)
188 1.1 christos
189 1.1 christos
190 1.1 christos /* build with -DNDEBUG to remove all assert()s and DPRINTF()s */
191 1.1 christos #ifdef NDEBUG
192 1.1 christos #define DPRINTF(x, ...) (void)0
193 1.1 christos #else
194 1.1 christos #define DPRINTF(x, ...) /*LINTED null effect */(void)(Debug & (x) \
195 1.1 christos ? (printf("%s:%s:%s:%.4d\t", make_timestamp(NULL, true), \
196 1.1 christos __FILE__, __func__, __LINE__), printf(__VA_ARGS__)) : 0)
197 1.1 christos #endif
198 1.1 christos
199 1.1 christos /* shortcuts for libevent */
200 1.1 christos #define EVENT_ADD(x) do { \
201 1.1 christos DPRINTF(D_EVENT, "event_add(%s@%p)\n", #x, x); \
202 1.1 christos if (event_add(x, NULL) == -1) { \
203 1.1 christos DPRINTF(D_EVENT, "Failure in event_add()\n"); \
204 1.1 christos } \
205 1.1 christos } while (/*CONSTCOND*/0)
206 1.1 christos #define RETRYEVENT_ADD(x) do { \
207 1.1 christos struct timeval _tv; \
208 1.1 christos _tv.tv_sec = 0; \
209 1.1 christos _tv.tv_usec = TLS_RETRY_EVENT_USEC; \
210 1.1 christos DPRINTF(D_EVENT, "retryevent_add(%s@%p)\n", #x, x); \
211 1.1 christos if (event_add(x, &_tv) == -1) { \
212 1.1 christos DPRINTF(D_EVENT, "Failure in event_add()\n"); \
213 1.1 christos } \
214 1.1 christos } while (/*CONSTCOND*/0)
215 1.1 christos #define DEL_EVENT(x) do { \
216 1.1 christos DPRINTF(D_MEM2, "DEL_EVENT(%s@%p)\n", #x, x); \
217 1.1 christos if ((x) && (event_del(x) == -1)) { \
218 1.1 christos DPRINTF(D_EVENT, "Failure in event_del()\n"); \
219 1.1 christos } \
220 1.1 christos } while (/*CONSTCOND*/0)
221 1.1 christos
222 1.1 christos /* safe calls to free() */
223 1.1 christos #define FREEPTR(x) if (x) { \
224 1.1 christos DPRINTF(D_MEM2, "free(%s@%p)\n", #x, x); \
225 1.1 christos free(x); x = NULL; }
226 1.1 christos #define FREE_SSL(x) if (x) { \
227 1.1 christos DPRINTF(D_MEM2, "SSL_free(%s@%p)\n", #x, x); \
228 1.1 christos SSL_free(x); x = NULL; }
229 1.1 christos #define FREE_SSL_CTX(x) if (x) { \
230 1.1 christos DPRINTF(D_MEM2, "SSL_CTX_free(%s@%p)\n", #x, x); \
231 1.1 christos SSL_CTX_free(x); x = NULL; }
232 1.1 christos
233 1.1 christos /* reference counting macros for buffers */
234 1.1 christos #define NEWREF(x) ((x) ? (DPRINTF(D_BUFFER, "inc refcount of " #x \
235 1.1 christos " @ %p: %zu --> %zu\n", (x), (x)->refcount, \
236 1.1 christos (x)->refcount + 1), (x)->refcount++, (x))\
237 1.1 christos : (DPRINTF(D_BUFFER, "inc refcount of NULL!\n"), NULL))
238 1.1 christos #define DELREF(x) /*LINTED null effect*/(void)((x) ? (DPRINTF(D_BUFFER, "dec refcount of " #x \
239 1.1 christos " @ %p: %zu --> %zu\n", (x), (x)->refcount, \
240 1.1 christos (x)->refcount - 1), buf_msg_free(x), NULL) \
241 1.1 christos : (DPRINTF(D_BUFFER, "dec refcount of NULL!\n"), NULL))
242 1.1 christos
243 1.1 christos /* assumption:
244 1.1 christos * - malloc()/calloc() only fails if not enough memory available
245 1.1 christos * - once init() has set up all global variables etc.
246 1.1 christos * the bulk of available memory is used for buffers
247 1.1 christos * and can be freed if necessary
248 1.1 christos */
249 1.1 christos #define MALLOC(ptr, size) do { \
250 1.1 christos while(!(ptr = malloc(size))) { \
251 1.1 christos DPRINTF(D_MEM, "Unable to allocate memory"); \
252 1.1 christos message_allqueues_purge(); \
253 1.1 christos } \
254 1.1 christos DPRINTF(D_MEM2, "MALLOC(%s@%p, %zu)\n", #ptr, ptr, size); \
255 1.1 christos } while (/*CONSTCOND*/0)
256 1.1 christos
257 1.1 christos #define CALLOC(ptr, size) do { \
258 1.1 christos while(!(ptr = calloc(1, size))) { \
259 1.1 christos DPRINTF(D_MEM, "Unable to allocate memory"); \
260 1.1 christos message_allqueues_purge(); \
261 1.1 christos } \
262 1.1 christos DPRINTF(D_MEM2, "CALLOC(%s@%p, %zu)\n", #ptr, ptr, size); \
263 1.1 christos } while (/*CONSTCOND*/0)
264 1.1 christos
265 1.1 christos /* define strlen(NULL) to be 0 */
266 1.1 christos #define SAFEstrlen(x) ((x) ? strlen(x) : 0)
267 1.1 christos
268 1.1 christos /* shorthand to block/restore signals for the duration of one function */
269 1.1 christos #define BLOCK_SIGNALS(omask, newmask) do { \
270 1.1 christos sigemptyset(&newmask); \
271 1.1 christos sigaddset(&newmask, SIGHUP); \
272 1.1 christos sigaddset(&newmask, SIGALRM); \
273 1.1 christos sigprocmask(SIG_BLOCK, &newmask, &omask); \
274 1.1 christos } while (/*CONSTCOND*/0)
275 1.1 christos
276 1.1 christos #define RESTORE_SIGNALS(omask) sigprocmask(SIG_SETMASK, &omask, NULL)
277 1.1 christos
278 1.1 christos /* small optimization to call send_queue() only if queue has elements */
279 1.1 christos #define SEND_QUEUE(f) do { \
280 1.1 christos if ((f)->f_qelements) \
281 1.1 christos send_queue(0, 0, f); \
282 1.1 christos } while (/*CONSTCOND*/0)
283 1.1 christos
284 1.1 christos #define MAXUNAMES 20 /* maximum number of user names */
285 1.1 christos #define BSD_TIMESTAMPLEN 14+1
286 1.1 christos #define MAX_TIMESTAMPLEN 31+1
287 1.1 christos
288 1.1 christos /* maximum field lengths in syslog-protocol */
289 1.1 christos #define PRI_MAX 5
290 1.1 christos #define HOST_MAX 255
291 1.1 christos #define APPNAME_MAX 48
292 1.1 christos #define PROCID_MAX 128
293 1.1 christos #define MSGID_MAX 32
294 1.1 christos /* longest possible header length */
295 1.1 christos #define HEADER_LEN_MAX (PRI_MAX + 1 + 1 + MAX_TIMESTAMPLEN + 1 + HOST_MAX \
296 1.1 christos + 1 + APPNAME_MAX + 1 + PROCID_MAX + 1 + MSGID_MAX)
297 1.1 christos
298 1.1 christos /* allowed number of priorities by IETF standards */
299 1.1 christos #define IETF_NUM_PRIVALUES 192
300 1.1 christos
301 1.1 christos /* check if message with fac/sev belogs to a destination f */
302 1.1 christos #define MATCH_PRI(f, fac, sev) \
303 1.1 christos ( (((f)->f_pcmp[fac] & PRI_EQ) && ((f)->f_pmask[fac] == (sev))) \
304 1.1 christos ||(((f)->f_pcmp[fac] & PRI_LT) && ((f)->f_pmask[fac] < (sev))) \
305 1.1 christos ||(((f)->f_pcmp[fac] & PRI_GT) && ((f)->f_pmask[fac] > (sev))) \
306 1.1 christos )
307 1.1 christos
308 1.1 christos /* shorthand to test Byte Order Mark which indicates UTF-8 content */
309 1.1 christos #define IS_BOM(p) ( \
310 1.1 christos (p)[0] != '\0' && (unsigned char)(p)[0] == (unsigned char)0xEF && \
311 1.1 christos (p)[1] != '\0' && (unsigned char)(p)[1] == (unsigned char)0xBB && \
312 1.1 christos (p)[2] != '\0' && (unsigned char)(p)[2] == (unsigned char)0xBF)
313 1.1 christos
314 1.1 christos /* message buffer container used for processing, formatting, and queueing */
315 1.1 christos struct buf_msg {
316 1.1 christos size_t refcount;
317 1.1 christos int pri;
318 1.1 christos int flags;
319 1.1 christos char *timestamp;
320 1.1 christos char *recvhost;
321 1.1 christos char *host;
322 1.1 christos char *prog;
323 1.1 christos char *pid;
324 1.1 christos char *msgid;
325 1.1 christos char *sd; /* structured data */
326 1.1 christos char *msg; /* message content */
327 1.1 christos char *msgorig; /* in case we advance *msg beyond header fields
328 1.1 christos we still want to free() the original ptr */
329 1.1 christos size_t msglen; /* strlen(msg) */
330 1.1 christos size_t msgsize; /* allocated memory size */
331 1.1 christos size_t tlsprefixlen; /* bytes for the TLS length prefix */
332 1.1 christos size_t prilen; /* bytes for priority and version */
333 1.1 christos };
334 1.1 christos
335 1.1 christos /* queue of messages */
336 1.1 christos struct buf_queue {
337 1.1 christos struct buf_msg* msg;
338 1.1 christos STAILQ_ENTRY(buf_queue) entries;
339 1.1 christos };
340 1.1 christos STAILQ_HEAD(buf_queue_head, buf_queue);
341 1.1 christos
342 1.1 christos /* a pair of a socket and an associated event object */
343 1.1 christos struct socketEvent {
344 1.1 christos int fd;
345 1.1 christos struct event *ev;
346 1.1 christos };
347 1.1 christos
348 1.1 christos /*
349 1.1 christos * Flags to logmsg().
350 1.1 christos */
351 1.1 christos #define IGN_CONS 0x001 /* don't print on console */
352 1.1 christos #define SYNC_FILE 0x002 /* do fsync on file after printing */
353 1.1 christos #define ADDDATE 0x004 /* add a date to the message */
354 1.1 christos #define MARK 0x008 /* this message is a mark */
355 1.1 christos #define ISKERNEL 0x010 /* kernel generated message */
356 1.1 christos #define BSDSYSLOG 0x020 /* line in traditional BSD Syslog format */
357 1.1 christos #define SIGN_MSG 0x040 /* syslog-sign data, not signed again */
358 1.1 christos
359 1.1 christos /* strategies for message_queue_purge() */
360 1.1 christos #define PURGE_OLDEST 1
361 1.1 christos #define PURGE_BY_PRIORITY 2
362 1.1 christos
363 1.1 christos /*
364 1.1 christos * This structure represents the files that will have log
365 1.1 christos * copies printed.
366 1.1 christos * We require f_file to be valid if f_type is F_FILE, F_CONSOLE, F_TTY,
367 1.1 christos * or if f_type is F_PIPE and f_pid > 0.
368 1.1 christos */
369 1.1 christos
370 1.1 christos struct filed {
371 1.1 christos struct filed *f_next; /* next in linked list */
372 1.1 christos short f_type; /* entry type, see below */
373 1.1 christos short f_file; /* file descriptor */
374 1.1 christos time_t f_time; /* time this was last written */
375 1.1 christos char *f_host; /* host from which to record */
376 1.1 christos u_char f_pmask[LOG_NFACILITIES+1]; /* priority mask */
377 1.1 christos u_char f_pcmp[LOG_NFACILITIES+1]; /* compare priority */
378 1.1 christos #define PRI_LT 0x1
379 1.1 christos #define PRI_EQ 0x2
380 1.1 christos #define PRI_GT 0x4
381 1.1 christos char *f_program; /* program this applies to */
382 1.1 christos union {
383 1.1 christos char f_uname[MAXUNAMES][UT_NAMESIZE+1];
384 1.1 christos struct {
385 1.1 christos char f_hname[MAXHOSTNAMELEN];
386 1.1 christos struct addrinfo *f_addr;
387 1.1 christos } f_forw; /* UDP forwarding address */
388 1.1 christos #ifndef DISABLE_TLS
389 1.1 christos struct {
390 1.1 christos SSL *ssl; /* SSL object */
391 1.1 christos struct tls_conn_settings *tls_conn; /* certificate info */
392 1.1 christos } f_tls; /* TLS forwarding address */
393 1.1 christos #endif /* !DISABLE_TLS */
394 1.1 christos char f_fname[MAXPATHLEN];
395 1.1 christos struct {
396 1.1 christos char f_pname[MAXPATHLEN];
397 1.1 christos pid_t f_pid;
398 1.1 christos } f_pipe;
399 1.1 christos } f_un;
400 1.1 christos #ifndef DISABLE_SIGN
401 1.1 christos struct signature_group_t *f_sg; /* one signature group */
402 1.1 christos #endif /* !DISABLE_SIGN */
403 1.1 christos struct buf_queue_head f_qhead; /* undelivered msgs queue */
404 1.1 christos size_t f_qelements; /* elements in queue */
405 1.1 christos size_t f_qsize; /* size of queue in bytes */
406 1.1 christos struct buf_msg *f_prevmsg; /* last message logged */
407 1.1 christos struct event *f_sq_event; /* timer for send_queue() */
408 1.1 christos int f_prevcount; /* repetition cnt of prevmsg */
409 1.1 christos int f_repeatcount; /* number of "repeated" msgs */
410 1.1 christos int f_lasterror; /* last error on writev() */
411 1.1 christos int f_flags; /* file-specific flags */
412 1.1 christos #define FFLAG_SYNC 0x01 /* for F_FILE: fsync after every msg */
413 1.1 christos #define FFLAG_FULL 0x02 /* for F_FILE | F_PIPE: write PRI header */
414 1.1 christos #define FFLAG_SIGN 0x04 /* for syslog-sign with SG="3":
415 1.1 christos * sign the messages to this destination */
416 1.1 christos };
417 1.1 christos
418 1.1 christos #ifndef DISABLE_TLS
419 1.1 christos
420 1.1 christos /* linked list for allowed TLS peer credentials
421 1.1 christos * (one for fingerprint, one for cert-files)
422 1.1 christos */
423 1.1 christos SLIST_HEAD(peer_cred_head, peer_cred);
424 1.1 christos struct peer_cred {
425 1.1 christos SLIST_ENTRY(peer_cred) entries;
426 1.1 christos char *data;
427 1.1 christos };
428 1.1 christos
429 1.1 christos /* config options for TLS server-side */
430 1.1 christos struct tls_global_options_t {
431 1.1 christos SSL_CTX *global_TLS_CTX;
432 1.1 christos struct peer_cred_head fprint_head; /* trusted client fingerprints */
433 1.1 christos struct peer_cred_head cert_head; /* trusted client cert files */
434 1.1 christos char *keyfile; /* file with private key */
435 1.1 christos char *certfile; /* file with own certificate */
436 1.1 christos char *CAfile; /* file with CA certificate */
437 1.1 christos char *CAdir; /* alternative: path to directory with CA certs */
438 1.1 christos char *x509verify; /* level of peer verification */
439 1.1 christos char *bindhost; /* hostname/IP to bind to */
440 1.1 christos char *bindport; /* port/service to bind to */
441 1.1 christos char *server; /* if !NULL: do not listen to incoming TLS */
442 1.1 christos char *gen_cert; /* if !NULL: generate self-signed certificate */
443 1.1 christos };
444 1.1 christos
445 1.1 christos /* TLS needs three sets of sockets:
446 1.1 christos * - listening sockets: a fixed size array TLS_Listen_Set, just like finet for UDP.
447 1.1 christos * - outgoing connections: managed as part of struct filed.
448 1.1 christos * - incoming connections: variable sized, thus a linked list TLS_Incoming.
449 1.1 christos */
450 1.1 christos /* every connection has its own input buffer with status
451 1.1 christos * variables for message reading */
452 1.1 christos SLIST_HEAD(TLS_Incoming, TLS_Incoming_Conn);
453 1.1 christos
454 1.1 christos struct TLS_Incoming_Conn {
455 1.1 christos SLIST_ENTRY(TLS_Incoming_Conn) entries;
456 1.1 christos struct tls_conn_settings *tls_conn;
457 1.1 christos int socket;
458 1.1 christos char *inbuf; /* input buffer */
459 1.1 christos size_t inbuflen;
460 1.1 christos size_t cur_msg_len; /* length of current msg */
461 1.1 christos size_t cur_msg_start; /* beginning of current msg */
462 1.1 christos size_t read_pos; /* ring buffer position to write to */
463 1.1 christos size_t errorcount; /* to close faulty connections */
464 1.1 christos bool closenow; /* close connection as soon as buffer processed */
465 1.1 christos bool dontsave; /* for receiving oversized messages w/o saving them */
466 1.1 christos };
467 1.1 christos
468 1.1 christos #endif /* !DISABLE_TLS */
469 1.1 christos
470 1.1 christos #endif /*SYSLOGD_H_*/
471