Eliminate utmp_user global, just use the value in struct command details.

This commit is contained in:
Todd C. Miller
2023-03-24 14:44:56 -06:00
parent 778688d4fc
commit 7ac9ce001c
2 changed files with 6 additions and 8 deletions

View File

@@ -59,7 +59,6 @@ static struct monitor_message_list monitor_messages =
/* Globals for the pty_cleanup() hook. */ /* Globals for the pty_cleanup() hook. */
static char ptyname[PATH_MAX]; static char ptyname[PATH_MAX];
static const char *utmp_user;
static void sync_ttysize(struct exec_closure *ec); static void sync_ttysize(struct exec_closure *ec);
static void schedule_signal(struct exec_closure *ec, int signo); static void schedule_signal(struct exec_closure *ec, int signo);
@@ -89,11 +88,8 @@ pty_setup(struct command_details *details, const char *tty)
details->tty = ptyname; details->tty = ptyname;
/* Add entry to utmp/utmpx? */ /* Add entry to utmp/utmpx? */
if (ISSET(details->flags, CD_SET_UTMP)) { if (ISSET(details->flags, CD_SET_UTMP))
utmp_user = utmp_login(tty, ptyname, io_fds[SFD_FOLLOWER], details->utmp_user);
details->utmp_user ? details->utmp_user : user_details.username;
utmp_login(tty, ptyname, io_fds[SFD_FOLLOWER], utmp_user);
}
sudo_debug_printf(SUDO_DEBUG_INFO, sudo_debug_printf(SUDO_DEBUG_INFO,
"%s: %s fd %d, pty leader fd %d, pty follower fd %d", "%s: %s fd %d, pty leader fd %d, pty follower fd %d",
@@ -138,7 +134,7 @@ pty_cleanup_int(struct exec_closure *ec, int wstatus, bool init_only)
} }
/* Update utmp */ /* Update utmp */
if (utmp_user != NULL) if (ISSET(ec->details->flags, CD_SET_UTMP) && ptyname[0] != '\0')
utmp_logout(ptyname, wstatus); utmp_logout(ptyname, wstatus);
debug_return; debug_return;

View File

@@ -1,7 +1,7 @@
/* /*
* SPDX-License-Identifier: ISC * SPDX-License-Identifier: ISC
* *
* Copyright (c) 2009-2022 Todd C. Miller <Todd.Miller@sudo.ws> * Copyright (c) 2009-2023 Todd C. Miller <Todd.Miller@sudo.ws>
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@@ -869,6 +869,8 @@ command_info_to_details(char * const info[], struct command_details *details)
break; break;
} }
} }
if (details->utmp_user == NULL)
details->utmp_user = user_details.username;
/* Only use ptrace(2) for intercept/log_subcmds if supported. */ /* Only use ptrace(2) for intercept/log_subcmds if supported. */
exec_ptrace_fix_flags(details); exec_ptrace_fix_flags(details);