diff --git a/docs/sudo.man.in b/docs/sudo.man.in index 110f9c719..e42ea425b 100644 --- a/docs/sudo.man.in +++ b/docs/sudo.man.in @@ -2,7 +2,7 @@ .\" .\" SPDX-License-Identifier: ISC .\" -.\" Copyright (c) 1994-1996, 1998-2005, 2007-2024 +.\" Copyright (c) 1994-1996, 1998-2005, 2007-2025 .\" Todd C. Miller .\" .\" Permission to use, copy, modify, and distribute this software for any @@ -25,7 +25,7 @@ .nr BA @BAMAN@ .nr LC @LCMAN@ .nr PS @PSMAN@ -.TH "SUDO" "@mansectsu@" "December 20, 2024" "Sudo @PACKAGE_VERSION@" "System Manager's Manual" +.TH "SUDO" "@mansectsu@" "June 7, 2025" "Sudo @PACKAGE_VERSION@" "System Manager's Manual" .nh .if n .ad l .SH "NAME" @@ -1436,6 +1436,9 @@ If set, \fRPS1\fR will be set to its value for the program being run. .TP 17n +\fRSUDO_TTY\fR +Set to the terminal device of the user who invoked sudo, if one is present. +.TP 17n \fRSUDO_UID\fR Set to the user-ID of the user who invoked sudo. .TP 17n diff --git a/docs/sudo.mdoc.in b/docs/sudo.mdoc.in index ceb5d2834..3c0fe735e 100644 --- a/docs/sudo.mdoc.in +++ b/docs/sudo.mdoc.in @@ -1,7 +1,7 @@ .\" .\" SPDX-License-Identifier: ISC .\" -.\" Copyright (c) 1994-1996, 1998-2005, 2007-2024 +.\" Copyright (c) 1994-1996, 1998-2005, 2007-2025 .\" Todd C. Miller .\" .\" Permission to use, copy, modify, and distribute this software for any @@ -24,7 +24,7 @@ .nr BA @BAMAN@ .nr LC @LCMAN@ .nr PS @PSMAN@ -.Dd December 20, 2024 +.Dd June 7, 2025 .Dt SUDO @mansectsu@ .Os Sudo @PACKAGE_VERSION@ .Sh NAME @@ -1355,6 +1355,8 @@ option was specified. If set, .Ev PS1 will be set to its value for the program being run. +.It Ev SUDO_TTY +Set to the terminal device of the user who invoked sudo, if one is present. .It Ev SUDO_UID Set to the user-ID of the user who invoked sudo. .It Ev SUDO_USER diff --git a/plugins/sudoers/env.c b/plugins/sudoers/env.c index 95558e9ed..9368c0e32 100644 --- a/plugins/sudoers/env.c +++ b/plugins/sudoers/env.c @@ -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);