summaryrefslogtreecommitdiff
path: root/ssh-add.c
diff options
context:
space:
mode:
authordlg@openbsd.org <dlg@openbsd.org>2017-08-29 09:42:29 +0000
committerDamien Miller <djm@mindrot.org>2017-09-04 09:38:57 +1000
commit530591a5795a02d01c78877d58604723918aac87 (patch)
treed47ebb52179e01c2e7f6ff29d98632ab85512e1e /ssh-add.c
parenta54eb27dd64b5eca3ba94e15cec3535124bd5029 (diff)
upstream commit
add a -q option to ssh-add to make it quiet on success. if you want to silence ssh-add without this you generally redirect the output to /dev/null, but that can hide error output which you should see. ok djm@ Upstream-ID: 2f31b9b13f99dcf587e9a8ba443458e6c0d8997c
Diffstat (limited to 'ssh-add.c')
-rw-r--r--ssh-add.c36
1 files changed, 23 insertions, 13 deletions
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 }