version 1.356, 2016/10/18 17:32:54 |
version 1.357, 2017/02/01 02:59:09 |
|
|
} |
} |
packet_check_eom(); |
packet_check_eom(); |
c = channel_connect_to_port(host, host_port, |
c = channel_connect_to_port(host, host_port, |
"connected socket", originator_string); |
"connected socket", originator_string, NULL, NULL); |
free(originator_string); |
free(originator_string); |
free(host); |
free(host); |
if (c == NULL) { |
if (c == NULL) { |
|
|
memset(cctx, 0, sizeof(*cctx)); |
memset(cctx, 0, sizeof(*cctx)); |
} |
} |
|
|
/* Return CONNECTING channel to remote host:port or local socket path */ |
/* |
|
* Return CONNECTING channel to remote host:port or local socket path, |
|
* passing back the failure reason if appropriate. |
|
*/ |
static Channel * |
static Channel * |
connect_to(const char *name, int port, char *ctype, char *rname) |
connect_to_reason(const char *name, int port, char *ctype, char *rname, |
|
int *reason, const char **errmsg) |
{ |
{ |
struct addrinfo hints; |
struct addrinfo hints; |
int gaierr; |
int gaierr; |
|
|
hints.ai_family = IPv4or6; |
hints.ai_family = IPv4or6; |
hints.ai_socktype = SOCK_STREAM; |
hints.ai_socktype = SOCK_STREAM; |
snprintf(strport, sizeof strport, "%d", port); |
snprintf(strport, sizeof strport, "%d", port); |
if ((gaierr = getaddrinfo(name, strport, &hints, &cctx.aitop)) != 0) { |
if ((gaierr = getaddrinfo(name, strport, &hints, &cctx.aitop)) |
|
!= 0) { |
|
if (errmsg != NULL) |
|
*errmsg = ssh_gai_strerror(gaierr); |
|
if (reason != NULL) |
|
*reason = SSH2_OPEN_CONNECT_FAILED; |
error("connect_to %.100s: unknown host (%s)", name, |
error("connect_to %.100s: unknown host (%s)", name, |
ssh_gai_strerror(gaierr)); |
ssh_gai_strerror(gaierr)); |
return NULL; |
return NULL; |
|
|
return c; |
return c; |
} |
} |
|
|
|
/* Return CONNECTING channel to remote host:port or local socket path */ |
|
static Channel * |
|
connect_to(const char *name, int port, char *ctype, char *rname) |
|
{ |
|
return connect_to_reason(name, port, ctype, rname, NULL, NULL); |
|
} |
|
|
/* |
/* |
* returns either the newly connected channel or the downstream channel |
* returns either the newly connected channel or the downstream channel |
* that needs to deal with this connection. |
* that needs to deal with this connection. |
|
|
|
|
/* Check if connecting to that port is permitted and connect. */ |
/* Check if connecting to that port is permitted and connect. */ |
Channel * |
Channel * |
channel_connect_to_port(const char *host, u_short port, char *ctype, char *rname) |
channel_connect_to_port(const char *host, u_short port, char *ctype, |
|
char *rname, int *reason, const char **errmsg) |
{ |
{ |
int i, permit, permit_adm = 1; |
int i, permit, permit_adm = 1; |
|
|
|
|
if (!permit || !permit_adm) { |
if (!permit || !permit_adm) { |
logit("Received request to connect to host %.100s port %d, " |
logit("Received request to connect to host %.100s port %d, " |
"but the request was denied.", host, port); |
"but the request was denied.", host, port); |
|
if (reason != NULL) |
|
*reason = SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED; |
return NULL; |
return NULL; |
} |
} |
return connect_to(host, port, ctype, rname); |
return connect_to_reason(host, port, ctype, rname, reason, errmsg); |
} |
} |
|
|
/* Check if connecting to that path is permitted and connect. */ |
/* Check if connecting to that path is permitted and connect. */ |