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
3
* Author: Tatu Ylonen <[email protected] >
4
4
* Copyright (c) 1995 Tatu Ylonen <[email protected] >, Espoo, Finland
@@ -3067,7 +3067,7 @@ channel_input_port_open(int type, u_int32_t seq, void *ctxt)
3067
3067
}
3068
3068
packet_check_eom ();
3069
3069
c = channel_connect_to_port (host , host_port ,
3070
- "connected socket" , originator_string );
3070
+ "connected socket" , originator_string , NULL , NULL );
3071
3071
free (originator_string );
3072
3072
free (host );
3073
3073
if (c == NULL ) {
@@ -4028,9 +4028,13 @@ channel_connect_ctx_free(struct channel_connect *cctx)
4028
4028
memset (cctx , 0 , sizeof (* cctx ));
4029
4029
}
4030
4030
4031
- /* Return CONNECTING channel to remote host:port or local socket path */
4031
+ /*
4032
+ * Return CONNECTING channel to remote host:port or local socket path,
4033
+ * passing back the failure reason if appropriate.
4034
+ */
4032
4035
static Channel *
4033
- connect_to (const char * name , int port , char * ctype , char * rname )
4036
+ connect_to_reason (const char * name , int port , char * ctype , char * rname ,
4037
+ int * reason , const char * * errmsg )
4034
4038
{
4035
4039
struct addrinfo hints ;
4036
4040
int gaierr ;
@@ -4071,7 +4075,12 @@ connect_to(const char *name, int port, char *ctype, char *rname)
4071
4075
hints .ai_family = IPv4or6 ;
4072
4076
hints .ai_socktype = SOCK_STREAM ;
4073
4077
snprintf (strport , sizeof strport , "%d" , port );
4074
- if ((gaierr = getaddrinfo (name , strport , & hints , & cctx .aitop )) != 0 ) {
4078
+ if ((gaierr = getaddrinfo (name , strport , & hints , & cctx .aitop ))
4079
+ != 0 ) {
4080
+ if (errmsg != NULL )
4081
+ * errmsg = ssh_gai_strerror (gaierr );
4082
+ if (reason != NULL )
4083
+ * reason = SSH2_OPEN_CONNECT_FAILED ;
4075
4084
error ("connect_to %.100s: unknown host (%s)" , name ,
4076
4085
ssh_gai_strerror (gaierr ));
4077
4086
return NULL ;
@@ -4094,6 +4103,13 @@ connect_to(const char *name, int port, char *ctype, char *rname)
4094
4103
return c ;
4095
4104
}
4096
4105
4106
+ /* Return CONNECTING channel to remote host:port or local socket path */
4107
+ static Channel *
4108
+ connect_to (const char * name , int port , char * ctype , char * rname )
4109
+ {
4110
+ return connect_to_reason (name , port , ctype , rname , NULL , NULL );
4111
+ }
4112
+
4097
4113
/*
4098
4114
* returns either the newly connected channel or the downstream channel
4099
4115
* that needs to deal with this connection.
@@ -4138,7 +4154,8 @@ channel_connect_by_listen_path(const char *path, char *ctype, char *rname)
4138
4154
4139
4155
/* Check if connecting to that port is permitted and connect. */
4140
4156
Channel *
4141
- channel_connect_to_port (const char * host , u_short port , char * ctype , char * rname )
4157
+ channel_connect_to_port (const char * host , u_short port , char * ctype ,
4158
+ char * rname , int * reason , const char * * errmsg )
4142
4159
{
4143
4160
int i , permit , permit_adm = 1 ;
4144
4161
@@ -4163,9 +4180,11 @@ channel_connect_to_port(const char *host, u_short port, char *ctype, char *rname
4163
4180
if (!permit || !permit_adm ) {
4164
4181
logit ("Received request to connect to host %.100s port %d, "
4165
4182
"but the request was denied." , host , port );
4183
+ if (reason != NULL )
4184
+ * reason = SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED ;
4166
4185
return NULL ;
4167
4186
}
4168
- return connect_to (host , port , ctype , rname );
4187
+ return connect_to_reason (host , port , ctype , rname , reason , errmsg );
4169
4188
}
4170
4189
4171
4190
/* Check if connecting to that path is permitted and connect. */
0 commit comments