summaryrefslogtreecommitdiffstats
path: root/usr.bin/ssh/ssh-keyscan.c
diff options
context:
space:
mode:
authordjm <djm@openbsd.org>2015-10-24 22:56:19 +0000
committerdjm <djm@openbsd.org>2015-10-24 22:56:19 +0000
commita906b0cbc74b13321d175bc351920ab64a12b3bc (patch)
treeff299d7a05a103daa2bd35935233ea6073e09b60 /usr.bin/ssh/ssh-keyscan.c
parentskip "Could not chdir to home directory" message when chrooted (diff)
downloadwireguard-openbsd-a906b0cbc74b13321d175bc351920ab64a12b3bc.tar.xz
wireguard-openbsd-a906b0cbc74b13321d175bc351920ab64a12b3bc.zip
fix keyscan output for multiple hosts/addrs on one line when
host hashing or a non standard port is in use; bz#2479 ok dtucker@
Diffstat (limited to 'usr.bin/ssh/ssh-keyscan.c')
-rw-r--r--usr.bin/ssh/ssh-keyscan.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/usr.bin/ssh/ssh-keyscan.c b/usr.bin/ssh/ssh-keyscan.c
index 85bfb7a25ce..2ed32deb1a5 100644
--- a/usr.bin/ssh/ssh-keyscan.c
+++ b/usr.bin/ssh/ssh-keyscan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keyscan.c,v 1.101 2015/04/10 00:08:55 djm Exp $ */
+/* $OpenBSD: ssh-keyscan.c,v 1.102 2015/10/24 22:56:19 djm Exp $ */
/*
* Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
*
@@ -276,13 +276,10 @@ keygrab_ssh2(con *c)
}
static void
-keyprint(con *c, struct sshkey *key)
+keyprint_one(char *host, struct sshkey *key)
{
- char *host = c->c_output_name ? c->c_output_name : c->c_name;
- char *hostport = NULL;
+ char *hostport;
- if (!key)
- return;
if (hash_hosts && (host = host_hash(host, NULL, 0)) == NULL)
fatal("host_hash failed");
@@ -293,6 +290,24 @@ keyprint(con *c, struct sshkey *key)
free(hostport);
}
+static void
+keyprint(con *c, struct sshkey *key)
+{
+ char *hosts = c->c_output_name ? c->c_output_name : c->c_name;
+ char *host, *ohosts;
+
+ if (key == NULL)
+ return;
+ if (!hash_hosts && ssh_port == SSH_DEFAULT_PORT) {
+ keyprint_one(hosts, key);
+ return;
+ }
+ ohosts = hosts = xstrdup(hosts);
+ while ((host = strsep(&hosts, ",")) != NULL)
+ keyprint_one(host, key);
+ free(ohosts);
+}
+
static int
tcpconnect(char *host)
{