diff options
author | Werner Koch <[email protected]> | 2002-01-29 10:05:24 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2002-01-29 10:05:24 +0000 |
commit | cd30feaa8ebb37f98742228573da81e7ac8472aa (patch) | |
tree | 8c9b3d0dc1b48f8eefb7f32d0425393646736e50 /sm/keylist.c | |
parent | * findkey.c (agent_key_available): New. (diff) | |
download | gnupg-cd30feaa8ebb37f98742228573da81e7ac8472aa.tar.gz gnupg-cd30feaa8ebb37f98742228573da81e7ac8472aa.zip |
* call-agent.c (gpgsm_agent_havekey): New.
* keylist.c (list_cert_colon): New arg HAVE_SECRET, print "crs"
when we know that the secret key is available.
(gpgsm_list_keys): New arg MODE, check whether a secret key is
available. Changed all callers.
* gpgsm.c (main): New command --list-secret-keys.
* server.c (cmd_listsecretkeys): New.
(cmd_listkeys): Return secret keys with "crs" record.
Diffstat (limited to 'sm/keylist.c')
-rw-r--r-- | sm/keylist.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/sm/keylist.c b/sm/keylist.c index f4c90939f..0050ac464 100644 --- a/sm/keylist.c +++ b/sm/keylist.c @@ -113,13 +113,13 @@ email_kludge (const char *name) /* List one certificate in colon mode */ static void -list_cert_colon (KsbaCert cert, FILE *fp) +list_cert_colon (KsbaCert cert, FILE *fp, int have_secret) { int idx, trustletter = 0; char *p; KsbaSexp sexp; - fputs ("crt:", fp); + fputs (have_secret? "crs:":"crt:", fp); trustletter = 0; #if 0 if (is_not_valid (cert)) @@ -216,14 +216,21 @@ list_cert_colon (KsbaCert cert, FILE *fp) -/* List all keys or just the key given as NAMES */ +/* List all keys or just the key given as NAMES. + MODE controls the operation mode: + 0 = list all public keys but don't flag secret ones + 1 = list only public keys + 2 = list only secret keys + 3 = list secret and public keys + */ void -gpgsm_list_keys (CTRL ctrl, STRLIST names, FILE *fp) +gpgsm_list_keys (CTRL ctrl, STRLIST names, FILE *fp, unsigned int mode) { KEYDB_HANDLE hd; KsbaCert cert = NULL; int rc=0; const char *lastresname, *resname; + int have_secret; hd = keydb_new (0); if (!hd) @@ -262,10 +269,28 @@ gpgsm_list_keys (CTRL ctrl, STRLIST names, FILE *fp) lastresname = resname; } } - if (ctrl->with_colons) - list_cert_colon (cert, fp); - else - list_cert_colon (cert, fp); + + have_secret = 0; + if (mode) + { + char *p = gpgsm_get_keygrip_hexstring (cert); + if (p) + { + if (!gpgsm_agent_havekey (p)) + have_secret = 1; + xfree (p); + } + } + + if (!mode + || ((mode & 1) && !have_secret) + || ((mode & 2) && have_secret) ) + { + if (ctrl->with_colons) + list_cert_colon (cert, fp, have_secret); + else + list_cert_colon (cert, fp, have_secret); + } ksba_cert_release (cert); cert = NULL; } |