From 602a58e86a3562472499e339d40bed83e76109dc Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 8 Mar 2024 09:15:36 -0700 Subject: [PATCH] Set SUDO_HOME to the invoking user's home directory. GitHub issue #358 --- docs/sudo.man.in | 3 +++ docs/sudo.mdoc.in | 2 ++ plugins/sudoers/env.c | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/sudo.man.in b/docs/sudo.man.in index eab53e209..fe104a02b 100644 --- a/docs/sudo.man.in +++ b/docs/sudo.man.in @@ -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 diff --git a/docs/sudo.mdoc.in b/docs/sudo.mdoc.in index 9374f6c16..8a2e99178 100644 --- a/docs/sudo.mdoc.in +++ b/docs/sudo.mdoc.in @@ -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 diff --git a/plugins/sudoers/env.c b/plugins/sudoers/env.c index e3f28f1bb..95558e9ed 100644 --- a/plugins/sudoers/env.c +++ b/plugins/sudoers/env.c @@ -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);