A couple of X forwarding fixes for Unix Plink. Firstly, under Unix
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 2 Jan 2003 10:45:56 +0000 (10:45 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 2 Jan 2003 10:45:56 +0000 (10:45 +0000)
the default X display should be whatever comes out of $DISPLAY,
rather than Windows's hardwired `localhost:0'. Secondly, this may
give rise to a display name without a hostname (`:0' or similar),
which we now need to be able to deal with. Of course, we still don't
_properly_ support X forwarding in Unix Plink, since we still can't
authenticate with the local display.

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

settings.c
x11fwd.c

index 0c642f5..6f488d8 100644 (file)
@@ -598,8 +598,17 @@ void load_open_settings(void *sesskey, int do_host, Config *cfg)
     gppi(sesskey, "BCE", 1, &cfg->bce);
     gppi(sesskey, "BlinkText", 0, &cfg->blinktext);
     gppi(sesskey, "X11Forward", 0, &cfg->x11_forward);
+#ifdef _WINDOWS
     gpps(sesskey, "X11Display", "localhost:0", cfg->x11_display,
         sizeof(cfg->x11_display));
+#else
+    {
+       /* On Unix, the default X display should simply be $DISPLAY. */
+       char *disp = getenv("DISPLAY");
+       gpps(sesskey, "X11Display", disp, cfg->x11_display,
+            sizeof(cfg->x11_display));
+    }
+#endif
 
     gppi(sesskey, "LocalPortAcceptAll", 0, &cfg->lport_acceptall);
     gppi(sesskey, "RemotePortAcceptAll", 0, &cfg->rport_acceptall);
index d632e55..4b043fa 100644 (file)
--- a/x11fwd.c
+++ b/x11fwd.c
@@ -189,8 +189,16 @@ char *x11_init(Socket * s, char *display, void *c, void *auth)
        displaynum = 0;                /* sensible default */
     if (n > sizeof(host) - 1)
        n = sizeof(host) - 1;
-    strncpy(host, display, n);
-    host[n] = '\0';
+    if (n > 0) {
+       strncpy(host, display, n);
+       host[n] = '\0';
+    } else {
+       /*
+        * Local display numbers, particularly on Unix, often omit
+        * the display part completely.
+        */
+       strcpy(host, "localhost");
+    }
 
     /*
      * Try to find host.