version 1.301, 2018/07/18 11:34:04 |
version 1.302, 2018/07/19 10:28:47 |
|
|
} |
} |
|
|
/* |
/* |
* Creates a (possibly privileged) socket for use as the ssh connection. |
* Creates a ocket for use as the ssh connection. |
*/ |
*/ |
static int |
static int |
ssh_create_socket(int privileged, struct addrinfo *ai) |
ssh_create_socket(struct addrinfo *ai) |
{ |
{ |
int sock, r; |
int sock, r; |
struct sockaddr_storage bindaddr; |
struct sockaddr_storage bindaddr; |
|
|
fcntl(sock, F_SETFD, FD_CLOEXEC); |
fcntl(sock, F_SETFD, FD_CLOEXEC); |
|
|
/* Bind the socket to an alternative local IP address */ |
/* Bind the socket to an alternative local IP address */ |
if (options.bind_address == NULL && options.bind_interface == NULL && |
if (options.bind_address == NULL && options.bind_interface == NULL) |
!privileged) |
|
return sock; |
return sock; |
|
|
if (options.bind_address != NULL) { |
if (options.bind_address != NULL) { |
|
|
/* |
/* |
* Opens a TCP/IP connection to the remote server on the given host. |
* Opens a TCP/IP connection to the remote server on the given host. |
* The address of the remote host will be returned in hostaddr. |
* The address of the remote host will be returned in hostaddr. |
* If port is 0, the default port will be used. If needpriv is true, |
* If port is 0, the default port will be used. |
* a privileged port will be allocated to make the connection. |
|
* This requires super-user privileges if needpriv is true. |
|
* Connection_attempts specifies the maximum number of tries (one per |
* Connection_attempts specifies the maximum number of tries (one per |
* second). If proxy_command is non-NULL, it specifies the command (with %h |
* second). If proxy_command is non-NULL, it specifies the command (with %h |
* and %p substituted for host and port, respectively) to use to contact |
* and %p substituted for host and port, respectively) to use to contact |
|
|
static int |
static int |
ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop, |
ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop, |
struct sockaddr_storage *hostaddr, u_short port, int family, |
struct sockaddr_storage *hostaddr, u_short port, int family, |
int connection_attempts, int *timeout_ms, int want_keepalive, int needpriv) |
int connection_attempts, int *timeout_ms, int want_keepalive) |
{ |
{ |
int on = 1; |
int on = 1; |
int oerrno, sock = -1, attempt; |
int oerrno, sock = -1, attempt; |
char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
char ntop[NI_MAXHOST], strport[NI_MAXSERV]; |
struct addrinfo *ai; |
struct addrinfo *ai; |
|
|
debug2("%s: needpriv %d", __func__, needpriv); |
debug2("%s", __func__); |
memset(ntop, 0, sizeof(ntop)); |
memset(ntop, 0, sizeof(ntop)); |
memset(strport, 0, sizeof(strport)); |
memset(strport, 0, sizeof(strport)); |
|
|
|
|
host, ntop, strport); |
host, ntop, strport); |
|
|
/* Create a socket for connecting. */ |
/* Create a socket for connecting. */ |
sock = ssh_create_socket(needpriv, ai); |
sock = ssh_create_socket(ai); |
if (sock < 0) { |
if (sock < 0) { |
/* Any error is already output */ |
/* Any error is already output */ |
errno = 0; |
errno = 0; |
|
|
int |
int |
ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs, |
ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs, |
struct sockaddr_storage *hostaddr, u_short port, int family, |
struct sockaddr_storage *hostaddr, u_short port, int family, |
int connection_attempts, int *timeout_ms, int want_keepalive, int needpriv) |
int connection_attempts, int *timeout_ms, int want_keepalive) |
{ |
{ |
if (options.proxy_command == NULL) { |
if (options.proxy_command == NULL) { |
return ssh_connect_direct(ssh, host, addrs, hostaddr, port, |
return ssh_connect_direct(ssh, host, addrs, hostaddr, port, |
family, connection_attempts, timeout_ms, want_keepalive, |
family, connection_attempts, timeout_ms, want_keepalive); |
needpriv); |
|
} else if (strcmp(options.proxy_command, "-") == 0) { |
} else if (strcmp(options.proxy_command, "-") == 0) { |
if ((ssh_packet_set_connection(ssh, |
if ((ssh_packet_set_connection(ssh, |
STDIN_FILENO, STDOUT_FILENO)) == NULL) |
STDIN_FILENO, STDOUT_FILENO)) == NULL) |