summaryrefslogtreecommitdiff
authorPascal Bellard <pascal.bellard@ads-lu.com>2012-06-12 11:21:02 (GMT)
committer Tanguy Pruvot <tanguy.pruvot@gmail.com>2012-07-14 01:10:43 (GMT)
commit0414e02083560f89f33d79162b82471f32aa958c (patch)
treeaa71d3606903d0ac82c0456a944d37798250df9b
parent03dc3658e3d24c4f4b8b5bca6742da4e172af049 (diff)
downloadbusybox-0414e02083560f89f33d79162b82471f32aa958c.zip
busybox-0414e02083560f89f33d79162b82471f32aa958c.tar.gz
busybox-0414e02083560f89f33d79162b82471f32aa958c.tar.bz2
su: do not change to home dir unless -l
Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/setup_environment.c8
-rw-r--r--libbb/xfuncs_printf.c4
-rw-r--r--loginutils/su.c3
-rw-r--r--networking/httpd.c2
5 files changed, 11 insertions, 7 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 6176726..63caf8a 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1311,6 +1311,7 @@ int sd_listen_fds(void);
#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 */
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index 73229ca..4258656 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) {
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index b771ba5..29c963f 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -355,13 +355,13 @@ void FAST_FUNC xsetuid(uid_t uid)
void FAST_FUNC xchdir(const char *path)
{
if (chdir(path))
- bb_perror_msg_and_die("chdir(%s)", path);
+ bb_perror_msg_and_die("can't change directory to '%s'", path);
}
void FAST_FUNC xchroot(const char *path)
{
if (chroot(path))
- bb_perror_msg_and_die("can't change root directory to %s", path);
+ bb_perror_msg_and_die("can't change root directory to '%s'", path);
xchdir("/");
}
diff --git a/loginutils/su.c b/loginutils/su.c
index 57ea738..2ec05e1 100644
--- a/loginutils/su.c
+++ b/loginutils/su.c
@@ -131,7 +131,8 @@ int su_main(int argc UNUSED_PARAM, char **argv)
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);)
diff --git a/networking/httpd.c b/networking/httpd.c
index 12218a0..a942794 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1414,7 +1414,7 @@ static void send_cgi_and_exit(
if (script != url) { /* paranoia */
*script = '\0';
if (chdir(url + 1) != 0) {
- bb_perror_msg("chdir(%s)", url + 1);
+ bb_perror_msg("can't change directory to '%s'", url + 1);
goto error_execing_cgi;
}
// not needed: *script = '/';