From: Anas Nashif Date: Tue, 12 Feb 2013 13:57:08 +0000 (-0800) Subject: openssh-5.9p1-xauthlocalhostname.diff X-Git-Tag: accepted/tizen/common/20141229.125255~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b3e8da40f6303c79b8b1c838eba247d4fdc901ce;p=platform%2Fupstream%2Fopenssh.git openssh-5.9p1-xauthlocalhostname.diff =================================================================== --- diff --git a/session.c b/session.c index 2bcf818..11bdcb5 100644 --- a/session.c +++ b/session.c @@ -1151,7 +1151,7 @@ copy_environment(char **source, char ***env, u_int *envsize) } static char ** -do_setup_env(Session *s, const char *shell) +do_setup_env(Session *s, const char *shell, int *env_size) { char buf[256]; u_int i, envsize; @@ -1338,6 +1338,8 @@ do_setup_env(Session *s, const char *shell) for (i = 0; env[i]; i++) fprintf(stderr, " %.200s\n", env[i]); } + + *env_size = envsize; return env; } @@ -1346,7 +1348,7 @@ do_setup_env(Session *s, const char *shell) * first in this order). */ static void -do_rc_files(Session *s, const char *shell) +do_rc_files(Session *s, const char *shell, char **env, int *env_size) { FILE *f = NULL; char cmd[1024]; @@ -1400,12 +1402,20 @@ do_rc_files(Session *s, const char *shell) options.xauth_location); f = popen(cmd, "w"); if (f) { + char hostname[MAXHOSTNAMELEN]; + fprintf(f, "remove %s\n", s->auth_display); fprintf(f, "add %s %s %s\n", s->auth_display, s->auth_proto, s->auth_data); pclose(f); + if (gethostname(hostname,sizeof(hostname)) >= 0) + child_set_env(&env,env_size,"XAUTHLOCALHOSTNAME", + hostname); + else + debug("Cannot set up XAUTHLOCALHOSTNAME %s\n", + strerror(errno)); } else { fprintf(stderr, "Could not run %s\n", cmd); @@ -1669,6 +1679,7 @@ do_child(Session *s, const char *command) { extern char **environ; char **env; + int env_size; char *argv[ARGV_MAX]; const char *shell, *shell0, *hostname = NULL; struct passwd *pw = s->pw; @@ -1735,7 +1746,7 @@ do_child(Session *s, const char *command) * Make sure $SHELL points to the shell from the password file, * even if shell is overridden from login.conf */ - env = do_setup_env(s, shell); + env = do_setup_env(s, shell, &env_size); #ifdef HAVE_LOGIN_CAP shell = login_getcapstr(lc, "shell", (char *)shell, (char *)shell); @@ -1804,7 +1815,7 @@ do_child(Session *s, const char *command) closefrom(STDERR_FILENO + 1); if (!options.use_login) - do_rc_files(s, shell); + do_rc_files(s, shell, env, &env_size); /* restore SIGPIPE for child */ signal(SIGPIPE, SIG_DFL);