Mercurial > dropbear
diff cli-tcpfwd.c @ 910:89555751c489 asm
merge up to 2013.63, improve ASM makefile rules a bit
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 27 Feb 2014 21:35:58 +0800 |
parents | 115f8a3c2d5a |
children | 5daedffd0769 |
line wrap: on
line diff
--- a/cli-tcpfwd.c Sun Oct 06 22:32:03 2013 +0800 +++ b/cli-tcpfwd.c Thu Feb 27 21:35:58 2014 +0800 @@ -161,9 +161,10 @@ if (!fwd->have_reply) { fwd->have_reply = 1; if (fwd->listenport == 0) { - /* The server should let us know which port was allocated if we requestd port 0 */ + /* The server should let us know which port was allocated if we requested port 0 */ int allocport = buf_getint(ses.payload); if (allocport > 0) { + fwd->listenport = allocport; dropbear_log(LOG_INFO, "Allocated port %d for remote forward to %s:%d", allocport, fwd->connectaddr, fwd->connectport); } @@ -193,8 +194,8 @@ struct TCPFwdEntry *fwd = (struct TCPFwdEntry*)iter->item; if (!fwd->listenaddr) { - // we store the addresses so that we can compare them - // when the server sends them back + /* we store the addresses so that we can compare them + when the server sends them back */ if (opts.listen_fwd_all) { fwd->listenaddr = m_strdup(""); } else { @@ -220,18 +221,33 @@ origaddr = buf_getstring(ses.payload, NULL); origport = buf_getint(ses.payload); - /* Find which port corresponds */ + /* Find which port corresponds. First try and match address as well as port, + in case they want to forward different ports separately ... */ for (iter = cli_opts.remotefwds->first; iter; iter = iter->next) { fwd = (struct TCPFwdEntry*)iter->item; if (origport == fwd->listenport - && (strcmp(origaddr, fwd->listenaddr) == 0)) { + && strcmp(origaddr, fwd->listenaddr) == 0) { break; } } + if (!iter) + { + /* ... otherwise try to generically match the only forwarded port + without address (also handles ::1 vs 127.0.0.1 vs localhost case). + rfc4254 is vague about the definition of "address that was connected" */ + for (iter = cli_opts.remotefwds->first; iter; iter = iter->next) { + fwd = (struct TCPFwdEntry*)iter->item; + if (origport == fwd->listenport) { + break; + } + } + } + + if (iter == NULL) { /* We didn't request forwarding on that port */ - cleantext(origaddr); + cleantext(origaddr); dropbear_log(LOG_INFO, "Server sent unrequested forward from \"%s:%d\"", origaddr, origport); goto out;