diff --git a/include/sudo_eventlog.h b/include/sudo_eventlog.h index 74a67dd46..8d4d8b75f 100644 --- a/include/sudo_eventlog.h +++ b/include/sudo_eventlog.h @@ -103,6 +103,7 @@ struct eventlog { char *rungroup; char *runuser; char *peeraddr; + char *signal_name; char *submithost; char *submituser; char *submitgroup; @@ -112,10 +113,13 @@ struct eventlog { char **envp; struct timespec submit_time; struct timespec iolog_offset; + struct timespec run_time; + int exit_value; int lines; int columns; uid_t runuid; gid_t rungid; + bool dumped_core; char sessid[7]; char uuid_str[37]; }; diff --git a/lib/iolog/iolog_json.c b/lib/iolog/iolog_json.c index 4933c0834..6945ac7d1 100644 --- a/lib/iolog/iolog_json.c +++ b/lib/iolog/iolog_json.c @@ -85,6 +85,31 @@ json_store_command(struct json_item *item, struct eventlog *evlog) debug_return_bool(true); } +static bool +json_store_dumped_core(struct json_item *item, struct eventlog *evlog) +{ + debug_decl(json_store_dumped_core, SUDO_DEBUG_UTIL); + + evlog->dumped_core = item->u.boolean; + debug_return_bool(true); +} + +static bool +json_store_exit_value(struct json_item *item, struct eventlog *evlog) +{ + debug_decl(json_store_exit_value, SUDO_DEBUG_UTIL); + + if (item->u.number < 0 || item->u.number > INT_MAX) { + sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, + "exit value %lld: out of range", item->u.number); + evlog->exit_value = -1; + debug_return_bool(false); + } + + evlog->exit_value = item->u.number; + debug_return_bool(true); +} + static bool json_store_lines(struct json_item *item, struct eventlog *evlog) { @@ -229,6 +254,17 @@ json_store_runcwd(struct json_item *item, struct eventlog *evlog) debug_return_bool(true); } +static bool +json_store_signal(struct json_item *item, struct eventlog *evlog) +{ + debug_decl(json_store_signal, SUDO_DEBUG_UTIL); + + free(evlog->signal_name); + evlog->signal_name = item->u.string; + item->u.string = NULL; + debug_return_bool(true); +} + static bool json_store_submitcwd(struct json_item *item, struct eventlog *evlog) { @@ -263,27 +299,39 @@ json_store_submituser(struct json_item *item, struct eventlog *evlog) } static bool -json_store_timestamp(struct json_item *item, struct eventlog *evlog) +json_store_timespec(struct json_item *item, struct timespec *ts) { struct json_object *object; - debug_decl(json_store_timestamp, SUDO_DEBUG_UTIL); + debug_decl(json_store_timespec, SUDO_DEBUG_UTIL); object = &item->u.child; TAILQ_FOREACH(item, &object->items, entries) { if (item->type != JSON_NUMBER) continue; if (strcmp(item->name, "seconds") == 0) { - evlog->submit_time.tv_sec = item->u.number; + ts->tv_sec = item->u.number; continue; } if (strcmp(item->name, "nanoseconds") == 0) { - evlog->submit_time.tv_nsec = item->u.number; + ts->tv_nsec = item->u.number; continue; } } debug_return_bool(true); } +static bool +json_store_run_time(struct json_item *item, struct eventlog *evlog) +{ + return json_store_timespec(item, &evlog->run_time); +} + +static bool +json_store_timestamp(struct json_item *item, struct eventlog *evlog) +{ + return json_store_timespec(item, &evlog->submit_time); +} + static bool json_store_ttyname(struct json_item *item, struct eventlog *evlog) { @@ -302,7 +350,10 @@ static struct iolog_json_key { } iolog_json_keys[] = { { "columns", JSON_NUMBER, json_store_columns }, { "command", JSON_STRING, json_store_command }, + { "dumped_core", JSON_BOOL, json_store_dumped_core }, + { "exit_value", JSON_NUMBER, json_store_exit_value }, { "lines", JSON_NUMBER, json_store_lines }, + { "run_time", JSON_OBJECT, json_store_run_time }, { "runargv", JSON_ARRAY, json_store_runargv }, { "runenv", JSON_ARRAY, json_store_runenv }, { "rungid", JSON_ID, json_store_rungid }, @@ -311,6 +362,7 @@ static struct iolog_json_key { { "runuser", JSON_STRING, json_store_runuser }, { "runchroot", JSON_STRING, json_store_runchroot }, { "runcwd", JSON_STRING, json_store_runcwd }, + { "signal", JSON_STRING, json_store_signal }, { "submitcwd", JSON_STRING, json_store_submitcwd }, { "submithost", JSON_STRING, json_store_submithost }, { "submituser", JSON_STRING, json_store_submituser }, diff --git a/lib/iolog/iolog_loginfo.c b/lib/iolog/iolog_loginfo.c index daf2a7105..9b7d90389 100644 --- a/lib/iolog/iolog_loginfo.c +++ b/lib/iolog/iolog_loginfo.c @@ -78,6 +78,7 @@ iolog_parse_loginfo(int dfd, const char *iolog_dir) } evlog->runuid = (uid_t)-1; evlog->rungid = (gid_t)-1; + evlog->exit_value = -1; ok = legacy ? iolog_parse_loginfo_legacy(fp, iolog_dir, evlog) : iolog_parse_loginfo_json(fp, iolog_dir, evlog); diff --git a/logsrvd/iolog_writer.c b/logsrvd/iolog_writer.c index 82b867b9a..2d9f4431e 100644 --- a/logsrvd/iolog_writer.c +++ b/logsrvd/iolog_writer.c @@ -146,6 +146,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen, evlog->columns = 80; evlog->runuid = (uid_t)-1; evlog->rungid = (gid_t)-1; + evlog->exit_value = -1; /* Pull out values by key from info array. */ for (idx = 0; idx < infolen; idx++) {