components/openssh/patches/031-per_session_xauthfile.patch
author Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
Fri, 07 Oct 2016 22:43:37 -0700
changeset 7203 c08b4f974065
parent 5613 27ea636da8ce
permissions -rw-r--r--
21866045 move /etc/pam.d/gdm-autologin from system/core-os to system/display-manager/gdm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4744
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     1
#
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     2
# This patch is to fix a X11 connection failure when a user's home directory
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     3
# is read-only. 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     4
#
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     5
# We have contributed back this fix to the OpenSSH upstream community. For
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     6
# more information, see https://bugzilla.mindrot.org/show_bug.cgi?id=2440
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     7
# In the future, if this fix is accepted by the upsteam in a later release, we
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     8
# will remove this patch when we upgrade to that release.
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     9
#
5613
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
    10
diff -pur old/session.c new/session.c
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
    11
--- old/session.c
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
    12
+++ new/session.c
4744
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    13
@@ -62,6 +62,10 @@
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    14
 #include <unistd.h>
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    15
 #include <limits.h>
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    16
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    17
+#ifdef PER_SESSION_XAUTHFILE
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    18
+#include <libgen.h>
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    19
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    20
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    21
 #include "openbsd-compat/sys-queue.h"
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    22
 #include "xmalloc.h"
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    23
 #include "ssh.h"
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    24
@@ -132,6 +136,11 @@
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    25
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    26
 static int session_pty_req(Session *);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    27
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    28
+#ifdef PER_SESSION_XAUTHFILE
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    29
+void   session_xauthfile_cleanup(Session *);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    30
+void   cleanup_all_session_xauthfile();
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    31
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    32
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    33
 /* import */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    34
 extern ServerOptions options;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    35
 extern char *__progname;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    36
@@ -1218,6 +1227,11 @@
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    37
 	if (getenv("TZ"))
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    38
 		child_set_env(&env, &envsize, "TZ", getenv("TZ"));
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    39
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    40
+#ifdef PER_SESSION_XAUTHFILE
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    41
+        if (s->auth_file != NULL)
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    42
+                child_set_env(&env, &envsize, "XAUTHORITY", s->auth_file);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    43
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    44
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    45
 	/* Set custom environment options from RSA authentication. */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    46
 	if (!options.use_login) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    47
 		while (custom_environment) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    48
@@ -2170,6 +2184,11 @@
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    49
 {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    50
 	int success;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    51
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    52
+#ifdef PER_SESSION_XAUTHFILE
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    53
+	int fd;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    54
+        char xauthdir[] = "/tmp/ssh-xauth-XXXXXX";
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    55
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    56
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    57
 	if (s->auth_proto != NULL || s->auth_data != NULL) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    58
 		error("session_x11_req: session %d: "
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    59
 		    "x11 forwarding already active", s->self);
5613
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
    60
@@ -2188,6 +2207,50 @@
4744
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    61
 		s->auth_proto = NULL;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    62
 		s->auth_data = NULL;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    63
 	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    64
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    65
+#ifdef PER_SESSION_XAUTHFILE
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    66
+	/*
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    67
+	 * Create per session X authority file in the /tmp directory.
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    68
+	 *
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    69
+	 * If mkdtemp() or open() fails then s->auth_file remains NULL which
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    70
+	 * means that we won't set XAUTHORITY variable in child's environment
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    71
+	 * and xauth(1) will use the default location for the authority file.
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    72
+	 */
5613
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
    73
+	temporarily_use_uid(s->pw);
4744
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    74
+	if (mkdtemp(xauthdir) != NULL) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    75
+		s->auth_file = xmalloc(MAXPATHLEN);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    76
+		snprintf(s->auth_file, MAXPATHLEN, "%s/xauthfile",
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    77
+		    xauthdir);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    78
+		/*
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    79
+		 * we don't want that "creating new authority file" message to
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    80
+                 * be printed by xauth(1) so we must create that file
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    81
+		 * beforehand.
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    82
+		 */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    83
+		if ((fd = open(s->auth_file, O_CREAT | O_EXCL | O_RDONLY,
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    84
+		    S_IRUSR | S_IWUSR)) == -1) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    85
+			error("failed to create the temporary X authority "
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    86
+			    "file %s: %.100s; will use the default one",
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    87
+			    s->auth_file, strerror(errno));
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    88
+			free(s->auth_file);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    89
+			s->auth_file = NULL;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    90
+			if (rmdir(xauthdir) == -1) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    91
+				error("cannot remove xauth directory "
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    92
+				    "%s: %.100s", xauthdir, strerror(errno));
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    93
+			}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    94
+		} else {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    95
+			close(fd);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    96
+			debug("temporary X authority file %s created",
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    97
+			    s->auth_file);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    98
+                        debug("session number = %d", s->self);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    99
+		}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   100
+	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   101
+	else {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   102
+		error("failed to create a directory for the temporary X "
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   103
+		    "authority file: %.100s; will use the default xauth file",
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   104
+		    strerror(errno));
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   105
+	}
5613
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
   106
