1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00

Get rid of the error-return mechanism from x11_init.

Now that it doesn't actually make a network connection because that's
deferred until after the X authorisation exchange, there's no point in
having it return an error message and write the real output through a
pointer argument. Instead, we can just have it return xconn directly
and simplify the call sites.

[originally from svn r10081]
This commit is contained in:
Simon Tatham 2013-11-17 14:05:23 +00:00
parent 94e8f97d3f
commit e5a3e28eec
3 changed files with 25 additions and 44 deletions

27
ssh.c
View File

@ -4887,21 +4887,10 @@ static void ssh1_smsg_x11_open(Ssh ssh, struct Packet *pktin)
PKT_INT, remoteid, PKT_END); PKT_INT, remoteid, PKT_END);
logevent("Rejected X11 connect request"); logevent("Rejected X11 connect request");
} else { } else {
char *err;
c = snew(struct ssh_channel); c = snew(struct ssh_channel);
c->ssh = ssh; c->ssh = ssh;
if ((err = x11_init(&c->u.x11.xconn, ssh->x11authtree, c, c->u.x11.xconn = x11_init(ssh->x11authtree, c, NULL, -1);
NULL, -1)) != NULL) {
logeventf(ssh, "Opening X11 forward connection failed: %s", err);
sfree(err);
sfree(c);
send_packet(ssh, SSH1_MSG_CHANNEL_OPEN_FAILURE,
PKT_INT, remoteid, PKT_END);
} else {
logevent
("Opening X11 forward connection succeeded");
c->remoteid = remoteid; c->remoteid = remoteid;
c->halfopen = FALSE; c->halfopen = FALSE;
c->localid = alloc_channel_id(ssh); c->localid = alloc_channel_id(ssh);
@ -4915,7 +4904,6 @@ static void ssh1_smsg_x11_open(Ssh ssh, struct Packet *pktin)
c->localid, PKT_END); c->localid, PKT_END);
logevent("Opened X11 forward channel"); logevent("Opened X11 forward channel");
} }
}
} }
static void ssh1_smsg_agent_open(Ssh ssh, struct Packet *pktin) static void ssh1_smsg_agent_open(Ssh ssh, struct Packet *pktin)
@ -7563,7 +7551,6 @@ static void ssh2_msg_channel_open(Ssh ssh, struct Packet *pktin)
if (typelen == 3 && !memcmp(type, "x11", 3)) { if (typelen == 3 && !memcmp(type, "x11", 3)) {
char *addrstr; char *addrstr;
char *x11err;
ssh_pkt_getstring(pktin, &peeraddr, &peeraddrlen); ssh_pkt_getstring(pktin, &peeraddr, &peeraddrlen);
addrstr = snewn(peeraddrlen+1, char); addrstr = snewn(peeraddrlen+1, char);
@ -7576,14 +7563,12 @@ static void ssh2_msg_channel_open(Ssh ssh, struct Packet *pktin)
if (!ssh->X11_fwd_enabled) if (!ssh->X11_fwd_enabled)
error = "X11 forwarding is not enabled"; error = "X11 forwarding is not enabled";
else if ((x11err = x11_init(&c->u.x11.xconn, ssh->x11authtree, c, else {
addrstr, peerport)) != NULL) { c->u.x11.xconn = x11_init(ssh->x11authtree, c,
logeventf(ssh, "Local X11 connection failed: %s", x11err); addrstr, peerport);
sfree(x11err);
error = "Unable to open an X11 connection";
} else {
logevent("Opening X11 forward connection succeeded");
c->type = CHAN_X11; c->type = CHAN_X11;
logevent("Opened X11 forward channel");
} }
sfree(addrstr); sfree(addrstr);

3
ssh.h
View File

@ -418,8 +418,7 @@ 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);
struct X11Connection; /* opaque outside x11fwd.c */ struct X11Connection; /* opaque outside x11fwd.c */
extern char *x11_init(struct X11Connection **, tree234 *authtree, struct X11Connection *x11_init(tree234 *authtree, void *, const char *, int);
void *, const char *, int);
extern void x11_close(struct X11Connection *); extern void x11_close(struct X11Connection *);
extern int x11_send(struct X11Connection *, char *, int); extern int x11_send(struct X11Connection *, char *, int);
extern void x11_send_eof(struct X11Connection *s); extern void x11_send_eof(struct X11Connection *s);

View File

@ -649,13 +649,10 @@ int x11_get_screen_number(char *display)
} }
/* /*
* Called to set up the raw connection. * Called to set up the X11Connection structure, though this does not
* * yet connect to an actual server.
* On success, returns NULL and fills in *xconnret. On error, returns
* a dynamically allocated error message string.
*/ */
extern char *x11_init(struct X11Connection **xconnret, struct X11Connection *x11_init(tree234 *authtree, void *c,
tree234 *authtree, void *c,
const char *peeraddr, int peerport) const char *peeraddr, int peerport)
{ {
static const struct plug_function_table fn_table = { static const struct plug_function_table fn_table = {
@ -671,7 +668,7 @@ extern char *x11_init(struct X11Connection **xconnret,
/* /*
* Open socket. * Open socket.
*/ */
xconn = *xconnret = snew(struct X11Connection); xconn = snew(struct X11Connection);
xconn->fn = &fn_table; xconn->fn = &fn_table;
xconn->auth_protocol = NULL; xconn->auth_protocol = NULL;
xconn->authtree = authtree; xconn->authtree = authtree;
@ -698,7 +695,7 @@ extern char *x11_init(struct X11Connection **xconnret,
xconn->peer_addr = peeraddr ? dupstr(peeraddr) : NULL; xconn->peer_addr = peeraddr ? dupstr(peeraddr) : NULL;
xconn->peer_port = peerport; xconn->peer_port = peerport;
return NULL; return xconn;
} }
void x11_close(struct X11Connection *xconn) void x11_close(struct X11Connection *xconn)