diff --git a/ssh.h b/ssh.h index 8706e9f1..6ef465fe 100644 --- a/ssh.h +++ b/ssh.h @@ -921,8 +921,12 @@ int x11_authcmp(void *av, void *bv); /* for putting X11FakeAuth in a tree234 */ * the supplied authtype parameter configures the preferred * authorisation protocol to use at the remote end. The local auth * details are looked up by calling platform_get_x11_auth. + * + * If the returned pointer is NULL, then *error_msg will contain a + * dynamically allocated error message string. */ -extern struct X11Display *x11_setup_display(const char *display, Conf *); +extern struct X11Display *x11_setup_display(const char *display, Conf *, + char **error_msg); void x11_free_display(struct X11Display *disp); struct X11FakeAuth *x11_invent_fake_auth(tree234 *t, int authtype); void x11_free_fake_auth(struct X11FakeAuth *auth); diff --git a/ssh1connection.c b/ssh1connection.c index 3cf75967..07105176 100644 --- a/ssh1connection.c +++ b/ssh1connection.c @@ -649,13 +649,15 @@ static void ssh1_connection_process_queue(PacketProtocolLayer *ppl) } if (conf_get_int(s->conf, CONF_x11_forward)) { + char *x11_setup_err; + s->x11disp = x11_setup_display(conf_get_str(s->conf, CONF_x11_display), - s->conf); + s->conf, &x11_setup_err); if (!s->x11disp) { - /* FIXME: return an error message from x11_setup_display */ ppl_logevent(("X11 forwarding not enabled: unable to" - " initialise X display")); + " initialise X display: %s", x11_setup_err)); + sfree(x11_setup_err); } else { s->x11auth = x11_invent_fake_auth (s->x11authtree, conf_get_int(s->conf, CONF_x11_auth)); diff --git a/ssh2connection.c b/ssh2connection.c index 6da82951..e51d221f 100644 --- a/ssh2connection.c +++ b/ssh2connection.c @@ -1249,12 +1249,14 @@ static void ssh2_connection_process_queue(PacketProtocolLayer *ppl) /* Potentially enable X11 forwarding. */ if (conf_get_int(s->conf, CONF_x11_forward)) { + char *x11_setup_err; s->x11disp = x11_setup_display( - conf_get_str(s->conf, CONF_x11_display), s->conf); + conf_get_str(s->conf, CONF_x11_display), + s->conf, &x11_setup_err); if (!s->x11disp) { - /* FIXME: return an error message from x11_setup_display */ ppl_logevent(("X11 forwarding not enabled: unable to" - " initialise X display")); + " initialise X display: %s", x11_setup_err)); + sfree(x11_setup_err); } else { s->x11auth = x11_invent_fake_auth( s->x11authtree, conf_get_int(s->conf, CONF_x11_auth)); diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index 8feff9df..90a624a8 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -801,12 +801,19 @@ void run_agent(void) int greetinglen; Socket *s; struct X11Connection *conn; + char *x11_setup_err; if (!display) { fprintf(stderr, "pageant: no DISPLAY for -X mode\n"); exit(1); } - disp = x11_setup_display(display, conf); + disp = x11_setup_display(display, conf, &x11_setup_err); + if (!disp) { + fprintf(stderr, "pageant: unable to connect to X server: %s\n", + x11_setup_err); + sfree(x11_setup_err); + exit(1); + } conn = snew(struct X11Connection); conn->plug.vt = &X11Connection_plugvt; diff --git a/x11fwd.c b/x11fwd.c index 9cdefeea..0aaa3a60 100644 --- a/x11fwd.c +++ b/x11fwd.c @@ -175,11 +175,14 @@ int x11_authcmp(void *av, void *bv) } } -struct X11Display *x11_setup_display(const char *display, Conf *conf) +struct X11Display *x11_setup_display(const char *display, Conf *conf, + char **error_msg) { struct X11Display *disp = snew(struct X11Display); char *localcopy; + *error_msg = NULL; + if (!display || !*display) { localcopy = platform_get_x_display(); if (!localcopy || !*localcopy) { @@ -217,9 +220,12 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf) colon = host_strrchr(localcopy, ':'); if (!colon) { + *error_msg = dupprintf("display name '%s' has no ':number'" + " suffix", localcopy); + sfree(disp); sfree(localcopy); - return NULL; /* FIXME: report a specific error? */ + return NULL; } *colon++ = '\0'; @@ -275,11 +281,14 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf) NULL, NULL); if ((err = sk_addr_error(disp->addr)) != NULL) { + *error_msg = dupprintf("unable to resolve host name '%s' in " + "display name", disp->hostname); + sk_addr_free(disp->addr); sfree(disp->hostname); sfree(disp->unixsocketpath); sfree(disp); - return NULL; /* FIXME: report an error */ + return NULL; } }