OS X Leopard, it turns out, has a new and exciting strategy for
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 28 May 2008 19:23:57 +0000 (19:23 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 28 May 2008 19:23:57 +0000 (19:23 +0000)
addressing X displays. Update PuTTY's display-name-to-Unix-socket-
path translation code to cope with it, thus causing X forwarding to
start working again on Leopard.

git-svn-id: svn://svn.tartarus.org/sgt/putty@8020 cda61777-01e9-0310-a592-d414129be87e

mac/macnet.c
ssh.h
unix/uxnet.c
windows/winnet.c
x11fwd.c

index 2ed0069..fc022dc 100644 (file)
@@ -175,7 +175,8 @@ int net_service_lookup(char *service)
     return 0;
 }
 
-SockAddr platform_get_x11_unix_address(int displaynum, char **canonicalname)
+SockAddr platform_get_x11_unix_address(const char *display, int displaynum,
+                                      char **canonicalname)
 {
     return NULL;
 }
diff --git a/ssh.h b/ssh.h
index 3031141..1bc7a98 100644 (file)
--- a/ssh.h
+++ b/ssh.h
@@ -344,7 +344,8 @@ extern void platform_get_x11_auth(char *display, int *proto,
                                   unsigned char *data, int *datalen);
 extern const char platform_x11_best_transport[];
 /* best X11 hostname for this platform if none specified */
-SockAddr platform_get_x11_unix_address(int displaynum, char **canonicalname);
+SockAddr platform_get_x11_unix_address(const char *display, int displaynum,
+                                      char **canonicalname);
 /* make up a SockAddr naming the address for displaynum */
 char *platform_get_x_display(void);
 /* allocated local X display string, if any */
index bd40937..c082567 100644 (file)
@@ -1292,15 +1292,29 @@ int net_service_lookup(char *service)
        return 0;
 }
 
-SockAddr platform_get_x11_unix_address(int displaynum, char **canonicalname)
+SockAddr platform_get_x11_unix_address(const char *display, int displaynum,
+                                      char **canonicalname)
 {
     SockAddr ret = snew(struct SockAddr_tag);
     int n;
 
     memset(ret, 0, sizeof *ret);
     ret->family = AF_UNIX;
-    n = snprintf(ret->hostname, sizeof ret->hostname,
-                "%s%d", X11_UNIX_PATH, displaynum);
+    /*
+     * Mac OS X Leopard uses an innovative X display naming
+     * convention in which the entire display name is the path to
+     * the Unix socket, including the trailing :0 which only
+     * _looks_ like a display number. Heuristically, I think
+     * detecting this by means of a leading slash ought to be
+     * adequate.
+     */
+    if (display[0] == '/') {
+       n = snprintf(ret->hostname, sizeof ret->hostname,
+                    "%s", display);
+    } else {
+       n = snprintf(ret->hostname, sizeof ret->hostname,
+                    "%s%d", X11_UNIX_PATH, displaynum);
+    }
     if(n < 0)
        ret->error = "snprintf failed";
     else if(n >= sizeof ret->hostname)
index 19babb0..89d2f47 100644 (file)
@@ -1637,7 +1637,8 @@ int net_service_lookup(char *service)
        return 0;
 }
 
-SockAddr platform_get_x11_unix_address(int displaynum, char **canonicalname)
+SockAddr platform_get_x11_unix_address(const char *display, int displaynum,
+                                      char **canonicalname)
 {
     SockAddr ret = snew(struct SockAddr_tag);
     memset(ret, 0, sizeof(struct SockAddr_tag));
index 139cb77..4621ac9 100644 (file)
--- a/x11fwd.c
+++ b/x11fwd.c
@@ -301,9 +301,9 @@ const char *x11_init(Socket * s, char *display, void *c, void *auth,
     host[n] = '\0';
     sfree(display);
     
-    if(!strcmp(host, "unix")) {
+    if(!strcmp(host, "unix") || host[0] == '/') {
        /* use AF_UNIX sockets (doesn't make sense on all platforms) */
-       addr = platform_get_x11_unix_address(displaynum,
+       addr = platform_get_x11_unix_address(display, displaynum,
                                             &dummy_realhost);
        port = 0;               /* to show we are not confused */
     } else {