summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--channels.c71
-rw-r--r--channels.h8
-rw-r--r--serverloop.c9
-rw-r--r--ssh.c4
5 files changed, 45 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index e38f073ff..ff90e5b86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -182,6 +182,9 @@
182 - markus@cvs.openbsd.org 2002/01/14 13:57:03 182 - markus@cvs.openbsd.org 2002/01/14 13:57:03
183 [channels.h nchan.c] 183 [channels.h nchan.c]
184 (c) 2002 184 (c) 2002
185 - markus@cvs.openbsd.org 2002/01/16 13:17:51
186 [channels.c channels.h serverloop.c ssh.c]
187 wrapper for channel_setup_fwd_listener
185 188
18620020121 18920020121
187 - (djm) Rework ssh-rand-helper: 190 - (djm) Rework ssh-rand-helper:
@@ -7329,4 +7332,4 @@
7329 - Wrote replacements for strlcpy and mkdtemp 7332 - Wrote replacements for strlcpy and mkdtemp
7330 - Released 1.0pre1 7333 - Released 1.0pre1
7331 7334
7332$Id: ChangeLog,v 1.1774 2002/01/22 12:29:03 djm Exp $ 7335$Id: ChangeLog,v 1.1775 2002/01/22 12:29:22 djm Exp $
diff --git a/channels.c b/channels.c
index 473c5efe4..03f12d396 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.159 2002/01/14 13:55:55 markus Exp $"); 42RCSID("$OpenBSD: channels.c,v 1.160 2002/01/16 13:17:51 markus Exp $");
43 43
44#include "ssh.h" 44#include "ssh.h"
45#include "ssh1.h" 45#include "ssh1.h"
@@ -2037,53 +2037,30 @@ channel_set_af(int af)
2037 IPv4or6 = af; 2037 IPv4or6 = af;
2038} 2038}
2039 2039
2040/* 2040static int
2041 * Initiate forwarding of connections to local port "port" through the secure 2041channel_setup_fwd_listener(int type, const char *listen_addr, u_short listen_port,
2042 * channel to host:port from remote side. 2042 const char *host_to_connect, u_short port_to_connect, int gateway_ports)
2043 */
2044int
2045channel_request_local_forwarding(u_short listen_port, const char *host_to_connect,
2046 u_short port_to_connect, int gateway_ports)
2047{
2048 return channel_request_forwarding(
2049 NULL, listen_port,
2050 host_to_connect, port_to_connect,
2051 gateway_ports, /*remote_fwd*/ 0);
2052}
2053
2054/*
2055 * If 'remote_fwd' is true we have a '-R style' listener for protocol 2
2056 * (SSH_CHANNEL_RPORT_LISTENER).
2057 */
2058int
2059channel_request_forwarding(
2060 const char *listen_address, u_short listen_port,
2061 const char *host_to_connect, u_short port_to_connect,
2062 int gateway_ports, int remote_fwd)
2063{ 2043{
2064 Channel *c; 2044 Channel *c;
2065 int success, sock, on = 1, type; 2045 int success, sock, on = 1;
2066 struct addrinfo hints, *ai, *aitop; 2046 struct addrinfo hints, *ai, *aitop;
2067 char ntop[NI_MAXHOST], strport[NI_MAXSERV];
2068 const char *host; 2047 const char *host;
2048 char ntop[NI_MAXHOST], strport[NI_MAXSERV];
2069 struct linger linger; 2049 struct linger linger;
2070 2050
2071 success = 0; 2051 success = 0;
2052 host = (type == SSH_CHANNEL_RPORT_LISTENER) ?
2053 listen_addr : host_to_connect;
2072 2054
2073 if (remote_fwd) { 2055 if (host == NULL) {
2074 host = listen_address; 2056 error("No forward host name.");
2075 type = SSH_CHANNEL_RPORT_LISTENER; 2057 return success;
2076 } else {
2077 host = host_to_connect;
2078 type = SSH_CHANNEL_PORT_LISTENER;
2079 } 2058 }
2080
2081 if (strlen(host) > SSH_CHANNEL_PATH_LEN - 1) { 2059 if (strlen(host) > SSH_CHANNEL_PATH_LEN - 1) {
2082 error("Forward host name too long."); 2060 error("Forward host name too long.");
2083 return success; 2061 return success;
2084 } 2062 }
2085 2063
2086 /* XXX listen_address is currently ignored */
2087 /* 2064 /*
2088 * getaddrinfo returns a loopback address if the hostname is 2065 * getaddrinfo returns a loopback address if the hostname is
2089 * set to NULL and hints.ai_flags is not AI_PASSIVE 2066 * set to NULL and hints.ai_flags is not AI_PASSIVE
@@ -2101,7 +2078,7 @@ channel_request_forwarding(
2101 continue; 2078 continue;
2102 if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop, sizeof(ntop), 2079 if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop, sizeof(ntop),
2103 strport, sizeof(strport), NI_NUMERICHOST|NI_NUMERICSERV) != 0) { 2080 strport, sizeof(strport), NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
2104 error("channel_request_forwarding: getnameinfo failed"); 2081 error("channel_setup_fwd_listener: getnameinfo failed");
2105 continue; 2082 continue;
2106 } 2083 }
2107 /* Create a port to listen for the host. */ 2084 /* Create a port to listen for the host. */
@@ -2143,7 +2120,7 @@ channel_request_forwarding(
2143 CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT, 2120 CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT,
2144 0, xstrdup("port listener"), 1); 2121 0, xstrdup("port listener"), 1);
2145 if (c == NULL) { 2122 if (c == NULL) {
2146 error("channel_request_forwarding: channel_new failed"); 2123 error("channel_setup_fwd_listener: channel_new failed");
2147 close(sock); 2124 close(sock);
2148 continue; 2125 continue;
2149 } 2126 }
@@ -2153,12 +2130,30 @@ channel_request_forwarding(
2153 success = 1; 2130 success = 1;
2154 } 2131 }
2155 if (success == 0) 2132 if (success == 0)
2156 error("channel_request_forwarding: cannot listen to port: %d", 2133 error("channel_setup_fwd_listener: cannot listen to port: %d",
2157 listen_port); 2134 listen_port);
2158 freeaddrinfo(aitop); 2135 freeaddrinfo(aitop);
2159 return success; 2136 return success;
2160} 2137}
2161 2138
2139/* protocol local port fwd, used by ssh (and sshd in v1) */
2140int
2141channel_setup_local_fwd_listener(u_short listen_port,
2142 const char *host_to_connect, u_short port_to_connect, int gateway_ports)
2143{
2144 return channel_setup_fwd_listener(SSH_CHANNEL_PORT_LISTENER,
2145 NULL, listen_port, host_to_connect, port_to_connect, gateway_ports);
2146}
2147
2148/* protocol v2 remote port fwd, used by sshd */
2149int
2150channel_setup_remote_fwd_listener(const char *listen_address,
2151 u_short listen_port, int gateway_ports)
2152{
2153 return channel_setup_fwd_listener(SSH_CHANNEL_RPORT_LISTENER,
2154 listen_address, listen_port, NULL, 0, gateway_ports);
2155}
2156
2162/* 2157/*
2163 * Initiate forwarding of connections to port "port" on remote host through 2158 * Initiate forwarding of connections to port "port" on remote host through
2164 * the secure channel to host:port from local side. 2159 * the secure channel to host:port from local side.
@@ -2244,7 +2239,7 @@ channel_input_port_forward_request(int is_root, int gateway_ports)
2244 port); 2239 port);
2245#endif 2240#endif
2246 /* Initiate forwarding */ 2241 /* Initiate forwarding */
2247 channel_request_local_forwarding(port, hostname, host_port, gateway_ports); 2242 channel_setup_local_fwd_listener(port, hostname, host_port, gateway_ports);
2248 2243
2249 /* Free the argument string. */ 2244 /* Free the argument string. */
2250 xfree(hostname); 2245 xfree(hostname);
diff --git a/channels.h b/channels.h
index 3422d9644..6c6008f91 100644
--- a/channels.h
+++ b/channels.h
@@ -32,7 +32,7 @@
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35/* RCSID("$OpenBSD: channels.h,v 1.59 2002/01/14 13:57:03 markus Exp $"); */ 35/* RCSID("$OpenBSD: channels.h,v 1.60 2002/01/16 13:17:51 markus Exp $"); */
36 36
37#ifndef CHANNEL_H 37#ifndef CHANNEL_H
38#define CHANNEL_H 38#define CHANNEL_H
@@ -190,10 +190,8 @@ void channel_input_port_forward_request(int, int);
190int channel_connect_to(const char *, u_short); 190int channel_connect_to(const char *, u_short);
191int channel_connect_by_listen_address(u_short); 191int channel_connect_by_listen_address(u_short);
192void channel_request_remote_forwarding(u_short, const char *, u_short); 192void channel_request_remote_forwarding(u_short, const char *, u_short);
193int channel_request_local_forwarding(u_short, const char *, u_short, int); 193int channel_setup_local_fwd_listener(u_short, const char *, u_short, int);
194int 194int channel_setup_remote_fwd_listener(const char *, u_short, int);
195channel_request_forwarding(const char *, u_short, const char *, u_short, int,
196 int);
197 195
198/* x11 forwarding */ 196/* x11 forwarding */
199 197
diff --git a/serverloop.c b/serverloop.c
index 39d992057..6c8719a3f 100644
--- a/serverloop.c
+++ b/serverloop.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$OpenBSD: serverloop.c,v 1.94 2002/01/10 11:13:29 markus Exp $"); 38RCSID("$OpenBSD: serverloop.c,v 1.95 2002/01/16 13:17:51 markus Exp $");
39 39
40#include "xmalloc.h" 40#include "xmalloc.h"
41#include "packet.h" 41#include "packet.h"
@@ -991,11 +991,8 @@ server_input_global_request(int type, u_int32_t seq, void *ctxt)
991 packet_send_debug("Server has disabled port forwarding."); 991 packet_send_debug("Server has disabled port forwarding.");
992 } else { 992 } else {
993 /* Start listening on the port */ 993 /* Start listening on the port */
994 success = channel_request_forwarding( 994 success = channel_setup_remote_fwd_listener(
995 listen_address, listen_port, 995 listen_address, listen_port, options.gateway_ports);
996 /*unspec host_to_connect*/ "<unspec host>",
997 /*unspec port_to_connect*/ 0,
998 options.gateway_ports, /*remote*/ 1);
999 } 996 }
1000 xfree(listen_address); 997 xfree(listen_address);
1001 } 998 }
diff --git a/ssh.c b/ssh.c
index e4db59bcc..8e1604e21 100644
--- a/ssh.c
+++ b/ssh.c
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41#include "includes.h" 41#include "includes.h"
42RCSID("$OpenBSD: ssh.c,v 1.157 2001/12/28 15:06:00 markus Exp $"); 42RCSID("$OpenBSD: ssh.c,v 1.158 2002/01/16 13:17:51 markus Exp $");
43 43
44#include <openssl/evp.h> 44#include <openssl/evp.h>
45#include <openssl/err.h> 45#include <openssl/err.h>
@@ -841,7 +841,7 @@ ssh_init_forwarding(void)
841 options.local_forwards[i].port, 841 options.local_forwards[i].port,
842 options.local_forwards[i].host, 842 options.local_forwards[i].host,
843 options.local_forwards[i].host_port); 843 options.local_forwards[i].host_port);
844 success += channel_request_local_forwarding( 844 success += channel_setup_local_fwd_listener(
845 options.local_forwards[i].port, 845 options.local_forwards[i].port,
846 options.local_forwards[i].host, 846 options.local_forwards[i].host,
847 options.local_forwards[i].host_port, 847 options.local_forwards[i].host_port,