Handle a missing run_time in an ExitMessage.
It is now possible to pass a NULL run_time to eventlog_exit().
This commit is contained in:
@@ -900,11 +900,13 @@ format_json(int event_type, struct eventlog_args *args,
|
||||
}
|
||||
|
||||
/* Log event time from client */
|
||||
if (args->event_time != NULL) {
|
||||
if (!json_add_timestamp(&json, time_str, args->event_time, format_timestamp)) {
|
||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
||||
"unable format timestamp");
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
||||
if (event_type == EVLOG_EXIT) {
|
||||
/* Exit events don't need evlog details if there is a UUID. */
|
||||
@@ -1136,7 +1138,6 @@ do_logfile_sudo(const char *logline, const struct eventlog *evlog,
|
||||
char *full_line, timebuf[8192], *timestr = NULL;
|
||||
const char *timefmt = evl_conf->time_fmt;
|
||||
const char *logfile = evl_conf->logpath;
|
||||
time_t tv_sec = event_time->tv_sec;
|
||||
struct tm tm;
|
||||
bool ret = false;
|
||||
FILE *fp;
|
||||
@@ -1152,6 +1153,8 @@ do_logfile_sudo(const char *logline, const struct eventlog *evlog,
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (event_time != NULL) {
|
||||
time_t tv_sec = event_time->tv_sec;
|
||||
if (localtime_r(&tv_sec, &tm) != NULL) {
|
||||
/* strftime() does not guarantee to NUL-terminate so we must check. */
|
||||
timebuf[sizeof(timebuf) - 1] = '\0';
|
||||
@@ -1160,6 +1163,7 @@ do_logfile_sudo(const char *logline, const struct eventlog *evlog,
|
||||
timestr = timebuf;
|
||||
}
|
||||
}
|
||||
}
|
||||
len = asprintf(&full_line, "%s : %s : %s",
|
||||
timestr ? timestr : "invalid date", evlog->submituser, logline);
|
||||
if (len == -1) {
|
||||
|
@@ -264,12 +264,16 @@ bool
|
||||
store_exit_local(ExitMessage *msg, uint8_t *buf, size_t len,
|
||||
struct connection_closure *closure)
|
||||
{
|
||||
struct timespec ts, *run_time = NULL;
|
||||
const char *signame = NULL;
|
||||
struct timespec run_time = { msg->run_time->tv_sec, msg->run_time->tv_nsec };
|
||||
int flags = 0;
|
||||
mode_t mode;
|
||||
debug_decl(store_exit_local, SUDO_DEBUG_UTIL);
|
||||
|
||||
if (msg->run_time != NULL) {
|
||||
ts.tv_sec = msg->run_time->tv_sec;
|
||||
ts.tv_nsec = msg->run_time->tv_nsec;
|
||||
run_time = &ts;
|
||||
}
|
||||
if (msg->signal != NULL && msg->signal[0] != '\0') {
|
||||
signame = msg->signal;
|
||||
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
|
||||
@@ -280,7 +284,7 @@ store_exit_local(ExitMessage *msg, uint8_t *buf, size_t len,
|
||||
"command exited with %d", msg->exit_value);
|
||||
}
|
||||
if (logsrvd_conf_log_exit()) {
|
||||
if (!eventlog_exit(closure->evlog, flags, &run_time, msg->exit_value,
|
||||
if (!eventlog_exit(closure->evlog, flags, run_time, msg->exit_value,
|
||||
signame, msg->dumped_core)) {
|
||||
closure->errstr = _("error logging exit event");
|
||||
debug_return_bool(false);
|
||||
@@ -289,7 +293,7 @@ store_exit_local(ExitMessage *msg, uint8_t *buf, size_t len,
|
||||
|
||||
if (closure->log_io) {
|
||||
/* Clear write bits from I/O timing file to indicate completion. */
|
||||
mode = logsrvd_conf_iolog_mode();
|
||||
mode_t mode = logsrvd_conf_iolog_mode();
|
||||
CLR(mode, S_IWUSR|S_IWGRP|S_IWOTH);
|
||||
if (fchmodat(closure->iolog_dir_fd, "timing", mode, 0) == -1) {
|
||||
sudo_warn("chmod 0%o %s/%s", (unsigned int)mode, "timing",
|
||||
|
Reference in New Issue
Block a user