1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 01:02:24 +00:00

Return an error message from x11_setup_display.

The lack of one of those has been a long-standing FIXME for ages.
This commit is contained in:
Simon Tatham 2018-10-06 10:43:04 +01:00
parent 9396fcc9f7
commit 461ade43d1
5 changed files with 35 additions and 11 deletions

6
ssh.h
View File

@ -921,8 +921,12 @@ int x11_authcmp(void *av, void *bv); /* for putting X11FakeAuth in a tree234 */
* the supplied authtype parameter configures the preferred * the supplied authtype parameter configures the preferred
* authorisation protocol to use at the remote end. The local auth * authorisation protocol to use at the remote end. The local auth
* details are looked up by calling platform_get_x11_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); void x11_free_display(struct X11Display *disp);
struct X11FakeAuth *x11_invent_fake_auth(tree234 *t, int authtype); struct X11FakeAuth *x11_invent_fake_auth(tree234 *t, int authtype);
void x11_free_fake_auth(struct X11FakeAuth *auth); void x11_free_fake_auth(struct X11FakeAuth *auth);

View File

@ -649,13 +649,15 @@ static void ssh1_connection_process_queue(PacketProtocolLayer *ppl)
} }
if (conf_get_int(s->conf, CONF_x11_forward)) { if (conf_get_int(s->conf, CONF_x11_forward)) {
char *x11_setup_err;
s->x11disp = s->x11disp =
x11_setup_display(conf_get_str(s->conf, CONF_x11_display), x11_setup_display(conf_get_str(s->conf, CONF_x11_display),
s->conf); s->conf, &x11_setup_err);
if (!s->x11disp) { if (!s->x11disp) {
/* FIXME: return an error message from x11_setup_display */
ppl_logevent(("X11 forwarding not enabled: unable to" ppl_logevent(("X11 forwarding not enabled: unable to"
" initialise X display")); " initialise X display: %s", x11_setup_err));
sfree(x11_setup_err);
} else { } else {
s->x11auth = x11_invent_fake_auth s->x11auth = x11_invent_fake_auth
(s->x11authtree, conf_get_int(s->conf, CONF_x11_auth)); (s->x11authtree, conf_get_int(s->conf, CONF_x11_auth));

View File

@ -1249,12 +1249,14 @@ static void ssh2_connection_process_queue(PacketProtocolLayer *ppl)
/* Potentially enable X11 forwarding. */ /* Potentially enable X11 forwarding. */
if (conf_get_int(s->conf, CONF_x11_forward)) { if (conf_get_int(s->conf, CONF_x11_forward)) {
char *x11_setup_err;
s->x11disp = x11_setup_display( 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) { if (!s->x11disp) {
/* FIXME: return an error message from x11_setup_display */
ppl_logevent(("X11 forwarding not enabled: unable to" ppl_logevent(("X11 forwarding not enabled: unable to"
" initialise X display")); " initialise X display: %s", x11_setup_err));
sfree(x11_setup_err);
} else { } else {
s->x11auth = x11_invent_fake_auth( s->x11auth = x11_invent_fake_auth(
s->x11authtree, conf_get_int(s->conf, CONF_x11_auth)); s->x11authtree, conf_get_int(s->conf, CONF_x11_auth));

View File

@ -801,12 +801,19 @@ void run_agent(void)
int greetinglen; int greetinglen;
Socket *s; Socket *s;
struct X11Connection *conn; struct X11Connection *conn;
char *x11_setup_err;
if (!display) { if (!display) {
fprintf(stderr, "pageant: no DISPLAY for -X mode\n"); fprintf(stderr, "pageant: no DISPLAY for -X mode\n");
exit(1); 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 = snew(struct X11Connection);
conn->plug.vt = &X11Connection_plugvt; conn->plug.vt = &X11Connection_plugvt;

View File

@ -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); struct X11Display *disp = snew(struct X11Display);
char *localcopy; char *localcopy;
*error_msg = NULL;
if (!display || !*display) { if (!display || !*display) {
localcopy = platform_get_x_display(); localcopy = platform_get_x_display();
if (!localcopy || !*localcopy) { if (!localcopy || !*localcopy) {
@ -217,9 +220,12 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf)
colon = host_strrchr(localcopy, ':'); colon = host_strrchr(localcopy, ':');
if (!colon) { if (!colon) {
*error_msg = dupprintf("display name '%s' has no ':number'"
" suffix", localcopy);
sfree(disp); sfree(disp);
sfree(localcopy); sfree(localcopy);
return NULL; /* FIXME: report a specific error? */ return NULL;
} }
*colon++ = '\0'; *colon++ = '\0';
@ -275,11 +281,14 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf)
NULL, NULL); NULL, NULL);
if ((err = sk_addr_error(disp->addr)) != 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); sk_addr_free(disp->addr);
sfree(disp->hostname); sfree(disp->hostname);
sfree(disp->unixsocketpath); sfree(disp->unixsocketpath);
sfree(disp); sfree(disp);
return NULL; /* FIXME: report an error */ return NULL;
} }
} }