diff options
| author | Ed Maste <emaste@FreeBSD.org> | 2021-02-14 21:00:25 +0000 |
|---|---|---|
| committer | Ed Maste <emaste@FreeBSD.org> | 2021-02-14 21:00:25 +0000 |
| commit | 0194e6d04277a638afac6c4a664d3bc6a0d944eb (patch) | |
| tree | e97a6dcafc6763aea7c804e4e113c2750cb1400d /sshconnect.c | |
| parent | f02e39982452024dafcf0ea6e536ebff586ffce4 (diff) | |
Diffstat (limited to 'sshconnect.c')
| -rw-r--r-- | sshconnect.c | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/sshconnect.c b/sshconnect.c index fdcdcd85544a..6230dad32476 100644 --- a/sshconnect.c +++ b/sshconnect.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshconnect.c,v 1.314 2019/02/27 19:37:01 markus Exp $ */ +/* $OpenBSD: sshconnect.c,v 1.319 2019/09/13 04:31:19 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -56,7 +56,6 @@ #include "compat.h" #include "sshkey.h" #include "sshconnect.h" -#include "hostfile.h" #include "log.h" #include "misc.h" #include "readconf.h" @@ -87,14 +86,18 @@ static void warn_changed_key(struct sshkey *); /* Expand a proxy command */ static char * expand_proxy_command(const char *proxy_command, const char *user, - const char *host, int port) + const char *host, const char *host_arg, int port) { char *tmp, *ret, strport[NI_MAXSERV]; snprintf(strport, sizeof strport, "%d", port); xasprintf(&tmp, "exec %s", proxy_command); - ret = percent_expand(tmp, "h", host, "p", strport, - "r", options.user, (char *)NULL); + ret = percent_expand(tmp, + "h", host, + "n", host_arg, + "p", strport, + "r", options.user, + (char *)NULL); free(tmp); return ret; } @@ -122,8 +125,8 @@ stderr_null(void) * a connected fd back to us. */ static int -ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port, - const char *proxy_command) +ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, + const char *host_arg, u_short port, const char *proxy_command) { char *command_string; int sp[2], sock; @@ -133,12 +136,12 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port, if ((shell = getenv("SHELL")) == NULL) 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 " "proxy dialer: %.100s", strerror(errno)); command_string = expand_proxy_command(proxy_command, options.user, - host, port); + host_arg, host, port); debug("Executing proxy dialer command: %.500s", command_string); /* Fork and execute the proxy command. */ @@ -148,11 +151,11 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port, close(sp[1]); /* Redirect stdin and stdout. */ if (sp[0] != 0) { - if (dup2(sp[0], 0) < 0) + if (dup2(sp[0], 0) == -1) perror("dup2 stdin"); } if (sp[0] != 1) { - if (dup2(sp[0], 1) < 0) + if (dup2(sp[0], 1) == -1) perror("dup2 stdout"); } if (sp[0] >= 2) @@ -180,7 +183,7 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port, exit(1); } /* Parent. */ - if (pid < 0) + if (pid == -1) fatal("fork failed: %.100s", strerror(errno)); close(sp[0]); free(command_string); @@ -204,8 +207,8 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, u_short port, * Connect to the given ssh server using a proxy command. */ static int -ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port, - const char *proxy_command) +ssh_proxy_connect(struct ssh *ssh, const char *host, const char *host_arg, + u_short port, const char *proxy_command) { char *command_string; int pin[2], pout[2]; @@ -216,12 +219,12 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port, shell = _PATH_BSHELL; /* 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", strerror(errno)); command_string = expand_proxy_command(proxy_command, options.user, - host, port); + host_arg, host, port); debug("Executing proxy command: %.500s", command_string); /* Fork and execute the proxy command. */ @@ -231,12 +234,12 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port, /* Redirect stdin and stdout. */ close(pin[1]); if (pin[0] != 0) { - if (dup2(pin[0], 0) < 0) + if (dup2(pin[0], 0) == -1) perror("dup2 stdin"); close(pin[0]); } close(pout[0]); - if (dup2(pout[1], 1) < 0) + if (dup2(pout[1], 1) == -1) perror("dup2 stdout"); /* Cannot be 1 because pin allocated two descriptors. */ close(pout[1]); @@ -262,7 +265,7 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, u_short port, exit(1); } /* Parent. */ - if (pid < 0) + if (pid == -1) fatal("fork failed: %.100s", strerror(errno)); else proxy_command_pid = pid; /* save pid to clean up later */ @@ -371,7 +374,7 @@ ssh_create_socket(struct addrinfo *ai) char ntop[NI_MAXHOST]; sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (sock < 0) { + if (sock == -1) { error("socket: %s", strerror(errno)); return -1; } @@ -532,20 +535,20 @@ ssh_connect_direct(struct ssh *ssh, const char *host, struct addrinfo *aitop, /* Set SO_KEEPALIVE if requested. */ if (want_keepalive && setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, - sizeof(on)) < 0) + sizeof(on)) == -1) error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno)); /* Set the connection. */ if (ssh_packet_set_connection(ssh, sock, sock) == NULL) return -1; /* ssh_packet_set_connection logs error */ - return 0; + return 0; } int -ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs, - struct sockaddr_storage *hostaddr, u_short port, int family, - int connection_attempts, int *timeout_ms, int want_keepalive) +ssh_connect(struct ssh *ssh, const char *host, const char *host_arg, + struct addrinfo *addrs, struct sockaddr_storage *hostaddr, u_short port, + int family, int connection_attempts, int *timeout_ms, int want_keepalive) { int in, out; @@ -553,8 +556,8 @@ ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs, return ssh_connect_direct(ssh, host, addrs, hostaddr, port, family, connection_attempts, timeout_ms, want_keepalive); } else if (strcmp(options.proxy_command, "-") == 0) { - if ((in = dup(STDIN_FILENO)) < 0 || - (out = dup(STDOUT_FILENO)) < 0) { + if ((in = dup(STDIN_FILENO)) == -1 || + (out = dup(STDOUT_FILENO)) == -1) { if (in >= 0) close(in); error("%s: dup() in/out failed", __func__); @@ -564,10 +567,11 @@ ssh_connect(struct ssh *ssh, const char *host, struct addrinfo *addrs, return -1; /* ssh_packet_set_connection logs error */ return 0; } else if (options.proxy_use_fdpass) { - return ssh_proxy_fdpass_connect(ssh, host, port, + return ssh_proxy_fdpass_connect(ssh, host, host_arg, port, options.proxy_command); } - return ssh_proxy_connect(ssh, host, port, options.proxy_command); + return ssh_proxy_connect(ssh, host, host_arg, port, + options.proxy_command); } /* defaults to 'no' */ @@ -789,7 +793,7 @@ check_host_key(char *hostname, struct sockaddr *hostaddr, u_short port, ip_status = check_key_in_hostkeys(ip_hostkeys, host_key, &ip_found); if (host_status == HOST_CHANGED && - (ip_status != HOST_CHANGED || + (ip_status != HOST_CHANGED || (ip_found != NULL && !sshkey_equal(ip_found->key, host_found->key)))) host_ip_differ = 1; @@ -1292,6 +1296,7 @@ ssh_login(struct ssh *ssh, Sensitive *sensitive, const char *orighost, ssh_kex2(ssh, host, hostaddr, port); ssh_userauth2(ssh, local_user, server_user, host, sensitive); free(local_user); + free(host); } /* print all known host keys for a given host, but skip keys of given type */ @@ -1400,7 +1405,7 @@ ssh_local_cmd(const char *args) } void -maybe_add_key_to_agent(char *authfile, const struct sshkey *private, +maybe_add_key_to_agent(char *authfile, struct sshkey *private, char *comment, char *passphrase) { int auth_sock = -1, r; |