+	restore_uid();
4744
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   107
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   108
 	return success;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   109
 }
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   110
 
5613
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
   111
@@ -2378,6 +2441,50 @@
4744
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   112
 	PRIVSEP(session_pty_cleanup2(s));
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   113
 }
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   114
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   115
+#ifdef PER_SESSION_XAUTHFILE
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   116
+/*
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   117
+ * We use a different temporary X authority file per session so we should
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   118
+ * remove those files when cleanup_exit() is called.
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   119
+ */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   120
+void
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   121
+session_xauthfile_cleanup(Session *s)
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   122
+{
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   123
+	if (s == NULL || s->auth_file == NULL) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   124
+		return;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   125
+	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   126
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   127
+	debug("session_xauthfile_cleanup: session %d removing %s", s->self,
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   128
+	    s->auth_file);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   129
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   130
+	if (unlink(s->auth_file) == -1) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   131
+		error("session_xauthfile_cleanup: cannot remove xauth file: "
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   132
+		    "%.100s", strerror(errno));
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   133
+		return;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   134
+	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   135
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   136
+	/* dirname() will modify s->auth_file but that's ok */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   137
+	if (rmdir(dirname(s->auth_file)) == -1) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   138
+		error("session_xauthfile_cleanup: "
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   139
+		    "cannot remove xauth directory: %.100s", strerror(errno));
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   140
+		return;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   141
+	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   142
+	free(s->auth_file);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   143
+	s->auth_file = NULL;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   144
+}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   145
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   146
+/*
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   147
+ * This is called by do_cleanup() when cleanup_exit() is called. 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   148
+ */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   149
+void
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   150
+cleanup_all_session_xauthfile()
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   151
+{
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   152
+	int i;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   153
+	for (i = 0; i < sessions_nalloc; i++) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   154
+                session_xauthfile_cleanup(&sessions[i]);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   155
+	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   156
+}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   157
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   158
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   159
 static char *
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   160
 sig2name(int sig)
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   161
 {
5613
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
   162
@@ -2512,6 +2619,9 @@
4744
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   163
 	free(s->auth_display);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   164
 	free(s->auth_data);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   165
 	free(s->auth_proto);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   166
+#ifdef PER_SESSION_XAUTHFILE
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   167
+	session_xauthfile_cleanup(s);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   168
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   169
 	free(s->subsys);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   170
 	if (s->env != NULL) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   171
 		for (i = 0; i < s->num_env; i++) {
5613
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
   172
@@ -2763,6 +2873,10 @@
4744
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   173
 	/* remove agent socket */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   174
 	auth_sock_cleanup_proc(authctxt->pw);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   175
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   176
+#ifdef PER_SESSION_XAUTHFILE
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   177
+	cleanup_all_session_xauthfile();
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   178
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   179
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   180
 	/*
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   181
 	 * Cleanup ptys/utmp only if privsep is disabled,
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   182
 	 * or if running in monitor.
5613
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
   183
diff -pur old/session.h new/session.h
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
   184
--- old/session.h
27ea636da8ce 22842240 per-session xauth file does not work when UsePrivilege is set to no
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 4744
diff changeset
   185
+++ new/session.h
4744
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   186
@@ -49,6 +49,9 @@
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   187
 	char	*auth_display;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   188
 	char	*auth_proto;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   189
 	char	*auth_data;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   190
+#ifdef PER_SESSION_XAUTHFILE
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   191
+	char    *auth_file;	/* xauth(1) authority file */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   192
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   193
 	int	single_connection;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   194
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   195
 	/* proto 2 */