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

Remove downstream remote port forwardings in ssh.c too.

Another piece of half-finished machinery that I can't have tested
properly when I set up connection sharing: I had the function
ssh_alloc_sharing_rportfwd which is how sshshare.c asks ssh.c to start
sending it channel-open requests for a given remote forwarded port,
but I had no companion function that removes one of those requests
again when a downstream remote port forwarding goes away (either by
mid-session cancel-tcpip-forward or by the whole downstream
disconnecting).

As a result, the _second_ attempt to set up the same remote port
forwarding, after a sharing downstream had done so once and then
stopped, would quietly fail.
This commit is contained in:
Simon Tatham 2018-06-03 07:54:00 +01:00
parent 314c8f5270
commit 3f1f7c3ce7
3 changed files with 25 additions and 0 deletions

15
ssh.c
View File

@ -5236,6 +5236,21 @@ int ssh_alloc_sharing_rportfwd(Ssh ssh, const char *shost, int sport,
return TRUE;
}
void ssh_remove_sharing_rportfwd(Ssh ssh, const char *shost, int sport,
void *share_ctx)
{
struct ssh_rportfwd pf, *realpf;
assert(ssh->rportfwds);
pf.shost = dupstr(shost);
pf.sport = sport;
realpf = del234(ssh->rportfwds, &pf);
assert(realpf);
assert(realpf->share_ctx == share_ctx);
sfree(realpf->shost);
sfree(realpf);
}
static void ssh_sharing_global_request_response(Ssh ssh, struct Packet *pktin,
void *ctx)
{

2
ssh.h
View File

@ -38,6 +38,8 @@ unsigned ssh_alloc_sharing_channel(Ssh ssh, void *sharing_ctx);
void ssh_delete_sharing_channel(Ssh ssh, unsigned localid);
int ssh_alloc_sharing_rportfwd(Ssh ssh, const char *shost, int sport,
void *share_ctx);
void ssh_remove_sharing_rportfwd(Ssh ssh, const char *shost, int sport,
void *share_ctx);
void ssh_sharing_queue_global_request(Ssh ssh, void *share_ctx);
struct X11FakeAuth *ssh_sharing_add_x11_display(Ssh ssh, int authtype,
void *share_cs,

View File

@ -857,6 +857,8 @@ static void share_try_cleanup(struct ssh_sharing_connstate *cs)
"cleanup after downstream went away");
strbuf_free(packet);
ssh_remove_sharing_rportfwd(cs->parent->ssh,
fwd->host, fwd->port, cs);
share_remove_forwarding(cs, fwd);
i--; /* don't accidentally skip one as a result */
}
@ -1392,6 +1394,12 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs,
"", 0, NULL);
}
} else {
/*
* Tell ssh.c to stop sending us channel-opens for
* this forwarding.
*/
ssh_remove_sharing_rportfwd(cs->parent->ssh, host, port, cs);
/*
* Pass the cancel request on to the SSH server, but
* set want_reply even if it wasn't originally set, so