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

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

# HG changeset patch
# Parent  18c2690afd988b9cb0fd0fa927d02cf5336dce9c
# --used to be called '-xauth'
try to remove xauth cookies on logout

bnc#98815
---
 session.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/session.c b/session.c
index cbc2f1ac..8eb643c6 100644
--- a/session.c
+++ b/session.c
@@ -2545,6 +2545,34 @@ session_close(Session *s)
 	    get_remote_port(),
 	    s->self);
 
+	if ((s->display != NULL) && (s->auth_proto != NULL) &&
+	    (s->auth_data != NULL) && (options.xauth_location != NULL)) {
+		pid_t pid;
+		FILE *f;
+		char cmd[1024];
+		struct passwd * pw = s->pw;
+
+		if (!(pid = fork())) {
+			permanently_set_uid(pw);
+
+			/* Remove authority data from .Xauthority if appropriate. */
+			debug("Running %.500s remove %.100s\n",
+			    options.xauth_location, s->auth_display);
+
+			snprintf(cmd, sizeof cmd, "unset XAUTHORITY && HOME=\"%.200s\" %s -q -",
+                     	    s->pw->pw_dir, options.xauth_location);
+            		f = popen(cmd, "w");
+			if (f) {
+				fprintf(f, "remove %s\n", s->auth_display);
+				pclose(f);
+			} else
+				error("Could not run %s\n", cmd);
+			exit(0);
+		} else if (pid > 0) {
+			waitpid(pid, NULL, 0);
+		}
+	}
+
 	if (s->ttyfd != -1)
 		session_pty_cleanup(s);
 	free(s->term);
-- 
2.38.0

openSUSE Build Service is sponsored by