summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJakob Schlyter <jakob@cvs.openbsd.org>2006-03-15 08:46:45 +0000
committerJakob Schlyter <jakob@cvs.openbsd.org>2006-03-15 08:46:45 +0000
commite83f53bb855669ad1ea9af15b06d0cf575334c41 (patch)
tree0c1905a3311a9531c3aab33a1dc07c9474999c74 /usr.bin
parentda6c1c6aef921ae5d3540bc3d81d080c145c97df (diff)
if no key file are given when printing the DNS host record, use the
host key file(s) as default. ok djm@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ssh/ssh-keygen.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/usr.bin/ssh/ssh-keygen.c b/usr.bin/ssh/ssh-keygen.c
index 8554e2a66b9..e118e4e2b45 100644
--- a/usr.bin/ssh/ssh-keygen.c
+++ b/usr.bin/ssh/ssh-keygen.c
@@ -12,7 +12,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh-keygen.c,v 1.137 2006/03/13 08:43:16 dtucker Exp $");
+RCSID("$OpenBSD: ssh-keygen.c,v 1.138 2006/03/15 08:46:44 jakob Exp $");
#include <sys/types.h>
#include <sys/stat.h>
@@ -859,30 +859,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);
}
@@ -1220,7 +1222,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