Bugzilla – Attachment 3416 Details for
Bug 3180
ssh-add -d cannot take key from stdin
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Implement support for "ssh-add -d -"
bz3180.diff (text/plain), 4.02 KB, created by
Damien Miller
on 2020-06-26 13:52:48 AEST
(
hide
)
Description:
Implement support for "ssh-add -d -"
Filename:
MIME Type:
Creator:
Damien Miller
Created:
2020-06-26 13:52:48 AEST
Size:
4.02 KB
patch
obsolete
>diff --git a/authfd.c b/authfd.c >index 4880875..45388bf 100644 >--- a/authfd.c >+++ b/authfd.c >@@ -335,7 +335,7 @@ ssh_free_identitylist(struct ssh_identitylist *idl) > * Returns 0 if found, or a negative SSH_ERR_* error code on failure. > */ > int >-ssh_agent_has_key(int sock, struct sshkey *key) >+ssh_agent_has_key(int sock, const struct sshkey *key) > { > int r, ret = SSH_ERR_KEY_NOT_FOUND; > size_t i; >@@ -533,7 +533,7 @@ ssh_add_identity_constrained(int sock, struct sshkey *key, > * This call is intended only for use by ssh-add(1) and like applications. > */ > int >-ssh_remove_identity(int sock, struct sshkey *key) >+ssh_remove_identity(int sock, const struct sshkey *key) > { > struct sshbuf *msg; > int r; >diff --git a/authfd.h b/authfd.h >index c3bf625..93b0f1a 100644 >--- a/authfd.h >+++ b/authfd.h >@@ -33,8 +33,8 @@ void ssh_free_identitylist(struct ssh_identitylist *idl); > int ssh_add_identity_constrained(int sock, struct sshkey *key, > const char *comment, u_int life, u_int confirm, u_int maxsign, > const char *provider); >-int ssh_agent_has_key(int sock, struct sshkey *key); >-int ssh_remove_identity(int sock, struct sshkey *key); >+int ssh_agent_has_key(int sock, const struct sshkey *key); >+int ssh_remove_identity(int sock, const struct sshkey *key); > int ssh_update_card(int sock, int add, const char *reader_id, > const char *pin, u_int life, u_int confirm); > int ssh_remove_all_identities(int sock, int version); >diff --git a/ssh-add.c b/ssh-add.c >index 14055d2..e74594c 100644 >--- a/ssh-add.c >+++ b/ssh-add.c >@@ -103,6 +103,54 @@ clear_pass(void) > } > } > >+static int >+delete_one(int agent_fd, const struct sshkey *key, const char *comment, >+ const char *path, int qflag) >+{ >+ int r; >+ >+ if ((r = ssh_remove_identity(agent_fd, key)) != 0) { >+ fprintf(stderr, "Could not remove identity \"%s\": %s\n", >+ path, ssh_err(r)); >+ return r; >+ } >+ if (!qflag) { >+ fprintf(stderr, "Identity removed: %s %s (%s)\n", path, >+ sshkey_type(key), comment); >+ } >+ return 0; >+} >+ >+static int >+delete_stdin(int agent_fd, int qflag) >+{ >+ char *line = NULL, *cp; >+ size_t linesize = 0; >+ struct sshkey *key = NULL; >+ int lnum = 0, r, ret = -1; >+ >+ while (getline(&line, &linesize, stdin) != -1) { >+ lnum++; >+ sshkey_free(key); >+ key = NULL; >+ line[strcspn(line, "\n")] = '\0'; >+ cp = line + strspn(line, " \t"); >+ if (*cp == '#' || *cp == '\0') >+ continue; >+ if ((key = sshkey_new(KEY_UNSPEC)) == NULL) >+ fatal("%s: sshkey_new", __func__); >+ if ((r = sshkey_read(key, &cp)) != 0) { >+ error("(stdin):%d: invalid key: %s", lnum, ssh_err(r)); >+ continue; >+ } >+ if (delete_one(agent_fd, key, cp, "(stdin)", qflag) == 0) >+ ret = 0; >+ } >+ sshkey_free(key); >+ free(line); >+ return ret; >+} >+ > static int > delete_file(int agent_fd, const char *filename, int key_only, int qflag) > { >@@ -110,19 +158,15 @@ delete_file(int agent_fd, const char *filename, int key_only, int qflag) > char *certpath = NULL, *comment = NULL; > int r, ret = -1; > >+ if (strcmp(filename, "-") == 0) >+ return delete_stdin(agent_fd, qflag); >+ > if ((r = sshkey_load_public(filename, &public, &comment)) != 0) { > printf("Bad key file %s: %s\n", filename, ssh_err(r)); > return -1; > } >- if ((r = ssh_remove_identity(agent_fd, public)) == 0) { >- if (!qflag) { >- fprintf(stderr, "Identity removed: %s (%s)\n", >- filename, comment); >- } >+ if (delete_one(agent_fd, public, comment, filename, qflag) == 0) > ret = 0; >- } else >- fprintf(stderr, "Could not remove identity \"%s\": %s\n", >- filename, ssh_err(r)); > > if (key_only) > goto out; >@@ -142,15 +186,8 @@ delete_file(int agent_fd, const char *filename, int key_only, int qflag) > fatal("Certificate %s does not match private key %s", > certpath, filename); > >- if ((r = ssh_remove_identity(agent_fd, cert)) == 0) { >- if (!qflag) { >- fprintf(stderr, "Identity removed: %s (%s)\n", >- certpath, comment); >- } >+ if (delete_one(agent_fd, cert, comment, certpath, qflag) == 0) > ret = 0; >- } else >- fprintf(stderr, "Could not remove identity \"%s\": %s\n", >- certpath, ssh_err(r)); > > out: > sshkey_free(cert);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
dtucker
:
ok+
Actions:
View
|
Diff
Attachments on
bug 3180
: 3416 |
3418