version 1.256, 2015/01/18 21:49:42 |
version 1.257, 2015/01/18 21:51:19 |
|
|
} |
} |
|
|
struct known_hosts_ctx { |
struct known_hosts_ctx { |
FILE *out; |
const char *host; /* Hostname searched for in find/delete case */ |
const char *host; |
FILE *out; /* Output file, stdout for find_hosts case */ |
int has_unhashed, found_key, inplace, invalid; |
int has_unhashed; /* When hashing, original had unhashed hosts */ |
|
int found_key; /* For find/delete, host was found */ |
|
int invalid; /* File contained invalid items; don't delete */ |
}; |
}; |
|
|
static int |
static int |
|
|
fprintf(stderr, "%s:%ld: ignoring host name " |
fprintf(stderr, "%s:%ld: ignoring host name " |
"with wildcard: %.64s\n", l->path, |
"with wildcard: %.64s\n", l->path, |
l->linenum, l->hosts); |
l->linenum, l->hosts); |
ctx->has_unhashed = 1; |
|
} |
} |
return 0; |
return 0; |
} |
} |
|
|
do_known_hosts(struct passwd *pw, const char *name) |
do_known_hosts(struct passwd *pw, const char *name) |
{ |
{ |
char *cp, tmp[MAXPATHLEN], old[MAXPATHLEN]; |
char *cp, tmp[MAXPATHLEN], old[MAXPATHLEN]; |
int r, fd, oerrno; |
int r, fd, oerrno, inplace = 0; |
struct known_hosts_ctx ctx; |
struct known_hosts_ctx ctx; |
|
|
if (!have_identity) { |
if (!have_identity) { |
|
|
unlink(tmp); |
unlink(tmp); |
fatal("fdopen: %s", strerror(oerrno)); |
fatal("fdopen: %s", strerror(oerrno)); |
} |
} |
ctx.inplace = 1; |
inplace = 1; |
} |
} |
|
|
/* XXX support identity_file == "-" for stdin */ |
/* XXX support identity_file == "-" for stdin */ |
|
|
name, find_host ? HKF_WANT_MATCH_HOST : 0)) != 0) |
name, find_host ? HKF_WANT_MATCH_HOST : 0)) != 0) |
fatal("%s: hostkeys_foreach failed: %s", __func__, ssh_err(r)); |
fatal("%s: hostkeys_foreach failed: %s", __func__, ssh_err(r)); |
|
|
if (ctx.inplace) |
if (inplace) |
fclose(ctx.out); |
fclose(ctx.out); |
|
|
if (ctx.invalid) { |
if (ctx.invalid) { |
fprintf(stderr, "%s is not a valid known_hosts file.\n", |
fprintf(stderr, "%s is not a valid known_hosts file.\n", |
identity_file); |
identity_file); |
if (ctx.inplace) { |
if (inplace) { |
fprintf(stderr, "Not replacing existing known_hosts " |
fprintf(stderr, "Not replacing existing known_hosts " |
"file because of errors\n"); |
"file because of errors\n"); |
unlink(tmp); |
unlink(tmp); |
|
|
fprintf(stderr, "Host %s not found in %s\n", |
fprintf(stderr, "Host %s not found in %s\n", |
name, identity_file); |
name, identity_file); |
unlink(tmp); |
unlink(tmp); |
} else if (ctx.inplace) { |
} else if (inplace) { |
/* Backup existing file */ |
/* Backup existing file */ |
if (unlink(old) == -1 && errno != ENOENT) |
if (unlink(old) == -1 && errno != ENOENT) |
fatal("unlink %.100s: %s", old, strerror(errno)); |
fatal("unlink %.100s: %s", old, strerror(errno)); |