]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream commit
authordjm@openbsd.org <djm@openbsd.org>
Sat, 24 Oct 2015 22:56:19 +0000 (22:56 +0000)
committerDamien Miller <djm@mindrot.org>
Sun, 25 Oct 2015 00:42:07 +0000 (11:42 +1100)
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@

Upstream-ID: 5321dabfaeceba343da3c8a8b5754c6f4a0a307b

ssh-keyscan.c

index 57d88429b059ba6a5337da25c0f844ba7c9b896b..7db0e10e536d894c7e7f16bdf067750ab1f408f9 100644 (file)
@@ -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>.
  *
@@ -296,13 +296,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");
 
@@ -313,6 +310,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)
 {