summaryrefslogtreecommitdiff
path: root/ssh-add.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-add.c')
-rw-r--r--ssh-add.c62
1 files changed, 39 insertions, 23 deletions
diff --git a/ssh-add.c b/ssh-add.c
index adcc45998..627c02983 100644
--- a/ssh-add.c
+++ b/ssh-add.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-add.c,v 1.135 2018/02/23 15:58:37 markus Exp $ */ 1/* $OpenBSD: ssh-add.c,v 1.136 2018/09/19 02:03:02 djm 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
@@ -166,7 +166,7 @@ delete_file(int agent_fd, const char *filename, int key_only, int qflag)
166 166
167/* Send a request to remove all identities. */ 167/* Send a request to remove all identities. */
168static int 168static int
169delete_all(int agent_fd) 169delete_all(int agent_fd, int qflag)
170{ 170{
171 int ret = -1; 171 int ret = -1;
172 172
@@ -180,10 +180,10 @@ delete_all(int agent_fd)
180 /* ignore error-code for ssh1 */ 180 /* ignore error-code for ssh1 */
181 ssh_remove_all_identities(agent_fd, 1); 181 ssh_remove_all_identities(agent_fd, 1);
182 182
183 if (ret == 0) 183 if (ret != 0)
184 fprintf(stderr, "All identities removed.\n");
185 else
186 fprintf(stderr, "Failed to remove all identities.\n"); 184 fprintf(stderr, "Failed to remove all identities.\n");
185 else if (!qflag)
186 fprintf(stderr, "All identities removed.\n");
187 187
188 return ret; 188 return ret;
189} 189}
@@ -310,14 +310,19 @@ add_file(int agent_fd, const char *filename, int key_only, int qflag)
310 310
311 if ((r = ssh_add_identity_constrained(agent_fd, private, comment, 311 if ((r = ssh_add_identity_constrained(agent_fd, private, comment,
312 lifetime, confirm, maxsign)) == 0) { 312 lifetime, confirm, maxsign)) == 0) {
313 fprintf(stderr, "Identity added: %s (%s)\n", filename, comment);
314 ret = 0; 313 ret = 0;
315 if (lifetime != 0) 314 if (!qflag) {
316 fprintf(stderr, 315 fprintf(stderr, "Identity added: %s (%s)\n",
317 "Lifetime set to %d seconds\n", lifetime); 316 filename, comment);
318 if (confirm != 0) 317 if (lifetime != 0) {
319 fprintf(stderr, 318 fprintf(stderr,
320 "The user must confirm each use of the key\n"); 319 "Lifetime set to %d seconds\n", lifetime);
320 }
321 if (confirm != 0) {
322 fprintf(stderr, "The user must confirm "
323 "each use of the key\n");
324 }
325 }
321 } else { 326 } else {
322 fprintf(stderr, "Could not add identity \"%s\": %s\n", 327 fprintf(stderr, "Could not add identity \"%s\": %s\n",
323 filename, ssh_err(r)); 328 filename, ssh_err(r));
@@ -362,12 +367,20 @@ add_file(int agent_fd, const char *filename, int key_only, int qflag)
362 private->cert->key_id, ssh_err(r)); 367 private->cert->key_id, ssh_err(r));
363 goto out; 368 goto out;
364 } 369 }
365 fprintf(stderr, "Certificate added: %s (%s)\n", certpath, 370 /* success */
366 private->cert->key_id); 371 if (!qflag) {
367 if (lifetime != 0) 372 fprintf(stderr, "Certificate added: %s (%s)\n", certpath,
368 fprintf(stderr, "Lifetime set to %d seconds\n", lifetime); 373 private->cert->key_id);
369 if (confirm != 0) 374 if (lifetime != 0) {
370 fprintf(stderr, "The user must confirm each use of the key\n"); 375 fprintf(stderr, "Lifetime set to %d seconds\n",
376 lifetime);
377 }
378 if (confirm != 0) {
379 fprintf(stderr, "The user must confirm each use "
380 "of the key\n");
381 }
382 }
383
371 out: 384 out:
372 free(certpath); 385 free(certpath);
373 free(comment); 386 free(comment);
@@ -377,7 +390,7 @@ add_file(int agent_fd, const char *filename, int key_only, int qflag)
377} 390}
378 391
379static int 392static int
380update_card(int agent_fd, int add, const char *id) 393update_card(int agent_fd, int add, const char *id, int qflag)
381{ 394{
382 char *pin = NULL; 395 char *pin = NULL;
383 int r, ret = -1; 396 int r, ret = -1;
@@ -390,9 +403,11 @@ update_card(int agent_fd, int add, const char *id)
390 403
391 if ((r = ssh_update_card(agent_fd, add, id, pin == NULL ? "" : pin, 404 if ((r = ssh_update_card(agent_fd, add, id, pin == NULL ? "" : pin,
392 lifetime, confirm)) == 0) { 405 lifetime, confirm)) == 0) {
393 fprintf(stderr, "Card %s: %s\n",
394 add ? "added" : "removed", id);
395 ret = 0; 406 ret = 0;
407 if (!qflag) {
408 fprintf(stderr, "Card %s: %s\n",
409 add ? "added" : "removed", id);
410 }
396 } else { 411 } else {
397 fprintf(stderr, "Could not %s card \"%s\": %s\n", 412 fprintf(stderr, "Could not %s card \"%s\": %s\n",
398 add ? "add" : "remove", id, ssh_err(r)); 413 add ? "add" : "remove", id, ssh_err(r));
@@ -630,7 +645,7 @@ main(int argc, char **argv)
630 ret = 1; 645 ret = 1;
631 goto done; 646 goto done;
632 } else if (Dflag) { 647 } else if (Dflag) {
633 if (delete_all(agent_fd) == -1) 648 if (delete_all(agent_fd, qflag) == -1)
634 ret = 1; 649 ret = 1;
635 goto done; 650 goto done;
636 } 651 }
@@ -638,7 +653,8 @@ main(int argc, char **argv)
638 argc -= optind; 653 argc -= optind;
639 argv += optind; 654 argv += optind;
640 if (pkcs11provider != NULL) { 655 if (pkcs11provider != NULL) {
641 if (update_card(agent_fd, !deleting, pkcs11provider) == -1) 656 if (update_card(agent_fd, !deleting, pkcs11provider,
657 qflag) == -1)
642 ret = 1; 658 ret = 1;
643 goto done; 659 goto done;
644 } 660 }