From: simon Date: Thu, 2 Jan 2003 10:45:56 +0000 (+0000) Subject: A couple of X forwarding fixes for Unix Plink. Firstly, under Unix X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/ecc0ba5b2e559a13cae7d4b515841ffe24624bbb A couple of X forwarding fixes for Unix Plink. Firstly, under Unix 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 --- diff --git a/settings.c b/settings.c index 0c642f50..6f488d82 100644 --- a/settings.c +++ b/settings.c @@ -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); diff --git a/x11fwd.c b/x11fwd.c index d632e553..4b043fa4 100644 --- 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.