File openssh-7.2p2-hostname_changes_when_forwarding_X.patch of Package openssh.29886

From 72847e31b9efc354ffb30175dcbd787a56fb0315 Mon Sep 17 00:00:00 2001
From: Old openssh patches <pcerny@suse.com>
Date: Tue, 25 Oct 2022 18:53:11 +0200
Subject: [PATCH] openssh-7.2p2-hostname_changes_when_forwarding_X

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

bnc#98627
---
 session.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/session.c b/session.c
index 87fddfc3..cbc2f1ac 100644
--- a/session.c
+++ b/session.c
@@ -1159,7 +1159,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;
@@ -1346,6 +1346,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;
 }
 
@@ -1354,7 +1356,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];
@@ -1409,12 +1411,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);
@@ -1686,6 +1696,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;
@@ -1752,7 +1763,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);
@@ -1821,7 +1832,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);
-- 
2.38.0

openSUSE Build Service is sponsored by