wok-stable view busybox/stuff/busybox-1.18-su-nochdir.u @ rev 12465

Up e2fsprogs (1.44.2)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Mar 04 18:42:23 2019 +0100 (2019-03-04)
parents a5fbfa5737a6
children
line source
1 su should not chdir to home
2 --- busybox-1.18.4/include/libbb.h
3 +++ busybox-1.18.4/include/libbb.h
4 @@ -1213,6 +1213,7 @@
5 #define SETUP_ENV_CHANGEENV (1 << 0)
6 #define SETUP_ENV_CLEARENV (1 << 1)
7 #define SETUP_ENV_TO_TMP (1 << 2)
8 +#define SETUP_ENV_NO_CHDIR (1 << 4)
9 extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
10 extern int correct_password(const struct passwd *pw) FAST_FUNC;
11 /* Returns a malloced string */
13 --- busybox-1.18.4/libbb/setup_environment.c
14 +++ busybox-1.18.4/libbb/setup_environment.c
15 @@ -34,9 +34,11 @@
16 {
17 /* Change the current working directory to be the home directory
18 * of the user */
19 - if (chdir(pw->pw_dir)) {
20 - xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/");
21 - bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir);
22 + if ((flags & SETUP_ENV_NO_CHDIR) == 0) {
23 + if (chdir(pw->pw_dir)) {
24 + xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/");
25 + bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir);
26 + }
27 }
29 if (flags & SETUP_ENV_CLEARENV) {
31 --- busybox-1.18.4/loginutils/su.c
32 +++ busybox-1.18.4/loginutils/su.c
33 @@ -126,7 +126,8 @@
34 change_identity(pw);
35 setup_environment(opt_shell,
36 ((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV)
37 - + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV),
38 + + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV)
39 + + (!(flags & SU_OPT_l) * SETUP_ENV_NO_CHDIR),
40 pw);
41 IF_SELINUX(set_current_security_context(NULL);)