Skip to content

Commit

Permalink
Copy environment from sshd, do not rewrite USER and PATH on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikushin committed Jan 31, 2020
1 parent f5f6aa7 commit 5be53e4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions session.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,13 +933,14 @@ read_etc_default_login(char ***env, u_int *envsize, uid_t uid)
if (tmpenv == NULL)
return;

#ifndef __ANDROID__
if (uid == 0)
var = child_get_env(tmpenv, "SUPATH");
else
var = child_get_env(tmpenv, "PATH");
if (var != NULL)
child_set_env(env, envsize, "PATH", var);

#endif
if ((var = child_get_env(tmpenv, "UMASK")) != NULL)
if (sscanf(var, "%5lo", &mask) == 1)
umask((mode_t)mask);
Expand All @@ -950,7 +951,7 @@ read_etc_default_login(char ***env, u_int *envsize, uid_t uid)
}
#endif /* HAVE_ETC_DEFAULT_LOGIN */

#if defined(USE_PAM) || defined(HAVE_CYGWIN)
#if defined(USE_PAM) || defined(HAVE_CYGWIN) || defined(__ANDROID__)
static void
copy_environment_blacklist(char **source, char ***env, u_int *envsize,
const char *blacklist)
Expand Down Expand Up @@ -980,7 +981,7 @@ copy_environment_blacklist(char **source, char ***env, u_int *envsize,
}
#endif /* defined(USE_PAM) || defined(HAVE_CYGWIN) */

#ifdef HAVE_CYGWIN
#if defined(HAVE_CYGWIN) || defined(__ANDROID__)
static void
copy_environment(char **source, char ***env, u_int *envsize)
{
Expand Down Expand Up @@ -1026,20 +1027,31 @@ do_setup_env(struct ssh *ssh, Session *s, const char *shell)
ssh_gssapi_do_child(&env, &envsize);
#endif

#ifdef __ANDROID__
/* Copy environment from the current process (sshd)
environment
*/
copy_environment(environ, &env, &envsize);
#endif

/* Set basic environment. */
for (i = 0; i < s->num_env; i++)
child_set_env(&env, &envsize, s->env[i].name, s->env[i].val);
#ifndef __ANDROID__
child_set_env(&env, &envsize, "USER", pw->pw_name);
#endif
child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
#ifdef _AIX
child_set_env(&env, &envsize, "LOGIN", pw->pw_name);
#endif
child_set_env(&env, &envsize, "HOME", pw->pw_dir);
#ifdef HAVE_LOGIN_CAP
#ifndef __ANDROID__
if (setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH) < 0)
child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
else
child_set_env(&env, &envsize, "PATH", getenv("PATH"));
#endif
#else /* HAVE_LOGIN_CAP */
# ifndef HAVE_CYGWIN
/*
Expand All @@ -1053,8 +1065,10 @@ do_setup_env(struct ssh *ssh, Session *s, const char *shell)
path = child_get_env(env, "PATH");
# endif /* HAVE_ETC_DEFAULT_LOGIN */
if (path == NULL || *path == '\0') {
#ifndef __ANDROID__
child_set_env(&env, &envsize, "PATH",
s->pw->pw_uid == 0 ? SUPERUSER_PATH : _PATH_STDPATH);
#endif
}
# endif /* HAVE_CYGWIN */
#endif /* HAVE_LOGIN_CAP */
Expand Down

0 comments on commit 5be53e4

Please sign in to comment.