Use libeventlog in sudoers instead of doing our own logging.
This commit is contained in:
@@ -66,6 +66,7 @@ struct eventlog_config {
|
|||||||
int syslog_alertpri;
|
int syslog_alertpri;
|
||||||
int syslog_maxlen;
|
int syslog_maxlen;
|
||||||
uid_t mailuid;
|
uid_t mailuid;
|
||||||
|
bool omit_hostname;
|
||||||
const char *logpath;
|
const char *logpath;
|
||||||
const char *time_fmt;
|
const char *time_fmt;
|
||||||
const char *mailerpath;
|
const char *mailerpath;
|
||||||
|
@@ -127,7 +127,7 @@ new_logline(int flags, const char *message, const char *errstr,
|
|||||||
len += strlen(message) + 3;
|
len += strlen(message) + 3;
|
||||||
if (errstr != NULL)
|
if (errstr != NULL)
|
||||||
len += strlen(errstr) + 3;
|
len += strlen(errstr) + 3;
|
||||||
if (details->submithost != NULL)
|
if (details->submithost != NULL && !evl_conf.omit_hostname)
|
||||||
len += sizeof(LL_HOST_STR) + 2 + strlen(details->submithost);
|
len += sizeof(LL_HOST_STR) + 2 + strlen(details->submithost);
|
||||||
if (details->ttyname != NULL)
|
if (details->ttyname != NULL)
|
||||||
len += sizeof(LL_TTY_STR) + 2 + strlen(details->ttyname);
|
len += sizeof(LL_TTY_STR) + 2 + strlen(details->ttyname);
|
||||||
@@ -184,7 +184,7 @@ new_logline(int flags, const char *message, const char *errstr,
|
|||||||
strlcat(line, " ; ", len) >= len)
|
strlcat(line, " ; ", len) >= len)
|
||||||
goto toobig;
|
goto toobig;
|
||||||
}
|
}
|
||||||
if (details->submithost != NULL) {
|
if (details->submithost != NULL && !evl_conf.omit_hostname) {
|
||||||
if (strlcat(line, LL_HOST_STR, len) >= len ||
|
if (strlcat(line, LL_HOST_STR, len) >= len ||
|
||||||
strlcat(line, details->submithost, len) >= len ||
|
strlcat(line, details->submithost, len) >= len ||
|
||||||
strlcat(line, " ; ", len) >= len)
|
strlcat(line, " ; ", len) >= len)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -196,7 +196,7 @@ sudoers_audit_accept(const char *plugin_name, unsigned int plugin_type,
|
|||||||
if (audit_success(run_argv) != 0 && !def_ignore_audit_errors)
|
if (audit_success(run_argv) != 0 && !def_ignore_audit_errors)
|
||||||
ret = false;
|
ret = false;
|
||||||
|
|
||||||
if (!log_allowed(VALIDATE_SUCCESS) && !def_ignore_logfile_errors)
|
if (!log_allowed() && !def_ignore_logfile_errors)
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,8 +207,8 @@ static int
|
|||||||
sudoers_audit_reject(const char *plugin_name, unsigned int plugin_type,
|
sudoers_audit_reject(const char *plugin_name, unsigned int plugin_type,
|
||||||
const char *message, char * const command_info[], const char **errstr)
|
const char *message, char * const command_info[], const char **errstr)
|
||||||
{
|
{
|
||||||
|
struct eventlog evlog;
|
||||||
int ret = true;
|
int ret = true;
|
||||||
char *logline;
|
|
||||||
debug_decl(sudoers_audit_reject, SUDOERS_DEBUG_PLUGIN);
|
debug_decl(sudoers_audit_reject, SUDOERS_DEBUG_PLUGIN);
|
||||||
|
|
||||||
/* Skip reject events that sudoers generated itself. */
|
/* Skip reject events that sudoers generated itself. */
|
||||||
@@ -223,27 +223,10 @@ sudoers_audit_reject(const char *plugin_name, unsigned int plugin_type,
|
|||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
logline = new_logline(message, NULL);
|
sudoers_to_eventlog(&evlog);
|
||||||
if (logline == NULL) {
|
if (!eventlog_reject(&evlog, 0, message, NULL, NULL))
|
||||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
|
||||||
ret = false;
|
ret = false;
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if (def_syslog) {
|
|
||||||
if (!do_syslog(def_syslog_badpri, logline)) {
|
|
||||||
if (!def_ignore_logfile_errors)
|
|
||||||
ret = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (def_logfile) {
|
|
||||||
if (!do_logfile(logline)) {
|
|
||||||
if (!def_ignore_logfile_errors)
|
|
||||||
ret = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(logline);
|
|
||||||
|
|
||||||
done:
|
|
||||||
debug_return_int(ret);
|
debug_return_int(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,6 +234,8 @@ static int
|
|||||||
sudoers_audit_error(const char *plugin_name, unsigned int plugin_type,
|
sudoers_audit_error(const char *plugin_name, unsigned int plugin_type,
|
||||||
const char *message, char * const command_info[], const char **errstr)
|
const char *message, char * const command_info[], const char **errstr)
|
||||||
{
|
{
|
||||||
|
struct eventlog evlog;
|
||||||
|
struct timespec now;
|
||||||
int ret = true;
|
int ret = true;
|
||||||
debug_decl(sudoers_audit_error, SUDOERS_DEBUG_PLUGIN);
|
debug_decl(sudoers_audit_error, SUDOERS_DEBUG_PLUGIN);
|
||||||
|
|
||||||
@@ -262,18 +247,15 @@ sudoers_audit_error(const char *plugin_name, unsigned int plugin_type,
|
|||||||
if (!def_ignore_audit_errors)
|
if (!def_ignore_audit_errors)
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
if (def_syslog) {
|
|
||||||
if (!do_syslog(def_syslog_badpri, message)) {
|
if (sudo_gettime_real(&now)) {
|
||||||
if (!def_ignore_logfile_errors)
|
sudo_warn("%s", U_("unable to get time of day"));
|
||||||
|
debug_return_bool(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
sudoers_to_eventlog(&evlog);
|
||||||
|
if (!eventlog_alert(&evlog, 0, &now, message, NULL))
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (def_logfile) {
|
|
||||||
if (!do_logfile(message)) {
|
|
||||||
if (!def_ignore_logfile_errors)
|
|
||||||
ret = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
debug_return_int(ret);
|
debug_return_int(ret);
|
||||||
}
|
}
|
||||||
|
@@ -620,6 +620,9 @@ init_defaults(void)
|
|||||||
if (!init_envtables())
|
if (!init_envtables())
|
||||||
goto oom;
|
goto oom;
|
||||||
|
|
||||||
|
/* Update eventlog config. */
|
||||||
|
update_eventlog_config();
|
||||||
|
|
||||||
firsttime = 0;
|
firsttime = 0;
|
||||||
|
|
||||||
debug_return_bool(true);
|
debug_return_bool(true);
|
||||||
@@ -754,6 +757,10 @@ update_defaults(struct sudoers_parse_tree *parse_tree,
|
|||||||
if (!set_default(d->var, d->val, d->op, d->file, d->lineno, quiet))
|
if (!set_default(d->var, d->val, d->op, d->file, d->lineno, quiet))
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update eventlog config. */
|
||||||
|
update_eventlog_config();
|
||||||
|
|
||||||
debug_return_bool(ret);
|
debug_return_bool(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#define DEFAULT_TEXT_DOMAIN "sudoers"
|
#define DEFAULT_TEXT_DOMAIN "sudoers"
|
||||||
|
|
||||||
#include "sudo_compat.h"
|
#include "sudo_compat.h"
|
||||||
|
#include "sudo_eventlog.h"
|
||||||
#include "sudo_fatal.h"
|
#include "sudo_fatal.h"
|
||||||
#include "sudo_gettext.h"
|
#include "sudo_gettext.h"
|
||||||
#include "sudoers_debug.h"
|
#include "sudoers_debug.h"
|
||||||
|
@@ -57,167 +57,7 @@
|
|||||||
/* Special message for log_warning() so we know to use ngettext() */
|
/* Special message for log_warning() so we know to use ngettext() */
|
||||||
#define INCORRECT_PASSWORD_ATTEMPT ((char *)0x01)
|
#define INCORRECT_PASSWORD_ATTEMPT ((char *)0x01)
|
||||||
|
|
||||||
static bool send_mail(const char *fmt, ...);
|
|
||||||
static bool should_mail(int);
|
static bool should_mail(int);
|
||||||
static void mysyslog(int, const char *, ...);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We do an openlog(3)/closelog(3) for each message because some
|
|
||||||
* authentication methods (notably PAM) use syslog(3) for their
|
|
||||||
* own nefarious purposes and may call openlog(3) and closelog(3).
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
mysyslog(int pri, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
const int flags = def_syslog_pid ? LOG_PID : 0;
|
|
||||||
va_list ap;
|
|
||||||
debug_decl(mysyslog, SUDOERS_DEBUG_LOGGING);
|
|
||||||
|
|
||||||
openlog("sudo", flags, def_syslog);
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vsyslog(pri, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
closelog();
|
|
||||||
debug_return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Log a message to syslog, pre-pending the username and splitting the
|
|
||||||
* message into parts if it is longer than syslog_maxlen.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
do_syslog(int pri, const char *msg)
|
|
||||||
{
|
|
||||||
size_t maxlen;
|
|
||||||
char *copy, *cp, *ep;
|
|
||||||
const char *fmt;
|
|
||||||
int oldlocale;
|
|
||||||
debug_decl(do_syslog, SUDOERS_DEBUG_LOGGING);
|
|
||||||
|
|
||||||
/* A priority of -1 corresponds to "none". */
|
|
||||||
if (pri == -1)
|
|
||||||
debug_return_bool(true);
|
|
||||||
|
|
||||||
if ((copy = strdup(msg)) == NULL) {
|
|
||||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
|
||||||
debug_return_bool(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, &oldlocale);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Log the full line, breaking into multiple syslog(3) calls if necessary
|
|
||||||
*/
|
|
||||||
fmt = _("%8s : %s");
|
|
||||||
maxlen = def_syslog_maxlen - (strlen(fmt) - 5 + strlen(user_name));
|
|
||||||
for (cp = copy; *cp != '\0'; ) {
|
|
||||||
size_t len = strlen(cp);
|
|
||||||
if (len > maxlen) {
|
|
||||||
/*
|
|
||||||
* Break up the line into what will fit on one syslog(3) line
|
|
||||||
* Try to avoid breaking words into several lines if possible.
|
|
||||||
*/
|
|
||||||
ep = memrchr(cp, ' ', maxlen);
|
|
||||||
if (ep != NULL)
|
|
||||||
*ep++ = '\0';
|
|
||||||
else
|
|
||||||
ep = cp + maxlen;
|
|
||||||
|
|
||||||
mysyslog(pri, fmt, user_name, cp);
|
|
||||||
|
|
||||||
/* Advance cp and eliminate leading whitespace */
|
|
||||||
for (cp = ep; *cp == ' '; cp++)
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
mysyslog(pri, fmt, user_name, cp);
|
|
||||||
cp += len;
|
|
||||||
}
|
|
||||||
fmt = _("%8s : (command continued) %s");
|
|
||||||
maxlen = def_syslog_maxlen - (strlen(fmt) - 5 + strlen(user_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
free(copy);
|
|
||||||
|
|
||||||
sudoers_setlocale(oldlocale, NULL);
|
|
||||||
|
|
||||||
debug_return_bool(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
do_logfile(const char *msg)
|
|
||||||
{
|
|
||||||
static bool warned = false;
|
|
||||||
const char *timestr;
|
|
||||||
int len, oldlocale;
|
|
||||||
bool ret = false;
|
|
||||||
char *full_line;
|
|
||||||
mode_t oldmask;
|
|
||||||
FILE *fp;
|
|
||||||
debug_decl(do_logfile, SUDOERS_DEBUG_LOGGING);
|
|
||||||
|
|
||||||
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, &oldlocale);
|
|
||||||
|
|
||||||
oldmask = umask(S_IRWXG|S_IRWXO);
|
|
||||||
fp = fopen(def_logfile, "a");
|
|
||||||
(void) umask(oldmask);
|
|
||||||
if (fp == NULL) {
|
|
||||||
if (!warned) {
|
|
||||||
log_warning(SLOG_SEND_MAIL|SLOG_NO_LOG,
|
|
||||||
N_("unable to open log file: %s"), def_logfile);
|
|
||||||
warned = true;
|
|
||||||
}
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if (!sudo_lock_file(fileno(fp), SUDO_LOCK)) {
|
|
||||||
if (!warned) {
|
|
||||||
log_warning(SLOG_SEND_MAIL|SLOG_NO_LOG,
|
|
||||||
N_("unable to lock log file: %s"), def_logfile);
|
|
||||||
warned = true;
|
|
||||||
}
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
timestr = get_timestr(time(NULL), def_log_year);
|
|
||||||
if (timestr == NULL)
|
|
||||||
timestr = "invalid date";
|
|
||||||
if (def_log_host) {
|
|
||||||
len = asprintf(&full_line, "%s : %s : HOST=%s : %s",
|
|
||||||
timestr, user_name, user_srunhost, msg);
|
|
||||||
} else {
|
|
||||||
len = asprintf(&full_line, "%s : %s : %s",
|
|
||||||
timestr, user_name, msg);
|
|
||||||
}
|
|
||||||
if (len == -1) {
|
|
||||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if ((size_t)def_loglinelen < sizeof(LOG_INDENT)) {
|
|
||||||
/* Don't pretty-print long log file lines (hard to grep). */
|
|
||||||
(void) fputs(full_line, fp);
|
|
||||||
(void) fputc('\n', fp);
|
|
||||||
} else {
|
|
||||||
/* Write line with word wrap around def_loglinelen chars. */
|
|
||||||
writeln_wrap(fp, full_line, len, def_loglinelen);
|
|
||||||
}
|
|
||||||
free(full_line);
|
|
||||||
(void) fflush(fp);
|
|
||||||
if (ferror(fp)) {
|
|
||||||
if (!warned) {
|
|
||||||
log_warning(SLOG_SEND_MAIL|SLOG_NO_LOG,
|
|
||||||
N_("unable to write log file: %s"), def_logfile);
|
|
||||||
warned = true;
|
|
||||||
}
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
ret = true;
|
|
||||||
|
|
||||||
done:
|
|
||||||
if (fp != NULL)
|
|
||||||
(void) fclose(fp);
|
|
||||||
sudoers_setlocale(oldlocale, NULL);
|
|
||||||
|
|
||||||
debug_return_bool(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Log, audit and mail the denial message, optionally informing the user.
|
* Log, audit and mail the denial message, optionally informing the user.
|
||||||
@@ -225,11 +65,11 @@ done:
|
|||||||
bool
|
bool
|
||||||
log_denial(int status, bool inform_user)
|
log_denial(int status, bool inform_user)
|
||||||
{
|
{
|
||||||
|
struct eventlog evlog;
|
||||||
const char *message;
|
const char *message;
|
||||||
char *logline;
|
|
||||||
int oldlocale;
|
int oldlocale;
|
||||||
bool uid_changed, ret = true;
|
int evl_flags = 0;
|
||||||
bool mailit;
|
bool mailit, ret = true;
|
||||||
debug_decl(log_denial, SUDOERS_DEBUG_LOGGING);
|
debug_decl(log_denial, SUDOERS_DEBUG_LOGGING);
|
||||||
|
|
||||||
/* Send mail based on status. */
|
/* Send mail based on status. */
|
||||||
@@ -250,30 +90,14 @@ log_denial(int status, bool inform_user)
|
|||||||
/* Log and mail messages should be in the sudoers locale. */
|
/* Log and mail messages should be in the sudoers locale. */
|
||||||
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, &oldlocale);
|
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, &oldlocale);
|
||||||
|
|
||||||
logline = new_logline(_(message), NULL);
|
if (mailit) {
|
||||||
if (logline == NULL)
|
SET(evl_flags, EVLOG_MAIL);
|
||||||
debug_return_bool(false);
|
if (!def_log_denied)
|
||||||
|
SET(evl_flags, EVLOG_MAIL_ONLY);
|
||||||
/* Become root if we are not already. */
|
|
||||||
uid_changed = set_perms(PERM_ROOT);
|
|
||||||
|
|
||||||
if (mailit)
|
|
||||||
send_mail("%s", logline); /* XXX - return value */
|
|
||||||
|
|
||||||
/* Log via syslog and/or a file. */
|
|
||||||
if (def_log_denied) {
|
|
||||||
if (def_syslog && !do_syslog(def_syslog_badpri, logline))
|
|
||||||
ret = false;
|
|
||||||
if (def_logfile && !do_logfile(logline))
|
|
||||||
ret = false;
|
|
||||||
}
|
}
|
||||||
|
sudoers_to_eventlog(&evlog);
|
||||||
if (uid_changed) {
|
if (!eventlog_reject(&evlog, evl_flags, message, NULL, NULL))
|
||||||
if (!restore_perms())
|
ret = false;
|
||||||
ret = false; /* XXX - return -1 instead? */
|
|
||||||
}
|
|
||||||
|
|
||||||
free(logline);
|
|
||||||
|
|
||||||
/* Restore locale. */
|
/* Restore locale. */
|
||||||
sudoers_setlocale(oldlocale, NULL);
|
sudoers_setlocale(oldlocale, NULL);
|
||||||
@@ -385,46 +209,29 @@ log_auth_failure(int status, unsigned int tries)
|
|||||||
* Log and potentially mail the allowed command.
|
* Log and potentially mail the allowed command.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
log_allowed(int status)
|
log_allowed(void)
|
||||||
{
|
{
|
||||||
char *logline;
|
struct eventlog evlog;
|
||||||
int oldlocale;
|
int oldlocale;
|
||||||
bool uid_changed, ret = true;
|
int evl_flags = 0;
|
||||||
bool mailit;
|
bool mailit, ret = true;
|
||||||
debug_decl(log_allowed, SUDOERS_DEBUG_LOGGING);
|
debug_decl(log_allowed, SUDOERS_DEBUG_LOGGING);
|
||||||
|
|
||||||
/* Send mail based on status. */
|
/* Send mail based on status. */
|
||||||
mailit = should_mail(status);
|
mailit = should_mail(VALIDATE_SUCCESS);
|
||||||
|
|
||||||
if (def_log_allowed || mailit) {
|
if (def_log_allowed || mailit) {
|
||||||
/* Log and mail messages should be in the sudoers locale. */
|
/* Log and mail messages should be in the sudoers locale. */
|
||||||
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, &oldlocale);
|
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, &oldlocale);
|
||||||
|
|
||||||
if ((logline = new_logline(NULL, NULL)) == NULL)
|
sudoers_to_eventlog(&evlog);
|
||||||
debug_return_bool(false);
|
if (mailit) {
|
||||||
|
SET(evl_flags, EVLOG_MAIL);
|
||||||
/* Become root if we are not already. */
|
if (!def_log_allowed)
|
||||||
uid_changed = set_perms(PERM_ROOT);
|
SET(evl_flags, EVLOG_MAIL_ONLY);
|
||||||
|
|
||||||
if (mailit)
|
|
||||||
send_mail("%s", logline); /* XXX - return value */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Log via syslog and/or a file.
|
|
||||||
*/
|
|
||||||
if (def_log_allowed) {
|
|
||||||
if (def_syslog && !do_syslog(def_syslog_goodpri, logline))
|
|
||||||
ret = false;
|
|
||||||
if (def_logfile && !do_logfile(logline))
|
|
||||||
ret = false;
|
|
||||||
}
|
}
|
||||||
|
if (!eventlog_accept(&evlog, evl_flags, NULL, NULL))
|
||||||
if (uid_changed) {
|
ret = false;
|
||||||
if (!restore_perms())
|
|
||||||
ret = false; /* XXX - return -1 instead? */
|
|
||||||
}
|
|
||||||
|
|
||||||
free(logline);
|
|
||||||
|
|
||||||
sudoers_setlocale(oldlocale, NULL);
|
sudoers_setlocale(oldlocale, NULL);
|
||||||
}
|
}
|
||||||
@@ -494,12 +301,14 @@ done:
|
|||||||
static bool
|
static bool
|
||||||
vlog_warning(int flags, int errnum, const char *fmt, va_list ap)
|
vlog_warning(int flags, int errnum, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
int oldlocale;
|
struct eventlog evlog;
|
||||||
|
struct timespec now;
|
||||||
const char *errstr = NULL;
|
const char *errstr = NULL;
|
||||||
char *logline, *message;
|
char *message;
|
||||||
bool uid_changed, ret = true;
|
bool ret = true;
|
||||||
|
int len, oldlocale;
|
||||||
|
int evl_flags = 0;
|
||||||
va_list ap2;
|
va_list ap2;
|
||||||
int len;
|
|
||||||
debug_decl(vlog_warning, SUDOERS_DEBUG_LOGGING);
|
debug_decl(vlog_warning, SUDOERS_DEBUG_LOGGING);
|
||||||
|
|
||||||
/* Do auditing first (audit_failure() handles the locale itself). */
|
/* Do auditing first (audit_failure() handles the locale itself). */
|
||||||
@@ -541,45 +350,22 @@ vlog_warning(int flags, int errnum, const char *fmt, va_list ap)
|
|||||||
SUDO_DEBUG_WARN|sudo_debug_subsys, "%s", message);
|
SUDO_DEBUG_WARN|sudo_debug_subsys, "%s", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ISSET(flags, SLOG_RAW_MSG)) {
|
if (ISSET(flags, SLOG_SEND_MAIL) || !ISSET(flags, SLOG_NO_LOG)) {
|
||||||
logline = message;
|
if (sudo_gettime_real(&now) == -1) {
|
||||||
} else {
|
sudo_warn("%s", U_("unable to get time of day"));
|
||||||
logline = new_logline(message, errstr);
|
|
||||||
free(message);
|
|
||||||
if (logline == NULL) {
|
|
||||||
ret = false;
|
|
||||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
if (ISSET(flags, SLOG_RAW_MSG))
|
||||||
|
SET(evl_flags, EVLOG_RAW);
|
||||||
|
if (ISSET(flags, SLOG_SEND_MAIL)) {
|
||||||
|
SET(evl_flags, EVLOG_MAIL);
|
||||||
|
if (ISSET(flags, SLOG_NO_LOG))
|
||||||
|
SET(evl_flags, EVLOG_MAIL_ONLY);
|
||||||
}
|
}
|
||||||
|
sudoers_to_eventlog(&evlog);
|
||||||
/* Become root if we are not already. */
|
eventlog_alert(&evlog, evl_flags, &now, message, errstr);
|
||||||
uid_changed = set_perms(PERM_ROOT);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Send a copy of the error via mail.
|
|
||||||
* XXX - return value
|
|
||||||
*/
|
|
||||||
if (ISSET(flags, SLOG_SEND_MAIL))
|
|
||||||
send_mail("%s", logline);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Log to syslog and/or a file.
|
|
||||||
*/
|
|
||||||
if (!ISSET(flags, SLOG_NO_LOG)) {
|
|
||||||
if (def_syslog && !do_syslog(def_syslog_badpri, logline))
|
|
||||||
ret = false;
|
|
||||||
if (def_logfile && !do_logfile(logline))
|
|
||||||
ret = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uid_changed) {
|
|
||||||
if (!restore_perms())
|
|
||||||
ret = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(logline);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tell the user (in their locale).
|
* Tell the user (in their locale).
|
||||||
*/
|
*/
|
||||||
@@ -658,262 +444,6 @@ gai_log_warning(int flags, int errnum, const char *fmt, ...)
|
|||||||
debug_return_bool(ret);
|
debug_return_bool(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
closefrom_nodebug(int lowfd)
|
|
||||||
{
|
|
||||||
unsigned char *debug_fds;
|
|
||||||
int fd, startfd;
|
|
||||||
debug_decl(closefrom_nodebug, SUDOERS_DEBUG_LOGGING);
|
|
||||||
|
|
||||||
startfd = sudo_debug_get_fds(&debug_fds) + 1;
|
|
||||||
if (lowfd > startfd)
|
|
||||||
startfd = lowfd;
|
|
||||||
|
|
||||||
/* Close fds higher than the debug fds. */
|
|
||||||
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,
|
|
||||||
"closing fds >= %d", startfd);
|
|
||||||
closefrom(startfd);
|
|
||||||
|
|
||||||
/* Close fds [lowfd, startfd) that are not in debug_fds. */
|
|
||||||
for (fd = lowfd; fd < startfd; fd++) {
|
|
||||||
if (sudo_isset(debug_fds, fd))
|
|
||||||
continue;
|
|
||||||
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,
|
|
||||||
"closing fd %d", fd);
|
|
||||||
#ifdef __APPLE__
|
|
||||||
/* Avoid potential libdispatch crash when we close its fds. */
|
|
||||||
(void) fcntl(fd, F_SETFD, FD_CLOEXEC);
|
|
||||||
#else
|
|
||||||
(void) close(fd);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
debug_return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define MAX_MAILFLAGS 63
|
|
||||||
|
|
||||||
static void __attribute__((__noreturn__))
|
|
||||||
exec_mailer(int pipein)
|
|
||||||
{
|
|
||||||
char *last, *p, *argv[MAX_MAILFLAGS + 1];
|
|
||||||
char *mflags, *mpath = def_mailerpath;
|
|
||||||
int i;
|
|
||||||
#ifdef NO_ROOT_MAILER
|
|
||||||
int perm = PERM_FULL_USER;
|
|
||||||
#else
|
|
||||||
int perm = PERM_ROOT;
|
|
||||||
static char *envp[] = {
|
|
||||||
"HOME=/",
|
|
||||||
"PATH=/usr/bin:/bin:/usr/sbin:/sbin",
|
|
||||||
"LOGNAME=root",
|
|
||||||
"USER=root",
|
|
||||||
# ifdef _AIX
|
|
||||||
"LOGIN=root",
|
|
||||||
# endif
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
#endif /* NO_ROOT_MAILER */
|
|
||||||
debug_decl(exec_mailer, SUDOERS_DEBUG_LOGGING);
|
|
||||||
|
|
||||||
/* Set stdin to read side of the pipe. */
|
|
||||||
if (dup3(pipein, STDIN_FILENO, 0) == -1) {
|
|
||||||
mysyslog(LOG_ERR, _("unable to dup stdin: %m"));
|
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR,
|
|
||||||
"unable to dup stdin: %s", strerror(errno));
|
|
||||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
|
||||||
_exit(127);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Build up an argv based on the mailer path and flags */
|
|
||||||
if ((mflags = strdup(def_mailerflags)) == NULL) {
|
|
||||||
mysyslog(LOG_ERR, _("unable to allocate memory"));
|
|
||||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
|
||||||
_exit(127);
|
|
||||||
}
|
|
||||||
if ((argv[0] = strrchr(mpath, '/')))
|
|
||||||
argv[0]++;
|
|
||||||
else
|
|
||||||
argv[0] = mpath;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
if ((p = strtok_r(mflags, " \t", &last))) {
|
|
||||||
do {
|
|
||||||
argv[i] = p;
|
|
||||||
} while (++i < MAX_MAILFLAGS && (p = strtok_r(NULL, " \t", &last)));
|
|
||||||
}
|
|
||||||
argv[i] = NULL;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Depending on the config, either run the mailer as root
|
|
||||||
* (so user cannot kill it) or as the user (for the paranoid).
|
|
||||||
*/
|
|
||||||
(void) set_perms(perm);
|
|
||||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
|
||||||
#ifdef NO_ROOT_MAILER
|
|
||||||
execv(mpath, argv);
|
|
||||||
#else
|
|
||||||
execve(mpath, argv, envp);
|
|
||||||
#endif
|
|
||||||
mysyslog(LOG_ERR, _("unable to execute %s: %m"), mpath);
|
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR, "unable to execute %s: %s",
|
|
||||||
mpath, strerror(errno));
|
|
||||||
_exit(127);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Send a message to MAILTO user
|
|
||||||
*/
|
|
||||||
static bool
|
|
||||||
send_mail(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
FILE *mail;
|
|
||||||
char *p;
|
|
||||||
const char *timestr;
|
|
||||||
int fd, pfd[2], status;
|
|
||||||
pid_t pid, rv;
|
|
||||||
struct stat sb;
|
|
||||||
va_list ap;
|
|
||||||
debug_decl(send_mail, SUDOERS_DEBUG_LOGGING);
|
|
||||||
|
|
||||||
/* If mailer is disabled just return. */
|
|
||||||
if (!def_mailerpath || !def_mailto)
|
|
||||||
debug_return_bool(true);
|
|
||||||
|
|
||||||
/* Make sure the mailer exists and is a regular file. */
|
|
||||||
if (stat(def_mailerpath, &sb) != 0 || !S_ISREG(sb.st_mode))
|
|
||||||
debug_return_bool(false);
|
|
||||||
|
|
||||||
/* Fork and return, child will daemonize. */
|
|
||||||
switch (pid = sudo_debug_fork()) {
|
|
||||||
case -1:
|
|
||||||
/* Error. */
|
|
||||||
sudo_warn("%s", U_("unable to fork"));
|
|
||||||
debug_return_bool(false);
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
/* Child. */
|
|
||||||
switch (fork()) {
|
|
||||||
case -1:
|
|
||||||
/* Error. */
|
|
||||||
mysyslog(LOG_ERR, _("unable to fork: %m"));
|
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR, "unable to fork: %s",
|
|
||||||
strerror(errno));
|
|
||||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
|
||||||
_exit(EXIT_FAILURE);
|
|
||||||
case 0:
|
|
||||||
/* Grandchild continues below. */
|
|
||||||
sudo_debug_enter(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* Parent will wait for us. */
|
|
||||||
_exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* Parent. */
|
|
||||||
for (;;) {
|
|
||||||
rv = waitpid(pid, &status, 0);
|
|
||||||
if (rv == -1 && errno != EINTR)
|
|
||||||
break;
|
|
||||||
if (rv != -1 && !WIFSTOPPED(status))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
|
|
||||||
"child (%d) exit value %d", (int)rv, status);
|
|
||||||
debug_return_bool(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Daemonize - disassociate from session/tty. */
|
|
||||||
if (setsid() == -1)
|
|
||||||
sudo_warn("setsid");
|
|
||||||
if (chdir("/") == -1)
|
|
||||||
sudo_warn("chdir(/)");
|
|
||||||
fd = open(_PATH_DEVNULL, O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
|
||||||
if (fd != -1) {
|
|
||||||
(void) dup2(fd, STDIN_FILENO);
|
|
||||||
(void) dup2(fd, STDOUT_FILENO);
|
|
||||||
(void) dup2(fd, STDERR_FILENO);
|
|
||||||
}
|
|
||||||
|
|
||||||
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, NULL);
|
|
||||||
|
|
||||||
/* Close non-debug fds so we don't leak anything. */
|
|
||||||
closefrom_nodebug(STDERR_FILENO + 1);
|
|
||||||
|
|
||||||
if (pipe2(pfd, O_CLOEXEC) == -1) {
|
|
||||||
mysyslog(LOG_ERR, _("unable to open pipe: %m"));
|
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR, "unable to open pipe: %s",
|
|
||||||
strerror(errno));
|
|
||||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
|
||||||
_exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (pid = sudo_debug_fork()) {
|
|
||||||
case -1:
|
|
||||||
/* Error. */
|
|
||||||
mysyslog(LOG_ERR, _("unable to fork: %m"));
|
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR, "unable to fork: %s",
|
|
||||||
strerror(errno));
|
|
||||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
|
||||||
_exit(EXIT_FAILURE);
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
/* Child. */
|
|
||||||
exec_mailer(pfd[0]);
|
|
||||||
/* NOTREACHED */
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) close(pfd[0]);
|
|
||||||
mail = fdopen(pfd[1], "w");
|
|
||||||
|
|
||||||
/* Pipes are all setup, send message. */
|
|
||||||
(void) fprintf(mail, "To: %s\nFrom: %s\nAuto-Submitted: %s\nSubject: ",
|
|
||||||
def_mailto, def_mailfrom ? def_mailfrom : user_name, "auto-generated");
|
|
||||||
for (p = _(def_mailsub); *p; p++) {
|
|
||||||
/* Expand escapes in the subject */
|
|
||||||
if (*p == '%' && *(p+1) != '%') {
|
|
||||||
switch (*(++p)) {
|
|
||||||
case 'h':
|
|
||||||
(void) fputs(user_host, mail);
|
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
(void) fputs(user_name, mail);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
p--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
(void) fputc(*p, mail);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(HAVE_NL_LANGINFO) && defined(CODESET)
|
|
||||||
if (strcmp(def_sudoers_locale, "C") != 0)
|
|
||||||
(void) fprintf(mail, "\nContent-Type: text/plain; charset=\"%s\"\nContent-Transfer-Encoding: 8bit", nl_langinfo(CODESET));
|
|
||||||
#endif /* HAVE_NL_LANGINFO && CODESET */
|
|
||||||
|
|
||||||
if ((timestr = get_timestr(time(NULL), def_log_year)) == NULL)
|
|
||||||
timestr = "invalid date";
|
|
||||||
(void) fprintf(mail, "\n\n%s : %s : %s : ", user_host, timestr, user_name);
|
|
||||||
va_start(ap, fmt);
|
|
||||||
(void) vfprintf(mail, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
fputs("\n\n", mail);
|
|
||||||
|
|
||||||
fclose(mail);
|
|
||||||
for (;;) {
|
|
||||||
rv = waitpid(pid, &status, 0);
|
|
||||||
if (rv == -1 && errno != EINTR)
|
|
||||||
break;
|
|
||||||
if (rv != -1 && !WIFSTOPPED(status))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
|
|
||||||
"child (%d) exit value %d", (int)rv, status);
|
|
||||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
|
||||||
_exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine whether we should send mail based on "status" and defaults options.
|
* Determine whether we should send mail based on "status" and defaults options.
|
||||||
*/
|
*/
|
||||||
@@ -929,177 +459,150 @@ should_mail(int status)
|
|||||||
(def_mail_no_perms && !ISSET(status, VALIDATE_SUCCESS)));
|
(def_mail_no_perms && !ISSET(status, VALIDATE_SUCCESS)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LL_TTY_STR "TTY="
|
|
||||||
#define LL_CHROOT_STR "CHROOT="
|
|
||||||
#define LL_CWD_STR "PWD=" /* XXX - should be CWD= */
|
|
||||||
#define LL_USER_STR "USER="
|
|
||||||
#define LL_GROUP_STR "GROUP="
|
|
||||||
#define LL_ENV_STR "ENV="
|
|
||||||
#define LL_CMND_STR "COMMAND="
|
|
||||||
#define LL_TSID_STR "TSID="
|
|
||||||
|
|
||||||
#define IS_SESSID(s) ( \
|
|
||||||
isalnum((unsigned char)(s)[0]) && isalnum((unsigned char)(s)[1]) && \
|
|
||||||
(s)[2] == '/' && \
|
|
||||||
isalnum((unsigned char)(s)[3]) && isalnum((unsigned char)(s)[4]) && \
|
|
||||||
(s)[5] == '/' && \
|
|
||||||
isalnum((unsigned char)(s)[6]) && isalnum((unsigned char)(s)[7]) && \
|
|
||||||
(s)[8] == '\0')
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate and fill in a new logline.
|
* Build a struct eventlog from sudoers data.
|
||||||
|
* The values in the resulting eventlog struct should not be freed.
|
||||||
*/
|
*/
|
||||||
char *
|
void
|
||||||
new_logline(const char *message, const char *errstr)
|
sudoers_to_eventlog(struct eventlog *evlog)
|
||||||
{
|
{
|
||||||
char *line = NULL, *evstr = NULL;
|
debug_decl(sudoers_to_eventlog, SUDOERS_DEBUG_LOGGING);
|
||||||
#ifndef SUDOERS_NO_SEQ
|
|
||||||
char sessid[7];
|
|
||||||
#endif
|
|
||||||
const char *tsid = NULL;
|
|
||||||
size_t len = 0;
|
|
||||||
debug_decl(new_logline, SUDOERS_DEBUG_LOGGING);
|
|
||||||
|
|
||||||
#ifndef SUDOERS_NO_SEQ
|
memset(evlog, 0, sizeof(*evlog));
|
||||||
/* A TSID may be a sudoers-style session ID or a free-form string. */
|
/* TODO: iolog_path */
|
||||||
if (sudo_user.iolog_file != NULL) {
|
evlog->iolog_file = sudo_user.iolog_file;
|
||||||
if (IS_SESSID(sudo_user.iolog_file)) {
|
evlog->command = safe_cmnd;
|
||||||
sessid[0] = sudo_user.iolog_file[0];
|
evlog->cwd = user_cwd;
|
||||||
sessid[1] = sudo_user.iolog_file[1];
|
if (def_runchroot != NULL && strcmp(def_runchroot, "*") != 0) {
|
||||||
sessid[2] = sudo_user.iolog_file[3];
|
evlog->runchroot = def_runchroot;
|
||||||
sessid[3] = sudo_user.iolog_file[4];
|
}
|
||||||
sessid[4] = sudo_user.iolog_file[6];
|
if (def_runcwd && strcmp(def_runcwd, "*") != 0) {
|
||||||
sessid[5] = sudo_user.iolog_file[7];
|
evlog->runcwd = def_runcwd;
|
||||||
sessid[6] = '\0';
|
} else if (ISSET(sudo_mode, MODE_LOGIN_SHELL)) {
|
||||||
tsid = sessid;
|
evlog->runcwd = runas_pw->pw_dir;
|
||||||
} else {
|
} else {
|
||||||
tsid = sudo_user.iolog_file;
|
evlog->runcwd = user_cwd;
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Compute line length
|
|
||||||
*/
|
|
||||||
if (message != NULL)
|
|
||||||
len += strlen(message) + 3;
|
|
||||||
if (errstr != NULL)
|
|
||||||
len += strlen(errstr) + 3;
|
|
||||||
len += sizeof(LL_TTY_STR) + 2 + strlen(user_tty);
|
|
||||||
if (user_runchroot != NULL)
|
|
||||||
len += sizeof(LL_CHROOT_STR) + 2 + strlen(user_runchroot);
|
|
||||||
len += sizeof(LL_CWD_STR) + 2 + strlen(user_runcwd);
|
|
||||||
if (runas_pw != NULL)
|
|
||||||
len += sizeof(LL_USER_STR) + 2 + strlen(runas_pw->pw_name);
|
|
||||||
if (runas_gr != NULL)
|
|
||||||
len += sizeof(LL_GROUP_STR) + 2 + strlen(runas_gr->gr_name);
|
|
||||||
if (tsid != NULL)
|
|
||||||
len += sizeof(LL_TSID_STR) + 2 + strlen(tsid);
|
|
||||||
if (sudo_user.env_vars != NULL) {
|
|
||||||
size_t evlen = 0;
|
|
||||||
char * const *ep;
|
|
||||||
|
|
||||||
for (ep = sudo_user.env_vars; *ep != NULL; ep++)
|
|
||||||
evlen += strlen(*ep) + 1;
|
|
||||||
if (evlen != 0) {
|
|
||||||
if ((evstr = malloc(evlen)) == NULL)
|
|
||||||
goto oom;
|
|
||||||
evstr[0] = '\0';
|
|
||||||
for (ep = sudo_user.env_vars; *ep != NULL; ep++) {
|
|
||||||
strlcat(evstr, *ep, evlen);
|
|
||||||
strlcat(evstr, " ", evlen); /* NOTE: last one will fail */
|
|
||||||
}
|
|
||||||
len += sizeof(LL_ENV_STR) + 2 + evlen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (user_cmnd != NULL) {
|
|
||||||
/* Note: we log "sudo -l command arg ..." as "list command arg ..." */
|
|
||||||
len += sizeof(LL_CMND_STR) - 1 + strlen(user_cmnd);
|
|
||||||
if (ISSET(sudo_mode, MODE_CHECK))
|
|
||||||
len += sizeof("list ") - 1;
|
|
||||||
if (user_args != NULL)
|
|
||||||
len += strlen(user_args) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate and build up the line.
|
|
||||||
*/
|
|
||||||
if ((line = malloc(++len)) == NULL)
|
|
||||||
goto oom;
|
|
||||||
line[0] = '\0';
|
|
||||||
|
|
||||||
if (message != NULL) {
|
|
||||||
if (strlcat(line, message, len) >= len ||
|
|
||||||
strlcat(line, errstr ? " : " : " ; ", len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
}
|
|
||||||
if (errstr != NULL) {
|
|
||||||
if (strlcat(line, errstr, len) >= len ||
|
|
||||||
strlcat(line, " ; ", len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
}
|
|
||||||
if (strlcat(line, LL_TTY_STR, len) >= len ||
|
|
||||||
strlcat(line, user_tty, len) >= len ||
|
|
||||||
strlcat(line, " ; ", len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
if (user_runchroot != NULL) {
|
|
||||||
if (strlcat(line, LL_CHROOT_STR, len) >= len ||
|
|
||||||
strlcat(line, user_runchroot, len) >= len ||
|
|
||||||
strlcat(line, " ; ", len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
}
|
|
||||||
if (strlcat(line, LL_CWD_STR, len) >= len ||
|
|
||||||
strlcat(line, user_runcwd, len) >= len ||
|
|
||||||
strlcat(line, " ; ", len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
if (runas_pw != NULL) {
|
|
||||||
if (strlcat(line, LL_USER_STR, len) >= len ||
|
|
||||||
strlcat(line, runas_pw->pw_name, len) >= len ||
|
|
||||||
strlcat(line, " ; ", len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
}
|
}
|
||||||
if (runas_gr != NULL) {
|
if (runas_gr != NULL) {
|
||||||
if (strlcat(line, LL_GROUP_STR, len) >= len ||
|
evlog->rungroup = runas_gr->gr_name;
|
||||||
strlcat(line, runas_gr->gr_name, len) >= len ||
|
|
||||||
strlcat(line, " ; ", len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
}
|
|
||||||
if (tsid != NULL) {
|
|
||||||
if (strlcat(line, LL_TSID_STR, len) >= len ||
|
|
||||||
strlcat(line, tsid, len) >= len ||
|
|
||||||
strlcat(line, " ; ", len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
}
|
|
||||||
if (evstr != NULL) {
|
|
||||||
if (strlcat(line, LL_ENV_STR, len) >= len ||
|
|
||||||
strlcat(line, evstr, len) >= len ||
|
|
||||||
strlcat(line, " ; ", len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
free(evstr);
|
|
||||||
evstr = NULL;
|
|
||||||
}
|
|
||||||
if (user_cmnd != NULL) {
|
|
||||||
if (strlcat(line, LL_CMND_STR, len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
if (ISSET(sudo_mode, MODE_CHECK) && strlcat(line, "list ", len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
if (strlcat(line, user_cmnd, len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
if (user_args != NULL) {
|
|
||||||
if (strlcat(line, " ", len) >= len ||
|
|
||||||
strlcat(line, user_args, len) >= len)
|
|
||||||
goto toobig;
|
|
||||||
}
|
}
|
||||||
|
evlog->runuser = runas_pw->pw_name;
|
||||||
|
evlog->submithost = user_host;
|
||||||
|
evlog->submituser = user_name;
|
||||||
|
/* TODO - submitgroup */
|
||||||
|
/* XXX - use ttypath for JSON logs */
|
||||||
|
evlog->ttyname = user_tty;
|
||||||
|
evlog->argv = NewArgv;
|
||||||
|
evlog->env_add = (char **)sudo_user.env_vars;
|
||||||
|
evlog->envp = env_get();
|
||||||
|
evlog->submit_time = sudo_user.submit_time;
|
||||||
|
evlog->lines = sudo_user.lines;
|
||||||
|
evlog->columns = sudo_user.cols;
|
||||||
|
evlog->runuid = runas_pw->pw_uid;
|
||||||
|
evlog->rungid = runas_pw->pw_gid;
|
||||||
|
|
||||||
|
debug_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_return_str(line);
|
static FILE *
|
||||||
oom:
|
sudoers_log_open(int type, const char *log_file)
|
||||||
free(evstr);
|
{
|
||||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
static bool warned = false; /* XXX */
|
||||||
debug_return_str(NULL);
|
bool uid_changed;
|
||||||
toobig:
|
FILE *fp = NULL;
|
||||||
free(evstr);
|
mode_t oldmask;
|
||||||
free(line);
|
debug_decl(sudoers_log_open, SUDOERS_DEBUG_DEFAULTS);
|
||||||
sudo_warnx(U_("internal error, %s overflow"), __func__);
|
|
||||||
debug_return_str(NULL);
|
switch (type) {
|
||||||
|
case EVLOG_SYSLOG:
|
||||||
|
openlog("sudo", def_syslog_pid ? LOG_PID : 0, def_syslog);
|
||||||
|
break;
|
||||||
|
case EVLOG_FILE:
|
||||||
|
/* Open log file as root, mode 0600. */
|
||||||
|
oldmask = umask(S_IRWXG|S_IRWXO);
|
||||||
|
uid_changed = set_perms(PERM_ROOT);
|
||||||
|
fp = fopen(log_file, "a");
|
||||||
|
if (uid_changed && !restore_perms()) {
|
||||||
|
if (fp != NULL) {
|
||||||
|
fclose(fp);
|
||||||
|
fp = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(void) umask(oldmask);
|
||||||
|
if (fp == NULL && !warned) {
|
||||||
|
log_warning(SLOG_SEND_MAIL|SLOG_NO_LOG,
|
||||||
|
N_("unable to open log file: %s"), log_file);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
||||||
|
"unsupported log type %d", type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
debug_return_ptr(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sudoers_log_close(int type, FILE *fp)
|
||||||
|
{
|
||||||
|
debug_decl(sudoers_log_close, SUDOERS_DEBUG_DEFAULTS);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case EVLOG_SYSLOG:
|
||||||
|
break;
|
||||||
|
case EVLOG_FILE:
|
||||||
|
if (fp != NULL) {
|
||||||
|
fclose(fp);
|
||||||
|
} else {
|
||||||
|
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
||||||
|
"tried to close NULL");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
||||||
|
"unsupported log type %d", type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
debug_return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
update_eventlog_config(void)
|
||||||
|
{
|
||||||
|
struct eventlog_config evconf;
|
||||||
|
debug_decl(update_eventlog_config, SUDOERS_DEBUG_DEFAULTS);
|
||||||
|
|
||||||
|
memset(&evconf, 0, sizeof(evconf));
|
||||||
|
if (def_syslog) {
|
||||||
|
evconf.type |= EVLOG_SYSLOG;
|
||||||
|
evconf.syslog_acceptpri = def_syslog_goodpri;
|
||||||
|
evconf.syslog_rejectpri = def_syslog_badpri;
|
||||||
|
evconf.syslog_alertpri = def_syslog_badpri;
|
||||||
|
evconf.syslog_maxlen = def_syslog_maxlen;
|
||||||
|
}
|
||||||
|
if (def_logfile) {
|
||||||
|
evconf.type |= EVLOG_FILE;
|
||||||
|
evconf.logpath = def_logfile;
|
||||||
|
}
|
||||||
|
evconf.format = EVLOG_SUDO;
|
||||||
|
evconf.time_fmt = def_log_year ? "%h %e %T %Y" : "%h %e %T";
|
||||||
|
if (!def_log_host)
|
||||||
|
evconf.omit_hostname = true;
|
||||||
|
#ifdef NO_ROOT_MAILER
|
||||||
|
evconf.mailuid = user_uid;
|
||||||
|
#else
|
||||||
|
evconf.mailuid = ROOT_UID;
|
||||||
|
#endif
|
||||||
|
evconf.mailerpath = def_mailerpath;
|
||||||
|
evconf.mailerflags = def_mailerflags;
|
||||||
|
evconf.mailfrom = def_mailfrom;
|
||||||
|
evconf.mailto = def_mailto;
|
||||||
|
evconf.open_log = sudoers_log_open;
|
||||||
|
evconf.close_log = sudoers_log_close;
|
||||||
|
|
||||||
|
eventlog_setconf(&evconf);
|
||||||
|
|
||||||
|
debug_return;
|
||||||
}
|
}
|
||||||
|
@@ -58,15 +58,12 @@ extern char *audit_msg;
|
|||||||
|
|
||||||
union sudo_defs_val;
|
union sudo_defs_val;
|
||||||
|
|
||||||
bool do_logfile(const char *msg);
|
|
||||||
bool do_syslog(int pri, const char *msg);
|
|
||||||
char *new_logline(const char *, const char *);
|
|
||||||
bool sudoers_warn_setlocale(bool restore, int *cookie);
|
bool sudoers_warn_setlocale(bool restore, int *cookie);
|
||||||
bool sudoers_setlocale(int locale_type, int *prev_locale);
|
bool sudoers_setlocale(int locale_type, int *prev_locale);
|
||||||
int sudoers_getlocale(void);
|
int sudoers_getlocale(void);
|
||||||
int audit_failure(char *const argv[], char const *const fmt, ...) __printflike(2, 3);
|
int audit_failure(char *const argv[], char const *const fmt, ...) __printflike(2, 3);
|
||||||
int vaudit_failure(char *const argv[], char const *const fmt, va_list ap) __printflike(2, 0);
|
int vaudit_failure(char *const argv[], char const *const fmt, va_list ap) __printflike(2, 0);
|
||||||
bool log_allowed(int status);
|
bool log_allowed(void);
|
||||||
bool log_auth_failure(int status, unsigned int tries);
|
bool log_auth_failure(int status, unsigned int tries);
|
||||||
bool log_denial(int status, bool inform_user);
|
bool log_denial(int status, bool inform_user);
|
||||||
bool log_failure(int status, int flags);
|
bool log_failure(int status, int flags);
|
||||||
@@ -76,5 +73,7 @@ bool gai_log_warning(int flags, int errnum, const char *fmt, ...) __printflike(3
|
|||||||
bool sudoers_initlocale(const char *ulocale, const char *slocale);
|
bool sudoers_initlocale(const char *ulocale, const char *slocale);
|
||||||
bool sudoers_locale_callback(const union sudo_defs_val *);
|
bool sudoers_locale_callback(const union sudo_defs_val *);
|
||||||
int writeln_wrap(FILE *fp, char *line, size_t len, size_t maxlen);
|
int writeln_wrap(FILE *fp, char *line, size_t len, size_t maxlen);
|
||||||
|
void sudoers_to_eventlog(struct eventlog *evlog);
|
||||||
|
void update_eventlog_config(void);
|
||||||
|
|
||||||
#endif /* SUDOERS_LOGGING_H */
|
#endif /* SUDOERS_LOGGING_H */
|
||||||
|
@@ -110,6 +110,11 @@ sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group)
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
if (sudo_gettime_real(&sudo_user.submit_time) == -1) {
|
||||||
|
sudo_warn("%s", U_("unable to get time of day"));
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse sudo.conf plugin args. */
|
/* Parse sudo.conf plugin args. */
|
||||||
if (info->plugin_args != NULL) {
|
if (info->plugin_args != NULL) {
|
||||||
for (cur = info->plugin_args; *cur != NULL; cur++) {
|
for (cur = info->plugin_args; *cur != NULL; cur++) {
|
||||||
|
@@ -87,6 +87,13 @@ set_cmnd_path(const char *runchroot)
|
|||||||
return FOUND;
|
return FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* STUB */
|
||||||
|
void
|
||||||
|
update_eventlog_config(void)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look up the hostname and set user_host and user_shost.
|
* Look up the hostname and set user_host and user_shost.
|
||||||
*/
|
*/
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
#include "sudo_compat.h"
|
#include "sudo_compat.h"
|
||||||
#include "sudo_conf.h"
|
#include "sudo_conf.h"
|
||||||
|
#include "sudo_eventlog.h"
|
||||||
#include "sudo_fatal.h"
|
#include "sudo_fatal.h"
|
||||||
#include "sudo_gettext.h"
|
#include "sudo_gettext.h"
|
||||||
#include "sudo_nss.h"
|
#include "sudo_nss.h"
|
||||||
@@ -76,8 +77,10 @@ struct group_list {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Info pertaining to the invoking user.
|
* Info pertaining to the invoking user.
|
||||||
|
* XXX - can we embed struct eventlog here or use it instead?
|
||||||
*/
|
*/
|
||||||
struct sudo_user {
|
struct sudo_user {
|
||||||
|
struct timespec submit_time;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
struct passwd *_runas_pw;
|
struct passwd *_runas_pw;
|
||||||
struct group *_runas_gr;
|
struct group *_runas_gr;
|
||||||
|
@@ -500,6 +500,12 @@ restore_perms(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
update_eventlog_config(void)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
set_cmnd_path(const char *runchroot)
|
set_cmnd_path(const char *runchroot)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user