From 7ac9ce001cf898a7db28d41e704a821b801b083c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 24 Mar 2023 14:44:56 -0600 Subject: [PATCH] Eliminate utmp_user global, just use the value in struct command details. --- src/exec_pty.c | 10 +++------- src/sudo.c | 4 +++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/exec_pty.c b/src/exec_pty.c index 283a7b384..de13e5a8e 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -59,7 +59,6 @@ static struct monitor_message_list monitor_messages = /* Globals for the pty_cleanup() hook. */ static char ptyname[PATH_MAX]; -static const char *utmp_user; static void sync_ttysize(struct exec_closure *ec); 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; /* Add entry to utmp/utmpx? */ - if (ISSET(details->flags, CD_SET_UTMP)) { - utmp_user = - details->utmp_user ? details->utmp_user : user_details.username; - utmp_login(tty, ptyname, io_fds[SFD_FOLLOWER], utmp_user); - } + if (ISSET(details->flags, CD_SET_UTMP)) + utmp_login(tty, ptyname, io_fds[SFD_FOLLOWER], details->utmp_user); sudo_debug_printf(SUDO_DEBUG_INFO, "%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 */ - if (utmp_user != NULL) + if (ISSET(ec->details->flags, CD_SET_UTMP) && ptyname[0] != '\0') utmp_logout(ptyname, wstatus); debug_return; diff --git a/src/sudo.c b/src/sudo.c index a8a18bbb5..9ae477133 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -1,7 +1,7 @@ /* * SPDX-License-Identifier: ISC * - * Copyright (c) 2009-2022 Todd C. Miller + * Copyright (c) 2009-2023 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * 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; } } + if (details->utmp_user == NULL) + details->utmp_user = user_details.username; /* Only use ptrace(2) for intercept/log_subcmds if supported. */ exec_ptrace_fix_flags(details);