# HG changeset patch # User Pascal Bellard # Date 1331313606 -3600 # Node ID a5fbfa5737a669c6c52283c6d54e2c6d3bff6d4b # Parent 0adddcc6b22770410a1fe5c6b3c3ca6c79d49d28 busybox: su should not chdir diff -r 0adddcc6b227 -r a5fbfa5737a6 busybox/receipt --- a/busybox/receipt Fri Mar 09 18:19:26 2012 +0100 +++ b/busybox/receipt Fri Mar 09 18:20:06 2012 +0100 @@ -30,6 +30,7 @@ cmdline.u conspy.u httpd.u +su-nochdir.u EOT cp $stuff/$PACKAGE-${VERSION%.*}.config .config } diff -r 0adddcc6b227 -r a5fbfa5737a6 busybox/stuff/busybox-1.18-su-nochdir.u --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/busybox/stuff/busybox-1.18-su-nochdir.u Fri Mar 09 18:20:06 2012 +0100 @@ -0,0 +1,42 @@ +su should not chdir to home +--- busybox-1.18.4/include/libbb.h ++++ busybox-1.18.4/include/libbb.h +@@ -1213,6 +1213,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.18.4/libbb/setup_environment.c ++++ busybox-1.18.4/libbb/setup_environment.c +@@ -34,9 +34,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.18.4/loginutils/su.c ++++ busybox-1.18.4/loginutils/su.c +@@ -126,7 +126,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) ++ + SETUP_ENV_NO_CHDIR, + pw); + IF_SELINUX(set_current_security_context(NULL);) +