wok rev 12084

busybox: su should not chdir
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Mar 09 18:20:06 2012 +0100 (2012-03-09)
parents 0adddcc6b227
children 77d4b6bb3e69
files busybox/receipt busybox/stuff/busybox-1.18-su-nochdir.u
line diff
     1.1 --- a/busybox/receipt	Fri Mar 09 18:19:26 2012 +0100
     1.2 +++ b/busybox/receipt	Fri Mar 09 18:20:06 2012 +0100
     1.3 @@ -30,6 +30,7 @@
     1.4  cmdline.u
     1.5  conspy.u
     1.6  httpd.u
     1.7 +su-nochdir.u
     1.8  EOT
     1.9      cp $stuff/$PACKAGE-${VERSION%.*}.config .config
    1.10  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/busybox/stuff/busybox-1.18-su-nochdir.u	Fri Mar 09 18:20:06 2012 +0100
     2.3 @@ -0,0 +1,42 @@
     2.4 +su should not chdir to home
     2.5 +--- busybox-1.18.4/include/libbb.h
     2.6 ++++ busybox-1.18.4/include/libbb.h
     2.7 +@@ -1213,6 +1213,7 @@
     2.8 + #define SETUP_ENV_CHANGEENV (1 << 0)
     2.9 + #define SETUP_ENV_CLEARENV  (1 << 1)
    2.10 + #define SETUP_ENV_TO_TMP    (1 << 2)
    2.11 ++#define SETUP_ENV_NO_CHDIR  (1 << 4)
    2.12 + extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
    2.13 + extern int correct_password(const struct passwd *pw) FAST_FUNC;
    2.14 + /* Returns a malloced string */
    2.15 +
    2.16 +--- busybox-1.18.4/libbb/setup_environment.c
    2.17 ++++ busybox-1.18.4/libbb/setup_environment.c
    2.18 +@@ -34,9 +34,11 @@
    2.19 + {
    2.20 + 	/* Change the current working directory to be the home directory
    2.21 + 	 * of the user */
    2.22 +-	if (chdir(pw->pw_dir)) {
    2.23 +-		xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/");
    2.24 +-		bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir);
    2.25 ++	if ((flags & SETUP_ENV_NO_CHDIR) == 0) {
    2.26 ++		if (chdir(pw->pw_dir)) {
    2.27 ++			xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/");
    2.28 ++			bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir);
    2.29 ++		}
    2.30 + 	}
    2.31 + 
    2.32 + 	if (flags & SETUP_ENV_CLEARENV) {
    2.33 +
    2.34 +--- busybox-1.18.4/loginutils/su.c
    2.35 ++++ busybox-1.18.4/loginutils/su.c
    2.36 +@@ -126,7 +126,8 @@
    2.37 + 	change_identity(pw);
    2.38 + 	setup_environment(opt_shell,
    2.39 + 			((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV)
    2.40 +-			+ (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV),
    2.41 ++			+ (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV)
    2.42 ++			+ SETUP_ENV_NO_CHDIR,
    2.43 + 			pw);
    2.44 + 	IF_SELINUX(set_current_security_context(NULL);)
    2.45 +