From 3eff92ec990017265e24eed1c233dfced3fa21a8 Mon Sep 17 00:00:00 2001 From: djm Date: Sun, 26 Mar 2006 02:48:01 +0000 Subject: [PATCH] - OpenBSD CVS Sync - jakob@cvs.openbsd.org 2006/03/15 08:46:44 [ssh-keygen.c] if no key file are given when printing the DNS host record, use the host key file(s) as default. ok djm@ --- ChangeLog | 7 +++++++ ssh-keygen.c | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70a35a66..9d8dee10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +20060326 + - OpenBSD CVS Sync + - jakob@cvs.openbsd.org 2006/03/15 08:46:44 + [ssh-keygen.c] + if no key file are given when printing the DNS host record, use the + host key file(s) as default. ok djm@ + 20060325 - OpenBSD CVS Sync - djm@cvs.openbsd.org 2006/03/16 04:24:42 diff --git a/ssh-keygen.c b/ssh-keygen.c index c527252b..12655646 100644 --- a/ssh-keygen.c +++ b/ssh-keygen.c @@ -858,30 +858,32 @@ do_change_passphrase(struct passwd *pw) /* * Print the SSHFP RR. */ -static void -do_print_resource_record(struct passwd *pw, char *hname) +static int +do_print_resource_record(struct passwd *pw, char *fname, char *hname) { Key *public; char *comment = NULL; struct stat st; - if (!have_identity) + if (fname == NULL) ask_filename(pw, "Enter file in which the key is"); - if (stat(identity_file, &st) < 0) { - perror(identity_file); + if (stat(fname, &st) < 0) { + if (errno == ENOENT) + return 0; + perror(fname); exit(1); } - public = key_load_public(identity_file, &comment); + public = key_load_public(fname, &comment); if (public != NULL) { export_dns_rr(hname, public, stdout, print_generic); key_free(public); xfree(comment); - exit(0); + return 1; } if (comment) xfree(comment); - printf("failed to read v2 public key from %s.\n", identity_file); + printf("failed to read v2 public key from %s.\n", fname); exit(1); } @@ -1224,7 +1226,27 @@ main(int ac, char **av) if (print_public) do_print_public(pw); if (rr_hostname != NULL) { - do_print_resource_record(pw, rr_hostname); + unsigned int n = 0; + + if (have_identity) { + n = do_print_resource_record(pw, + identity_file, rr_hostname); + if (n == 0) { + perror(identity_file); + exit(1); + } + exit(0); + } else { + + n += do_print_resource_record(pw, + _PATH_HOST_RSA_KEY_FILE, rr_hostname); + n += do_print_resource_record(pw, + _PATH_HOST_DSA_KEY_FILE, rr_hostname); + + if (n == 0) + fatal("no keys found."); + exit(0); + } } if (reader_id != NULL) { #ifdef SMARTCARD -- 2.45.1