aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2022-01-13 12:50:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2022-01-13 12:50:48 +0100
commit931c55f9e2b41473132683488820c6fb7c47506b (patch)
tree56cbfd7e7b1d85998192e5b61c132b9d4a465b8b
parentb3eec1651fb02d70716caa355f49320719f74c75 (diff)
downloadbusybox-w32-931c55f9e2b41473132683488820c6fb7c47506b.tar.gz
busybox-w32-931c55f9e2b41473132683488820c6fb7c47506b.tar.bz2
busybox-w32-931c55f9e2b41473132683488820c6fb7c47506b.zip
libbb: invert the meaning of SETUP_ENV_NO_CHDIR -> SETUP_ENV_CHDIR
Double negatives are hard to grok. function old new delta login_main 986 988 +2 su_main 474 470 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 2/-4) Total: -2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h6
-rw-r--r--libbb/setup_environment.c5
-rw-r--r--loginutils/login.c4
-rw-r--r--loginutils/su.c7
-rw-r--r--loginutils/sulogin.c9
-rw-r--r--miscutils/crontab.c4
-rw-r--r--shell/ash.c2
-rw-r--r--shell/hush.c2
8 files changed, 22 insertions, 17 deletions
diff --git a/include/libbb.h b/include/libbb.h
index a0ffbef62..780e9ae7d 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1726,7 +1726,7 @@ extern void selinux_or_die(void) FAST_FUNC;
1726 1726
1727 1727
1728/* setup_environment: 1728/* setup_environment:
1729 * if !SETUP_ENV_NO_CHDIR: 1729 * if SETUP_ENV_CHDIR:
1730 * if cd(pw->pw_dir): ok: else if SETUP_ENV_TO_TMP: cd(/tmp) else: cd(/) or die 1730 * if cd(pw->pw_dir): ok: else if SETUP_ENV_TO_TMP: cd(/tmp) else: cd(/) or die
1731 * if SETUP_ENV_CLEARENV: cd(pw->pw_dir), clear environment, then set 1731 * if SETUP_ENV_CLEARENV: cd(pw->pw_dir), clear environment, then set
1732 * TERM=(old value) 1732 * TERM=(old value)
@@ -1734,7 +1734,7 @@ extern void selinux_or_die(void) FAST_FUNC;
1734 * PATH=bb_default_[root_]path 1734 * PATH=bb_default_[root_]path
1735 * HOME=pw->pw_dir 1735 * HOME=pw->pw_dir
1736 * SHELL=shell 1736 * SHELL=shell
1737 * else if SETUP_ENV_CHANGEENV: 1737 * else if SETUP_ENV_CHANGEENV | SETUP_ENV_CHANGEENV_LOGNAME:
1738 * if not root (if pw->pw_uid != 0) or if SETUP_ENV_CHANGEENV_LOGNAME: 1738 * if not root (if pw->pw_uid != 0) or if SETUP_ENV_CHANGEENV_LOGNAME:
1739 * USER=pw->pw_name, LOGNAME=pw->pw_name 1739 * USER=pw->pw_name, LOGNAME=pw->pw_name
1740 * HOME=pw->pw_dir 1740 * HOME=pw->pw_dir
@@ -1748,7 +1748,7 @@ extern void selinux_or_die(void) FAST_FUNC;
1748#define SETUP_ENV_CHANGEENV_LOGNAME (1 << 1) 1748#define SETUP_ENV_CHANGEENV_LOGNAME (1 << 1)
1749#define SETUP_ENV_CLEARENV (1 << 2) 1749#define SETUP_ENV_CLEARENV (1 << 2)
1750#define SETUP_ENV_TO_TMP (1 << 3) 1750#define SETUP_ENV_TO_TMP (1 << 3)
1751#define SETUP_ENV_NO_CHDIR (1 << 4) 1751#define SETUP_ENV_CHDIR (1 << 4)
1752void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; 1752void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
1753void nuke_str(char *str) FAST_FUNC; 1753void nuke_str(char *str) FAST_FUNC;
1754#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM 1754#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index df2983958..37777204e 100644
--- a/libbb/setup_environment.c
+++ b/libbb/setup_environment.c
@@ -36,7 +36,7 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass
36 36
37 /* Change the current working directory to be the home directory 37 /* Change the current working directory to be the home directory
38 * of the user */ 38 * of the user */
39 if (!(flags & SETUP_ENV_NO_CHDIR)) { 39 if (flags & SETUP_ENV_CHDIR) {
40 if (chdir(pw->pw_dir) != 0) { 40 if (chdir(pw->pw_dir) != 0) {
41 bb_error_msg("can't change directory to '%s'", pw->pw_dir); 41 bb_error_msg("can't change directory to '%s'", pw->pw_dir);
42 xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); 42 xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/");
@@ -59,7 +59,8 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass
59 //xsetenv("LOGNAME", pw->pw_name); 59 //xsetenv("LOGNAME", pw->pw_name);
60 //xsetenv("HOME", pw->pw_dir); 60 //xsetenv("HOME", pw->pw_dir);
61 //xsetenv("SHELL", shell); 61 //xsetenv("SHELL", shell);
62 } else if (flags & SETUP_ENV_CHANGEENV) { 62 } else
63 if (flags & (SETUP_ENV_CHANGEENV|SETUP_ENV_CHANGEENV_LOGNAME)) {
63 /* Set HOME, SHELL, and if not becoming a super-user 64 /* Set HOME, SHELL, and if not becoming a super-user
64 * or if SETUP_ENV_CHANGEENV_LOGNAME, USER and LOGNAME. */ 65 * or if SETUP_ENV_CHANGEENV_LOGNAME, USER and LOGNAME. */
65 if ((flags & SETUP_ENV_CHANGEENV_LOGNAME) || pw->pw_uid != 0) { 66 if ((flags & SETUP_ENV_CHANGEENV_LOGNAME) || pw->pw_uid != 0) {
diff --git a/loginutils/login.c b/loginutils/login.c
index cac4349b2..332238181 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -564,7 +564,9 @@ int login_main(int argc UNUSED_PARAM, char **argv)
564 564
565 change_identity(pw); 565 change_identity(pw);
566 setup_environment(pw->pw_shell, 566 setup_environment(pw->pw_shell,
567 (!(opt & LOGIN_OPT_p) * SETUP_ENV_CLEARENV) + SETUP_ENV_CHANGEENV, 567 (!(opt & LOGIN_OPT_p) * SETUP_ENV_CLEARENV)
568 + SETUP_ENV_CHANGEENV
569 + SETUP_ENV_CHDIR,
568 pw); 570 pw);
569 571
570#if ENABLE_PAM 572#if ENABLE_PAM
diff --git a/loginutils/su.c b/loginutils/su.c
index e1db7590f..6efe1981a 100644
--- a/loginutils/su.c
+++ b/loginutils/su.c
@@ -176,10 +176,9 @@ int su_main(int argc UNUSED_PARAM, char **argv)
176 176
177 change_identity(pw); 177 change_identity(pw);
178 setup_environment(opt_shell, 178 setup_environment(opt_shell,
179 ((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV) 179 ((flags & SU_OPT_l) ? (SETUP_ENV_CLEARENV + SETUP_ENV_CHDIR) : 0)
180 + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV) 180 + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV),
181 + (!(flags & SU_OPT_l) * SETUP_ENV_NO_CHDIR), 181 pw);
182 pw);
183 IF_SELINUX(set_current_security_context(NULL);) 182 IF_SELINUX(set_current_security_context(NULL);)
184 183
185 if (opt_command) { 184 if (opt_command) {
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index c9817960c..681022acb 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -94,10 +94,13 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv)
94 shell = pwd->pw_shell; 94 shell = pwd->pw_shell;
95 95
96 /* util-linux 2.36.1 compat: cd to root's HOME, set a few envvars */ 96 /* util-linux 2.36.1 compat: cd to root's HOME, set a few envvars */
97 setup_environment(shell, SETUP_ENV_CHANGEENV | SETUP_ENV_CHANGEENV_LOGNAME, pwd); 97 setup_environment(shell, 0
98 + SETUP_ENV_CHANGEENV_LOGNAME
99 + SETUP_ENV_CHDIR
100 , pwd);
98 // no SETUP_ENV_CLEARENV 101 // no SETUP_ENV_CLEARENV
99 // SETUP_ENV_CHANGEENV[+LOGNAME] - set HOME, SHELL, USER,and LOGNAME 102 // SETUP_ENV_CHANGEENV_LOGNAME - set HOME, SHELL, USER,and LOGNAME
100 // no SETUP_ENV_NO_CHDIR - IOW: cd to $HOME 103 // SETUP_ENV_CHDIR - cd to $HOME
101 104
102 /* util-linux 2.36.1 compat: steal ctty if we don't have it yet 105 /* util-linux 2.36.1 compat: steal ctty if we don't have it yet
103 * (yes, util-linux uses force=1) */ 106 * (yes, util-linux uses force=1) */
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index 411a18a50..1111f4d54 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -55,8 +55,8 @@ static void edit_file(const struct passwd *pas, const char *file)
55 /* initgroups, setgid, setuid */ 55 /* initgroups, setgid, setuid */
56 change_identity(pas); 56 change_identity(pas);
57 setup_environment(pas->pw_shell, 57 setup_environment(pas->pw_shell,
58 SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP, 58 SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP | SETUP_ENV_CHDIR,
59 pas); 59 pas);
60 ptr = getenv("VISUAL"); 60 ptr = getenv("VISUAL");
61 if (!ptr) { 61 if (!ptr) {
62 ptr = getenv("EDITOR"); 62 ptr = getenv("EDITOR");
diff --git a/shell/ash.c b/shell/ash.c
index 12b2db3a9..ca5c755b6 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -10791,7 +10791,7 @@ preadfd(void)
10791 write(STDOUT_FILENO, "^C", 2); 10791 write(STDOUT_FILENO, "^C", 2);
10792 raise(SIGINT); 10792 raise(SIGINT);
10793 /* raise(SIGINT) did not work! (e.g. if SIGINT 10793 /* raise(SIGINT) did not work! (e.g. if SIGINT
10794 * is SIG_INGed on startup, it stays SIG_IGNed) 10794 * is SIG_IGNed on startup, it stays SIG_IGNed)
10795 */ 10795 */
10796 if (trap[SIGINT]) { 10796 if (trap[SIGINT]) {
10797 buf[0] = '\n'; 10797 buf[0] = '\n';
diff --git a/shell/hush.c b/shell/hush.c
index 982fc356a..7d0dc67e4 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -10361,7 +10361,7 @@ int hush_main(int argc, char **argv)
10361//it ignores TERM: 10361//it ignores TERM:
10362// bash -i -c 'kill $$; echo ALIVE' 10362// bash -i -c 'kill $$; echo ALIVE'
10363// ALIVE 10363// ALIVE
10364//it resets SIG_INGed HUP to SIG_DFL: 10364//it resets SIG_IGNed HUP to SIG_DFL:
10365// trap '' hup; bash -i -c 'kill -hup $$; echo ALIVE' 10365// trap '' hup; bash -i -c 'kill -hup $$; echo ALIVE'
10366// Hangup [the message is not printed by bash, it's the shell which started it] 10366// Hangup [the message is not printed by bash, it's the shell which started it]
10367//is talkative about jobs and exiting: 10367//is talkative about jobs and exiting: