Set SUDO_HOME to the invoking user's home directory.

GitHub issue #358
This commit is contained in:
Todd C. Miller
2024-03-08 09:15:36 -07:00
parent 836d2b556b
commit 602a58e86a
3 changed files with 7 additions and 1 deletions

View File

@@ -1415,6 +1415,9 @@ Default editor to use in
\fRSUDO_GID\fR
Set to the group-ID of the user who invoked sudo.
.TP 17n
\fRSUDO_HOME\fR
Set to the home directory of the user who invoked sudo.
.TP 17n
\fRSUDO_PROMPT\fR
Used as the default password prompt unless the
\fB\-p\fR

View File

@@ -1345,6 +1345,8 @@ Default editor to use in
(sudoedit) mode.
.It Ev SUDO_GID
Set to the group-ID of the user who invoked sudo.
.It Ev SUDO_HOME
Set to the home directory of the user who invoked sudo.
.It Ev SUDO_PROMPT
Used as the default password prompt unless the
.Fl p

View File

@@ -1123,12 +1123,13 @@ rebuild_env(const struct sudoers_context *ctx)
CHECK_SETENV2("SUDO_COMMAND", ctx->user.cmnd, true, true);
}
/* Add the SUDO_USER, SUDO_UID, SUDO_GID environment variables. */
/* Add the SUDO_{USER,UID,GID,HOME} 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);
debug_return_bool(true);