diff svr-tcpfwd.c @ 258:306499676384

* add -g (dbclient) and -a (dropbear) options for allowing non-local hosts to connect to forwarded ports. Rearranged various some of the tcp listening code. * changed to /* */ style brackets in svr-authpam.c
author Matt Johnston <matt@ucc.asn.au>
date Sun, 04 Dec 2005 16:13:11 +0000
parents 84925eceeb13
children c049490e43fe
line wrap: on
line diff
--- a/svr-tcpfwd.c	Wed Nov 30 10:11:24 2005 +0000
+++ b/svr-tcpfwd.c	Sun Dec 04 16:13:11 2005 +0000
@@ -72,7 +72,7 @@
 
 	TRACE(("enter recv_msg_global_request_remotetcp"))
 
-	if (opts.noremotetcp) {
+	if (svr_opts.noremotetcp) {
 		TRACE(("leave recv_msg_global_request_remotetcp: remote tcp forwarding disabled"))
 		goto out;
 	}
@@ -129,9 +129,9 @@
 	const struct TCPListener *info1 = (struct TCPListener*)typedata1;
 	const struct TCPListener *info2 = (struct TCPListener*)typedata2;
 
-	return (info1->sendport == info2->sendport)
+	return (info1->listenport == info2->listenport)
 			&& (info1->chantype == info2->chantype)
-			&& (strcmp(info1->sendaddr, info2->sendaddr) == 0);
+			&& (strcmp(info1->listenaddr, info2->listenaddr) == 0);
 }
 
 static int svr_cancelremotetcp() {
@@ -153,8 +153,10 @@
 
 	port = buf_getint(ses.payload);
 
-	tcpinfo.sendaddr = bindaddr;
-	tcpinfo.sendport = port;
+	tcpinfo.sendaddr = NULL;
+	tcpinfo.sendport = 0;
+	tcpinfo.listenaddr = bindaddr;
+	tcpinfo.listenport = port;
 	listener = get_listener(CHANNEL_ID_TCPFORWARDED, &tcpinfo, matchtcp);
 	if (listener) {
 		remove_listener( listener );
@@ -177,7 +179,6 @@
 
 	TRACE(("enter remotetcpreq"))
 
-	/* NOTE: at this stage, we ignore bindaddr. see below and listen_tcpfwd */
 	bindaddr = buf_getstring(ses.payload, &addrlen);
 	if (addrlen > MAX_IP_LEN) {
 		TRACE(("addr len too long: %d", addrlen))
@@ -202,20 +203,19 @@
 	}
 
 	tcpinfo = (struct TCPListener*)m_malloc(sizeof(struct TCPListener));
-	tcpinfo->sendaddr = bindaddr;
-	tcpinfo->sendport = port;
+	tcpinfo->sendaddr = NULL;
+	tcpinfo->sendport = 0;
+	tcpinfo->listenaddr = bindaddr;
 	tcpinfo->listenport = port;
 	tcpinfo->chantype = &svr_chan_tcpremote;
 
-	/* Note: bindaddr is actually ignored by listen_tcpfwd, since
-	 * we only want to bind to localhost */
 	ret = listen_tcpfwd(tcpinfo);
 
 out:
 	if (ret == DROPBEAR_FAILURE) {
 		/* we only free it if a listener wasn't created, since the listener
 		 * has to remember it if it's to be cancelled */
-		m_free(tcpinfo->sendaddr);
+		m_free(tcpinfo->listenaddr);
 		m_free(tcpinfo);
 	}
 	TRACE(("leave remotetcpreq"))
@@ -235,7 +235,7 @@
 	int len;
 	int err = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED;
 
-	if (opts.nolocaltcp) {
+	if (svr_opts.nolocaltcp) {
 		TRACE(("leave newtcpdirect: local tcp forwarding disabled"))
 		goto out;
 	}