2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-09-05 08:45:28 +00:00

Add SUDO_TTY environment variable if the user has a tty

This can be used to find the user's original tty device when sudo
runs the command in its own pty.  GitHub issue #447.
This commit is contained in:
Todd C. Miller
2025-06-07 16:20:37 -06:00
parent a925829e60
commit afd01d856b
3 changed files with 12 additions and 5 deletions

View File

@@ -1123,13 +1123,15 @@ rebuild_env(const struct sudoers_context *ctx)
CHECK_SETENV2("SUDO_COMMAND", ctx->user.cmnd, true, true);
}
/* Add the SUDO_{USER,UID,GID,HOME} environment variables. */
/* Add the SUDO_{USER,UID,GID,HOME,TTY,TTY} environment variables. */
CHECK_SETENV2("SUDO_USER", ctx->user.name, true, true);
(void)snprintf(idbuf, sizeof(idbuf), "%u", (unsigned int) ctx->user.uid);
CHECK_SETENV2("SUDO_UID", idbuf, true, true);
(void)snprintf(idbuf, sizeof(idbuf), "%u", (unsigned int) ctx->user.gid);
CHECK_SETENV2("SUDO_GID", idbuf, true, true);
CHECK_SETENV2("SUDO_HOME", ctx->user.pw->pw_dir, true, true);
if (ctx->user.ttypath != NULL)
CHECK_SETENV2("SUDO_TTY", ctx->user.ttypath, true, true);
debug_return_bool(true);