comparison svr-tcpfwd.c @ 675:dfdb9d9189ff

Server shouldn't return "localhost" in response to -R forward connections if that wasn't what the client requested.
author Matt Johnston <matt@ucc.asn.au>
date Wed, 09 May 2012 21:09:34 +0800
parents c519b78b6d1a
children c19acba28590
comparison
equal deleted inserted replaced
674:1291413c7c7e 675:dfdb9d9189ff
170 } 170 }
171 171
172 static int svr_remotetcpreq() { 172 static int svr_remotetcpreq() {
173 173
174 int ret = DROPBEAR_FAILURE; 174 int ret = DROPBEAR_FAILURE;
175 unsigned char * bindaddr = NULL; 175 unsigned char * request_addr = NULL;
176 unsigned int addrlen; 176 unsigned int addrlen;
177 struct TCPListener *tcpinfo = NULL; 177 struct TCPListener *tcpinfo = NULL;
178 unsigned int port; 178 unsigned int port;
179 179
180 TRACE(("enter remotetcpreq")) 180 TRACE(("enter remotetcpreq"))
181 181
182 bindaddr = buf_getstring(ses.payload, &addrlen); 182 request_addr = buf_getstring(ses.payload, &addrlen);
183 if (addrlen > MAX_IP_LEN) { 183 if (addrlen > MAX_IP_LEN) {
184 TRACE(("addr len too long: %d", addrlen)) 184 TRACE(("addr len too long: %d", addrlen))
185 goto out; 185 goto out;
186 } 186 }
187 187
207 tcpinfo->sendport = 0; 207 tcpinfo->sendport = 0;
208 tcpinfo->listenport = port; 208 tcpinfo->listenport = port;
209 tcpinfo->chantype = &svr_chan_tcpremote; 209 tcpinfo->chantype = &svr_chan_tcpremote;
210 tcpinfo->tcp_type = forwarded; 210 tcpinfo->tcp_type = forwarded;
211 211
212 if (!opts.listen_fwd_all || (strcmp(bindaddr, "localhost") == 0) ) { 212 tcpinfo->request_listenaddr = request_addr;
213 if (!opts.listen_fwd_all || (strcmp(request_addr, "localhost") == 0) ) {
213 // NULL means "localhost only" 214 // NULL means "localhost only"
214 m_free(bindaddr); 215 tcpinfo->listenaddr = NULL;
215 bindaddr = NULL; 216 }
216 } 217 else
217 tcpinfo->listenaddr = bindaddr; 218 {
219 tcpinfo->listenaddr = request_addr;
220 }
218 221
219 ret = listen_tcpfwd(tcpinfo); 222 ret = listen_tcpfwd(tcpinfo);
220 223
221 out: 224 out:
222 if (ret == DROPBEAR_FAILURE) { 225 if (ret == DROPBEAR_FAILURE) {
223 /* we only free it if a listener wasn't created, since the listener 226 /* we only free it if a listener wasn't created, since the listener
224 * has to remember it if it's to be cancelled */ 227 * has to remember it if it's to be cancelled */
225 m_free(bindaddr); 228 m_free(request_addr);
226 m_free(tcpinfo); 229 m_free(tcpinfo);
227 } 230 }
228 TRACE(("leave remotetcpreq")) 231 TRACE(("leave remotetcpreq"))
229 return ret; 232 return ret;
230 } 233 }