aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2004-02-21 13:05:52 +0000
committerWerner Koch <[email protected]>2004-02-21 13:05:52 +0000
commit0c224cadf3f8b5ae259d8936f7963b56f63a0c26 (patch)
treea72e923d4d3d40e148e843d1be3608ec634a36f3
parent* command.c (cmd_passwd): Take acount of a key description. (diff)
downloadgnupg-0c224cadf3f8b5ae259d8936f7963b56f63a0c26.tar.gz
gnupg-0c224cadf3f8b5ae259d8936f7963b56f63a0c26.zip
* keylist.c (list_internal_keys): Return error codes.
(list_external_keys, gpgsm_list_keys): Ditto. * server.c (do_listkeys): Ditto. * gpgsm.c (main): Display a key description for --passwd. * call-agent.c (gpgsm_agent_passwd): New arg DESC.
-rw-r--r--sm/ChangeLog9
-rw-r--r--sm/call-agent.c16
-rw-r--r--sm/gpgsm.c6
-rw-r--r--sm/gpgsm.h5
-rw-r--r--sm/keylist.c31
-rw-r--r--sm/server.c5
6 files changed, 56 insertions, 16 deletions
diff --git a/sm/ChangeLog b/sm/ChangeLog
index a8a8f3f44..e543bbcba 100644
--- a/sm/ChangeLog
+++ b/sm/ChangeLog
@@ -1,3 +1,12 @@
+2004-02-21 Werner Koch <[email protected]>
+
+ * keylist.c (list_internal_keys): Return error codes.
+ (list_external_keys, gpgsm_list_keys): Ditto.
+ * server.c (do_listkeys): Ditto.
+
+ * gpgsm.c (main): Display a key description for --passwd.
+ * call-agent.c (gpgsm_agent_passwd): New arg DESC.
+
2004-02-20 Werner Koch <[email protected]>
* gpgsm.c (main): New option --debug-ignore-expiration.
diff --git a/sm/call-agent.c b/sm/call-agent.c
index a0a1da5c3..053959b2c 100644
--- a/sm/call-agent.c
+++ b/sm/call-agent.c
@@ -710,9 +710,11 @@ gpgsm_agent_learn ()
}
-/* Ask the agent to change the passphrase of the key identified by HEXKEYGRIP. */
+/* Ask the agent to change the passphrase of the key identified by
+ HEXKEYGRIP. If DESC is not NULL, display instead of the default
+ description message. */
int
-gpgsm_agent_passwd (const char *hexkeygrip)
+gpgsm_agent_passwd (const char *hexkeygrip, const char *desc)
{
int rc;
char line[ASSUAN_LINELENGTH];
@@ -724,6 +726,16 @@ gpgsm_agent_passwd (const char *hexkeygrip)
if (!hexkeygrip || strlen (hexkeygrip) != 40)
return gpg_error (GPG_ERR_INV_VALUE);
+ if (desc)
+ {
+ snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc);
+ line[DIM(line)-1] = 0;
+ rc = assuan_transact (agent_ctx, line,
+ NULL, NULL, NULL, NULL, NULL, NULL);
+ if (rc)
+ return map_assuan_err (rc);
+ }
+
snprintf (line, DIM(line)-1, "PASSWD %s", hexkeygrip);
line[DIM(line)-1] = 0;
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index 68214a6d8..6f3e62a33 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -1452,7 +1452,11 @@ main ( int argc, char **argv)
else if (!(grip = gpgsm_get_keygrip_hexstring (cert)))
rc = gpg_error (GPG_ERR_BUG);
else
- rc = gpgsm_agent_passwd (grip);
+ {
+ char *desc = gpgsm_format_keydesc (cert);
+ rc = gpgsm_agent_passwd (grip, desc);
+ xfree (desc);
+ }
if (rc)
log_error ("error changing passphrase: %s\n", gpg_strerror (rc));
xfree (grip);
diff --git a/sm/gpgsm.h b/sm/gpgsm.h
index 6cf3ed094..c0434d79c 100644
--- a/sm/gpgsm.h
+++ b/sm/gpgsm.h
@@ -239,7 +239,8 @@ void gpgsm_release_certlist (certlist_t list);
int gpgsm_find_cert (const char *name, ksba_cert_t *r_cert);
/*-- keylist.c --*/
-void gpgsm_list_keys (ctrl_t ctrl, STRLIST names, FILE *fp, unsigned int mode);
+gpg_error_t gpgsm_list_keys (ctrl_t ctrl, STRLIST names,
+ FILE *fp, unsigned int mode);
/*-- import.c --*/
int gpgsm_import (ctrl_t ctrl, int in_fd);
@@ -284,7 +285,7 @@ int gpgsm_agent_istrusted (ksba_cert_t cert);
int gpgsm_agent_havekey (const char *hexkeygrip);
int gpgsm_agent_marktrusted (ksba_cert_t cert);
int gpgsm_agent_learn (void);
-int gpgsm_agent_passwd (const char *hexkeygrip);
+int gpgsm_agent_passwd (const char *hexkeygrip, const char *desc);
/*-- call-dirmngr.c --*/
int gpgsm_dirmngr_isvalid (ksba_cert_t cert, int use_ocsp);
diff --git a/sm/keylist.c b/sm/keylist.c
index a73d18e92..3ebbe3ba3 100644
--- a/sm/keylist.c
+++ b/sm/keylist.c
@@ -496,7 +496,7 @@ list_cert_chain (ctrl_t ctrl, ksba_cert_t cert, FILE *fp, int with_validation)
/* List all internal keys or just the key given as NAMES.
*/
-static void
+static gpg_error_t
list_internal_keys (CTRL ctrl, STRLIST names, FILE *fp, unsigned int mode)
{
KEYDB_HANDLE hd;
@@ -504,7 +504,7 @@ list_internal_keys (CTRL ctrl, STRLIST names, FILE *fp, unsigned int mode)
STRLIST sl;
int ndesc;
ksba_cert_t cert = NULL;
- int rc=0;
+ gpg_error_t rc = 0;
const char *lastresname, *resname;
int have_secret;
@@ -512,6 +512,7 @@ list_internal_keys (CTRL ctrl, STRLIST names, FILE *fp, unsigned int mode)
if (!hd)
{
log_error ("keydb_new failed\n");
+ rc = gpg_error (GPG_ERR_GENERAL);
goto leave;
}
@@ -526,6 +527,7 @@ list_internal_keys (CTRL ctrl, STRLIST names, FILE *fp, unsigned int mode)
desc = xtrycalloc (ndesc, sizeof *desc);
if (!ndesc)
{
+ rc = gpg_error_from_errno (errno);
log_error ("out of core\n");
goto leave;
}
@@ -599,8 +601,12 @@ list_internal_keys (CTRL ctrl, STRLIST names, FILE *fp, unsigned int mode)
char *p = gpgsm_get_keygrip_hexstring (cert);
if (p)
{
- if (!gpgsm_agent_havekey (p))
+ rc = gpgsm_agent_havekey (p);
+ if (!rc)
have_secret = 1;
+ else if ( gpg_err_code (rc) != GPG_ERR_NO_SECKEY)
+ goto leave;
+ rc = 0;
xfree (p);
}
}
@@ -623,13 +629,16 @@ list_internal_keys (CTRL ctrl, STRLIST names, FILE *fp, unsigned int mode)
ksba_cert_release (cert);
cert = NULL;
}
- if (rc && rc != -1)
+ if (gpg_err_code (rc) == GPG_ERR_EOF || rc == -1 )
+ rc = 0;
+ if (rc)
log_error ("keydb_search failed: %s\n", gpg_strerror (rc));
leave:
ksba_cert_release (cert);
xfree (desc);
keydb_release (hd);
+ return rc;
}
@@ -669,7 +678,7 @@ list_external_cb (void *cb_value, ksba_cert_t cert)
/* List external keys similar to internal one. Note: mode does not
make sense here because it would be unwise to list external secret
keys */
-static void
+static gpg_error_t
list_external_keys (CTRL ctrl, STRLIST names, FILE *fp)
{
int rc;
@@ -684,6 +693,7 @@ list_external_keys (CTRL ctrl, STRLIST names, FILE *fp)
rc = gpgsm_dirmngr_lookup (ctrl, names, list_external_cb, &parm);
if (rc)
log_error ("listing external keys failed: %s\n", gpg_strerror (rc));
+ return rc;
}
/* List all keys or just the key given as NAMES.
@@ -696,11 +706,14 @@ list_external_keys (CTRL ctrl, STRLIST names, FILE *fp)
Bit 6: list internal keys
Bit 7: list external keys
*/
-void
+gpg_error_t
gpgsm_list_keys (CTRL ctrl, STRLIST names, FILE *fp, unsigned int mode)
{
+ gpg_error_t err = 0;
+
if ((mode & (1<<6)))
- list_internal_keys (ctrl, names, fp, (mode & 3));
- if ((mode & (1<<7)))
- list_external_keys (ctrl, names, fp);
+ err = list_internal_keys (ctrl, names, fp, (mode & 3));
+ if (!err && (mode & (1<<7)))
+ err = list_external_keys (ctrl, names, fp);
+ return err;
}
diff --git a/sm/server.c b/sm/server.c
index 8cc1b900e..a132f9f2b 100644
--- a/sm/server.c
+++ b/sm/server.c
@@ -651,6 +651,7 @@ do_listkeys (ASSUAN_CONTEXT ctx, char *line, int mode)
char *p;
STRLIST list, sl;
unsigned int listmode;
+ gpg_error_t err;
if (!fp)
return set_error (General_Error, "no data stream");
@@ -684,9 +685,9 @@ do_listkeys (ASSUAN_CONTEXT ctx, char *line, int mode)
listmode |= (1<<6);
if (ctrl->server_local->list_external)
listmode |= (1<<7);
- gpgsm_list_keys (assuan_get_pointer (ctx), list, fp, listmode);
+ err = gpgsm_list_keys (assuan_get_pointer (ctx), list, fp, listmode);
free_strlist (list);
- return 0;
+ return map_to_assuan_status (err);
}
static int