summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2011-10-02 18:59:03 +1100
committerDarren Tucker <dtucker@zip.com.au>2011-10-02 18:59:03 +1100
commit68afb8c5f242ec74f48fd86137122399435dd757 (patch)
treea41fb99a2df717111d5c1a05f51b3791580218d1 /channels.c
parent1338b9e067055259033a05e14db0bc2ad5536482 (diff)
- markus@cvs.openbsd.org 2011/09/23 07:45:05
[mux.c readconf.h channels.h compat.h compat.c ssh.c readconf.c channels.c version.h] unbreak remote portforwarding with dynamic allocated listen ports: 1) send the actual listen port in the open message (instead of 0). this allows multiple forwardings with a dynamic listen port 2) update the matching permit-open entry, so we can identify where to connect to report: den at skbkontur.ru and P. Szczygielski feedback and ok djm@
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/channels.c b/channels.c
index 00e9af84a..f6e9b4d8c 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.c,v 1.314 2011/09/23 00:22:04 dtucker Exp $ */ 1/* $OpenBSD: channels.c,v 1.315 2011/09/23 07:45:05 markus Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -2814,8 +2814,12 @@ channel_setup_fwd_listener(int type, const char *listen_addr,
2814 0, "port listener", 1); 2814 0, "port listener", 1);
2815 c->path = xstrdup(host); 2815 c->path = xstrdup(host);
2816 c->host_port = port_to_connect; 2816 c->host_port = port_to_connect;
2817 c->listening_port = listen_port;
2818 c->listening_addr = addr == NULL ? NULL : xstrdup(addr); 2817 c->listening_addr = addr == NULL ? NULL : xstrdup(addr);
2818 if (listen_port == 0 && allocated_listen_port != NULL &&
2819 !(datafellows & SSH_BUG_DYNAMIC_RPORT))
2820 c->listening_port = *allocated_listen_port;
2821 else
2822 c->listening_port = listen_port;
2819 success = 1; 2823 success = 1;
2820 } 2824 }
2821 if (success == 0) 2825 if (success == 0)
@@ -2924,12 +2928,14 @@ channel_rfwd_bind_host(const char *listen_host)
2924/* 2928/*
2925 * Initiate forwarding of connections to port "port" on remote host through 2929 * Initiate forwarding of connections to port "port" on remote host through
2926 * the secure channel to host:port from local side. 2930 * the secure channel to host:port from local side.
2931 * Returns handle (index) for updating the dynamic listen port with
2932 * channel_update_permitted_opens().
2927 */ 2933 */
2928int 2934int
2929channel_request_remote_forwarding(const char *listen_host, u_short listen_port, 2935channel_request_remote_forwarding(const char *listen_host, u_short listen_port,
2930 const char *host_to_connect, u_short port_to_connect) 2936 const char *host_to_connect, u_short port_to_connect)
2931{ 2937{
2932 int type, success = 0; 2938 int type, success = 0, idx = -1;
2933 2939
2934 /* Send the forward request to the remote side. */ 2940 /* Send the forward request to the remote side. */
2935 if (compat20) { 2941 if (compat20) {
@@ -2968,12 +2974,12 @@ channel_request_remote_forwarding(const char *listen_host, u_short listen_port,
2968 /* Record that connection to this host/port is permitted. */ 2974 /* Record that connection to this host/port is permitted. */
2969 permitted_opens = xrealloc(permitted_opens, 2975 permitted_opens = xrealloc(permitted_opens,
2970 num_permitted_opens + 1, sizeof(*permitted_opens)); 2976 num_permitted_opens + 1, sizeof(*permitted_opens));
2971 permitted_opens[num_permitted_opens].host_to_connect = xstrdup(host_to_connect); 2977 idx = num_permitted_opens++;
2972 permitted_opens[num_permitted_opens].port_to_connect = port_to_connect; 2978 permitted_opens[idx].host_to_connect = xstrdup(host_to_connect);
2973 permitted_opens[num_permitted_opens].listen_port = listen_port; 2979 permitted_opens[idx].port_to_connect = port_to_connect;
2974 num_permitted_opens++; 2980 permitted_opens[idx].listen_port = listen_port;
2975 } 2981 }
2976 return (success ? 0 : -1); 2982 return (idx);
2977} 2983}
2978 2984
2979/* 2985/*
@@ -3078,6 +3084,35 @@ channel_add_permitted_opens(char *host, int port)
3078 all_opens_permitted = 0; 3084 all_opens_permitted = 0;
3079} 3085}
3080 3086
3087/*
3088 * Update the listen port for a dynamic remote forward, after
3089 * the actual 'newport' has been allocated. If 'newport' < 0 is
3090 * passed then they entry will be invalidated.
3091 */
3092void
3093channel_update_permitted_opens(int idx, int newport)
3094{
3095 if (idx < 0 || idx >= num_permitted_opens) {
3096 debug("channel_update_permitted_opens: index out of range:"
3097 " %d num_permitted_opens %d", idx, num_permitted_opens);
3098 return;
3099 }
3100 debug("%s allowed port %d for forwarding to host %s port %d",
3101 newport > 0 ? "Updating" : "Removing",
3102 newport,
3103 permitted_opens[idx].host_to_connect,
3104 permitted_opens[idx].port_to_connect);
3105 if (newport >= 0) {
3106 permitted_opens[idx].listen_port =
3107 (datafellows & SSH_BUG_DYNAMIC_RPORT) ? 0 : newport;
3108 } else {
3109 permitted_opens[idx].listen_port = 0;
3110 permitted_opens[idx].port_to_connect = 0;
3111 xfree(permitted_opens[idx].host_to_connect);
3112 permitted_opens[idx].host_to_connect = NULL;
3113 }
3114}
3115
3081int 3116int
3082channel_add_adm_permitted_opens(char *host, int port) 3117channel_add_adm_permitted_opens(char *host, int port)
3083{ 3118{