diff options
| author | Pascal Bellard <pascal.bellard@ads-lu.com> | 2012-06-12 13:21:02 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-06-12 13:21:02 +0200 |
| commit | 70fc8c17e2d032f34162f7abc3e65a67c0ff272a (patch) | |
| tree | b2a4b1b2f6d52b01056e4601aca1c676e7f0f80f | |
| parent | 588e284f53da2dc5c58f3d1b9efacd6e9061baf1 (diff) | |
| download | busybox-w32-70fc8c17e2d032f34162f7abc3e65a67c0ff272a.tar.gz busybox-w32-70fc8c17e2d032f34162f7abc3e65a67c0ff272a.tar.bz2 busybox-w32-70fc8c17e2d032f34162f7abc3e65a67c0ff272a.zip | |
su: do not change to home dir unless -l
Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | include/libbb.h | 1 | ||||
| -rw-r--r-- | libbb/setup_environment.c | 8 | ||||
| -rw-r--r-- | libbb/xfuncs_printf.c | 4 | ||||
| -rw-r--r-- | loginutils/su.c | 3 | ||||
| -rw-r--r-- | networking/httpd.c | 2 |
5 files changed, 11 insertions, 7 deletions
diff --git a/include/libbb.h b/include/libbb.h index 5e5c8c7e8..322a28cab 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -1286,6 +1286,7 @@ int sd_listen_fds(void); | |||
| 1286 | #define SETUP_ENV_CHANGEENV (1 << 0) | 1286 | #define SETUP_ENV_CHANGEENV (1 << 0) |
| 1287 | #define SETUP_ENV_CLEARENV (1 << 1) | 1287 | #define SETUP_ENV_CLEARENV (1 << 1) |
| 1288 | #define SETUP_ENV_TO_TMP (1 << 2) | 1288 | #define SETUP_ENV_TO_TMP (1 << 2) |
| 1289 | #define SETUP_ENV_NO_CHDIR (1 << 4) | ||
| 1289 | extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; | 1290 | extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; |
| 1290 | extern int correct_password(const struct passwd *pw) FAST_FUNC; | 1291 | extern int correct_password(const struct passwd *pw) FAST_FUNC; |
| 1291 | /* Returns a malloced string */ | 1292 | /* Returns a malloced string */ |
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index 73229ca6c..4258656fe 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c | |||
| @@ -37,9 +37,11 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass | |||
| 37 | 37 | ||
| 38 | /* Change the current working directory to be the home directory | 38 | /* Change the current working directory to be the home directory |
| 39 | * of the user */ | 39 | * of the user */ |
| 40 | if (chdir(pw->pw_dir)) { | 40 | if (!(flags & SETUP_ENV_NO_CHDIR)) { |
| 41 | xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); | 41 | if (chdir(pw->pw_dir) != 0) { |
| 42 | bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir); | 42 | bb_error_msg("can't change directory to '%s'", pw->pw_dir); |
| 43 | xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); | ||
| 44 | } | ||
| 43 | } | 45 | } |
| 44 | 46 | ||
| 45 | if (flags & SETUP_ENV_CLEARENV) { | 47 | if (flags & SETUP_ENV_CLEARENV) { |
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index d8a42ba0b..05aa07ce8 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c | |||
| @@ -355,13 +355,13 @@ void FAST_FUNC xsetuid(uid_t uid) | |||
| 355 | void FAST_FUNC xchdir(const char *path) | 355 | void FAST_FUNC xchdir(const char *path) |
| 356 | { | 356 | { |
| 357 | if (chdir(path)) | 357 | if (chdir(path)) |
| 358 | bb_perror_msg_and_die("chdir(%s)", path); | 358 | bb_perror_msg_and_die("can't change directory to '%s'", path); |
| 359 | } | 359 | } |
| 360 | 360 | ||
| 361 | void FAST_FUNC xchroot(const char *path) | 361 | void FAST_FUNC xchroot(const char *path) |
| 362 | { | 362 | { |
| 363 | if (chroot(path)) | 363 | if (chroot(path)) |
| 364 | bb_perror_msg_and_die("can't change root directory to %s", path); | 364 | bb_perror_msg_and_die("can't change root directory to '%s'", path); |
| 365 | xchdir("/"); | 365 | xchdir("/"); |
| 366 | } | 366 | } |
| 367 | 367 | ||
diff --git a/loginutils/su.c b/loginutils/su.c index 57ea738f4..2ec05e125 100644 --- a/loginutils/su.c +++ b/loginutils/su.c | |||
| @@ -131,7 +131,8 @@ int su_main(int argc UNUSED_PARAM, char **argv) | |||
| 131 | change_identity(pw); | 131 | change_identity(pw); |
| 132 | setup_environment(opt_shell, | 132 | setup_environment(opt_shell, |
| 133 | ((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV) | 133 | ((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV) |
| 134 | + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV), | 134 | + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV) |
| 135 | + (!(flags & SU_OPT_l) * SETUP_ENV_NO_CHDIR), | ||
| 135 | pw); | 136 | pw); |
| 136 | IF_SELINUX(set_current_security_context(NULL);) | 137 | IF_SELINUX(set_current_security_context(NULL);) |
| 137 | 138 | ||
diff --git a/networking/httpd.c b/networking/httpd.c index 12218a0a3..a942794f5 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
| @@ -1414,7 +1414,7 @@ static void send_cgi_and_exit( | |||
| 1414 | if (script != url) { /* paranoia */ | 1414 | if (script != url) { /* paranoia */ |
| 1415 | *script = '\0'; | 1415 | *script = '\0'; |
| 1416 | if (chdir(url + 1) != 0) { | 1416 | if (chdir(url + 1) != 0) { |
| 1417 | bb_perror_msg("chdir(%s)", url + 1); | 1417 | bb_perror_msg("can't change directory to '%s'", url + 1); |
| 1418 | goto error_execing_cgi; | 1418 | goto error_execing_cgi; |
| 1419 | } | 1419 | } |
| 1420 | // not needed: *script = '/'; | 1420 | // not needed: *script = '/'; |
