2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-23 02:17:35 +00:00

struct eventlog: rename argv/env to runargv/runenv.

This matches the JSON logs.
This commit is contained in:
Todd C. Miller 2023-10-21 19:15:46 -06:00
parent c7a61a9438
commit 726b646b48
13 changed files with 67 additions and 65 deletions

View File

@ -110,9 +110,9 @@ struct eventlog {
char *submituser; char *submituser;
char *submitgroup; char *submitgroup;
char *ttyname; char *ttyname;
char **argv; char **runargv;
char **runenv;
char **env_add; char **env_add;
char **envp;
struct timespec submit_time; struct timespec submit_time;
struct timespec iolog_offset; struct timespec iolog_offset;
struct timespec run_time; struct timespec run_time;

View File

@ -191,24 +191,24 @@ new_logline(int event_type, int flags, struct eventlog_args *args,
} }
sudo_lbuf_append(lbuf, " ; "); sudo_lbuf_append(lbuf, " ; ");
} }
if (evlog->command != NULL && evlog->argv != NULL) { if (evlog->command != NULL && evlog->runargv != NULL) {
/* Command plus argv. */ /* Command plus argv. */
sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL|LBUF_ESC_BLANK, sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL|LBUF_ESC_BLANK,
"COMMAND=%s", evlog->command); "COMMAND=%s", evlog->command);
if (evlog->argv[0] != NULL) { if (evlog->runargv[0] != NULL) {
for (i = 1; evlog->argv[i] != NULL; i++) { for (i = 1; evlog->runargv[i] != NULL; i++) {
sudo_lbuf_append(lbuf, " "); sudo_lbuf_append(lbuf, " ");
if (strchr(evlog->argv[i], ' ') != NULL) { if (strchr(evlog->runargv[i], ' ') != NULL) {
/* Wrap args containing spaces in single quotes. */ /* Wrap args containing spaces in single quotes. */
sudo_lbuf_append(lbuf, "'"); sudo_lbuf_append(lbuf, "'");
sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL|LBUF_ESC_QUOTE, sudo_lbuf_append_esc(lbuf, LBUF_ESC_CNTRL|LBUF_ESC_QUOTE,
"%s", evlog->argv[i]); "%s", evlog->runargv[i]);
sudo_lbuf_append(lbuf, "'"); sudo_lbuf_append(lbuf, "'");
} else { } else {
/* Escape quotes here too for consistency. */ /* Escape quotes here too for consistency. */
sudo_lbuf_append_esc(lbuf, sudo_lbuf_append_esc(lbuf,
LBUF_ESC_CNTRL|LBUF_ESC_BLANK|LBUF_ESC_QUOTE, LBUF_ESC_CNTRL|LBUF_ESC_BLANK|LBUF_ESC_QUOTE,
"%s", evlog->argv[i]); "%s", evlog->runargv[i]);
} }
} }
} }
@ -733,10 +733,10 @@ eventlog_store_json(struct json_container *jsonc, const struct eventlog *evlog)
if (!sudo_json_add_value(jsonc, "lines", &json_value)) if (!sudo_json_add_value(jsonc, "lines", &json_value))
goto oom; goto oom;
if (evlog->argv != NULL) { if (evlog->runargv != NULL) {
if (!sudo_json_open_array(jsonc, "runargv")) if (!sudo_json_open_array(jsonc, "runargv"))
goto oom; goto oom;
for (i = 0; (cp = evlog->argv[i]) != NULL; i++) { for (i = 0; (cp = evlog->runargv[i]) != NULL; i++) {
json_value.type = JSON_STRING; json_value.type = JSON_STRING;
json_value.u.string = cp; json_value.u.string = cp;
if (!sudo_json_add_value(jsonc, NULL, &json_value)) if (!sudo_json_add_value(jsonc, NULL, &json_value))
@ -746,10 +746,10 @@ eventlog_store_json(struct json_container *jsonc, const struct eventlog *evlog)
goto oom; goto oom;
} }
if (evlog->envp != NULL) { if (evlog->runenv != NULL) {
if (!sudo_json_open_array(jsonc, "runenv")) if (!sudo_json_open_array(jsonc, "runenv"))
goto oom; goto oom;
for (i = 0; (cp = evlog->envp[i]) != NULL; i++) { for (i = 0; (cp = evlog->runenv[i]) != NULL; i++) {
json_value.type = JSON_STRING; json_value.type = JSON_STRING;
json_value.u.string = cp; json_value.u.string = cp;
if (!sudo_json_add_value(jsonc, NULL, &json_value)) if (!sudo_json_add_value(jsonc, NULL, &json_value))

View File

@ -59,15 +59,15 @@ eventlog_free(struct eventlog *evlog)
free(evlog->submituser); free(evlog->submituser);
free(evlog->submitgroup); free(evlog->submitgroup);
free(evlog->ttyname); free(evlog->ttyname);
if (evlog->argv != NULL) { if (evlog->runargv != NULL) {
for (i = 0; evlog->argv[i] != NULL; i++) for (i = 0; evlog->runargv[i] != NULL; i++)
free(evlog->argv[i]); free(evlog->runargv[i]);
free(evlog->argv); free(evlog->runargv);
} }
if (evlog->envp != NULL) { if (evlog->runenv != NULL) {
for (i = 0; evlog->envp[i] != NULL; i++) for (i = 0; evlog->runenv[i] != NULL; i++)
free(evlog->envp[i]); free(evlog->runenv[i]);
free(evlog->envp); free(evlog->runenv);
} }
if (evlog->env_add != NULL) { if (evlog->env_add != NULL) {
for (i = 0; evlog->env_add[i] != NULL; i++) for (i = 0; evlog->env_add[i] != NULL; i++)

View File

@ -201,14 +201,14 @@ json_store_runargv(struct json_item *item, struct eventlog *evlog)
size_t i; size_t i;
debug_decl(json_store_runargv, SUDO_DEBUG_UTIL); debug_decl(json_store_runargv, SUDO_DEBUG_UTIL);
if (evlog->argv != NULL) { if (evlog->runargv != NULL) {
for (i = 0; evlog->argv[i] != NULL; i++) for (i = 0; evlog->runargv[i] != NULL; i++)
free(evlog->argv[i]); free(evlog->runargv[i]);
free(evlog->argv); free(evlog->runargv);
} }
evlog->argv = json_array_to_strvec(&item->u.child); evlog->runargv = json_array_to_strvec(&item->u.child);
debug_return_bool(evlog->argv != NULL); debug_return_bool(evlog->runargv != NULL);
} }
static bool static bool
@ -217,14 +217,14 @@ json_store_runenv(struct json_item *item, struct eventlog *evlog)
size_t i; size_t i;
debug_decl(json_store_runenv, SUDO_DEBUG_UTIL); debug_decl(json_store_runenv, SUDO_DEBUG_UTIL);
if (evlog->envp != NULL) { if (evlog->runenv != NULL) {
for (i = 0; evlog->envp[i] != NULL; i++) for (i = 0; evlog->runenv[i] != NULL; i++)
free(evlog->envp[i]); free(evlog->runenv[i]);
free(evlog->envp); free(evlog->runenv);
} }
evlog->envp = json_array_to_strvec(&item->u.child); evlog->runenv = json_array_to_strvec(&item->u.child);
debug_return_bool(evlog->envp != NULL); debug_return_bool(evlog->runenv != NULL);
} }
static bool static bool

View File

@ -131,7 +131,7 @@ iolog_write_info_file_legacy(int dfd, struct eventlog *evlog)
evlog->lines, evlog->columns, evlog->lines, evlog->columns,
evlog->cwd ? evlog->cwd : "unknown"); evlog->cwd ? evlog->cwd : "unknown");
fputs(evlog->command ? evlog->command : "unknown", fp); fputs(evlog->command ? evlog->command : "unknown", fp);
for (av = evlog->argv + 1; *av != NULL; av++) { for (av = evlog->runargv + 1; *av != NULL; av++) {
fputc(' ', fp); fputc(' ', fp);
fputs(*av, fp); fputs(*av, fp);
} }

View File

@ -205,8 +205,8 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
case 'r': case 'r':
if (strcmp(key, "runargv") == 0) { if (strcmp(key, "runargv") == 0) {
if (type_matches(info, source, INFO_MESSAGE__VALUE_STRLISTVAL)) { if (type_matches(info, source, INFO_MESSAGE__VALUE_STRLISTVAL)) {
evlog->argv = strlist_copy(info->u.strlistval); evlog->runargv = strlist_copy(info->u.strlistval);
if (evlog->argv == NULL) if (evlog->runargv == NULL)
goto bad; goto bad;
} }
continue; continue;
@ -233,8 +233,8 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
} }
if (strcmp(key, "runenv") == 0) { if (strcmp(key, "runenv") == 0) {
if (type_matches(info, source, INFO_MESSAGE__VALUE_STRLISTVAL)) { if (type_matches(info, source, INFO_MESSAGE__VALUE_STRLISTVAL)) {
evlog->envp = strlist_copy(info->u.strlistval); evlog->runenv = strlist_copy(info->u.strlistval);
if (evlog->envp == NULL) if (evlog->runenv == NULL)
goto bad; goto bad;
} }
continue; continue;

View File

@ -507,9 +507,9 @@ fmt_runargv(const struct eventlog *evlog)
debug_decl(fmt_runargv, SUDO_DEBUG_UTIL); debug_decl(fmt_runargv, SUDO_DEBUG_UTIL);
/* We may have runargv from the log.json file. */ /* We may have runargv from the log.json file. */
if (evlog->argv != NULL && evlog->argv[0] != NULL) { if (evlog->runargv != NULL && evlog->runargv[0] != NULL) {
/* Convert evlog->argv into a StringList. */ /* Convert evlog->runargv into a StringList. */
runargv = vec_to_stringlist(evlog->argv); runargv = vec_to_stringlist(evlog->runargv);
if (runargv != NULL) { if (runargv != NULL) {
/* Make sure command doesn't include arguments. */ /* Make sure command doesn't include arguments. */
char *cp = strchr(evlog->command, ' '); char *cp = strchr(evlog->command, ' ');
@ -533,10 +533,10 @@ fmt_runenv(const struct eventlog *evlog)
debug_decl(fmt_runenv, SUDO_DEBUG_UTIL); debug_decl(fmt_runenv, SUDO_DEBUG_UTIL);
/* Only present in log.json. */ /* Only present in log.json. */
if (evlog->envp == NULL || evlog->envp[0] == NULL) if (evlog->runenv == NULL || evlog->runenv[0] == NULL)
debug_return_ptr(NULL); debug_return_ptr(NULL);
debug_return_ptr(vec_to_stringlist(evlog->envp)); debug_return_ptr(vec_to_stringlist(evlog->runenv));
} }
static InfoMessage ** static InfoMessage **

View File

@ -197,10 +197,10 @@ free_iolog_details(void)
if (iolog_details.evlog != NULL) { if (iolog_details.evlog != NULL) {
/* We only make a shallow copy of argv and envp. */ /* We only make a shallow copy of argv and envp. */
free(iolog_details.evlog->argv); free(iolog_details.evlog->runargv);
iolog_details.evlog->argv = NULL; iolog_details.evlog->runargv = NULL;
free(iolog_details.evlog->envp); free(iolog_details.evlog->runenv);
iolog_details.evlog->envp = NULL; iolog_details.evlog->runenv = NULL;
eventlog_free(iolog_details.evlog); eventlog_free(iolog_details.evlog);
} }
str_list_free(iolog_details.log_servers); str_list_free(iolog_details.log_servers);
@ -601,13 +601,13 @@ iolog_deserialize_info(struct log_details *details, char * const user_info[],
} }
if (argv != NULL) { if (argv != NULL) {
evlog->argv = copy_vector_shallow(argv); evlog->runargv = copy_vector_shallow(argv);
if (evlog->argv == NULL) if (evlog->runargv == NULL)
goto oom; goto oom;
} }
if (user_env != NULL) { if (user_env != NULL) {
evlog->envp = copy_vector_shallow(user_env); evlog->runenv = copy_vector_shallow(user_env);
if (evlog->envp == NULL) if (evlog->runenv == NULL)
goto oom; goto oom;
} }

View File

@ -823,20 +823,20 @@ fmt_info_messages(struct client_closure *closure, struct eventlog *evlog,
debug_decl(fmt_info_messages, SUDOERS_DEBUG_UTIL); debug_decl(fmt_info_messages, SUDOERS_DEBUG_UTIL);
/* Convert NULL-terminated vectors to StringList. */ /* Convert NULL-terminated vectors to StringList. */
if (evlog->argv != NULL) { if (evlog->runargv != NULL) {
if ((runargv = malloc(sizeof(*runargv))) == NULL) if ((runargv = malloc(sizeof(*runargv))) == NULL)
goto bad; goto bad;
info_message__string_list__init(runargv); info_message__string_list__init(runargv);
runargv->strings = evlog->argv; runargv->strings = evlog->runargv;
while (runargv->strings[runargv->n_strings] != NULL) while (runargv->strings[runargv->n_strings] != NULL)
runargv->n_strings++; runargv->n_strings++;
} }
if (evlog->envp != NULL) { if (evlog->runenv != NULL) {
if ((runenv = malloc(sizeof(*runenv))) == NULL) if ((runenv = malloc(sizeof(*runenv))) == NULL)
goto bad; goto bad;
info_message__string_list__init(runenv); info_message__string_list__init(runenv);
runenv->strings = evlog->envp; runenv->strings = evlog->runenv;
while (runenv->strings[runenv->n_strings] != NULL) while (runenv->strings[runenv->n_strings] != NULL)
runenv->n_strings++; runenv->n_strings++;
} }

View File

@ -1001,9 +1001,9 @@ sudoers_to_eventlog(const struct sudoers_context *ctx, struct eventlog *evlog,
if (grp != NULL) if (grp != NULL)
evlog->submitgroup = grp->gr_name; evlog->submitgroup = grp->gr_name;
evlog->ttyname = ctx->user.ttypath; evlog->ttyname = ctx->user.ttypath;
evlog->argv = (char **)argv; evlog->runargv = (char **)argv;
evlog->env_add = (char **)ctx->user.env_add; evlog->env_add = (char **)ctx->user.env_add;
evlog->envp = (char **)envp; evlog->runenv = (char **)envp;
evlog->submit_time = ctx->submit_time; evlog->submit_time = ctx->submit_time;
evlog->lines = ctx->user.lines; evlog->lines = ctx->user.lines;
evlog->columns = ctx->user.cols; evlog->columns = ctx->user.cols;

View File

@ -989,7 +989,8 @@ init_vars(struct sudoers_context *ctx, char * const envp[])
#define MATCHES(s, v) \ #define MATCHES(s, v) \
(strncmp((s), (v), sizeof(v) - 1) == 0 && (s)[sizeof(v) - 1] != '\0') (strncmp((s), (v), sizeof(v) - 1) == 0 && (s)[sizeof(v) - 1] != '\0')
for (ep = envp; *ep; ep++) { ctx->user.envp = envp;
for (ep = ctx->user.envp; *ep; ep++) {
switch (**ep) { switch (**ep) {
case 'K': case 'K':
if (MATCHES(*ep, "KRB5CCNAME=")) if (MATCHES(*ep, "KRB5CCNAME="))

View File

@ -131,6 +131,7 @@ struct sudoers_user_context {
char *cmnd_list; char *cmnd_list;
char *ccname; char *ccname;
struct gid_list *gid_list; struct gid_list *gid_list;
char * const * envp;
char * const * env_add; char * const * env_add;
int closefrom; int closefrom;
int lines; int lines;

View File

@ -366,9 +366,9 @@ main(int argc, char *argv[])
if ((evlog = iolog_parse_loginfo(iolog_dir_fd, iolog_dir)) == NULL) if ((evlog = iolog_parse_loginfo(iolog_dir_fd, iolog_dir)) == NULL)
goto done; goto done;
printf(_("Replaying sudo session: %s"), evlog->command); printf(_("Replaying sudo session: %s"), evlog->command);
if (evlog->argv != NULL && evlog->argv[0] != NULL) { if (evlog->runargv != NULL && evlog->runargv[0] != NULL) {
for (i = 1; evlog->argv[i] != NULL; i++) for (i = 1; evlog->runargv[i] != NULL; i++)
printf(" %s", evlog->argv[i]); printf(" %s", evlog->runargv[i]);
} }
/* Setup terminal if appropriate. */ /* Setup terminal if appropriate. */
@ -1321,15 +1321,15 @@ expand_command(struct eventlog *evlog, char **newbuf)
int ac; int ac;
debug_decl(expand_command, SUDO_DEBUG_UTIL); debug_decl(expand_command, SUDO_DEBUG_UTIL);
if (evlog->argv == NULL || evlog->argv[0] == NULL || evlog->argv[1] == NULL) { if (evlog->runargv == NULL || evlog->runargv[0] == NULL || evlog->runargv[1] == NULL) {
/* No arguments, we can use the command as-is. */ /* No arguments, we can use the command as-is. */
*newbuf = NULL; *newbuf = NULL;
debug_return_str(evlog->command); debug_return_str(evlog->command);
} }
/* Skip argv[0], we use evlog->command instead. */ /* Skip argv[0], we use evlog->command instead. */
for (ac = 1; evlog->argv[ac] != NULL; ac++) for (ac = 1; evlog->runargv[ac] != NULL; ac++)
bufsize += strlen(evlog->argv[ac]) + 1; bufsize += strlen(evlog->runargv[ac]) + 1;
if ((buf = malloc(bufsize)) == NULL) if ((buf = malloc(bufsize)) == NULL)
sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_fatalx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
@ -1341,13 +1341,13 @@ expand_command(struct eventlog *evlog, char **newbuf)
cp += len; cp += len;
bufsize -= len; bufsize -= len;
for (ac = 1; evlog->argv[ac] != NULL; ac++) { for (ac = 1; evlog->runargv[ac] != NULL; ac++) {
if (bufsize < 2) if (bufsize < 2)
sudo_fatalx(U_("internal error, %s overflow"), __func__); sudo_fatalx(U_("internal error, %s overflow"), __func__);
*cp++ = ' '; *cp++ = ' ';
bufsize--; bufsize--;
len = strlcpy(cp, evlog->argv[ac], bufsize); len = strlcpy(cp, evlog->runargv[ac], bufsize);
if (len >= bufsize) if (len >= bufsize)
sudo_fatalx(U_("internal error, %s overflow"), __func__); sudo_fatalx(U_("internal error, %s overflow"), __func__);
cp += len; cp += len;