diff options
author | Ron Yorston <rmy@pobox.com> | 2014-12-11 21:37:43 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2014-12-11 21:37:43 +0000 |
commit | f8077fbe6831018338dae29077a21d4b06ba7e85 (patch) | |
tree | 597c2c906ff4f3cacd79a93c72f5526cb99acd3e | |
parent | 70c80aefd34a8a1526a813d6d5a831b88b24245f (diff) | |
download | busybox-w32-f8077fbe6831018338dae29077a21d4b06ba7e85.tar.gz busybox-w32-f8077fbe6831018338dae29077a21d4b06ba7e85.tar.bz2 busybox-w32-f8077fbe6831018338dae29077a21d4b06ba7e85.zip |
sh: don't overwrite login environment variables if already set
Certain environment variables (HOME, LOGNAME, USER, SHELL) are set
during early shell startup to emulate what login/su would do on
UNIX. If any of these are already set don't overwrite them.
-rw-r--r-- | libbb/setup_environment.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index 4258656fe..944ac5538 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c | |||
@@ -30,6 +30,14 @@ | |||
30 | 30 | ||
31 | #include "libbb.h" | 31 | #include "libbb.h" |
32 | 32 | ||
33 | #if ENABLE_PLATFORM_MINGW32 | ||
34 | static void xsetenv_if_unset(const char *key, const char *value) | ||
35 | { | ||
36 | if (!getenv(key)) | ||
37 | xsetenv(key, value); | ||
38 | } | ||
39 | #endif | ||
40 | |||
33 | void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) | 41 | void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) |
34 | { | 42 | { |
35 | if (!shell || !shell[0]) | 43 | if (!shell || !shell[0]) |
@@ -61,6 +69,9 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass | |||
61 | //xsetenv("HOME", pw->pw_dir); | 69 | //xsetenv("HOME", pw->pw_dir); |
62 | //xsetenv("SHELL", shell); | 70 | //xsetenv("SHELL", shell); |
63 | } else if (flags & SETUP_ENV_CHANGEENV) { | 71 | } else if (flags & SETUP_ENV_CHANGEENV) { |
72 | #if ENABLE_PLATFORM_MINGW32 | ||
73 | #define xsetenv(k, v) xsetenv_if_unset(k, v) | ||
74 | #endif | ||
64 | /* Set HOME, SHELL, and if not becoming a super-user, | 75 | /* Set HOME, SHELL, and if not becoming a super-user, |
65 | * USER and LOGNAME. */ | 76 | * USER and LOGNAME. */ |
66 | if (pw->pw_uid) { | 77 | if (pw->pw_uid) { |