mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-01 16:33:02 +01:00
agent: Slightly change structure of cmd_readkey.
* agent/command.c (cmd_readkey): Avoid a leave label in the middle of the code. Remove the special return. -- This helps to get better debug output. The set_error macro which is used by parse_keygrip merely sets the error code into the Assuan context. It is thus no problem anymore to call leave_cmd after having used set_error. This might havve been diffferent in the past. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
5e7dfd979d
commit
fdb653a33e
@ -391,7 +391,9 @@ progress_cb (ctrl_t ctrl, const char *what, int printchar,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Helper to print a message while leaving a command. */
|
/* Helper to print a message while leaving a command. Note that this
|
||||||
|
* function does not call assuan_set_error; the caller may do this
|
||||||
|
* prior to calling us. */
|
||||||
static gpg_error_t
|
static gpg_error_t
|
||||||
leave_cmd (assuan_context_t ctx, gpg_error_t err)
|
leave_cmd (assuan_context_t ctx, gpg_error_t err)
|
||||||
{
|
{
|
||||||
@ -1000,17 +1002,19 @@ cmd_readkey (assuan_context_t ctx, char *line)
|
|||||||
unsigned char grip[20];
|
unsigned char grip[20];
|
||||||
gcry_sexp_t s_pkey = NULL;
|
gcry_sexp_t s_pkey = NULL;
|
||||||
unsigned char *pkbuf = NULL;
|
unsigned char *pkbuf = NULL;
|
||||||
|
char *serialno = NULL;
|
||||||
size_t pkbuflen;
|
size_t pkbuflen;
|
||||||
|
const char *opt_card;
|
||||||
|
|
||||||
if (ctrl->restricted)
|
if (ctrl->restricted)
|
||||||
return leave_cmd (ctx, gpg_error (GPG_ERR_FORBIDDEN));
|
return leave_cmd (ctx, gpg_error (GPG_ERR_FORBIDDEN));
|
||||||
|
|
||||||
if (has_option_name (line, "--card"))
|
opt_card = has_option_name (line, "--card");
|
||||||
{
|
line = skip_options (line);
|
||||||
const char *keyid;
|
|
||||||
char *serialno = NULL;
|
|
||||||
|
|
||||||
keyid = skip_options (line);
|
if (opt_card)
|
||||||
|
{
|
||||||
|
const char *keyid = opt_card;
|
||||||
|
|
||||||
rc = agent_card_getattr (ctrl, "SERIALNO", &serialno);
|
rc = agent_card_getattr (ctrl, "SERIALNO", &serialno);
|
||||||
if (rc)
|
if (rc)
|
||||||
@ -1042,35 +1046,33 @@ cmd_readkey (assuan_context_t ctx, char *line)
|
|||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
rc = assuan_send_data (ctx, pkbuf, pkbuflen);
|
rc = assuan_send_data (ctx, pkbuf, pkbuflen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rc = parse_keygrip (ctx, line, grip);
|
||||||
|
if (rc)
|
||||||
|
goto leave;
|
||||||
|
|
||||||
|
rc = agent_public_key_from_file (ctrl, grip, &s_pkey);
|
||||||
|
if (!rc)
|
||||||
|
{
|
||||||
|
pkbuflen = gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, NULL, 0);
|
||||||
|
log_assert (pkbuflen);
|
||||||
|
pkbuf = xtrymalloc (pkbuflen);
|
||||||
|
if (!pkbuf)
|
||||||
|
rc = gpg_error_from_syserror ();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, pkbuf, pkbuflen);
|
||||||
|
rc = assuan_send_data (ctx, pkbuf, pkbuflen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
xfree (serialno);
|
xfree (serialno);
|
||||||
xfree (pkbuf);
|
xfree (pkbuf);
|
||||||
gcry_sexp_release (s_pkey);
|
gcry_sexp_release (s_pkey);
|
||||||
return leave_cmd (ctx, rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = parse_keygrip (ctx, line, grip);
|
|
||||||
if (rc)
|
|
||||||
return rc; /* Return immediately as this is already an Assuan error code.*/
|
|
||||||
|
|
||||||
rc = agent_public_key_from_file (ctrl, grip, &s_pkey);
|
|
||||||
if (!rc)
|
|
||||||
{
|
|
||||||
pkbuflen = gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, NULL, 0);
|
|
||||||
assert (pkbuflen);
|
|
||||||
pkbuf = xtrymalloc (pkbuflen);
|
|
||||||
if (!pkbuf)
|
|
||||||
rc = gpg_error_from_syserror ();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, pkbuf, pkbuflen);
|
|
||||||
rc = assuan_send_data (ctx, pkbuf, pkbuflen);
|
|
||||||
xfree (pkbuf);
|
|
||||||
}
|
|
||||||
gcry_sexp_release (s_pkey);
|
|
||||||
}
|
|
||||||
|
|
||||||
return leave_cmd (ctx, rc);
|
return leave_cmd (ctx, rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user