comparison svr-tcpfwd.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 7ce577234a10
children 454a34b2dfd1 75940fef22dd
comparison
equal deleted inserted replaced
247:c07de41b53d7 293:9d110777f345
70 unsigned int wantreply = 0; 70 unsigned int wantreply = 0;
71 int ret = DROPBEAR_FAILURE; 71 int ret = DROPBEAR_FAILURE;
72 72
73 TRACE(("enter recv_msg_global_request_remotetcp")) 73 TRACE(("enter recv_msg_global_request_remotetcp"))
74 74
75 if (opts.noremotetcp) { 75 if (svr_opts.noremotetcp) {
76 TRACE(("leave recv_msg_global_request_remotetcp: remote tcp forwarding disabled")) 76 TRACE(("leave recv_msg_global_request_remotetcp: remote tcp forwarding disabled"))
77 goto out; 77 goto out;
78 } 78 }
79 79
80 reqname = buf_getstring(ses.payload, &namelen); 80 reqname = buf_getstring(ses.payload, &namelen);
81 wantreply = buf_getbool(ses.payload); 81 wantreply = buf_getbool(ses.payload);
82 82
83 if (namelen > MAXNAMLEN) { 83 if (namelen > MAX_NAME_LEN) {
84 TRACE(("name len is wrong: %d", namelen)) 84 TRACE(("name len is wrong: %d", namelen))
85 goto out; 85 goto out;
86 } 86 }
87 87
88 if (strcmp("tcpip-forward", reqname) == 0) { 88 if (strcmp("tcpip-forward", reqname) == 0) {
127 static int matchtcp(void* typedata1, void* typedata2) { 127 static int matchtcp(void* typedata1, void* typedata2) {
128 128
129 const struct TCPListener *info1 = (struct TCPListener*)typedata1; 129 const struct TCPListener *info1 = (struct TCPListener*)typedata1;
130 const struct TCPListener *info2 = (struct TCPListener*)typedata2; 130 const struct TCPListener *info2 = (struct TCPListener*)typedata2;
131 131
132 return (info1->sendport == info2->sendport) 132 return (info1->listenport == info2->listenport)
133 && (info1->chantype == info2->chantype) 133 && (info1->chantype == info2->chantype)
134 && (strcmp(info1->sendaddr, info2->sendaddr) == 0); 134 && (strcmp(info1->listenaddr, info2->listenaddr) == 0);
135 } 135 }
136 136
137 static int svr_cancelremotetcp() { 137 static int svr_cancelremotetcp() {
138 138
139 int ret = DROPBEAR_FAILURE; 139 int ret = DROPBEAR_FAILURE;
151 goto out; 151 goto out;
152 } 152 }
153 153
154 port = buf_getint(ses.payload); 154 port = buf_getint(ses.payload);
155 155
156 tcpinfo.sendaddr = bindaddr; 156 tcpinfo.sendaddr = NULL;
157 tcpinfo.sendport = port; 157 tcpinfo.sendport = 0;
158 tcpinfo.listenaddr = bindaddr;
159 tcpinfo.listenport = port;
158 listener = get_listener(CHANNEL_ID_TCPFORWARDED, &tcpinfo, matchtcp); 160 listener = get_listener(CHANNEL_ID_TCPFORWARDED, &tcpinfo, matchtcp);
159 if (listener) { 161 if (listener) {
160 remove_listener( listener ); 162 remove_listener( listener );
161 ret = DROPBEAR_SUCCESS; 163 ret = DROPBEAR_SUCCESS;
162 } 164 }
175 struct TCPListener *tcpinfo = NULL; 177 struct TCPListener *tcpinfo = NULL;
176 unsigned int port; 178 unsigned int port;
177 179
178 TRACE(("enter remotetcpreq")) 180 TRACE(("enter remotetcpreq"))
179 181
180 /* NOTE: at this stage, we ignore bindaddr. see below and listen_tcpfwd */
181 bindaddr = buf_getstring(ses.payload, &addrlen); 182 bindaddr = buf_getstring(ses.payload, &addrlen);
182 if (addrlen > MAX_IP_LEN) { 183 if (addrlen > MAX_IP_LEN) {
183 TRACE(("addr len too long: %d", addrlen)) 184 TRACE(("addr len too long: %d", addrlen))
184 goto out; 185 goto out;
185 } 186 }
200 TRACE(("can't assign port < 1024 for non-root")) 201 TRACE(("can't assign port < 1024 for non-root"))
201 goto out; 202 goto out;
202 } 203 }
203 204
204 tcpinfo = (struct TCPListener*)m_malloc(sizeof(struct TCPListener)); 205 tcpinfo = (struct TCPListener*)m_malloc(sizeof(struct TCPListener));
205 tcpinfo->sendaddr = bindaddr; 206 tcpinfo->sendaddr = NULL;
206 tcpinfo->sendport = port; 207 tcpinfo->sendport = 0;
208 tcpinfo->listenaddr = bindaddr;
207 tcpinfo->listenport = port; 209 tcpinfo->listenport = port;
208 tcpinfo->chantype = &svr_chan_tcpremote; 210 tcpinfo->chantype = &svr_chan_tcpremote;
209 211 tcpinfo->tcp_type = forwarded;
210 /* Note: bindaddr is actually ignored by listen_tcpfwd, since 212
211 * we only want to bind to localhost */
212 ret = listen_tcpfwd(tcpinfo); 213 ret = listen_tcpfwd(tcpinfo);
213 214
214 out: 215 out:
215 if (ret == DROPBEAR_FAILURE) { 216 if (ret == DROPBEAR_FAILURE) {
216 /* we only free it if a listener wasn't created, since the listener 217 /* we only free it if a listener wasn't created, since the listener
217 * has to remember it if it's to be cancelled */ 218 * has to remember it if it's to be cancelled */
218 m_free(tcpinfo->sendaddr); 219 m_free(tcpinfo->listenaddr);
219 m_free(tcpinfo); 220 m_free(tcpinfo);
220 } 221 }
221 TRACE(("leave remotetcpreq")) 222 TRACE(("leave remotetcpreq"))
222 return ret; 223 return ret;
223 } 224 }
233 char portstring[NI_MAXSERV]; 234 char portstring[NI_MAXSERV];
234 int sock; 235 int sock;
235 int len; 236 int len;
236 int err = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED; 237 int err = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED;
237 238
238 if (opts.nolocaltcp) { 239 if (svr_opts.nolocaltcp) {
239 TRACE(("leave newtcpdirect: local tcp forwarding disabled")) 240 TRACE(("leave newtcpdirect: local tcp forwarding disabled"))
240 goto out; 241 goto out;
241 } 242 }
242 243
243 desthost = buf_getstring(ses.payload, &len); 244 desthost = buf_getstring(ses.payload, &len);
270 goto out; 271 goto out;
271 } 272 }
272 273
273 ses.maxfd = MAX(ses.maxfd, sock); 274 ses.maxfd = MAX(ses.maxfd, sock);
274 275
275 /* Note that infd is actually the "outgoing" direction on the 276 /* We don't set readfd, that will get set after the connection's
276 * tcp connection, vice versa for outfd.
277 * We don't set outfd, that will get set after the connection's
278 * progress succeeds */ 277 * progress succeeds */
279 channel->infd = sock; 278 channel->writefd = sock;
280 channel->initconn = 1; 279 channel->initconn = 1;
281 280
282 err = SSH_OPEN_IN_PROGRESS; 281 err = SSH_OPEN_IN_PROGRESS;
283 282
284 out: 283 out: