Hi, while working on a patch for Claws-Mail, I realized that
gpgme_get_key ignores context configuration set with either
gpgme_set_ctx_flag or gpgme_set_offline.

Looking at the source code in gpgme/src/keylist.c, I saw that a new
listctx is created "to avoid the user's I/O callback handlers" and 
part of the calling ctx's configuration is copied there.

However, imho, at least "auto-key-locate" ctx flag and offline mode
should be copied too, to actually serve the caller's request, as
they may impact the key retrieval.


You can find a patch attached.


Cheers,


Giacomo

PS: I tried to report this on bugzilla, but the registration page
suggest to ask here for credentials. Feel free to use "giacomo" as
handle, "Giacomo Tesio" as shown name, and this address as email.
From 87e4ffeae92cfdd13161c65186d534989d5c9f91 Mon Sep 17 00:00:00 2001
From: Giacomo Tesio <[email protected]>
Date: Sat, 8 Nov 2025 14:47:53 +0100
Subject: [PATCH] gpgme_get_key: respect caller's ctx configuration

---
 src/keylist.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/keylist.c b/src/keylist.c
index 3246aaf0..67ac0fba 100644
--- a/src/keylist.c
+++ b/src/keylist.c
@@ -1534,13 +1534,18 @@ gpgme_get_key (gpgme_ctx_t ctx, const char *fpr, gpgme_key_t *r_key,
   if (err)
     return TRACE_ERR (err);
   {
+    const char *ctx_flag;
     gpgme_protocol_t proto;
     gpgme_engine_info_t info;
 
     /* Clone the relevant state.  */
     proto = gpgme_get_protocol (ctx);
     gpgme_set_protocol (listctx, proto);
+    gpgme_set_offline (listctx, gpgme_get_offline (ctx));
     gpgme_set_keylist_mode (listctx, gpgme_get_keylist_mode (ctx));
+    ctx_flag = gpgme_get_ctx_flag (ctx, "auto-key-locate");
+    if (ctx_flag != NULL)
+      gpgme_set_ctx_flag (listctx, "auto-key-locate", ctx_flag);
     info = gpgme_ctx_get_engine_info (ctx);
     while (info && info->protocol != proto)
       info = info->next;
-- 
2.47.3

Attachment: pgp_plh9zTyoN.pgp
Description: Firma digitale OpenPGP

_______________________________________________
Gnupg-devel mailing list
[email protected]
https://lists.gnupg.org/mailman/listinfo/gnupg-devel

Reply via email to