components/openssh/patches/031-per_session_xauthfile.patch
author Jan Parcel <jan.parcel@oracle.com>
Mon, 01 Feb 2016 06:53:50 -0800
changeset 5376 4615bc2f4a50
parent 4744 ed1ff241f25d
child 5613 27ea636da8ce
permissions -rw-r--r--
22631538 Patch comment incorrect/outdated for patch 039-sshd_config_5_defaults.patch
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
#
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    10
--- orig/session.c	Thu Jul 30 10:35:15 2015
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    11
+++ new/session.c	Tue Aug  4 11:29:22 2015
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    12
@@ -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
    13
 #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
    14
 #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
    15
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    16
+#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
    17
+#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
    18
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    19
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    20
 #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
    21
 #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
    22
 #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
    23
@@ -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
    24
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    25
 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
    26
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    27
+#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
    28
+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
    29
+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
    30
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    31
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    32
 /* import */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    33
 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
    34
 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
    35
@@ -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
    36
 	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
    37
 		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
    38
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    39
+#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
    40
+        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
    41
+                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
    42
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    43
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    44
 	/* 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
    45
 	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
    46
 		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
    47
@@ -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
    48
 {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    49
 	int success;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    50
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    51
+#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
    52
+	int fd;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    53
+        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
    54
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    55
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    56
 	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
    57
 		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
    58
 		    "x11 forwarding already active", s->self);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    59
@@ -2188,6 +2207,48 @@
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    60
 		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
    61
 		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
    62
 	}
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
+#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
    65
+	/*
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    66
+	 * 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
    67
+	 *
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    68
+	 * 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
    69
+	 * 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
    70
+	 * 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
    71
+	 */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    72
+	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
    73
+		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
    74
+		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
    75
+		    xauthdir);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    76
+		/*
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    77
+		 * 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
    78
+                 * 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
    79
+		 * beforehand.
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    80
+		 */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    81
+		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
    82
+		    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
    83
+			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
    84
+			    "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
    85
+			    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
    86
+			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
    87
+			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
    88
+			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
    89
+				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
    90
+				    "%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
    91
+			}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    92
+		} else {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    93
+			close(fd);
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    94
+			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
    95
+			    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
    96
+                        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
    97
+		}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    98
+	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    99
+	else {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   100
+		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
   101
+		    "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
   102
+		    strerror(errno));
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   103
+	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   104
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   105
 	return success;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   106
 }
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   107
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   108
@@ -2378,6 +2439,50 @@
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   109
 	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
   110
 }
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   111
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   112
+#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
   113
+/*
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   114
+ * 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
   115
+ * 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
   116
+ */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   117
+void
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   118
+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
   119
+{
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   120
+	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
   121
+		return;
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
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   124
+	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
   125
+	    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
   126
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   127
+	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
   128
+		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
   129
+		    "%.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
   130
+		return;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   131
+	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   132
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   133
+	/* 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
   134
+	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
   135
+		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
   136
+		    "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
   137
+		return;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   138
+	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   139
+	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
   140
+	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
   141
+}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   142
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   143
+/*
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   144
+ * 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
   145
+ */
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   146
+void
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   147
+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
   148
+{
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   149
+	int i;
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   150
+	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
   151
+                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
   152
+	}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   153
+}
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   154
+#endif
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
 static char *
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   157
 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
   158
 {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   159
@@ -2512,6 +2617,9 @@
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   160
 	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
   161
 	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
   162
 	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
   163
+#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
   164
+	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
   165
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   166
 	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
   167
 	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
   168
 		for (i = 0; i < s->num_env; i++) {
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   169
@@ -2763,6 +2871,10 @@
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   170
 	/* 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
   171
 	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
   172
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   173
+#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
   174
+	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
   175
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   176
+
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   177
 	/*
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   178
 	 * 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
   179
 	 * or if running in monitor.
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   180
--- orig/session.h	Thu Jul 30 10:35:12 2015
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   181
+++ new/session.h	Tue Aug  4 11:30:04 2015
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   182
@@ -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
   183
 	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
   184
 	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
   185
 	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
   186
+#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
   187
+	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
   188
+#endif
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   189
 	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
   190
 
ed1ff241f25d 19130869 migrate the Xforwarding bug fix (15350344) from SunSSH to OpenSSH
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   191
 	/* proto 2 */