File openssh-7.6p1-hostname_changes_when_forwarding_X.patch of Package openssh.10835

# HG changeset patch
# Parent  e4a7e5799420a3d4b8047c5984c75c4bd4331951
# -- uset do be called '-xauthlocalhostname'
handle hostname changes when forwarding X

bnc#98627

Index: openssh-7.6p1/session.c
===================================================================
--- openssh-7.6p1.orig/session.c	2019-03-12 14:34:00.203389950 +0100
+++ openssh-7.6p1/session.c	2019-03-12 14:34:21.007505834 +0100
@@ -958,7 +958,7 @@ copy_environment(char **source, char ***
 }
 
 static char **
-do_setup_env(struct ssh *ssh, Session *s, const char *shell)
+do_setup_env(struct ssh *ssh, Session *s, const char *shell, int *env_size)
 {
 	char buf[256];
 	u_int i, envsize;
@@ -1147,6 +1147,8 @@ do_setup_env(struct ssh *ssh, Session *s
 		for (i = 0; env[i]; i++)
 			fprintf(stderr, "  %.200s\n", env[i]);
 	}
+
+	*env_size = envsize;
 	return env;
 }
 
@@ -1155,7 +1157,7 @@ do_setup_env(struct ssh *ssh, Session *s
  * 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];
@@ -1210,12 +1212,20 @@ do_rc_files(Session *s, const char *shel
 		    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);
@@ -1466,6 +1476,7 @@ do_child(struct ssh *ssh, Session *s, co
 {
 	extern char **environ;
 	char **env;
+	int env_size;
 	char *argv[ARGV_MAX];
 	const char *shell, *shell0;
 	struct passwd *pw = s->pw;
@@ -1527,7 +1538,7 @@ do_child(struct ssh *ssh, Session *s, co
 	 * Make sure $SHELL points to the shell from the password file,
 	 * even if shell is overridden from login.conf
 	 */
-	env = do_setup_env(ssh, s, shell);
+	env = do_setup_env(ssh, s, shell, &env_size);
 
 #ifdef HAVE_LOGIN_CAP
 	shell = login_getcapstr(lc, "shell", (char *)shell, (char *)shell);
@@ -1591,7 +1602,7 @@ do_child(struct ssh *ssh, Session *s, co
 
 	closefrom(STDERR_FILENO + 1);
 
-	do_rc_files(s, shell);
+	do_rc_files(s, shell, env, &env_size);
 
 	/* restore SIGPIPE for child */
 	signal(SIGPIPE, SIG_DFL);