summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2015-01-18 21:51:19 +0000
committerDamien Miller <djm@mindrot.org>2015-01-20 00:20:44 +1100
commit2b3c3c76c30dc5076fe09d590f5b26880f148a54 (patch)
tree7b16591f1a13d7e4dcd2d86996443480fabe716e /ssh-keygen.c
parentcecb30bc2ba6d594366e657d664d5c494b6c8a7f (diff)
upstream commit
some feedback from markus@: comment hostkeys_foreach() context and avoid a member in it.
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 02db8b2bd..624cdebdb 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.256 2015/01/18 21:49:42 djm Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.257 2015/01/18 21:51:19 djm 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
@@ -1032,9 +1032,11 @@ do_gen_all_hostkeys(struct passwd *pw)
1032} 1032}
1033 1033
1034struct known_hosts_ctx { 1034struct known_hosts_ctx {
1035 FILE *out; 1035 const char *host; /* Hostname searched for in find/delete case */
1036 const char *host; 1036 FILE *out; /* Output file, stdout for find_hosts case */
1037 int has_unhashed, found_key, inplace, invalid; 1037 int has_unhashed; /* When hashing, original had unhashed hosts */
1038 int found_key; /* For find/delete, host was found */
1039 int invalid; /* File contained invalid items; don't delete */
1038}; 1040};
1039 1041
1040static int 1042static int
@@ -1062,7 +1064,6 @@ known_hosts_hash(struct hostkey_foreach_line *l, void *_ctx)
1062 fprintf(stderr, "%s:%ld: ignoring host name " 1064 fprintf(stderr, "%s:%ld: ignoring host name "
1063 "with wildcard: %.64s\n", l->path, 1065 "with wildcard: %.64s\n", l->path,
1064 l->linenum, l->hosts); 1066 l->linenum, l->hosts);
1065 ctx->has_unhashed = 1;
1066 } 1067 }
1067 return 0; 1068 return 0;
1068 } 1069 }
@@ -1133,7 +1134,7 @@ static void
1133do_known_hosts(struct passwd *pw, const char *name) 1134do_known_hosts(struct passwd *pw, const char *name)
1134{ 1135{
1135 char *cp, tmp[MAXPATHLEN], old[MAXPATHLEN]; 1136 char *cp, tmp[MAXPATHLEN], old[MAXPATHLEN];
1136 int r, fd, oerrno; 1137 int r, fd, oerrno, inplace = 0;
1137 struct known_hosts_ctx ctx; 1138 struct known_hosts_ctx ctx;
1138 1139
1139 if (!have_identity) { 1140 if (!have_identity) {
@@ -1167,7 +1168,7 @@ do_known_hosts(struct passwd *pw, const char *name)
1167 unlink(tmp); 1168 unlink(tmp);
1168 fatal("fdopen: %s", strerror(oerrno)); 1169 fatal("fdopen: %s", strerror(oerrno));
1169 } 1170 }
1170 ctx.inplace = 1; 1171 inplace = 1;
1171 } 1172 }
1172 1173
1173 /* XXX support identity_file == "-" for stdin */ 1174 /* XXX support identity_file == "-" for stdin */
@@ -1176,13 +1177,13 @@ do_known_hosts(struct passwd *pw, const char *name)
1176 name, find_host ? HKF_WANT_MATCH_HOST : 0)) != 0) 1177 name, find_host ? HKF_WANT_MATCH_HOST : 0)) != 0)
1177 fatal("%s: hostkeys_foreach failed: %s", __func__, ssh_err(r)); 1178 fatal("%s: hostkeys_foreach failed: %s", __func__, ssh_err(r));
1178 1179
1179 if (ctx.inplace) 1180 if (inplace)
1180 fclose(ctx.out); 1181 fclose(ctx.out);
1181 1182
1182 if (ctx.invalid) { 1183 if (ctx.invalid) {
1183 fprintf(stderr, "%s is not a valid known_hosts file.\n", 1184 fprintf(stderr, "%s is not a valid known_hosts file.\n",
1184 identity_file); 1185 identity_file);
1185 if (ctx.inplace) { 1186 if (inplace) {
1186 fprintf(stderr, "Not replacing existing known_hosts " 1187 fprintf(stderr, "Not replacing existing known_hosts "
1187 "file because of errors\n"); 1188 "file because of errors\n");
1188 unlink(tmp); 1189 unlink(tmp);
@@ -1192,7 +1193,7 @@ do_known_hosts(struct passwd *pw, const char *name)
1192 fprintf(stderr, "Host %s not found in %s\n", 1193 fprintf(stderr, "Host %s not found in %s\n",
1193 name, identity_file); 1194 name, identity_file);
1194 unlink(tmp); 1195 unlink(tmp);
1195 } else if (ctx.inplace) { 1196 } else if (inplace) {
1196 /* Backup existing file */ 1197 /* Backup existing file */
1197 if (unlink(old) == -1 && errno != ENOENT) 1198 if (unlink(old) == -1 && errno != ENOENT)
1198 fatal("unlink %.100s: %s", old, strerror(errno)); 1199 fatal("unlink %.100s: %s", old, strerror(errno));