RJK's patch to enable PuTTY's X forwarding to connect to local X
[sgt/putty] / unix / ux_x11.c
index 61b4f04..1c48b14 100644 (file)
@@ -4,7 +4,9 @@
 
 #include <ctype.h>
 #include <unistd.h>
+#include <assert.h>
 #include "putty.h"
+#include "ssh.h"
 
 void platform_get_x11_auth(char *display, int *protocol,
                            unsigned char *data, int *datalen)
@@ -13,30 +15,35 @@ void platform_get_x11_auth(char *display, int *protocol,
     char *command;
     int maxsize = *datalen;
     char *localbuf;
+    int proto = -1;
 
+    display = x11_display(display);
     /*
      * Normally we should run `xauth list DISPLAYNAME'. However,
      * there's an oddity when the display is local: the display
      * `localhost:0' (or `:0') should become just `:0'.
      */
-    if (!strncmp(display, "localhost:", 10))
-       command = dupprintf("xauth list %s 2>/dev/null", display+9);
+    if (!strncmp(display, "localhost:", 10)
+       || !strncmp(display, "unix:", 5))
+       command = dupprintf("xauth list %s 2>/dev/null",
+                           strchr(display, ':'));
     else
        command = dupprintf("xauth list %s 2>/dev/null", display);
+    sfree(display);
     fp = popen(command, "r");
     sfree(command);
 
     if (!fp)
         return;                        /* assume no auth */
 
-    localbuf = smalloc(maxsize);
+    localbuf = snewn(maxsize, char);
 
     while (1) {
         /*
          * Read a line from stdin, and attempt to parse it into a
          * display name (ignored), auth protocol, and auth string.
          */
-        int c, i, hexdigit, proto;
+        int c, i, hexdigit;
         char protoname[64];
 
         /* Skip the display name. */
@@ -112,3 +119,5 @@ void platform_get_x11_auth(char *display, int *protocol,
     pclose(fp);
     sfree(localbuf);
 }
+
+const char platform_x11_best_transport[] = "unix";