version 1.316, 2019/06/21 04:21:04 |
version 1.317, 2019/06/28 13:35:04 |
|
|
if ((shell = getenv("SHELL")) == NULL) |
if ((shell = getenv("SHELL")) == NULL) |
shell = _PATH_BSHELL; |
shell = _PATH_BSHELL; |
|
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) < 0) |
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) == -1) |
fatal("Could not create socketpair to communicate with " |
fatal("Could not create socketpair to communicate with " |
"proxy dialer: %.100s", strerror(errno)); |
"proxy dialer: %.100s", strerror(errno)); |
|
|
|
|
close(sp[1]); |
close(sp[1]); |
/* Redirect stdin and stdout. */ |
/* Redirect stdin and stdout. */ |
if (sp[0] != 0) { |
if (sp[0] != 0) { |
if (dup2(sp[0], 0) < 0) |
if (dup2(sp[0], 0) == -1) |
perror("dup2 stdin"); |
perror("dup2 stdin"); |
} |
} |
if (sp[0] != 1) { |
if (sp[0] != 1) { |
if (dup2(sp[0], 1) < 0) |
if (dup2(sp[0], 1) == -1) |
perror("dup2 stdout"); |
perror("dup2 stdout"); |
} |
} |
if (sp[0] >= 2) |
if (sp[0] >= 2) |
|
|
exit(1); |
exit(1); |
} |
} |
/* Parent. */ |
/* Parent. */ |
if (pid < 0) |
if (pid == -1) |
fatal("fork failed: %.100s", strerror(errno)); |
fatal("fork failed: %.100s", strerror(errno)); |
close(sp[0]); |
close(sp[0]); |
free(command_string); |
free(command_string); |
|
|
shell = _PATH_BSHELL; |
shell = _PATH_BSHELL; |
|
|
/* Create pipes for communicating with the proxy. */ |
/* Create pipes for communicating with the proxy. */ |
if (pipe(pin) < 0 || pipe(pout) < 0) |
if (pipe(pin) == -1 || pipe(pout) == -1) |
fatal("Could not create pipes to communicate with the proxy: %.100s", |
fatal("Could not create pipes to communicate with the proxy: %.100s", |
strerror(errno)); |
strerror(errno)); |
|
|
|
|
/* Redirect stdin and stdout. */ |
/* Redirect stdin and stdout. */ |
close(pin[1]); |
close(pin[1]); |
if (pin[0] != 0) { |
if (pin[0] != 0) { |
if (dup2(pin[0], 0) < 0) |
if (dup2(pin[0], 0) == -1) |
perror("dup2 stdin"); |
perror("dup2 stdin"); |
close(pin[0]); |
close(pin[0]); |
} |
} |
close(pout[0]); |
close(pout[0]); |
if (dup2(pout[1], 1) < 0) |
if (dup2(pout[1], 1) == -1) |
perror("dup2 stdout"); |
perror("dup2 stdout"); |
/* Cannot be 1 because pin allocated two descriptors. */ |
/* Cannot be 1 because pin allocated two descriptors. */ |
close(pout[1]); |
close(pout[1]); |
|
|
exit(1); |
exit(1); |
} |
} |
/* Parent. */ |
/* Parent. */ |
if (pid < 0) |
if (pid == -1) |
fatal("fork failed: %.100s", strerror(errno)); |
fatal("fork failed: %.100s", strerror(errno)); |
else |
else |
proxy_command_pid = pid; /* save pid to clean up later */ |
proxy_command_pid = pid; /* save pid to clean up later */ |
|
|
char ntop[NI_MAXHOST]; |
char ntop[NI_MAXHOST]; |
|
|
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); |
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); |
if (sock < 0) { |
if (sock == -1) { |
error("socket: %s", strerror(errno)); |
error("socket: %s", strerror(errno)); |
return -1; |
return -1; |
} |
} |
|
|
/* Set SO_KEEPALIVE if requested. */ |
/* Set SO_KEEPALIVE if requested. */ |
if (want_keepalive && |
if (want_keepalive && |
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, |
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, |
sizeof(on)) < 0) |
sizeof(on)) == -1) |
error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); |
error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); |
|
|
/* Set the connection. */ |
/* Set the connection. */ |
|
|
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); |
} else if (strcmp(options.proxy_command, "-") == 0) { |
} else if (strcmp(options.proxy_command, "-") == 0) { |
if ((in = dup(STDIN_FILENO)) < 0 || |
if ((in = dup(STDIN_FILENO)) == -1 || |
(out = dup(STDOUT_FILENO)) < 0) { |
(out = dup(STDOUT_FILENO)) == -1) { |
if (in >= 0) |
if (in >= 0) |
close(in); |
close(in); |
error("%s: dup() in/out failed", __func__); |
error("%s: dup() in/out failed", __func__); |