Blame SOURCES/sudo-1.8.23-who-am-i.patch

22f5af
commit b2f7983c84fd01e0b29895d7df776b4b162fd8a5
22f5af
Author: Todd C. Miller <Todd.Miller@sudo.ws>
22f5af
Date:   Wed Jan 2 07:39:33 2019 -0700
22f5af
22f5af
    Fix setting of utmp entry when running command in a pty.
22f5af
    Regression introduced in sudo 1.8.22.
22f5af
22f5af
diff --git a/src/exec_pty.c b/src/exec_pty.c
22f5af
index cbcccca3..68312a98 100644
22f5af
--- a/src/exec_pty.c
22f5af
+++ b/src/exec_pty.c
22f5af
@@ -140,7 +140,7 @@ pty_cleanup(void)
22f5af
  * and slavename globals.
22f5af
  */
22f5af
 static bool
22f5af
-pty_setup(uid_t uid, const char *tty)
22f5af
+pty_setup(struct command_details *details, const char *tty)
22f5af
 {
22f5af
     debug_decl(pty_setup, SUDO_DEBUG_EXEC);
22f5af
 
22f5af
@@ -152,12 +152,15 @@ pty_setup(uid_t uid, const char *tty)
22f5af
     }
22f5af
 
22f5af
     if (!get_pty(&io_fds[SFD_MASTER], &io_fds[SFD_SLAVE],
22f5af
-	slavename, sizeof(slavename), uid))
22f5af
+	slavename, sizeof(slavename), details->euid))
22f5af
 	sudo_fatal(U_("unable to allocate pty"));
22f5af
 
22f5af
     /* Add entry to utmp/utmpx? */
22f5af
-    if (utmp_user != NULL)
22f5af
+    if (ISSET(details->flags, CD_SET_UTMP)) {
22f5af
+	utmp_user =
22f5af
+	    details->utmp_user ? details->utmp_user : user_details.username;
22f5af
 	utmp_login(tty, slavename, io_fds[SFD_SLAVE], utmp_user);
22f5af
+    }
22f5af
 
22f5af
     sudo_debug_printf(SUDO_DEBUG_INFO,
22f5af
 	"%s: %s fd %d, pty master fd %d, pty slave fd %d",
22f5af
@@ -1302,12 +1305,11 @@ exec_pty(struct command_details *details, struct command_status *cstat)
22f5af
     /*
22f5af
      * Allocate a pty.
22f5af
      */
22f5af
-    if (pty_setup(details->euid, user_details.tty)) {
22f5af
-	if (ISSET(details->flags, CD_SET_UTMP))
22f5af
-	    utmp_user = details->utmp_user ? details->utmp_user : user_details.username;
22f5af
-    } else if (TAILQ_EMPTY(&io_plugins)) {
22f5af
-	/* Not logging I/O and didn't allocate a pty. */
22f5af
-	debug_return_bool(false);
22f5af
+    if (!pty_setup(details, user_details.tty)) {
22f5af
+	if (TAILQ_EMPTY(&io_plugins)) {
22f5af
+	    /* Not logging I/O and didn't allocate a pty. */
22f5af
+	    debug_return_bool(false);
22f5af
+	}
22f5af
     }
22f5af
 
22f5af
     /*