summaryrefslogtreecommitdiff
path: root/ssh-add.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-09-19 02:03:02 +0000
committerDamien Miller <djm@mindrot.org>2018-09-20 14:00:11 +1000
commitf80e68ea7d62e2dfafc12f1a60ab544ae4033a0f (patch)
treed85cf513810db773fac7e806e4887c2b26fce514 /ssh-add.c
parent5e532320e9e51de720d5f3cc2596e95d29f6e98f (diff)
downloadopenssh-git-f80e68ea7d62e2dfafc12f1a60ab544ae4033a0f.tar.gz
upstream: Make "ssh-add -q" do what it says on the tin: silence
output from successful operations. Based on patch from Thijs van Dijk; ok dtucker@ deraadt@ OpenBSD-Commit-ID: c4f754ecc055c10af166116ce7515104aa8522e1
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 adcc4599..627c0298 100644
--- a/ssh-add.c
+++ b/ssh-add.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-add.c,v 1.135 2018/02/23 15:58:37 markus Exp $ */
+/* $OpenBSD: ssh-add.c,v 1.136 2018/09/19 02:03:02 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* 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)
/* Send a request to remove all identities. */
static int
-delete_all(int agent_fd)
+delete_all(int agent_fd, int qflag)
{
int ret = -1;
@@ -180,10 +180,10 @@ delete_all(int agent_fd)
/* ignore error-code for ssh1 */
ssh_remove_all_identities(agent_fd, 1);
- if (ret == 0)
- fprintf(stderr, "All identities removed.\n");
- else
+ if (ret != 0)
fprintf(stderr, "Failed to remove all identities.\n");
+ else if (!qflag)
+ fprintf(stderr, "All identities removed.\n");
return ret;
}
@@ -310,14 +310,19 @@ add_file(int agent_fd, const char *filename, int key_only, int qflag)
if ((r = ssh_add_identity_constrained(agent_fd, private, comment,
lifetime, confirm, maxsign)) == 0) {
- fprintf(stderr, "Identity added: %s (%s)\n", filename, comment);
ret = 0;
- if (lifetime != 0)
- fprintf(stderr,
- "Lifetime set to %d seconds\n", lifetime);
- if (confirm != 0)
- fprintf(stderr,
- "The user must confirm each use of the key\n");
+ if (!qflag) {
+ fprintf(stderr, "Identity added: %s (%s)\n",
+ filename, comment);
+ if (lifetime != 0) {
+ fprintf(stderr,
+ "Lifetime set to %d seconds\n", lifetime);
+ }
+ if (confirm != 0) {
+ fprintf(stderr, "The user must confirm "
+ "each use of the key\n");
+ }
+ }
} else {
fprintf(stderr, "Could not add identity \"%s\": %s\n",
filename, ssh_err(r));
@@ -362,12 +367,20 @@ add_file(int agent_fd, const char *filename, int key_only, int qflag)
private->cert->key_id, ssh_err(r));
goto out;
}
- fprintf(stderr, "Certificate added: %s (%s)\n", certpath,
- private->cert->key_id);
- if (lifetime != 0)
- fprintf(stderr, "Lifetime set to %d seconds\n", lifetime);
- if (confirm != 0)
- fprintf(stderr, "The user must confirm each use of the key\n");
+ /* success */
+ if (!qflag) {
+ fprintf(stderr, "Certificate added: %s (%s)\n", certpath,
+ private->cert->key_id);
+ if (lifetime != 0) {
+ fprintf(stderr, "Lifetime set to %d seconds\n",
+ lifetime);
+ }
+ if (confirm != 0) {
+ fprintf(stderr, "The user must confirm each use "
+ "of the key\n");
+ }
+ }
+
out:
free(certpath);
free(comment);
@@ -377,7 +390,7 @@ add_file(int agent_fd, const char *filename, int key_only, int qflag)
}
static int
-update_card(int agent_fd, int add, const char *id)
+update_card(int agent_fd, int add, const char *id, int qflag)
{
char *pin = NULL;
int r, ret = -1;
@@ -390,9 +403,11 @@ update_card(int agent_fd, int add, const char *id)
if ((r = ssh_update_card(agent_fd, add, id, pin == NULL ? "" : pin,
lifetime, confirm)) == 0) {
- fprintf(stderr, "Card %s: %s\n",
- add ? "added" : "removed", id);
ret = 0;
+ if (!qflag) {
+ fprintf(stderr, "Card %s: %s\n",
+ add ? "added" : "removed", id);
+ }
} else {
fprintf(stderr, "Could not %s card \"%s\": %s\n",
add ? "add" : "remove", id, ssh_err(r));
@@ -630,7 +645,7 @@ main(int argc, char **argv)
ret = 1;
goto done;
} else if (Dflag) {
- if (delete_all(agent_fd) == -1)
+ if (delete_all(agent_fd, qflag) == -1)
ret = 1;
goto done;
}
@@ -638,7 +653,8 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
if (pkcs11provider != NULL) {
- if (update_card(agent_fd, !deleting, pkcs11provider) == -1)
+ if (update_card(agent_fd, !deleting, pkcs11provider,
+ qflag) == -1)
ret = 1;
goto done;
}