#ifndef SYSLOGD_H_
#define SYSLOGD_H_
#include <sys/cdefs.h>
#define MAXLINE 1024
#define DEFUPRI (LOG_USER|LOG_NOTICE)
#define DEFSPRI (LOG_KERN|LOG_NOTICE)
#define TIMERINTVL 30
#define TTYMSGTIME 1
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <sys/queue.h>
#include <netinet/in.h>
#include <sys/event.h>
#include <event.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <locale.h>
#include <netdb.h>
#include <pwd.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
#include <utmp.h>
#ifdef __NetBSD_Version__
#include <util.h>
#include "utmpentry.h"
#endif
#ifdef __FreeBSD_version
#include <libutil.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <limits.h>
#endif
#ifndef DISABLE_TLS
#include <netinet/tcp.h>
#include <openssl/ssl.h>
#endif
#include <sys/stdint.h>
#include <sys/resource.h>
#include "pathnames.h"
#include <sys/syslog.h>
#ifdef __FreeBSD_version
#undef _PATH_UNIX
#define _PATH_UNIX "kernel"
#define HAVE_STRNDUP 0
#endif
#ifdef __NetBSD_Version__
#define HAVE_STRNDUP 1
#define HAVE_DEHUMANIZE_NUMBER 1
#endif
#ifndef HAVE_DEHUMANIZE_NUMBER
extern int dehumanize_number(const char *str, int64_t *size);
#endif
#if !HAVE_STRNDUP
char *strndup(const char *str, size_t n);
#endif
#ifdef LIBWRAP
#include <tcpd.h>
#endif
#define FDMASK(fd) (1 << (fd))
#define A_CNT(x) (sizeof((x)) / sizeof((x)[0]))
#define D_NONE 0
#define D_CALL 1
#define D_DATA 2
#define D_NET 4
#define D_FILE 8
#define D_TLS 16
#define D_PARSE 32
#define D_EVENT 64
#define D_BUFFER 128
#define D_MEM 256
#define D_MEM2 1024
#define D_SIGN 2048
#define D_MISC 4096
#define D_ALL (D_CALL | D_DATA | D_NET | D_FILE | D_TLS | D_PARSE | \
D_EVENT | D_BUFFER | D_MEM | D_MEM2 | D_SIGN | D_MISC)
#define D_DEFAULT (D_CALL | D_NET | D_FILE | D_TLS | D_MISC)
#ifdef NDEBUG
#define DPRINTF(x, ...) (void)0
#else
void dbprintf(const char *, const char *, size_t, const char *, ...)
__printflike(4, 5);
#define DPRINTF(x, ...) (void)(Debug & (x) \
? dbprintf(__FILE__, __func__, __LINE__, __VA_ARGS__) : ((void)0))
#endif
#define EVENT_ADD(x) do { \
DPRINTF(D_EVENT, "event_add(%s@%p)\n", #x, x); \
if (event_add(x, NULL) == -1) { \
DPRINTF(D_EVENT, "Failure in event_add()\n"); \
} \
} while (0)
#define RETRYEVENT_ADD(x) do { \
struct timeval _tv; \
_tv.tv_sec = 0; \
_tv.tv_usec = TLS_RETRY_EVENT_USEC; \
DPRINTF(D_EVENT, "retryevent_add(%s@%p)\n", #x, x); \
if (event_add(x, &_tv) == -1) { \
DPRINTF(D_EVENT, "Failure in event_add()\n"); \
} \
} while (0)
#define DEL_EVENT(x) do { \
DPRINTF(D_MEM2, "DEL_EVENT(%s@%p)\n", #x, x); \
if ((x) && (event_del(x) == -1)) { \
DPRINTF(D_EVENT, "Failure in event_del()\n"); \
} \
} while (0)
#define FREEPTR(x) if (x) { \
DPRINTF(D_MEM2, "free(%s@%p)\n", #x, x); \
free(x); x = NULL; }
#define FREE_SSL(x) if (x) { \
DPRINTF(D_MEM2, "SSL_free(%s@%p)\n", #x, x); \
SSL_free(x); x = NULL; }
#define FREE_SSL_CTX(x) if (x) { \
DPRINTF(D_MEM2, "SSL_CTX_free(%s@%p)\n", #x, x); \
SSL_CTX_free(x); x = NULL; }
#define NEWREF(x) ((x) ? (DPRINTF(D_BUFFER, "inc refcount of " #x \
" @ %p: %zu --> %zu\n", (x), (x)->refcount, \
(x)->refcount + 1), (x)->refcount++, (x)) \
: (DPRINTF(D_BUFFER, "inc refcount of NULL!\n"), NULL))
#define DELREF(x) \
(void)((x) ? (DPRINTF(D_BUFFER, "dec refcount of " #x \
" @ %p: %zu --> %zu\n", (x), (x)->refcount, \
(x)->refcount - 1), buf_msg_free(x), NULL) \
: (DPRINTF(D_BUFFER, "dec refcount of NULL!\n"), NULL))
#define MALLOC(ptr, size) do { \
while (!(ptr = malloc(size))) { \
DPRINTF(D_MEM, "Unable to allocate memory"); \
message_allqueues_purge(); \
} \
DPRINTF(D_MEM2, "MALLOC(%s@%p, %zu)\n", #ptr, ptr, size); \
} while (0)
#define CALLOC(ptr, size) do { \
while (!(ptr = calloc(1, size))) { \
DPRINTF(D_MEM, "Unable to allocate memory"); \
message_allqueues_purge(); \
} \
DPRINTF(D_MEM2, "CALLOC(%s@%p, %zu)\n", #ptr, ptr, size); \
} while (0)
#define SAFEstrlen(x) ((x) ? strlen(x) : 0)
#define BLOCK_SIGNALS(omask, newmask) do { \
sigemptyset(&newmask); \
sigaddset(&newmask, SIGHUP); \
sigaddset(&newmask, SIGALRM); \
sigprocmask(SIG_BLOCK, &newmask, &omask); \
} while (0)
#define RESTORE_SIGNALS(omask) sigprocmask(SIG_SETMASK, &omask, NULL)
#define SEND_QUEUE(f) do { \
if ((f)->f_qelements) \
send_queue(0, 0, f); \
} while (0)
#define MAXUNAMES 20
#define BSD_TIMESTAMPLEN (14+1)
#define MAX_TIMESTAMPLEN (31+1)
#define PRI_MAX 5
#define HOST_MAX 255
#define APPNAME_MAX 48
#define PROCID_MAX 128
#define MSGID_MAX 32
#define HEADER_LEN_MAX (PRI_MAX + 1 + 1 + MAX_TIMESTAMPLEN + 1 + HOST_MAX \
+ 1 + APPNAME_MAX + 1 + PROCID_MAX + 1 + MSGID_MAX)
#define IETF_NUM_PRIVALUES 192
#define MATCH_PRI(f, fac, sev) \
( (((f)->f_pcmp[fac] & PRI_EQ) && ((f)->f_pmask[fac] == (sev))) \
||(((f)->f_pcmp[fac] & PRI_LT) && ((f)->f_pmask[fac] < (sev))) \
||(((f)->f_pcmp[fac] & PRI_GT) && ((f)->f_pmask[fac] > (sev))) \
)
#define IS_BOM(p) ( \
(p)[0] != '\0' && (unsigned char)(p)[0] == (unsigned char)0xEF && \
(p)[1] != '\0' && (unsigned char)(p)[1] == (unsigned char)0xBB && \
(p)[2] != '\0' && (unsigned char)(p)[2] == (unsigned char)0xBF)
struct buf_msg {
size_t refcount;
int pri;
int flags;
char *timestamp;
char *recvhost;
char *host;
char *prog;
char *pid;
char *msgid;
char *sd;
char *msg;
char *msgorig;
size_t msglen;
size_t msgsize;
size_t tlsprefixlen;
size_t prilen;
};
struct buf_queue {
struct buf_msg* msg;
STAILQ_ENTRY(buf_queue) entries;
};
STAILQ_HEAD(buf_queue_head, buf_queue);
struct socketEvent {
int fd;
int af;
struct event *ev;
};
#define IGN_CONS 0x001
#define SYNC_FILE 0x002
#define ADDDATE 0x004
#define MARK 0x008
#define ISKERNEL 0x010
#define BSDSYSLOG 0x020
#define SIGN_MSG 0x040
#define PURGE_OLDEST 1
#define PURGE_BY_PRIORITY 2
struct filed {
struct filed *f_next;
short f_type;
short f_file;
time_t f_time;
char *f_host;
u_char f_pmask[LOG_NFACILITIES+1];
u_char f_pcmp[LOG_NFACILITIES+1];
#define PRI_LT 0x1
#define PRI_EQ 0x2
#define PRI_GT 0x4
char *f_program;
union {
char f_uname[MAXUNAMES][UT_NAMESIZE+1];
struct {
char f_hname[MAXHOSTNAMELEN];
struct addrinfo *f_addr;
} f_forw;
#ifndef DISABLE_TLS
struct {
SSL *ssl;
struct tls_conn_settings *tls_conn;
} f_tls;
#endif
char f_fname[MAXPATHLEN];
struct {
char f_pname[MAXPATHLEN];
pid_t f_pid;
} f_pipe;
} f_un;
#ifndef DISABLE_SIGN
struct signature_group_t *f_sg;
#endif
struct buf_queue_head f_qhead;
size_t f_qelements;
size_t f_qsize;
struct buf_msg *f_prevmsg;
struct event *f_sq_event;
int f_prevcount;
int f_repeatcount;
int f_lasterror;
int f_flags;
#define FFLAG_SYNC 0x01
#define FFLAG_FULL 0x02
#define FFLAG_SIGN 0x04
};
#ifndef DISABLE_TLS
SLIST_HEAD(peer_cred_head, peer_cred);
struct peer_cred {
SLIST_ENTRY(peer_cred) entries;
char *data;
};
struct tls_global_options_t {
SSL_CTX *global_TLS_CTX;
struct peer_cred_head fprint_head;
struct peer_cred_head cert_head;
char *keyfile;
char *certfile;
char *CAfile;
char *CAdir;
char *x509verify;
char *bindhost;
char *bindport;
char *server;
char *gen_cert;
};
SLIST_HEAD(TLS_Incoming, TLS_Incoming_Conn);
struct TLS_Incoming_Conn {
SLIST_ENTRY(TLS_Incoming_Conn) entries;
struct tls_conn_settings *tls_conn;
int socket;
char *inbuf;
size_t inbuflen;
size_t cur_msg_len;
size_t cur_msg_start;
size_t read_pos;
size_t errorcount;
bool closenow;
bool dontsave;
};
#endif
#endif