diff options
Diffstat (limited to 'channels.c')
-rw-r--r-- | channels.c | 71 |
1 files changed, 33 insertions, 38 deletions
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" |
42 | RCSID("$OpenBSD: channels.c,v 1.159 2002/01/14 13:55:55 markus Exp $"); | 42 | RCSID("$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 | /* | 2040 | static int |
2041 | * Initiate forwarding of connections to local port "port" through the secure | 2041 | channel_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 | */ | ||
2044 | int | ||
2045 | channel_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 | */ | ||
2058 | int | ||
2059 | channel_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) */ | ||
2140 | int | ||
2141 | channel_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 */ | ||
2149 | int | ||
2150 | channel_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); |