#include <config.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <locale.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include <pathnames.h>
#include <sudo_compat.h>
#include <sudo_debug.h>
#include <sudo_eventlog.h>
#include <sudo_fatal.h>
#include <sudo_gettext.h>
#include <sudo_json.h>
#include <sudo_queue.h>
#include <sudo_util.h>
static FILE *eventlog_stub_open_log(int type, const char *logfile);
static void eventlog_stub_close_log(int type, FILE *fp);
static struct eventlog_config evl_conf = {
EVLOG_NONE,
EVLOG_SUDO,
0,
MAXSYSLOGLEN,
LOG_NOTICE,
LOG_ALERT,
LOG_ALERT,
ROOT_UID,
ROOT_GID,
false,
_PATH_SUDO_LOGFILE,
"%h %e %T",
#ifdef _PATH_SUDO_SENDMAIL
_PATH_SUDO_SENDMAIL,
#else
NULL,
#endif
"-t",
NULL,
MAILTO,
N_(MAILSUBJECT),
eventlog_stub_open_log,
eventlog_stub_close_log
};
static FILE *
eventlog_stub_open_log(int type, const char *logfile)
{
debug_decl(eventlog_stub_open_log, SUDO_DEBUG_UTIL);
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
"open_log not set, using stub");
debug_return_ptr(NULL);
}
static void
eventlog_stub_close_log(int type, FILE *fp)
{
debug_decl(eventlog_stub_close_log, SUDO_DEBUG_UTIL);
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
"close_log not set, using stub");
debug_return;
}
void
eventlog_set_type(int type)
{
evl_conf.type = type;
}
void
eventlog_set_format(enum eventlog_format format)
{
evl_conf.format = format;
}
void
eventlog_set_syslog_acceptpri(int pri)
{
evl_conf.syslog_acceptpri = pri;
}
void
eventlog_set_syslog_rejectpri(int pri)
{
evl_conf.syslog_rejectpri = pri;
}
void
eventlog_set_syslog_alertpri(int pri)
{
evl_conf.syslog_alertpri = pri;
}
void
eventlog_set_syslog_maxlen(size_t len)
{
evl_conf.syslog_maxlen = len;
}
void
eventlog_set_file_maxlen(size_t len)
{
evl_conf.file_maxlen = len;
}
void
eventlog_set_mailuser(uid_t uid, gid_t gid)
{
evl_conf.mailuid = uid;
evl_conf.mailgid = gid;
}
void
eventlog_set_omit_hostname(bool omit_hostname)
{
evl_conf.omit_hostname = omit_hostname;
}
void
eventlog_set_logpath(const char *path)
{
evl_conf.logpath = path;
}
void
eventlog_set_time_fmt(const char *fmt)
{
evl_conf.time_fmt = fmt;
}
void
eventlog_set_mailerpath(const char *path)
{
evl_conf.mailerpath = path;
}
void
eventlog_set_mailerflags(const char *mflags)
{
evl_conf.mailerflags = mflags;
}
void
eventlog_set_mailfrom(const char *from_addr)
{
evl_conf.mailfrom = from_addr;
}
void
eventlog_set_mailto(const char *to_addr)
{
evl_conf.mailto = to_addr;
}
void
eventlog_set_mailsub(const char *subject)
{
evl_conf.mailsub = subject;
}
void
eventlog_set_open_log(FILE *(*fn)(int type, const char *))
{
evl_conf.open_log = fn;
}
void
eventlog_set_close_log(void (*fn)(int type, FILE *))
{
evl_conf.close_log = fn;
}
const struct eventlog_config *
eventlog_getconf(void)
{
return &evl_conf;
}