[openssh-commits] [openssh] 01/01: If OSX is using launchd, remove screen no.

git+noreply at mindrot.org git+noreply at mindrot.org
Fri Mar 10 13:29:41 AEDT 2017


This is an automated email from the git hooks/post-receive script.

dtucker pushed a commit to branch V_7_4
in repository openssh.

commit 6f14de011f0d1586c607ef94270651722d0b4cb2
Author: Darren Tucker <dtucker at zip.com.au>
Date:   Fri Mar 10 13:22:32 2017 +1100

    If OSX is using launchd, remove screen no.
    
    Check for socket with and without screen number.  From Apple and Jakob
    Schlyter via bz#2341, with contributions from Ron Frederick, ok djm@
---
 channels.c | 48 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/channels.c b/channels.c
index bef8ad6..6ca7afb 100644
--- a/channels.c
+++ b/channels.c
@@ -4354,6 +4354,33 @@ connect_local_xsocket(u_int dnr)
 	return connect_local_xsocket_path(buf);
 }
 
+#ifdef __APPLE__
+static int
+is_path_to_xsocket(const char *display, char *path, size_t pathlen)
+{
+	struct stat sbuf;
+
+	if (strlcpy(path, display, pathlen) >= pathlen) {
+		error("%s: display path too long", __func__);
+		return 0;
+	}
+	if (display[0] != '/')
+		return 0;
+	if (stat(path, &sbuf) == 0) {
+		return 1;
+	} else {
+		char *dot = strrchr(path, '.');
+		if (dot != NULL) {
+			*dot = '\0';
+			if (stat(path, &sbuf) == 0) {
+				return 1;
+			}
+		}
+	}
+	return 0;
+}
+#endif
+
 int
 x11_connect_display(void)
 {
@@ -4375,15 +4402,22 @@ x11_connect_display(void)
 	 * connection to the real X server.
 	 */
 
-	/* Check if the display is from launchd. */
 #ifdef __APPLE__
-	if (strncmp(display, "/tmp/launch", 11) == 0) {
-		sock = connect_local_xsocket_path(display);
-		if (sock < 0)
-			return -1;
+	/* Check if display is a path to a socket (as set by launchd). */
+	{
+		char path[PATH_MAX];
 
-		/* OK, we now have a connection to the display. */
-		return sock;
+		if (is_path_to_xsocket(display, path, sizeof(path))) {
+			debug("x11_connect_display: $DISPLAY is launchd");
+
+			/* Create a socket. */
+			sock = connect_local_xsocket_path(path);
+			if (sock < 0)
+				return -1;
+
+			/* OK, we now have a connection to the display. */
+			return sock;
+		}
 	}
 #endif
 	/*

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list