summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2010-06-26 09:39:07 +1000
committerDamien Miller <djm@mindrot.org>2010-06-26 09:39:07 +1000
commitba3420acd2aceae99aa317ef539b85b047aa6c86 (patch)
treef9a7ca98ec0ab71121e88ead5ef5202d82d64e43
parentab6de351404d5a691a89cf2c9fbe9438271bd03d (diff)
- djm@cvs.openbsd.org 2010/06/22 04:32:06
[ssh-keygen.c] standardise error messages when attempting to open private key files to include "progname: filename: error reason" bz#1783; ok dtucker@
-rw-r--r--ChangeLog5
-rw-r--r--ssh-keygen.c126
2 files changed, 66 insertions, 65 deletions
diff --git a/ChangeLog b/ChangeLog
index 6ca101ab1..fc7ac30ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -31,6 +31,11 @@
31 AuthorizedKeysFile AuthorizedPrincipalsFile 31 AuthorizedKeysFile AuthorizedPrincipalsFile
32 HostbasedUsesNameFromPacketOnly PermitTunnel 32 HostbasedUsesNameFromPacketOnly PermitTunnel
33 bz#1764; feedback from imorgan AT nas.nasa.gov; ok dtucker@ 33 bz#1764; feedback from imorgan AT nas.nasa.gov; ok dtucker@
34 - djm@cvs.openbsd.org 2010/06/22 04:32:06
35 [ssh-keygen.c]
36 standardise error messages when attempting to open private key
37 files to include "progname: filename: error reason"
38 bz#1783; ok dtucker@
34 39
3520100622 4020100622
36 - (djm) [loginrec.c] crank LINFO_NAMESIZE (username length) to 512 41 - (djm) [loginrec.c] crank LINFO_NAMESIZE (username length) to 512
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 14eee6f87..121f94060 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.190 2010/05/20 23:46:02 djm Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.191 2010/06/22 04:32:06 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
@@ -414,11 +414,8 @@ do_convert_from_ssh2(struct passwd *pw)
414 perror(identity_file); 414 perror(identity_file);
415 exit(1); 415 exit(1);
416 } 416 }
417 fp = fopen(identity_file, "r"); 417 if ((fp = fopen(identity_file, "r")) == NULL)
418 if (fp == NULL) { 418 fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
419 perror(identity_file);
420 exit(1);
421 }
422 encoded[0] = '\0'; 419 encoded[0] = '\0';
423 while ((blen = get_line(fp, line, sizeof(line))) != -1) { 420 while ((blen = get_line(fp, line, sizeof(line))) != -1) {
424 if (line[blen - 1] == '\\') 421 if (line[blen - 1] == '\\')
@@ -561,67 +558,68 @@ do_fingerprint(struct passwd *pw)
561 comment = NULL; 558 comment = NULL;
562 } 559 }
563 560
564 f = fopen(identity_file, "r"); 561 if ((f = fopen(identity_file, "r")) == NULL)
565 if (f != NULL) { 562 fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
566 while (fgets(line, sizeof(line), f)) {
567 if ((cp = strchr(line, '\n')) == NULL) {
568 error("line %d too long: %.40s...",
569 num + 1, line);
570 skip = 1;
571 continue;
572 }
573 num++;
574 if (skip) {
575 skip = 0;
576 continue;
577 }
578 *cp = '\0';
579 563
580 /* Skip leading whitespace, empty and comment lines. */ 564 while (fgets(line, sizeof(line), f)) {
581 for (cp = line; *cp == ' ' || *cp == '\t'; cp++) 565 if ((cp = strchr(line, '\n')) == NULL) {
582 ; 566 error("line %d too long: %.40s...",
583 if (!*cp || *cp == '\n' || *cp == '#') 567 num + 1, line);
584 continue; 568 skip = 1;
585 i = strtol(cp, &ep, 10); 569 continue;
586 if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) { 570 }
587 int quoted = 0; 571 num++;
588 comment = cp; 572 if (skip) {
589 for (; *cp && (quoted || (*cp != ' ' && 573 skip = 0;
590 *cp != '\t')); cp++) { 574 continue;
591 if (*cp == '\\' && cp[1] == '"') 575 }
592 cp++; /* Skip both */ 576 *cp = '\0';
593 else if (*cp == '"') 577
594 quoted = !quoted; 578 /* Skip leading whitespace, empty and comment lines. */
595 } 579 for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
596 if (!*cp) 580 ;
597 continue; 581 if (!*cp || *cp == '\n' || *cp == '#')
598 *cp++ = '\0'; 582 continue;
583 i = strtol(cp, &ep, 10);
584 if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) {
585 int quoted = 0;
586 comment = cp;
587 for (; *cp && (quoted || (*cp != ' ' &&
588 *cp != '\t')); cp++) {
589 if (*cp == '\\' && cp[1] == '"')
590 cp++; /* Skip both */
591 else if (*cp == '"')
592 quoted = !quoted;
599 } 593 }
600 ep = cp; 594 if (!*cp)
601 public = key_new(KEY_RSA1); 595 continue;
596 *cp++ = '\0';
597 }
598 ep = cp;
599 public = key_new(KEY_RSA1);
600 if (key_read(public, &cp) != 1) {
601 cp = ep;
602 key_free(public);
603 public = key_new(KEY_UNSPEC);
602 if (key_read(public, &cp) != 1) { 604 if (key_read(public, &cp) != 1) {
603 cp = ep;
604 key_free(public); 605 key_free(public);
605 public = key_new(KEY_UNSPEC); 606 continue;
606 if (key_read(public, &cp) != 1) {
607 key_free(public);
608 continue;
609 }
610 } 607 }
611 comment = *cp ? cp : comment;
612 fp = key_fingerprint(public, fptype, rep);
613 ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART);
614 printf("%u %s %s (%s)\n", key_size(public), fp,
615 comment ? comment : "no comment", key_type(public));
616 if (log_level >= SYSLOG_LEVEL_VERBOSE)
617 printf("%s\n", ra);
618 xfree(ra);
619 xfree(fp);
620 key_free(public);
621 invalid = 0;
622 } 608 }
623 fclose(f); 609 comment = *cp ? cp : comment;
610 fp = key_fingerprint(public, fptype, rep);
611 ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART);
612 printf("%u %s %s (%s)\n", key_size(public), fp,
613 comment ? comment : "no comment", key_type(public));
614 if (log_level >= SYSLOG_LEVEL_VERBOSE)
615 printf("%s\n", ra);
616 xfree(ra);
617 xfree(fp);
618 key_free(public);
619 invalid = 0;
624 } 620 }
621 fclose(f);
622
625 if (invalid) { 623 if (invalid) {
626 printf("%s is not a public key file.\n", identity_file); 624 printf("%s is not a public key file.\n", identity_file);
627 exit(1); 625 exit(1);
@@ -676,7 +674,7 @@ do_known_hosts(struct passwd *pw, const char *name)
676 have_identity = 1; 674 have_identity = 1;
677 } 675 }
678 if ((in = fopen(identity_file, "r")) == NULL) 676 if ((in = fopen(identity_file, "r")) == NULL)
679 fatal("fopen: %s", strerror(errno)); 677 fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
680 678
681 /* 679 /*
682 * Find hosts goes to stdout, hash and deletions happen in-place 680 * Find hosts goes to stdout, hash and deletions happen in-place
@@ -1423,10 +1421,8 @@ do_show_cert(struct passwd *pw)
1423 1421
1424 if (!have_identity) 1422 if (!have_identity)
1425 ask_filename(pw, "Enter file in which the key is"); 1423 ask_filename(pw, "Enter file in which the key is");
1426 if (stat(identity_file, &st) < 0) { 1424 if (stat(identity_file, &st) < 0)
1427 perror(identity_file); 1425 fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
1428 exit(1);
1429 }
1430 if ((key = key_load_public(identity_file, NULL)) == NULL) 1426 if ((key = key_load_public(identity_file, NULL)) == NULL)
1431 fatal("%s is not a public key", identity_file); 1427 fatal("%s is not a public key", identity_file);
1432 if (!key_is_cert(key)) 1428 if (!key_is_cert(key))