summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ssh-add.18
-rw-r--r--ssh-add.c36
2 files changed, 28 insertions, 16 deletions
diff --git a/ssh-add.1 b/ssh-add.1
index 509d8fb47..471a23e7c 100644
--- a/ssh-add.1
+++ b/ssh-add.1
@@ -1,4 +1,4 @@
1.\" $OpenBSD: ssh-add.1,v 1.64 2017/05/05 10:41:58 naddy Exp $ 1.\" $OpenBSD: ssh-add.1,v 1.65 2017/08/29 09:42:29 dlg Exp $
2.\" 2.\"
3.\" Author: Tatu Ylonen <ylo@cs.hut.fi> 3.\" Author: Tatu Ylonen <ylo@cs.hut.fi>
4.\" Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4.\" Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -35,7 +35,7 @@
35.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37.\" 37.\"
38.Dd $Mdocdate: May 5 2017 $ 38.Dd $Mdocdate: August 29 2017 $
39.Dt SSH-ADD 1 39.Dt SSH-ADD 1
40.Os 40.Os
41.Sh NAME 41.Sh NAME
@@ -43,7 +43,7 @@
43.Nd adds private key identities to the authentication agent 43.Nd adds private key identities to the authentication agent
44.Sh SYNOPSIS 44.Sh SYNOPSIS
45.Nm ssh-add 45.Nm ssh-add
46.Op Fl cDdkLlXx 46.Op Fl cDdkLlqXx
47.Op Fl E Ar fingerprint_hash 47.Op Fl E Ar fingerprint_hash
48.Op Fl t Ar life 48.Op Fl t Ar life
49.Op Ar 49.Op Ar
@@ -134,6 +134,8 @@ Set a maximum lifetime when adding identities to an agent.
134The lifetime may be specified in seconds or in a time format 134The lifetime may be specified in seconds or in a time format
135specified in 135specified in
136.Xr sshd_config 5 . 136.Xr sshd_config 5 .
137.It Fl q
138Be quiet after a successful operation.
137.It Fl X 139.It Fl X
138Unlock the agent. 140Unlock the agent.
139.It Fl x 141.It Fl x
diff --git a/ssh-add.c b/ssh-add.c
index 72d89db4a..2afd48330 100644
--- a/ssh-add.c
+++ b/ssh-add.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-add.c,v 1.133 2017/07/01 13:50:45 djm Exp $ */ 1/* $OpenBSD: ssh-add.c,v 1.134 2017/08/29 09:42:29 dlg Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -102,7 +102,7 @@ clear_pass(void)
102} 102}
103 103
104static int 104static int
105delete_file(int agent_fd, const char *filename, int key_only) 105delete_file(int agent_fd, const char *filename, int key_only, int qflag)
106{ 106{
107 struct sshkey *public, *cert = NULL; 107 struct sshkey *public, *cert = NULL;
108 char *certpath = NULL, *comment = NULL; 108 char *certpath = NULL, *comment = NULL;
@@ -113,7 +113,10 @@ delete_file(int agent_fd, const char *filename, int key_only)
113 return -1; 113 return -1;
114 } 114 }
115 if ((r = ssh_remove_identity(agent_fd, public)) == 0) { 115 if ((r = ssh_remove_identity(agent_fd, public)) == 0) {
116 fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment); 116 if (!qflag) {
117 fprintf(stderr, "Identity removed: %s (%s)\n",
118 filename, comment);
119 }
117 ret = 0; 120 ret = 0;
118 } else 121 } else
119 fprintf(stderr, "Could not remove identity \"%s\": %s\n", 122 fprintf(stderr, "Could not remove identity \"%s\": %s\n",
@@ -138,8 +141,10 @@ delete_file(int agent_fd, const char *filename, int key_only)
138 certpath, filename); 141 certpath, filename);
139 142
140 if ((r = ssh_remove_identity(agent_fd, cert)) == 0) { 143 if ((r = ssh_remove_identity(agent_fd, cert)) == 0) {
141 fprintf(stderr, "Identity removed: %s (%s)\n", certpath, 144 if (!qflag) {
142 comment); 145 fprintf(stderr, "Identity removed: %s (%s)\n",
146 certpath, comment);
147 }
143 ret = 0; 148 ret = 0;
144 } else 149 } else
145 fprintf(stderr, "Could not remove identity \"%s\": %s\n", 150 fprintf(stderr, "Could not remove identity \"%s\": %s\n",
@@ -179,7 +184,7 @@ delete_all(int agent_fd)
179} 184}
180 185
181static int 186static int
182add_file(int agent_fd, const char *filename, int key_only) 187add_file(int agent_fd, const char *filename, int key_only, int qflag)
183{ 188{
184 struct sshkey *private, *cert; 189 struct sshkey *private, *cert;
185 char *comment = NULL; 190 char *comment = NULL;
@@ -427,13 +432,13 @@ lock_agent(int agent_fd, int lock)
427} 432}
428 433
429static int 434static int
430do_file(int agent_fd, int deleting, int key_only, char *file) 435do_file(int agent_fd, int deleting, int key_only, char *file, int qflag)
431{ 436{
432 if (deleting) { 437 if (deleting) {
433 if (delete_file(agent_fd, file, key_only) == -1) 438 if (delete_file(agent_fd, file, key_only, qflag) == -1)
434 return -1; 439 return -1;
435 } else { 440 } else {
436 if (add_file(agent_fd, file, key_only) == -1) 441 if (add_file(agent_fd, file, key_only, qflag) == -1)
437 return -1; 442 return -1;
438 } 443 }
439 return 0; 444 return 0;
@@ -456,6 +461,7 @@ usage(void)
456 fprintf(stderr, " -X Unlock agent.\n"); 461 fprintf(stderr, " -X Unlock agent.\n");
457 fprintf(stderr, " -s pkcs11 Add keys from PKCS#11 provider.\n"); 462 fprintf(stderr, " -s pkcs11 Add keys from PKCS#11 provider.\n");
458 fprintf(stderr, " -e pkcs11 Remove keys provided by PKCS#11 provider.\n"); 463 fprintf(stderr, " -e pkcs11 Remove keys provided by PKCS#11 provider.\n");
464 fprintf(stderr, " -q Be quiet after a successful operation.\n");
459} 465}
460 466
461int 467int
@@ -466,7 +472,7 @@ main(int argc, char **argv)
466 int agent_fd; 472 int agent_fd;
467 char *pkcs11provider = NULL; 473 char *pkcs11provider = NULL;
468 int r, i, ch, deleting = 0, ret = 0, key_only = 0; 474 int r, i, ch, deleting = 0, ret = 0, key_only = 0;
469 int xflag = 0, lflag = 0, Dflag = 0; 475 int xflag = 0, lflag = 0, Dflag = 0, qflag = 0;
470 476
471 ssh_malloc_init(); /* must be called before any mallocs */ 477 ssh_malloc_init(); /* must be called before any mallocs */
472 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ 478 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
@@ -494,7 +500,7 @@ main(int argc, char **argv)
494 exit(2); 500 exit(2);
495 } 501 }
496 502
497 while ((ch = getopt(argc, argv, "klLcdDxXE:e:s:t:")) != -1) { 503 while ((ch = getopt(argc, argv, "klLcdDxXE:e:qs:t:")) != -1) {
498 switch (ch) { 504 switch (ch) {
499 case 'E': 505 case 'E':
500 fingerprint_hash = ssh_digest_alg_by_name(optarg); 506 fingerprint_hash = ssh_digest_alg_by_name(optarg);
@@ -539,6 +545,9 @@ main(int argc, char **argv)
539 goto done; 545 goto done;
540 } 546 }
541 break; 547 break;
548 case 'q':
549 qflag = 1;
550 break;
542 default: 551 default:
543 usage(); 552 usage();
544 ret = 1; 553 ret = 1;
@@ -587,7 +596,8 @@ main(int argc, char **argv)
587 default_files[i]); 596 default_files[i]);
588 if (stat(buf, &st) < 0) 597 if (stat(buf, &st) < 0)
589 continue; 598 continue;
590 if (do_file(agent_fd, deleting, key_only, buf) == -1) 599 if (do_file(agent_fd, deleting, key_only, buf,
600 qflag) == -1)
591 ret = 1; 601 ret = 1;
592 else 602 else
593 count++; 603 count++;
@@ -597,7 +607,7 @@ main(int argc, char **argv)
597 } else { 607 } else {
598 for (i = 0; i < argc; i++) { 608 for (i = 0; i < argc; i++) {
599 if (do_file(agent_fd, deleting, key_only, 609 if (do_file(agent_fd, deleting, key_only,
600 argv[i]) == -1) 610 argv[i], qflag) == -1)
601 ret = 1; 611 ret = 1;
602 } 612 }
603 } 613 }