diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2010-02-24 16:10:09 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-02-26 09:31:40 +0100 |
commit | 99709ab03387ca623e3fc1cac69d242ed44da45c (patch) | |
tree | de266d18b15ab43efc0c46dd72f9d926db129c13 | |
parent | 7e7728cd66482f6898e3896bf05a12f0f8137e79 (diff) | |
download | busybox-w32-99709ab03387ca623e3fc1cac69d242ed44da45c.tar.gz busybox-w32-99709ab03387ca623e3fc1cac69d242ed44da45c.tar.bz2 busybox-w32-99709ab03387ca623e3fc1cac69d242ed44da45c.zip |
crontab: use setup_environment
function old new delta
setup_environment 184 198 +14
.rodata 131770 131747 -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-23) Total: -9 bytes
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
-rw-r--r-- | include/libbb.h | 5 | ||||
-rw-r--r-- | libbb/setup_environment.c | 7 | ||||
-rw-r--r-- | loginutils/login.c | 2 | ||||
-rw-r--r-- | miscutils/crontab.c | 21 |
4 files changed, 12 insertions, 23 deletions
diff --git a/include/libbb.h b/include/libbb.h index 9e3c18407..9d99b0d1a 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1142,6 +1142,7 @@ extern void selinux_or_die(void) FAST_FUNC; | |||
1142 | extern int restricted_shell(const char *shell) FAST_FUNC; | 1142 | extern int restricted_shell(const char *shell) FAST_FUNC; |
1143 | 1143 | ||
1144 | /* setup_environment: | 1144 | /* setup_environment: |
1145 | * if chdir pw->pw_dir: ok: else if to_tmp == 1: goto /tmp else: goto / or die | ||
1145 | * if clear_env = 1: cd(pw->pw_dir), clear environment, then set | 1146 | * if clear_env = 1: cd(pw->pw_dir), clear environment, then set |
1146 | * TERM=(old value) | 1147 | * TERM=(old value) |
1147 | * USER=pw->pw_name, LOGNAME=pw->pw_name | 1148 | * USER=pw->pw_name, LOGNAME=pw->pw_name |
@@ -1155,7 +1156,9 @@ extern int restricted_shell(const char *shell) FAST_FUNC; | |||
1155 | * SHELL=shell | 1156 | * SHELL=shell |
1156 | * else does nothing | 1157 | * else does nothing |
1157 | */ | 1158 | */ |
1158 | extern void setup_environment(const char *shell, int clear_env, int change_env, const struct passwd *pw) FAST_FUNC; | 1159 | #define SETUP_ENV_CHANGEENV (1<<0) |
1160 | #define SETUP_ENV_TO_TMP (1<<1) | ||
1161 | extern void setup_environment(const char *shell, int clear_env, int flags, const struct passwd *pw) FAST_FUNC; | ||
1159 | extern int correct_password(const struct passwd *pw) FAST_FUNC; | 1162 | extern int correct_password(const struct passwd *pw) FAST_FUNC; |
1160 | /* Returns a malloced string */ | 1163 | /* Returns a malloced string */ |
1161 | #if !ENABLE_USE_BB_CRYPT | 1164 | #if !ENABLE_USE_BB_CRYPT |
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index 78318ce62..f0802f0e5 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c | |||
@@ -30,12 +30,12 @@ | |||
30 | 30 | ||
31 | #include "libbb.h" | 31 | #include "libbb.h" |
32 | 32 | ||
33 | void FAST_FUNC setup_environment(const char *shell, int clear_env, int change_env, const struct passwd *pw) | 33 | void FAST_FUNC setup_environment(const char *shell, int clear_env, int flags, const struct passwd *pw) |
34 | { | 34 | { |
35 | /* Change the current working directory to be the home directory | 35 | /* Change the current working directory to be the home directory |
36 | * of the user */ | 36 | * of the user */ |
37 | if (chdir(pw->pw_dir)) { | 37 | if (chdir(pw->pw_dir)) { |
38 | xchdir("/"); | 38 | xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); |
39 | bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir); | 39 | bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir); |
40 | } | 40 | } |
41 | 41 | ||
@@ -55,8 +55,7 @@ void FAST_FUNC setup_environment(const char *shell, int clear_env, int change_en | |||
55 | //xsetenv("LOGNAME", pw->pw_name); | 55 | //xsetenv("LOGNAME", pw->pw_name); |
56 | //xsetenv("HOME", pw->pw_dir); | 56 | //xsetenv("HOME", pw->pw_dir); |
57 | //xsetenv("SHELL", shell); | 57 | //xsetenv("SHELL", shell); |
58 | } | 58 | } else if (flags & SETUP_ENV_CHANGEENV) { |
59 | else if (change_env) { | ||
60 | /* Set HOME, SHELL, and if not becoming a super-user, | 59 | /* Set HOME, SHELL, and if not becoming a super-user, |
61 | USER and LOGNAME. */ | 60 | USER and LOGNAME. */ |
62 | if (pw->pw_uid) { | 61 | if (pw->pw_uid) { |
diff --git a/loginutils/login.c b/loginutils/login.c index 7a6f246ad..974125d88 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -478,7 +478,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) | |||
478 | if (!tmp || !*tmp) | 478 | if (!tmp || !*tmp) |
479 | tmp = DEFAULT_SHELL; | 479 | tmp = DEFAULT_SHELL; |
480 | /* setup_environment params: shell, clear_env, change_env, pw */ | 480 | /* setup_environment params: shell, clear_env, change_env, pw */ |
481 | setup_environment(tmp, !(opt & LOGIN_OPT_p), 1, pw); | 481 | setup_environment(tmp, !(opt & LOGIN_OPT_p), SETUP_ENV_CHANGEENV, pw); |
482 | 482 | ||
483 | motd(); | 483 | motd(); |
484 | 484 | ||
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 044440435..7d5709521 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
@@ -17,22 +17,6 @@ | |||
17 | #define CRONUPDATE "cron.update" | 17 | #define CRONUPDATE "cron.update" |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | static void change_user(const struct passwd *pas) | ||
21 | { | ||
22 | xsetenv("USER", pas->pw_name); | ||
23 | xsetenv("HOME", pas->pw_dir); | ||
24 | xsetenv("SHELL", DEFAULT_SHELL); | ||
25 | |||
26 | /* initgroups, setgid, setuid */ | ||
27 | change_identity(pas); | ||
28 | |||
29 | if (chdir(pas->pw_dir) < 0) { | ||
30 | bb_perror_msg("chdir(%s) by %s failed", | ||
31 | pas->pw_dir, pas->pw_name); | ||
32 | xchdir("/tmp"); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | static void edit_file(const struct passwd *pas, const char *file) | 20 | static void edit_file(const struct passwd *pas, const char *file) |
37 | { | 21 | { |
38 | const char *ptr; | 22 | const char *ptr; |
@@ -46,7 +30,10 @@ static void edit_file(const struct passwd *pas, const char *file) | |||
46 | } | 30 | } |
47 | 31 | ||
48 | /* CHILD - change user and run editor */ | 32 | /* CHILD - change user and run editor */ |
49 | change_user(pas); | 33 | /* initgroups, setgid, setuid */ |
34 | change_identity(pas); | ||
35 | setup_environment(DEFAULT_SHELL, 0, | ||
36 | SETUP_ENV_CHANGEENV | SETUP_ENV_TO_TMP, pas); | ||
50 | ptr = getenv("VISUAL"); | 37 | ptr = getenv("VISUAL"); |
51 | if (!ptr) { | 38 | if (!ptr) { |
52 | ptr = getenv("EDITOR"); | 39 | ptr = getenv("EDITOR"); |