Mercurial > dropbear
diff tcp-accept.c @ 293:9d110777f345 contrib-blacklist
propagate from branch 'au.asn.ucc.matt.dropbear' (head 7ad1775ed65e75dbece27fe6b65bf1a234db386a)
to branch 'au.asn.ucc.matt.dropbear.contrib.blacklist' (head 1d86a4f0a401cc68c2670d821a2f6366c37af143)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 10 Mar 2006 06:31:29 +0000 |
parents | 3cea9d789cca |
children | 454a34b2dfd1 6aea2cfc113e |
line wrap: on
line diff
--- a/tcp-accept.c Tue Sep 06 04:57:14 2005 +0000 +++ b/tcp-accept.c Fri Mar 10 06:31:29 2006 +0000 @@ -39,6 +39,7 @@ struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata); m_free(tcpinfo->sendaddr); + m_free(tcpinfo->listenaddr); m_free(tcpinfo); } @@ -46,7 +47,7 @@ int fd; struct sockaddr_storage addr; - int len; + socklen_t len; char ipstring[NI_MAXHOST], portstring[NI_MAXSERV]; struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata); @@ -64,11 +65,28 @@ } if (send_msg_channel_open_init(fd, tcpinfo->chantype) == DROPBEAR_SUCCESS) { + unsigned char* addr = NULL; + unsigned int port = 0; - buf_putstring(ses.writepayload, tcpinfo->sendaddr, - strlen(tcpinfo->sendaddr)); - buf_putint(ses.writepayload, tcpinfo->sendport); + if (tcpinfo->tcp_type == direct) { + /* "direct-tcpip" */ + /* host to connect, port to connect */ + addr = tcpinfo->sendaddr; + port = tcpinfo->sendport; + } else { + dropbear_assert(tcpinfo->tcp_type == forwarded); + /* "forwarded-tcpip" */ + /* address that was connected, port that was connected */ + addr = tcpinfo->listenaddr; + port = tcpinfo->listenport; + } + + buf_putstring(ses.writepayload, addr, strlen(addr)); + buf_putint(ses.writepayload, port); + + /* originator ip */ buf_putstring(ses.writepayload, ipstring, strlen(ipstring)); + /* originator port */ buf_putint(ses.writepayload, atol(portstring)); encrypt_packet(); @@ -86,16 +104,21 @@ struct Listener *listener = NULL; int nsocks; char* errstring = NULL; + // listen_spec = NULL indicates localhost + const char* listen_spec = NULL; TRACE(("enter listen_tcpfwd")) /* first we try to bind, so don't need to do so much cleanup on failure */ snprintf(portstring, sizeof(portstring), "%d", tcpinfo->listenport); - /* XXX Note: we're just listening on localhost, no matter what they tell - * us. If someone wants to make it listen otherways, then change - * the "" argument. but that requires UI changes too */ - nsocks = dropbear_listen("", portstring, socks, + /* a listenaddr of "" will indicate all interfaces */ + if (opts.listen_fwd_all + && (strcmp(tcpinfo->listenaddr, "localhost") != 0) ) { + listen_spec = tcpinfo->listenaddr; + } + + nsocks = dropbear_listen(listen_spec, portstring, socks, DROPBEAR_MAX_SOCKS, &errstring, &ses.maxfd); if (nsocks < 0) { dropbear_log(LOG_INFO, "TCP forward failed: %s", errstring);