* 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.
This commit is contained in:
Werner Koch 2004-02-21 13:05:52 +00:00
parent a425334f48
commit 0c224cadf3
6 changed files with 56 additions and 16 deletions

View File

@ -1,3 +1,12 @@
2004-02-21 Werner Koch <wk@gnupg.org>
* 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 <wk@gnupg.org>
* gpgsm.c (main): New option --debug-ignore-expiration.

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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