summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/ssh.c b/ssh.c
index 86f143341..7b482dcb0 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.500 2019/01/19 21:43:56 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.507 2019/09/13 04:27:35 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -162,7 +162,7 @@ char *config = NULL;
162 162
163/* 163/*
164 * Name of the host we are connecting to. This is the name given on the 164 * Name of the host we are connecting to. This is the name given on the
165 * command line, or the HostName specified for the user-supplied name in a 165 * command line, or the Hostname specified for the user-supplied name in a
166 * configuration file. 166 * configuration file.
167 */ 167 */
168char *host; 168char *host;
@@ -236,7 +236,8 @@ resolve_host(const char *name, int port, int logerr, char *cname, size_t clen)
236{ 236{
237 char strport[NI_MAXSERV]; 237 char strport[NI_MAXSERV];
238 struct addrinfo hints, *res; 238 struct addrinfo hints, *res;
239 int gaierr, loglevel = SYSLOG_LEVEL_DEBUG1; 239 int gaierr;
240 LogLevel loglevel = SYSLOG_LEVEL_DEBUG1;
240 241
241 if (port <= 0) 242 if (port <= 0)
242 port = default_ssh_port(); 243 port = default_ssh_port();
@@ -595,7 +596,6 @@ main(int ac, char **av)
595 struct ssh_digest_ctx *md; 596 struct ssh_digest_ctx *md;
596 u_char conn_hash[SSH_DIGEST_MAX_LENGTH]; 597 u_char conn_hash[SSH_DIGEST_MAX_LENGTH];
597 598
598 ssh_malloc_init(); /* must be called before any mallocs */
599 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ 599 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
600 sanitise_stdfd(); 600 sanitise_stdfd();
601 601
@@ -775,7 +775,7 @@ main(int ac, char **av)
775 break; 775 break;
776 case 'i': 776 case 'i':
777 p = tilde_expand_filename(optarg, getuid()); 777 p = tilde_expand_filename(optarg, getuid());
778 if (stat(p, &st) < 0) 778 if (stat(p, &st) == -1)
779 fprintf(stderr, "Warning: Identity file %s " 779 fprintf(stderr, "Warning: Identity file %s "
780 "not accessible: %s.\n", p, 780 "not accessible: %s.\n", p,
781 strerror(errno)); 781 strerror(errno));
@@ -792,8 +792,11 @@ main(int ac, char **av)
792#endif 792#endif
793 break; 793 break;
794 case 'J': 794 case 'J':
795 if (options.jump_host != NULL) 795 if (options.jump_host != NULL) {
796 fatal("Only a single -J option permitted"); 796 fatal("Only a single -J option is permitted "
797 "(use commas to separate multiple "
798 "jump hops)");
799 }
797 if (options.proxy_command != NULL) 800 if (options.proxy_command != NULL)
798 fatal("Cannot specify -J with ProxyCommand"); 801 fatal("Cannot specify -J with ProxyCommand");
799 if (parse_jump(optarg, &options, 1) == -1) 802 if (parse_jump(optarg, &options, 1) == -1)
@@ -876,7 +879,7 @@ main(int ac, char **av)
876 } 879 }
877 break; 880 break;
878 case 'c': 881 case 'c':
879 if (!ciphers_valid(*optarg == '+' ? 882 if (!ciphers_valid(*optarg == '+' || *optarg == '^' ?
880 optarg + 1 : optarg)) { 883 optarg + 1 : optarg)) {
881 fprintf(stderr, "Unknown cipher type '%s'\n", 884 fprintf(stderr, "Unknown cipher type '%s'\n",
882 optarg); 885 optarg);
@@ -1368,7 +1371,7 @@ main(int ac, char **av)
1368 timeout_ms = options.connection_timeout * 1000; 1371 timeout_ms = options.connection_timeout * 1000;
1369 1372
1370 /* Open a connection to the remote host. */ 1373 /* Open a connection to the remote host. */
1371 if (ssh_connect(ssh, host, addrs, &hostaddr, options.port, 1374 if (ssh_connect(ssh, host_arg, host, addrs, &hostaddr, options.port,
1372 options.address_family, options.connection_attempts, 1375 options.address_family, options.connection_attempts,
1373 &timeout_ms, options.tcp_keep_alive) != 0) 1376 &timeout_ms, options.tcp_keep_alive) != 0)
1374 exit(255); 1377 exit(255);
@@ -1425,7 +1428,7 @@ main(int ac, char **av)
1425 if (config == NULL) { 1428 if (config == NULL) {
1426 r = snprintf(buf, sizeof buf, "%s%s%s", pw->pw_dir, 1429 r = snprintf(buf, sizeof buf, "%s%s%s", pw->pw_dir,
1427 strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR); 1430 strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR);
1428 if (r > 0 && (size_t)r < sizeof(buf) && stat(buf, &st) < 0) { 1431 if (r > 0 && (size_t)r < sizeof(buf) && stat(buf, &st) == -1) {
1429#ifdef WITH_SELINUX 1432#ifdef WITH_SELINUX
1430 ssh_selinux_setfscreatecon(buf); 1433 ssh_selinux_setfscreatecon(buf);
1431#endif 1434#endif
@@ -1592,7 +1595,7 @@ fork_postauth(void)
1592 control_persist_detach(); 1595 control_persist_detach();
1593 debug("forking to background"); 1596 debug("forking to background");
1594 fork_after_authentication_flag = 0; 1597 fork_after_authentication_flag = 0;
1595 if (daemon(1, 1) < 0) 1598 if (daemon(1, 1) == -1)
1596 fatal("daemon() failed: %.200s", strerror(errno)); 1599 fatal("daemon() failed: %.200s", strerror(errno));
1597} 1600}
1598 1601
@@ -1688,8 +1691,8 @@ ssh_init_stdio_forwarding(struct ssh *ssh)
1688 debug3("%s: %s:%d", __func__, options.stdio_forward_host, 1691 debug3("%s: %s:%d", __func__, options.stdio_forward_host,
1689 options.stdio_forward_port); 1692 options.stdio_forward_port);
1690 1693
1691 if ((in = dup(STDIN_FILENO)) < 0 || 1694 if ((in = dup(STDIN_FILENO)) == -1 ||
1692 (out = dup(STDOUT_FILENO)) < 0) 1695 (out = dup(STDOUT_FILENO)) == -1)
1693 fatal("channel_connect_stdio_fwd: dup() in/out failed"); 1696 fatal("channel_connect_stdio_fwd: dup() in/out failed");
1694 if ((c = channel_connect_stdio_fwd(ssh, options.stdio_forward_host, 1697 if ((c = channel_connect_stdio_fwd(ssh, options.stdio_forward_host,
1695 options.stdio_forward_port, in, out)) == NULL) 1698 options.stdio_forward_port, in, out)) == NULL)
@@ -1842,7 +1845,7 @@ ssh_session2_open(struct ssh *ssh)
1842 out = dup(STDOUT_FILENO); 1845 out = dup(STDOUT_FILENO);
1843 err = dup(STDERR_FILENO); 1846 err = dup(STDERR_FILENO);
1844 1847
1845 if (in < 0 || out < 0 || err < 0) 1848 if (in == -1 || out == -1 || err == -1)
1846 fatal("dup() in/out/err failed"); 1849 fatal("dup() in/out/err failed");
1847 1850
1848 /* enable nonblocking unless tty */ 1851 /* enable nonblocking unless tty */
@@ -1973,7 +1976,7 @@ ssh_session2(struct ssh *ssh, struct passwd *pw)
1973 if ((devnull = open(_PATH_DEVNULL, O_WRONLY)) == -1) 1976 if ((devnull = open(_PATH_DEVNULL, O_WRONLY)) == -1)
1974 error("%s: open %s: %s", __func__, 1977 error("%s: open %s: %s", __func__,
1975 _PATH_DEVNULL, strerror(errno)); 1978 _PATH_DEVNULL, strerror(errno));
1976 if (dup2(devnull, STDOUT_FILENO) < 0) 1979 if (dup2(devnull, STDOUT_FILENO) == -1)
1977 fatal("%s: dup2() stdout failed", __func__); 1980 fatal("%s: dup2() stdout failed", __func__);
1978 if (devnull > STDERR_FILENO) 1981 if (devnull > STDERR_FILENO)
1979 close(devnull); 1982 close(devnull);
@@ -2160,7 +2163,7 @@ main_sigchld_handler(int sig)
2160 int status; 2163 int status;
2161 2164
2162 while ((pid = waitpid(-1, &status, WNOHANG)) > 0 || 2165 while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
2163 (pid < 0 && errno == EINTR)) 2166 (pid == -1 && errno == EINTR))
2164 ; 2167 ;
2165 errno = save_errno; 2168 errno = save_errno;
2166} 2169}