Home | History | Annotate | Line # | Download | only in syslogd
syslogd.h revision 1.3.6.1
      1  1.3.6.1      yamt /*	$NetBSD: syslogd.h,v 1.3.6.1 2014/05/22 11:43:10 yamt 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.2   minskim  * hold common data structures and prototypes
     42      1.1  christos  * for syslogd.c and tls.c
     43      1.2   minskim  *
     44      1.1  christos  */
     45      1.2   minskim 
     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 #include "pathnames.h"
    101      1.1  christos #include <sys/syslog.h>
    102      1.1  christos 
    103      1.1  christos /* some differences between the BSDs  */
    104      1.1  christos #ifdef __FreeBSD_version
    105      1.1  christos #undef _PATH_UNIX
    106      1.1  christos #define _PATH_UNIX "kernel"
    107      1.1  christos #define HAVE_STRNDUP 0
    108      1.1  christos #endif /* __FreeBSD_version */
    109      1.1  christos 
    110      1.1  christos #ifdef __NetBSD_Version__
    111      1.1  christos #define HAVE_STRNDUP 1
    112      1.1  christos #define HAVE_DEHUMANIZE_NUMBER 1
    113      1.1  christos #endif /* __NetBSD_Version__ */
    114      1.1  christos 
    115      1.1  christos #ifndef HAVE_DEHUMANIZE_NUMBER	/* not in my 4.0-STABLE yet */
    116      1.1  christos extern int dehumanize_number(const char *str, int64_t *size);
    117      1.1  christos #endif /* !HAVE_DEHUMANIZE_NUMBER */
    118      1.1  christos 
    119      1.1  christos #if !HAVE_STRNDUP
    120      1.1  christos char *strndup(const char *str, size_t n);
    121      1.1  christos #endif /* !HAVE_STRNDUP */
    122      1.1  christos 
    123      1.1  christos #ifdef LIBWRAP
    124      1.1  christos #include <tcpd.h>
    125      1.1  christos #endif
    126      1.1  christos 
    127      1.1  christos #define FDMASK(fd)	(1 << (fd))
    128      1.1  christos 
    129      1.1  christos #define A_CNT(x)	(sizeof((x)) / sizeof((x)[0]))
    130      1.1  christos 
    131      1.1  christos /* debug messages with categories */
    132      1.1  christos #define D_NONE	   0
    133      1.1  christos #define D_CALL	   1	/* function calls */
    134      1.1  christos #define D_DATA	   2	/* syslog message reading/formatting */
    135      1.1  christos #define D_NET	   4	/* sockets/network */
    136      1.1  christos #define D_FILE	   8	/* local files */
    137      1.1  christos #define D_TLS	  16	/* TLS */
    138      1.1  christos #define D_PARSE	  32	/* configuration/parsing */
    139      1.1  christos #define D_EVENT	  64	/* libevent */
    140      1.1  christos #define D_BUFFER 128	/* message queues */
    141      1.1  christos #define D_MEM	 256	/* malloc/free */
    142      1.1  christos #define D_MEM2	1024	/* every single malloc/free */
    143      1.1  christos #define D_SIGN	2048	/* -sign */
    144      1.1  christos #define D_MISC	4096	/* everything else */
    145      1.1  christos #define D_ALL	(D_CALL | D_DATA | D_NET | D_FILE | D_TLS | D_PARSE |  \
    146      1.1  christos 		 D_EVENT | D_BUFFER | D_MEM | D_MEM2 | D_SIGN | D_MISC)
    147      1.1  christos #define D_DEFAULT (D_CALL | D_NET | D_FILE | D_TLS | D_MISC)
    148      1.1  christos 
    149      1.1  christos 
    150      1.1  christos /* build with -DNDEBUG to remove all assert()s and DPRINTF()s */
    151      1.1  christos #ifdef NDEBUG
    152      1.1  christos #define DPRINTF(x, ...) (void)0
    153      1.1  christos #else
    154      1.1  christos #define DPRINTF(x, ...) /*LINTED null effect */(void)(Debug & (x) \
    155      1.1  christos     ? (printf("%s:%s:%s:%.4d\t", make_timestamp(NULL, true), \
    156      1.1  christos     __FILE__, __func__, __LINE__), printf(__VA_ARGS__)) : 0)
    157      1.1  christos #endif
    158      1.1  christos 
    159      1.1  christos /* shortcuts for libevent */
    160      1.1  christos #define EVENT_ADD(x) do {						\
    161      1.1  christos 	DPRINTF(D_EVENT, "event_add(%s@%p)\n", #x, x);			\
    162      1.1  christos 	if (event_add(x, NULL) == -1) {					\
    163      1.1  christos 		DPRINTF(D_EVENT, "Failure in event_add()\n");		\
    164      1.1  christos 	}								\
    165      1.1  christos } while (/*CONSTCOND*/0)
    166      1.1  christos #define RETRYEVENT_ADD(x) do {						\
    167      1.1  christos 	struct timeval _tv;						\
    168      1.1  christos 	_tv.tv_sec = 0;							\
    169      1.1  christos 	_tv.tv_usec = TLS_RETRY_EVENT_USEC;				\
    170      1.1  christos 	DPRINTF(D_EVENT, "retryevent_add(%s@%p)\n", #x, x);		\
    171      1.1  christos 	if (event_add(x, &_tv) == -1) {					\
    172      1.1  christos 		DPRINTF(D_EVENT, "Failure in event_add()\n");		\
    173      1.1  christos 	}								\
    174      1.1  christos } while (/*CONSTCOND*/0)
    175      1.1  christos #define DEL_EVENT(x) do {						\
    176      1.1  christos 	DPRINTF(D_MEM2, "DEL_EVENT(%s@%p)\n", #x, x);			\
    177      1.1  christos 	if ((x) && (event_del(x) == -1)) {				\
    178      1.1  christos 		DPRINTF(D_EVENT, "Failure in event_del()\n");		\
    179      1.1  christos 	}								\
    180      1.1  christos } while (/*CONSTCOND*/0)
    181      1.1  christos 
    182      1.1  christos /* safe calls to free() */
    183      1.1  christos #define FREEPTR(x)	if (x) {					\
    184      1.1  christos 		DPRINTF(D_MEM2, "free(%s@%p)\n", #x, x);		\
    185      1.1  christos 		free(x);	 x = NULL; }
    186      1.1  christos #define FREE_SSL(x)	if (x) {					\
    187      1.1  christos 		DPRINTF(D_MEM2, "SSL_free(%s@%p)\n", #x, x);		\
    188      1.1  christos 		SSL_free(x);	 x = NULL; }
    189      1.1  christos #define FREE_SSL_CTX(x) if (x) {					\
    190      1.1  christos 		DPRINTF(D_MEM2, "SSL_CTX_free(%s@%p)\n", #x, x);	\
    191      1.1  christos 		SSL_CTX_free(x); x = NULL; }
    192      1.1  christos 
    193      1.2   minskim /* reference counting macros for buffers */
    194      1.1  christos #define NEWREF(x) ((x) ? (DPRINTF(D_BUFFER, "inc refcount of " #x \
    195      1.1  christos 			" @ %p: %zu --> %zu\n", (x), (x)->refcount, \
    196      1.1  christos 			(x)->refcount + 1), (x)->refcount++, (x))\
    197      1.1  christos 		       : (DPRINTF(D_BUFFER, "inc refcount of NULL!\n"), NULL))
    198      1.1  christos #define DELREF(x) /*LINTED null effect*/(void)((x) ? (DPRINTF(D_BUFFER, "dec refcount of " #x \
    199      1.1  christos 			" @ %p: %zu --> %zu\n", (x), (x)->refcount, \
    200      1.1  christos 			(x)->refcount - 1), buf_msg_free(x), NULL) \
    201      1.1  christos 		       : (DPRINTF(D_BUFFER, "dec refcount of NULL!\n"), NULL))
    202      1.1  christos 
    203      1.2   minskim /* assumption:
    204      1.1  christos  * - malloc()/calloc() only fails if not enough memory available
    205      1.1  christos  * - once init() has set up all global variables etc.
    206      1.1  christos  *   the bulk of available memory is used for buffers
    207      1.1  christos  *   and can be freed if necessary
    208      1.1  christos  */
    209      1.1  christos #define MALLOC(ptr, size) do {						\
    210      1.1  christos 	while(!(ptr = malloc(size))) {					\
    211      1.1  christos 		DPRINTF(D_MEM, "Unable to allocate memory");		\
    212      1.1  christos 		message_allqueues_purge();				\
    213      1.1  christos 	}								\
    214      1.1  christos 	DPRINTF(D_MEM2, "MALLOC(%s@%p, %zu)\n", #ptr, ptr, size);	\
    215      1.1  christos } while (/*CONSTCOND*/0)
    216      1.1  christos 
    217      1.1  christos #define CALLOC(ptr, size) do {						\
    218      1.1  christos 	while(!(ptr = calloc(1, size))) {				\
    219      1.1  christos 		DPRINTF(D_MEM, "Unable to allocate memory");		\
    220      1.1  christos 		message_allqueues_purge();				\
    221      1.1  christos 	}								\
    222      1.1  christos 	DPRINTF(D_MEM2, "CALLOC(%s@%p, %zu)\n", #ptr, ptr, size);	\
    223      1.1  christos } while (/*CONSTCOND*/0)
    224      1.1  christos 
    225      1.1  christos /* define strlen(NULL) to be 0 */
    226      1.1  christos #define SAFEstrlen(x) ((x) ? strlen(x) : 0)
    227      1.1  christos 
    228      1.1  christos /* shorthand to block/restore signals for the duration of one function */
    229      1.1  christos #define BLOCK_SIGNALS(omask, newmask) do {				\
    230      1.1  christos 	sigemptyset(&newmask);						\
    231      1.1  christos 	sigaddset(&newmask, SIGHUP);					\
    232      1.1  christos 	sigaddset(&newmask, SIGALRM);					\
    233      1.1  christos 	sigprocmask(SIG_BLOCK, &newmask, &omask);			\
    234      1.1  christos } while (/*CONSTCOND*/0)
    235      1.1  christos 
    236      1.1  christos #define RESTORE_SIGNALS(omask) sigprocmask(SIG_SETMASK, &omask, NULL)
    237      1.1  christos 
    238      1.1  christos /* small optimization to call send_queue() only if queue has elements */
    239      1.1  christos #define SEND_QUEUE(f) do {						\
    240      1.1  christos 	if ((f)->f_qelements)						\
    241      1.1  christos 		send_queue(0, 0, f);	      				\
    242      1.1  christos } while (/*CONSTCOND*/0)
    243      1.1  christos 
    244      1.1  christos #define MAXUNAMES		20	/* maximum number of user names */
    245      1.1  christos #define BSD_TIMESTAMPLEN	14+1
    246      1.1  christos #define MAX_TIMESTAMPLEN	31+1
    247      1.1  christos 
    248      1.1  christos /* maximum field lengths in syslog-protocol */
    249      1.1  christos #define PRI_MAX	      5
    250      1.1  christos #define HOST_MAX    255
    251      1.1  christos #define APPNAME_MAX  48
    252      1.1  christos #define PROCID_MAX  128
    253      1.1  christos #define MSGID_MAX    32
    254      1.1  christos /* longest possible header length */
    255      1.1  christos #define HEADER_LEN_MAX (PRI_MAX + 1 + 1 + MAX_TIMESTAMPLEN + 1 + HOST_MAX \
    256      1.1  christos 			+ 1 + APPNAME_MAX + 1 + PROCID_MAX + 1 + MSGID_MAX)
    257      1.1  christos 
    258      1.1  christos /* allowed number of priorities by IETF standards */
    259      1.1  christos #define IETF_NUM_PRIVALUES  192
    260      1.1  christos 
    261      1.2   minskim /* check if message with fac/sev belogs to a destination f */
    262      1.1  christos #define MATCH_PRI(f, fac, sev) \
    263      1.1  christos 	   (  (((f)->f_pcmp[fac] & PRI_EQ) && ((f)->f_pmask[fac] == (sev))) \
    264      1.1  christos 	    ||(((f)->f_pcmp[fac] & PRI_LT) && ((f)->f_pmask[fac]  < (sev)))  \
    265      1.1  christos 	    ||(((f)->f_pcmp[fac] & PRI_GT) && ((f)->f_pmask[fac]  > (sev)))  \
    266      1.1  christos 	   )
    267      1.1  christos 
    268      1.1  christos /* shorthand to test Byte Order Mark which indicates UTF-8 content */
    269      1.1  christos #define IS_BOM(p) ( \
    270      1.1  christos     (p)[0] != '\0' && (unsigned char)(p)[0] == (unsigned char)0xEF && \
    271      1.1  christos     (p)[1] != '\0' && (unsigned char)(p)[1] == (unsigned char)0xBB && \
    272      1.1  christos     (p)[2] != '\0' && (unsigned char)(p)[2] == (unsigned char)0xBF)
    273      1.1  christos 
    274      1.1  christos /* message buffer container used for processing, formatting, and queueing */
    275      1.1  christos struct buf_msg {
    276      1.1  christos 	size_t	 refcount;
    277      1.1  christos 	int	 pri;
    278      1.1  christos 	int	 flags;
    279      1.1  christos 	char	*timestamp;
    280      1.1  christos 	char	*recvhost;
    281      1.1  christos 	char	*host;
    282      1.1  christos 	char	*prog;
    283      1.1  christos 	char	*pid;
    284      1.1  christos 	char	*msgid;
    285      1.1  christos 	char	*sd;	    /* structured data */
    286      1.1  christos 	char	*msg;	    /* message content */
    287      1.1  christos 	char	*msgorig;   /* in case we advance *msg beyond header fields
    288      1.1  christos 			       we still want to free() the original ptr  */
    289      1.1  christos 	size_t	 msglen;    /* strlen(msg) */
    290      1.1  christos 	size_t	 msgsize;   /* allocated memory size   */
    291      1.1  christos 	size_t	 tlsprefixlen; /* bytes for the TLS length prefix */
    292      1.1  christos 	size_t	 prilen;       /* bytes for priority and version  */
    293      1.1  christos };
    294      1.1  christos 
    295      1.1  christos /* queue of messages */
    296      1.1  christos struct buf_queue {
    297      1.1  christos 	struct buf_msg* msg;
    298      1.1  christos 	STAILQ_ENTRY(buf_queue) entries;
    299      1.1  christos };
    300      1.1  christos STAILQ_HEAD(buf_queue_head, buf_queue);
    301      1.1  christos 
    302      1.1  christos /* a pair of a socket and an associated event object */
    303      1.1  christos struct socketEvent {
    304      1.1  christos 	int fd;
    305  1.3.6.1      yamt 	int af;
    306      1.1  christos 	struct event *ev;
    307      1.1  christos };
    308      1.1  christos 
    309      1.1  christos /*
    310      1.1  christos  * Flags to logmsg().
    311      1.1  christos  */
    312      1.1  christos #define IGN_CONS	0x001	/* don't print on console */
    313      1.1  christos #define SYNC_FILE	0x002	/* do fsync on file after printing */
    314      1.1  christos #define ADDDATE		0x004	/* add a date to the message */
    315      1.1  christos #define MARK		0x008	/* this message is a mark */
    316      1.1  christos #define ISKERNEL	0x010	/* kernel generated message */
    317      1.1  christos #define BSDSYSLOG	0x020	/* line in traditional BSD Syslog format */
    318      1.1  christos #define SIGN_MSG	0x040	/* syslog-sign data, not signed again */
    319      1.1  christos 
    320      1.1  christos /* strategies for message_queue_purge() */
    321      1.1  christos #define PURGE_OLDEST		1
    322      1.1  christos #define PURGE_BY_PRIORITY	2
    323      1.1  christos 
    324      1.1  christos /*
    325      1.1  christos  * This structure represents the files that will have log
    326      1.1  christos  * copies printed.
    327      1.1  christos  * We require f_file to be valid if f_type is F_FILE, F_CONSOLE, F_TTY,
    328      1.1  christos  * or if f_type is F_PIPE and f_pid > 0.
    329      1.1  christos  */
    330      1.1  christos 
    331      1.1  christos struct filed {
    332      1.1  christos 	struct	filed *f_next;		/* next in linked list */
    333      1.1  christos 	short	f_type;			/* entry type, see below */
    334      1.1  christos 	short	f_file;			/* file descriptor */
    335      1.1  christos 	time_t	f_time;			/* time this was last written */
    336      1.1  christos 	char	*f_host;		/* host from which to record */
    337      1.1  christos 	u_char	f_pmask[LOG_NFACILITIES+1];	/* priority mask */
    338      1.1  christos 	u_char	f_pcmp[LOG_NFACILITIES+1];	/* compare priority */
    339      1.1  christos #define PRI_LT	0x1
    340      1.1  christos #define PRI_EQ	0x2
    341      1.1  christos #define PRI_GT	0x4
    342      1.1  christos 	char	*f_program;		/* program this applies to */
    343      1.1  christos 	union {
    344      1.1  christos 		char	f_uname[MAXUNAMES][UT_NAMESIZE+1];
    345      1.1  christos 		struct {
    346      1.1  christos 			char	f_hname[MAXHOSTNAMELEN];
    347      1.1  christos 			struct	addrinfo *f_addr;
    348      1.1  christos 		} f_forw;		/* UDP forwarding address */
    349      1.1  christos #ifndef DISABLE_TLS
    350      1.1  christos 		struct {
    351      1.1  christos 			SSL	*ssl;			/* SSL object  */
    352      1.2   minskim 			struct tls_conn_settings *tls_conn;  /* certificate info */
    353      1.1  christos 		} f_tls;		/* TLS forwarding address */
    354      1.1  christos #endif /* !DISABLE_TLS */
    355      1.1  christos 		char	f_fname[MAXPATHLEN];
    356      1.1  christos 		struct {
    357      1.1  christos 			char	f_pname[MAXPATHLEN];
    358      1.1  christos 			pid_t	f_pid;
    359      1.1  christos 		} f_pipe;
    360      1.1  christos 	} f_un;
    361      1.1  christos #ifndef DISABLE_SIGN
    362      1.1  christos 	struct signature_group_t *f_sg;	     /* one signature group */
    363      1.1  christos #endif /* !DISABLE_SIGN */
    364      1.1  christos 	struct buf_queue_head f_qhead;	     /* undelivered msgs queue */
    365      1.1  christos 	size_t	      	      f_qelements;   /* elements in queue */
    366      1.1  christos 	size_t		      f_qsize;	     /* size of queue in bytes */
    367      1.1  christos 	struct buf_msg	     *f_prevmsg;     /* last message logged */
    368      1.1  christos 	struct event	     *f_sq_event;    /* timer for send_queue() */
    369      1.1  christos 	int		      f_prevcount;   /* repetition cnt of prevmsg */
    370      1.1  christos 	int		      f_repeatcount; /* number of "repeated" msgs */
    371      1.1  christos 	int		      f_lasterror;   /* last error on writev() */
    372      1.1  christos 	int		      f_flags;	     /* file-specific flags */
    373      1.1  christos #define FFLAG_SYNC	0x01	/* for F_FILE: fsync after every msg */
    374      1.1  christos #define FFLAG_FULL	0x02	/* for F_FILE | F_PIPE: write PRI header */
    375      1.1  christos #define FFLAG_SIGN	0x04	/* for syslog-sign with SG="3":
    376      1.1  christos 				 * sign the messages to this destination */
    377      1.1  christos };
    378      1.1  christos 
    379      1.1  christos #ifndef DISABLE_TLS
    380      1.1  christos 
    381      1.1  christos /* linked list for allowed TLS peer credentials
    382      1.1  christos  * (one for fingerprint, one for cert-files)
    383      1.1  christos  */
    384      1.1  christos SLIST_HEAD(peer_cred_head, peer_cred);
    385      1.1  christos struct peer_cred {
    386      1.1  christos 	SLIST_ENTRY(peer_cred) entries;
    387      1.1  christos 	char *data;
    388      1.1  christos };
    389      1.1  christos 
    390      1.1  christos /* config options for TLS server-side */
    391      1.1  christos struct tls_global_options_t {
    392      1.1  christos 	SSL_CTX *global_TLS_CTX;
    393      1.1  christos 	struct peer_cred_head fprint_head;  /* trusted client fingerprints */
    394      1.1  christos 	struct peer_cred_head cert_head;    /* trusted client cert files   */
    395      1.1  christos 	char *keyfile;	    /* file with private key	 */
    396      1.1  christos 	char *certfile;	    /* file with own certificate */
    397      1.1  christos 	char *CAfile;	    /* file with CA certificate	 */
    398      1.1  christos 	char *CAdir;	    /* alternative: path to directory with CA certs */
    399      1.1  christos 	char *x509verify;   /* level of peer verification */
    400      1.2   minskim 	char *bindhost;	    /* hostname/IP to bind to	  */
    401      1.1  christos 	char *bindport;	    /* port/service to bind to	  */
    402      1.1  christos 	char *server;	    /* if !NULL: do not listen to incoming TLS	  */
    403      1.1  christos 	char *gen_cert;	    /* if !NULL: generate self-signed certificate */
    404      1.1  christos };
    405      1.1  christos 
    406      1.1  christos /* TLS needs three sets of sockets:
    407      1.1  christos  * - listening sockets: a fixed size array TLS_Listen_Set, just like finet for UDP.
    408      1.1  christos  * - outgoing connections: managed as part of struct filed.
    409      1.1  christos  * - incoming connections: variable sized, thus a linked list TLS_Incoming.
    410      1.1  christos  */
    411      1.1  christos /* every connection has its own input buffer with status
    412      1.1  christos  * variables for message reading */
    413      1.1  christos SLIST_HEAD(TLS_Incoming, TLS_Incoming_Conn);
    414      1.2   minskim 
    415      1.1  christos struct TLS_Incoming_Conn {
    416      1.1  christos 	SLIST_ENTRY(TLS_Incoming_Conn) entries;
    417      1.1  christos 	struct tls_conn_settings *tls_conn;
    418      1.1  christos 	int socket;
    419      1.1  christos 	char *inbuf;		    /* input buffer */
    420      1.1  christos 	size_t inbuflen;
    421      1.1  christos 	size_t cur_msg_len;	    /* length of current msg */
    422      1.1  christos 	size_t cur_msg_start;	    /* beginning of current msg */
    423      1.1  christos 	size_t read_pos;	    /* ring buffer position to write to */
    424      1.1  christos 	size_t errorcount;	    /* to close faulty connections */
    425      1.1  christos 	bool closenow;		    /* close connection as soon as buffer processed */
    426      1.1  christos 	bool dontsave;		    /* for receiving oversized messages w/o saving them */
    427      1.1  christos };
    428      1.1  christos 
    429      1.1  christos #endif /* !DISABLE_TLS */
    430      1.1  christos 
    431      1.1  christos #endif /*SYSLOGD_H_*/
    432