summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2017-02-01 02:59:09 +0000
committerDarren Tucker <dtucker@zip.com.au>2017-02-03 14:23:24 +1100
commit858252fb1d451ebb0969cf9749116c8f0ee42753 (patch)
tree86168774d4d73763e0114ec62d7abeb29fbfba12 /channels.c
parent6ba9f893838489add6ec4213c7a997b425e4a9e0 (diff)
upstream commit
Return true reason for port forwarding failures where feasible rather than always "administratively prohibited". bz#2674, ok djm@ Upstream-ID: d901d9887951774e604ca970e1827afaaef9e419
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/channels.c b/channels.c
index bef8ad6aa..398da9a89 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.c,v 1.356 2016/10/18 17:32:54 dtucker Exp $ */ 1/* $OpenBSD: channels.c,v 1.357 2017/02/01 02:59:09 dtucker 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
@@ -3065,7 +3065,7 @@ channel_input_port_open(int type, u_int32_t seq, void *ctxt)
3065 } 3065 }
3066 packet_check_eom(); 3066 packet_check_eom();
3067 c = channel_connect_to_port(host, host_port, 3067 c = channel_connect_to_port(host, host_port,
3068 "connected socket", originator_string); 3068 "connected socket", originator_string, NULL, NULL);
3069 free(originator_string); 3069 free(originator_string);
3070 free(host); 3070 free(host);
3071 if (c == NULL) { 3071 if (c == NULL) {
@@ -4026,9 +4026,13 @@ channel_connect_ctx_free(struct channel_connect *cctx)
4026 memset(cctx, 0, sizeof(*cctx)); 4026 memset(cctx, 0, sizeof(*cctx));
4027} 4027}
4028 4028
4029/* Return CONNECTING channel to remote host:port or local socket path */ 4029/*
4030 * Return CONNECTING channel to remote host:port or local socket path,
4031 * passing back the failure reason if appropriate.
4032 */
4030static Channel * 4033static Channel *
4031connect_to(const char *name, int port, char *ctype, char *rname) 4034connect_to_reason(const char *name, int port, char *ctype, char *rname,
4035 int *reason, const char **errmsg)
4032{ 4036{
4033 struct addrinfo hints; 4037 struct addrinfo hints;
4034 int gaierr; 4038 int gaierr;
@@ -4069,7 +4073,12 @@ connect_to(const char *name, int port, char *ctype, char *rname)
4069 hints.ai_family = IPv4or6; 4073 hints.ai_family = IPv4or6;
4070 hints.ai_socktype = SOCK_STREAM; 4074 hints.ai_socktype = SOCK_STREAM;
4071 snprintf(strport, sizeof strport, "%d", port); 4075 snprintf(strport, sizeof strport, "%d", port);
4072 if ((gaierr = getaddrinfo(name, strport, &hints, &cctx.aitop)) != 0) { 4076 if ((gaierr = getaddrinfo(name, strport, &hints, &cctx.aitop))
4077 != 0) {
4078 if (errmsg != NULL)
4079 *errmsg = ssh_gai_strerror(gaierr);
4080 if (reason != NULL)
4081 *reason = SSH2_OPEN_CONNECT_FAILED;
4073 error("connect_to %.100s: unknown host (%s)", name, 4082 error("connect_to %.100s: unknown host (%s)", name,
4074 ssh_gai_strerror(gaierr)); 4083 ssh_gai_strerror(gaierr));
4075 return NULL; 4084 return NULL;
@@ -4092,6 +4101,13 @@ connect_to(const char *name, int port, char *ctype, char *rname)
4092 return c; 4101 return c;
4093} 4102}
4094 4103
4104/* Return CONNECTING channel to remote host:port or local socket path */
4105static Channel *
4106connect_to(const char *name, int port, char *ctype, char *rname)
4107{
4108 return connect_to_reason(name, port, ctype, rname, NULL, NULL);
4109}
4110
4095/* 4111/*
4096 * returns either the newly connected channel or the downstream channel 4112 * returns either the newly connected channel or the downstream channel
4097 * that needs to deal with this connection. 4113 * that needs to deal with this connection.
@@ -4136,7 +4152,8 @@ channel_connect_by_listen_path(const char *path, char *ctype, char *rname)
4136 4152
4137/* Check if connecting to that port is permitted and connect. */ 4153/* Check if connecting to that port is permitted and connect. */
4138Channel * 4154Channel *
4139channel_connect_to_port(const char *host, u_short port, char *ctype, char *rname) 4155channel_connect_to_port(const char *host, u_short port, char *ctype,
4156 char *rname, int *reason, const char **errmsg)
4140{ 4157{
4141 int i, permit, permit_adm = 1; 4158 int i, permit, permit_adm = 1;
4142 4159
@@ -4161,9 +4178,11 @@ channel_connect_to_port(const char *host, u_short port, char *ctype, char *rname
4161 if (!permit || !permit_adm) { 4178 if (!permit || !permit_adm) {
4162 logit("Received request to connect to host %.100s port %d, " 4179 logit("Received request to connect to host %.100s port %d, "
4163 "but the request was denied.", host, port); 4180 "but the request was denied.", host, port);
4181 if (reason != NULL)
4182 *reason = SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED;
4164 return NULL; 4183 return NULL;
4165 } 4184 }
4166 return connect_to(host, port, ctype, rname); 4185 return connect_to_reason(host, port, ctype, rname, reason, errmsg);
4167} 4186}
4168 4187
4169/* Check if connecting to that path is permitted and connect. */ 4188/* Check if connecting to that path is permitted and connect. */