# HG changeset patch # User Pascal Bellard # Date 1331373396 -3600 # Node ID baaa314a741df5943532058982aec64c0c4cb9ad # Parent 08522bf057e9f1f4e94842d81260b69ab9cdf45d busybox: su should not chdir diff -r 08522bf057e9 -r baaa314a741d busybox/receipt --- a/busybox/receipt Thu Mar 08 23:20:32 2012 +0000 +++ b/busybox/receipt Sat Mar 10 10:56:36 2012 +0100 @@ -29,6 +29,7 @@ cmdline.u conspy.u httpd.u +su-nochdir.u EOT cp $stuff/$PACKAGE-${VERSION%.*}.config .config } diff -r 08522bf057e9 -r baaa314a741d busybox/stuff/busybox-1.19-su-nochdir.u --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/busybox/stuff/busybox-1.19-su-nochdir.u Sat Mar 10 10:56:36 2012 +0100 @@ -0,0 +1,42 @@ +su should not chdir to home +--- busybox-1.19.4/include/libbb.h ++++ busybox-1.19.4/include/libbb.h +@@ -1274,6 +1274,7 @@ + #define SETUP_ENV_CHANGEENV (1 << 0) + #define SETUP_ENV_CLEARENV (1 << 1) + #define SETUP_ENV_TO_TMP (1 << 2) ++#define SETUP_ENV_NO_CHDIR (1 << 4) + extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; + extern int correct_password(const struct passwd *pw) FAST_FUNC; + /* Returns a malloced string */ + +--- busybox-1.19.4/libbb/setup_environment.c ++++ busybox-1.19.4/libbb/setup_environment.c +@@ -37,9 +37,11 @@ + + /* Change the current working directory to be the home directory + * of the user */ +- if (chdir(pw->pw_dir)) { +- xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); +- bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir); ++ if ((flags & SETUP_ENV_NO_CHDIR) == 0) { ++ if (chdir(pw->pw_dir)) { ++ xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); ++ bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir); ++ } + } + + if (flags & SETUP_ENV_CLEARENV) { + +--- busybox-1.19.4/loginutils/su.c ++++ busybox-1.19.4/loginutils/su.c +@@ -131,7 +131,8 @@ + change_identity(pw); + setup_environment(opt_shell, + ((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV) +- + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV), ++ + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV) ++ + (!(flags & SU_OPT_l) * SETUP_ENV_NO_CHDIR), + pw); + IF_SELINUX(set_current_security_context(NULL);) +