summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2013-09-14 09:45:03 +1000
committerDamien Miller <djm@mindrot.org>2013-09-14 09:45:03 +1000
commit660854859cad31d234edb9353fb7ca2780df8128 (patch)
treeb445d042762c31c679390f97fffd1bb194140bb0 /ssh-keygen.c
parent045bda5cb8acf0eb9d71c275ee1247e3154fc9e5 (diff)
- mikeb@cvs.openbsd.org 2013/08/28 12:34:27
[ssh-keygen.c] improve batch processing a bit by making use of the quite flag a bit more often and exit with a non zero code if asked to find a hostname in a known_hosts file and it wasn't there; originally from reyk@, ok djm
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 6ee8145af..9c19f00d0 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.232 2013/08/13 18:33:08 djm Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.233 2013/08/28 12:34:27 mikeb Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1001,6 +1001,7 @@ do_known_hosts(struct passwd *pw, const char *name)
1001 char line[16*1024], tmp[MAXPATHLEN], old[MAXPATHLEN]; 1001 char line[16*1024], tmp[MAXPATHLEN], old[MAXPATHLEN];
1002 int c, skip = 0, inplace = 0, num = 0, invalid = 0, has_unhashed = 0; 1002 int c, skip = 0, inplace = 0, num = 0, invalid = 0, has_unhashed = 0;
1003 int ca; 1003 int ca;
1004 int found_key = 0;
1004 1005
1005 if (!have_identity) { 1006 if (!have_identity) {
1006 cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid); 1007 cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid);
@@ -1103,11 +1104,13 @@ do_known_hosts(struct passwd *pw, const char *name)
1103 } 1104 }
1104 c = (strcmp(cp2, cp) == 0); 1105 c = (strcmp(cp2, cp) == 0);
1105 if (find_host && c) { 1106 if (find_host && c) {
1106 printf("# Host %s found: " 1107 if (!quiet)
1107 "line %d type %s%s\n", name, 1108 printf("# Host %s found: "
1108 num, key_type(pub), 1109 "line %d type %s%s\n", name,
1109 ca ? " (CA key)" : ""); 1110 num, key_type(pub),
1111 ca ? " (CA key)" : "");
1110 printhost(out, cp, pub, ca, 0); 1112 printhost(out, cp, pub, ca, 0);
1113 found_key = 1;
1111 } 1114 }
1112 if (delete_host) { 1115 if (delete_host) {
1113 if (!c && !ca) 1116 if (!c && !ca)
@@ -1124,12 +1127,14 @@ do_known_hosts(struct passwd *pw, const char *name)
1124 c = (match_hostname(name, cp, 1127 c = (match_hostname(name, cp,
1125 strlen(cp)) == 1); 1128 strlen(cp)) == 1);
1126 if (find_host && c) { 1129 if (find_host && c) {
1127 printf("# Host %s found: " 1130 if (!quiet)
1128 "line %d type %s%s\n", name, 1131 printf("# Host %s found: "
1129 num, key_type(pub), 1132 "line %d type %s%s\n", name,
1130 ca ? " (CA key)" : ""); 1133 num, key_type(pub),
1134 ca ? " (CA key)" : "");
1131 printhost(out, name, pub, 1135 printhost(out, name, pub,
1132 ca, hash_hosts && !ca); 1136 ca, hash_hosts && !ca);
1137 found_key = 1;
1133 } 1138 }
1134 if (delete_host) { 1139 if (delete_host) {
1135 if (!c && !ca) 1140 if (!c && !ca)
@@ -1205,7 +1210,7 @@ do_known_hosts(struct passwd *pw, const char *name)
1205 } 1210 }
1206 } 1211 }
1207 1212
1208 exit(0); 1213 exit (find_host && !found_key);
1209} 1214}
1210 1215
1211/* 1216/*