From 70fc8c17e2d032f34162f7abc3e65a67c0ff272a Mon Sep 17 00:00:00 2001 From: Pascal Bellard Date: Tue, 12 Jun 2012 13:21:02 +0200 Subject: su: do not change to home dir unless -l Signed-off-by: Pascal Bellard Signed-off-by: Denys Vlasenko --- libbb/setup_environment.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libbb/setup_environment.c') 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 /* 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)) { + if (chdir(pw->pw_dir) != 0) { + bb_error_msg("can't change directory to '%s'", pw->pw_dir); + xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); + } } if (flags & SETUP_ENV_CLEARENV) { -- cgit v1.2.3