summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
authorlum@openbsd.org <lum@openbsd.org>2019-05-29 08:30:26 +0000
committerDarren Tucker <dtucker@dtucker.net>2019-06-08 00:20:01 +1000
commit410b231aa41ff830b2f5b09b5aaf5e5cdc1ab86b (patch)
treed57e3e0c0d3ecf66ade2fbf9b04bd1248b34456f /ssh-keygen.c
parent2b3402dc9f1d9b0df70291b424f36e436cdfa7e0 (diff)
upstream: Make the standard output messages of both methods of
changing a key pair's comments (using -c and -C) more applicable to both methods. ok and suggestions djm@ dtucker@ OpenBSD-Commit-ID: b379338118109eb36e14a65bc0a12735205b3de6
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 3898b281e..db371090d 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.329 2019/03/25 16:19:44 dtucker Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.330 2019/05/29 08:30:26 lum 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
@@ -1488,14 +1488,14 @@ do_change_comment(struct passwd *pw, const char *identity_comment)
1488 exit(1); 1488 exit(1);
1489 } 1489 }
1490 if (comment) 1490 if (comment)
1491 printf("Key now has comment '%s'\n", comment); 1491 printf("Old comment: %s\n", comment);
1492 else 1492 else
1493 printf("Key now has no comment\n"); 1493 printf("No existing comment\n");
1494 1494
1495 if (identity_comment) { 1495 if (identity_comment) {
1496 strlcpy(new_comment, identity_comment, sizeof(new_comment)); 1496 strlcpy(new_comment, identity_comment, sizeof(new_comment));
1497 } else { 1497 } else {
1498 printf("Enter new comment: "); 1498 printf("New comment: ");
1499 fflush(stdout); 1499 fflush(stdout);
1500 if (!fgets(new_comment, sizeof(new_comment), stdin)) { 1500 if (!fgets(new_comment, sizeof(new_comment), stdin)) {
1501 explicit_bzero(passphrase, strlen(passphrase)); 1501 explicit_bzero(passphrase, strlen(passphrase));
@@ -1504,6 +1504,13 @@ do_change_comment(struct passwd *pw, const char *identity_comment)
1504 } 1504 }
1505 new_comment[strcspn(new_comment, "\n")] = '\0'; 1505 new_comment[strcspn(new_comment, "\n")] = '\0';
1506 } 1506 }
1507 if (comment != NULL && strcmp(comment, new_comment) == 0) {
1508 printf("No change to comment\n");
1509 free(passphrase);
1510 sshkey_free(private);
1511 free(comment);
1512 exit(0);
1513 }
1507 1514
1508 /* Save the file using the new passphrase. */ 1515 /* Save the file using the new passphrase. */
1509 if ((r = sshkey_save_private(private, identity_file, passphrase, 1516 if ((r = sshkey_save_private(private, identity_file, passphrase,
@@ -1537,7 +1544,11 @@ do_change_comment(struct passwd *pw, const char *identity_comment)
1537 1544
1538 free(comment); 1545 free(comment);
1539 1546
1540 printf("The comment in your key file has been changed.\n"); 1547 if (strlen(new_comment) > 0)
1548 printf("Comment '%s' applied\n", new_comment);
1549 else
1550 printf("Comment removed\n");
1551
1541 exit(0); 1552 exit(0);
1542} 1553}
1543 1554