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

@@ -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);