common: New put_membuf_cb to replace static membuf_data_cb.

* common/membuf.c (put_membuf_cb): New.
* agent/call-scd.c (membuf_data_cb): Remove.  Change callers to use
put_membuf_cb.
* common/get-passphrase.c (membuf_data_cb): Ditto.
* g10/call-agent.c (membuf_data_cb): Ditto.
* sm/call-agent.c (membuf_data_cb): Ditto.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-01-08 06:33:27 +01:00
parent 8fd406c317
commit 833ba5faa1
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
6 changed files with 41 additions and 73 deletions

View File

@ -113,8 +113,6 @@ static int primary_scd_ctx_reusable;
/* Local prototypes. */
static gpg_error_t membuf_data_cb (void *opaque,
const void *buffer, size_t length);
@ -354,7 +352,7 @@ start_scd (ctrl_t ctrl)
socket_name = NULL;
init_membuf (&data, 256);
assuan_transact (ctx, "GETINFO socket_name",
membuf_data_cb, &data, NULL, NULL, NULL, NULL);
put_membuf_cb, &data, NULL, NULL, NULL, NULL);
databuf = get_membuf (&data, &datalen);
if (databuf && datalen)
@ -688,16 +686,6 @@ agent_card_serialno (ctrl_t ctrl, char **r_serialno)
static gpg_error_t
membuf_data_cb (void *opaque, const void *buffer, size_t length)
{
membuf_t *data = opaque;
if (buffer)
put_membuf (data, buffer, length);
return 0;
}
/* Handle the NEEDPIN inquiry. */
static gpg_error_t
inq_needpin (void *opaque, const char *line)
@ -855,7 +843,7 @@ agent_card_pksign (ctrl_t ctrl,
snprintf (line, sizeof line, "PKSIGN %s %s",
hash_algo_option (mdalgo), keyid);
rc = assuan_transact (ctrl->scd_local->ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
inq_needpin, &inqparm,
NULL, NULL);
if (inqparm.any_inq_seen && (gpg_err_code(rc) == GPG_ERR_CANCELED ||
@ -944,7 +932,7 @@ agent_card_pkdecrypt (ctrl_t ctrl,
snprintf (line, DIM(line)-1, "PKDECRYPT %s", keyid);
line[DIM(line)-1] = 0;
rc = assuan_transact (ctrl->scd_local->ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
inq_needpin, &inqparm,
padding_info_cb, r_padding);
if (inqparm.any_inq_seen && (gpg_err_code(rc) == GPG_ERR_CANCELED ||
@ -984,7 +972,7 @@ agent_card_readcert (ctrl_t ctrl,
snprintf (line, DIM(line)-1, "READCERT %s", id);
line[DIM(line)-1] = 0;
rc = assuan_transact (ctrl->scd_local->ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
NULL, NULL,
NULL, NULL);
if (rc)
@ -1020,7 +1008,7 @@ agent_card_readkey (ctrl_t ctrl, const char *id, unsigned char **r_buf)
snprintf (line, DIM(line)-1, "READKEY %s", id);
line[DIM(line)-1] = 0;
rc = assuan_transact (ctrl->scd_local->ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
NULL, NULL,
NULL, NULL);
if (rc)

View File

@ -130,17 +130,6 @@ default_inq_cb (void *opaque, const char *line)
}
static gpg_error_t
membuf_data_cb (void *opaque, const void *buffer, size_t length)
{
membuf_t *data = opaque;
if (buffer)
put_membuf (data, buffer, length);
return 0;
}
/* Ask for a passphrase via gpg-agent. On success the caller needs to
free the string stored at R_PASSPHRASE. On error NULL will be
stored at R_PASSPHRASE and an appropriate gpg error code is
@ -214,7 +203,7 @@ gnupg_get_passphrase (const char *cache_id,
else
init_membuf (&data, 64);
err = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, NULL, NULL, NULL);
/* Older Pinentries return the old assuan error code for canceled

View File

@ -116,6 +116,20 @@ put_membuf (membuf_t *mb, const void *buf, size_t len)
}
/* A variant of put_membuf accepting a void * and returning a
gpg_error_t (which will always return 0) to be used as a generic
callback handler. This function also allows buffer to be NULL. */
gpg_error_t
put_membuf_cb (void *opaque, const void *buf, size_t len)
{
membuf_t *data = opaque;
if (buf)
put_membuf (data, buf, len);
return 0;
}
void
put_membuf_str (membuf_t *mb, const char *string)
{

View File

@ -53,6 +53,7 @@ void init_membuf (membuf_t *mb, int initiallen);
void init_membuf_secure (membuf_t *mb, int initiallen);
void clear_membuf (membuf_t *mb, size_t amount);
void put_membuf (membuf_t *mb, const void *buf, size_t len);
gpg_error_t put_membuf_cb (void *opaque, const void *buf, size_t len);
void put_membuf_str (membuf_t *mb, const char *string);
void put_membuf_printf (membuf_t *mb, const char *format,
...) GPGRT_ATTR_PRINTF(2,3);

View File

@ -137,18 +137,6 @@ status_sc_op_failure (int rc)
}
static gpg_error_t
membuf_data_cb (void *opaque, const void *buffer, size_t length)
{
membuf_t *data = opaque;
if (buffer)
put_membuf (data, buffer, length);
return 0;
}
/* This is the default inquiry callback. It mainly handles the
Pinentry notifications. */
static gpg_error_t
@ -214,7 +202,7 @@ check_hijacking (assuan_context_t ctx)
/* AGENT_ID is a command implemented by gnome-keyring-daemon. It
does not return any data but an OK line with a remark. */
if (assuan_transact (ctx, "AGENT_ID",
membuf_data_cb, &mb, NULL, NULL, NULL, NULL))
put_membuf_cb, &mb, NULL, NULL, NULL, NULL))
{
xfree (get_membuf (&mb, NULL));
return; /* Error - Probably not hijacked. */
@ -780,7 +768,7 @@ agent_scd_apdu (const char *hexapdu, unsigned int *r_sw)
snprintf (line, DIM(line)-1, "SCD APDU %s", hexapdu);
err = assuan_transact (agent_ctx, line,
membuf_data_cb, &mb, NULL, NULL, NULL, NULL);
put_membuf_cb, &mb, NULL, NULL, NULL, NULL);
if (!err)
{
data = get_membuf (&mb, &datalen);
@ -1292,7 +1280,7 @@ agent_scd_readcert (const char *certidstr,
snprintf (line, DIM(line)-1, "SCD READCERT %s", certidstr);
line[DIM(line)-1] = 0;
rc = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, &dfltparm,
NULL, NULL);
if (rc)
@ -1455,7 +1443,7 @@ agent_get_passphrase (const char *cache_id,
init_membuf_secure (&data, 64);
rc = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, &dfltparm,
NULL, NULL);
@ -1553,7 +1541,7 @@ agent_get_s2k_count (unsigned long *r_count)
init_membuf (&data, 32);
err = assuan_transact (agent_ctx, "GETINFO s2k_count",
membuf_data_cb, &data,
put_membuf_cb, &data,
NULL, NULL, NULL, NULL);
if (err)
xfree (get_membuf (&data, NULL));
@ -1825,7 +1813,7 @@ agent_genkey (ctrl_t ctrl, char **cache_nonce_addr,
cn_parm.cache_nonce_addr = cache_nonce_addr;
cn_parm.passwd_nonce_addr = NULL;
err = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
inq_genkey_parms, &gk_parm,
cache_nonce_status_cb, &cn_parm);
if (err)
@ -1879,7 +1867,7 @@ agent_readkey (ctrl_t ctrl, int fromcard, const char *hexkeygrip,
init_membuf (&data, 1024);
err = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, &dfltparm,
NULL, NULL);
if (err)
@ -1967,7 +1955,7 @@ agent_pksign (ctrl_t ctrl, const char *cache_nonce,
cache_nonce? " -- ":"",
cache_nonce? cache_nonce:"");
err = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, &dfltparm,
NULL, NULL);
if (err)
@ -2097,7 +2085,7 @@ agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc,
if (err)
return err;
err = assuan_transact (agent_ctx, "PKDECRYPT",
membuf_data_cb, &data,
put_membuf_cb, &data,
inq_ciphertext_cb, &parm,
padding_info_cb, r_padding);
xfree (parm.ciphertext);
@ -2177,7 +2165,7 @@ agent_keywrap_key (ctrl_t ctrl, int forexport, void **r_kek, size_t *r_keklen)
init_membuf_secure (&data, 64);
err = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, &dfltparm,
NULL, NULL);
if (err)
@ -2309,7 +2297,7 @@ agent_export_key (ctrl_t ctrl, const char *hexkeygrip, const char *desc,
cn_parm.cache_nonce_addr = cache_nonce_addr;
cn_parm.passwd_nonce_addr = NULL;
err = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, &dfltparm,
cache_nonce_status_cb, &cn_parm);
if (err)
@ -2428,7 +2416,7 @@ agent_get_version (ctrl_t ctrl, char **r_version)
init_membuf (&data, 64);
err = assuan_transact (agent_ctx, "GETINFO version",
membuf_data_cb, &data,
put_membuf_cb, &data,
NULL, NULL, NULL, NULL);
if (err)
{

View File

@ -128,18 +128,6 @@ start_agent (ctrl_t ctrl)
}
static gpg_error_t
membuf_data_cb (void *opaque, const void *buffer, size_t length)
{
membuf_t *data = opaque;
if (buffer)
put_membuf (data, buffer, length);
return 0;
}
/* This is the default inquiry callback. It mainly handles the
Pinentry notifications. */
static gpg_error_t
@ -215,7 +203,7 @@ gpgsm_agent_pksign (ctrl_t ctrl, const char *keygrip, const char *desc,
init_membuf (&data, 1024);
rc = assuan_transact (agent_ctx, "PKSIGN",
membuf_data_cb, &data, default_inq_cb, ctrl,
put_membuf_cb, &data, default_inq_cb, ctrl,
NULL, NULL);
if (rc)
{
@ -282,7 +270,7 @@ gpgsm_scd_pksign (ctrl_t ctrl, const char *keyid, const char *desc,
snprintf (line, DIM(line)-1, "SCD PKSIGN %s %s", hashopt, keyid);
line[DIM(line)-1] = 0;
rc = assuan_transact (agent_ctx, line,
membuf_data_cb, &data, default_inq_cb, ctrl,
put_membuf_cb, &data, default_inq_cb, ctrl,
NULL, NULL);
if (rc)
{
@ -392,7 +380,7 @@ gpgsm_agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc,
cipher_parm.ciphertext = ciphertext;
cipher_parm.ciphertextlen = ciphertextlen;
rc = assuan_transact (agent_ctx, "PKDECRYPT",
membuf_data_cb, &data,
put_membuf_cb, &data,
inq_ciphertext_cb, &cipher_parm, NULL, NULL);
if (rc)
{
@ -487,7 +475,7 @@ gpgsm_agent_genkey (ctrl_t ctrl,
if (!gk_parm.sexplen)
return gpg_error (GPG_ERR_INV_VALUE);
rc = assuan_transact (agent_ctx, "GENKEY",
membuf_data_cb, &data,
put_membuf_cb, &data,
inq_genkey_parms, &gk_parm, NULL, NULL);
if (rc)
{
@ -536,7 +524,7 @@ gpgsm_agent_readkey (ctrl_t ctrl, int fromcard, const char *hexkeygrip,
init_membuf (&data, 1024);
rc = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, ctrl, NULL, NULL);
if (rc)
{
@ -1117,7 +1105,7 @@ gpgsm_agent_ask_passphrase (ctrl_t ctrl, const char *desc_msg, int repeat,
init_membuf_secure (&data, 64);
err = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, NULL, NULL, NULL);
if (err)
@ -1157,7 +1145,7 @@ gpgsm_agent_keywrap_key (ctrl_t ctrl, int forexport,
init_membuf_secure (&data, 64);
err = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, ctrl, NULL, NULL);
if (err)
{
@ -1251,7 +1239,7 @@ gpgsm_agent_export_key (ctrl_t ctrl, const char *keygrip, const char *desc,
init_membuf_secure (&data, 1024);
err = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
put_membuf_cb, &data,
default_inq_cb, ctrl, NULL, NULL);
if (err)
{