mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 13:08:49 +00:00
Force setting $USER if UID is 0
Works around some weird su implementations. Fixes #3916.
This commit is contained in:
parent
3ade72266c
commit
3fa5d6c794
1 changed files with 11 additions and 1 deletions
12
src/env.cpp
12
src/env.cpp
|
@ -803,7 +803,13 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
|||
|
||||
// Set up the USER and PATH variables
|
||||
setup_path();
|
||||
setup_user(false);
|
||||
|
||||
// Some `su`s keep $USER when changing to root.
|
||||
// This leads to issues later on (and e.g. in prompts),
|
||||
// so we work around it by resetting $USER.
|
||||
// TODO: Figure out if that su actually checks if username == "root"(as the man page says) or UID == 0.
|
||||
uid_t uid = getuid();
|
||||
setup_user(uid == 0);
|
||||
|
||||
// Set up the version variable.
|
||||
wcstring version = str2wcstring(get_fish_version());
|
||||
|
@ -824,6 +830,10 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
|||
env_read_only.insert(L"SHLVL");
|
||||
|
||||
// Set up the HOME variable.
|
||||
// Unlike $USER, it doesn't seem that `su`s pass this along
|
||||
// if the target user is root, unless "--preserve-environment" is used.
|
||||
// Since that is an explicit choice, we should allow it to enable e.g.
|
||||
// env HOME=(mktemp -d) su --preserve-environment fish
|
||||
if (env_get_string(L"HOME").missing_or_empty()) {
|
||||
const env_var_t unam = env_get_string(L"USER");
|
||||
char *unam_narrow = wcs2str(unam.c_str());
|
||||
|
|
Loading…
Reference in a new issue