From e4ee706e270c38937afe26ce9f54d17d037cb86f Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 9 Sep 2020 12:12:51 +0200 Subject: [PATCH] core: Fully implement the inquire callback for assuan_transact * src/engine-assuan.c (inquire_cb): Implement returning data. * tests/opassuan/t-command.c (inq_cb): Send some test data. -- The old code only allowed to send an empty response which was good enough for scdaemon's KNOWNCARDP inquire but not to send actual data. A quick test using a test smartcard might be ./t-command 'scd setattr --inquire PRIVATE-DO-1' and then reading the data back using gpg-connect-agent 'scd getattr PRIVATE-DO-1' /bye Signed-off-by: Werner Koch --- src/engine-assuan.c | 25 +++++++++++++++++-------- tests/opassuan/t-command.c | 4 ++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/engine-assuan.c b/src/engine-assuan.c index b51c17e3..eb6d2a8e 100644 --- a/src/engine-assuan.c +++ b/src/engine-assuan.c @@ -445,7 +445,10 @@ llass_set_locale (void *engine, int category, const char *value) static gpgme_error_t inquire_cb (engine_llass_t llass, const char *keyword, const char *args) { - gpg_error_t err; + gpg_error_t err, err2; + gpgme_data_t data = NULL; + char buf[1024]; + gpgme_ssize_t n; if (llass->opt.gpg_agent && !strcmp (keyword, "PINENTRY_LAUNCHED")) { @@ -454,17 +457,23 @@ inquire_cb (engine_llass_t llass, const char *keyword, const char *args) if (llass->user.inq_cb) { - gpgme_data_t data = NULL; - err = llass->user.inq_cb (llass->user.inq_cb_value, keyword, args, &data); if (!err && data) { - /* FIXME: Returning data is not yet implemented. However we - need to allow the caller to cleanup his data object. - Thus we run the callback in finish mode immediately. */ - err = llass->user.inq_cb (llass->user.inq_cb_value, - NULL, NULL, &data); + while ((n = gpgme_data_read (data, buf, sizeof buf)) > 0) + { + err = assuan_send_data (llass->assuan_ctx, buf, n); + if (err) + break; + } + /* Tell the caller that we are finished with the data + * object. The error code from assuan_send_data has + * priority over the one from the cleanup function. */ + err2 = llass->user.inq_cb (llass->user.inq_cb_value, + NULL, NULL, &data); + if (!err) + err = err2; } } else diff --git a/tests/opassuan/t-command.c b/tests/opassuan/t-command.c index b7e184c4..2bc869d4 100644 --- a/tests/opassuan/t-command.c +++ b/tests/opassuan/t-command.c @@ -70,8 +70,9 @@ inq_cb (void *opaque, const char *name, const char *args, /* There shall be no data object. */ assert (!*r_data); - err = gpgme_data_new (&data); + err = gpgme_data_new_from_mem (&data, "Foo bar\nbaz\n", 10, 0); fail_if_err (err); + *r_data = data; printf (" sending data object %p\n", data); } @@ -142,4 +143,3 @@ main (int argc, char **argv) return 0; } -