summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c67
1 files changed, 63 insertions, 4 deletions
diff --git a/channels.c b/channels.c
index 55dc67342..2b1ce0e5c 100644
--- a/channels.c
+++ b/channels.c
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41#include "includes.h" 41#include "includes.h"
42RCSID("$OpenBSD: channels.c,v 1.201 2004/05/11 19:01:43 deraadt Exp $"); 42RCSID("$OpenBSD: channels.c,v 1.202 2004/05/21 11:33:11 djm Exp $");
43 43
44#include "ssh.h" 44#include "ssh.h"
45#include "ssh1.h" 45#include "ssh1.h"
@@ -2228,6 +2228,26 @@ channel_setup_fwd_listener(int type, const char *listen_addr, u_short listen_por
2228 return success; 2228 return success;
2229} 2229}
2230 2230
2231int
2232channel_cancel_rport_listener(const char *host, u_short port)
2233{
2234 int i, found = 0;
2235
2236 for(i = 0; i < channels_alloc; i++) {
2237 Channel *c = channels[i];
2238
2239 if (c != NULL && c->type == SSH_CHANNEL_RPORT_LISTENER &&
2240 strncmp(c->path, host, sizeof(c->path)) == 0 &&
2241 c->listening_port == port) {
2242 debug2("%s: close clannel %d", __func__, i);
2243 channel_free(c);
2244 found = 1;
2245 }
2246 }
2247
2248 return (found);
2249}
2250
2231/* protocol local port fwd, used by ssh (and sshd in v1) */ 2251/* protocol local port fwd, used by ssh (and sshd in v1) */
2232int 2252int
2233channel_setup_local_fwd_listener(u_short listen_port, 2253channel_setup_local_fwd_listener(u_short listen_port,
@@ -2305,6 +2325,42 @@ channel_request_remote_forwarding(u_short listen_port,
2305} 2325}
2306 2326
2307/* 2327/*
2328 * Request cancellation of remote forwarding of connection host:port from
2329 * local side.
2330 */
2331
2332void
2333channel_request_rforward_cancel(u_short port)
2334{
2335 int i;
2336 const char *address_to_bind = "0.0.0.0";
2337
2338 if (!compat20)
2339 return;
2340
2341 for (i = 0; i < num_permitted_opens; i++) {
2342 if (permitted_opens[i].host_to_connect != NULL &&
2343 permitted_opens[i].listen_port == port)
2344 break;
2345 }
2346 if (i >= num_permitted_opens) {
2347 debug("%s: requested forward not found", __func__);
2348 return;
2349 }
2350 packet_start(SSH2_MSG_GLOBAL_REQUEST);
2351 packet_put_cstring("cancel-tcpip-forward");
2352 packet_put_char(0);
2353 packet_put_cstring(address_to_bind);
2354 packet_put_int(port);
2355 packet_send();
2356
2357 permitted_opens[i].listen_port = 0;
2358 permitted_opens[i].port_to_connect = 0;
2359 free(permitted_opens[i].host_to_connect);
2360 permitted_opens[i].host_to_connect = NULL;
2361}
2362
2363/*
2308 * This is called after receiving CHANNEL_FORWARDING_REQUEST. This initates 2364 * This is called after receiving CHANNEL_FORWARDING_REQUEST. This initates
2309 * listening for the port, and sends back a success reply (or disconnect 2365 * listening for the port, and sends back a success reply (or disconnect
2310 * message if there was an error). This never returns if there was an error. 2366 * message if there was an error). This never returns if there was an error.
@@ -2373,7 +2429,8 @@ channel_clear_permitted_opens(void)
2373 int i; 2429 int i;
2374 2430
2375 for (i = 0; i < num_permitted_opens; i++) 2431 for (i = 0; i < num_permitted_opens; i++)
2376 xfree(permitted_opens[i].host_to_connect); 2432 if (permitted_opens[i].host_to_connect != NULL)
2433 xfree(permitted_opens[i].host_to_connect);
2377 num_permitted_opens = 0; 2434 num_permitted_opens = 0;
2378 2435
2379} 2436}
@@ -2441,7 +2498,8 @@ channel_connect_by_listen_address(u_short listen_port)
2441 int i; 2498 int i;
2442 2499
2443 for (i = 0; i < num_permitted_opens; i++) 2500 for (i = 0; i < num_permitted_opens; i++)
2444 if (permitted_opens[i].listen_port == listen_port) 2501 if (permitted_opens[i].host_to_connect != NULL &&
2502 permitted_opens[i].listen_port == listen_port)
2445 return connect_to( 2503 return connect_to(
2446 permitted_opens[i].host_to_connect, 2504 permitted_opens[i].host_to_connect,
2447 permitted_opens[i].port_to_connect); 2505 permitted_opens[i].port_to_connect);
@@ -2459,7 +2517,8 @@ channel_connect_to(const char *host, u_short port)
2459 permit = all_opens_permitted; 2517 permit = all_opens_permitted;
2460 if (!permit) { 2518 if (!permit) {
2461 for (i = 0; i < num_permitted_opens; i++) 2519 for (i = 0; i < num_permitted_opens; i++)
2462 if (permitted_opens[i].port_to_connect == port && 2520 if (permitted_opens[i].host_to_connect != NULL &&
2521 permitted_opens[i].port_to_connect == port &&
2463 strcmp(permitted_opens[i].host_to_connect, host) == 0) 2522 strcmp(permitted_opens[i].host_to_connect, host) == 0)
2464 permit = 1; 2523 permit = 1;
2465 2524