gpgme: gpgme_op_export() with non default keyserver

Seiya Kawashima skawashima at uchicago.edu
Mon Jun 13 17:19:06 CEST 2016


Hi,

I've been trying to modify how GPGME_EXPORT_MODE_EXTERN of gpgme_op_export() works with non default keyserver. And I hope that it would be useful for other users as well. I've cloned GPGME via git and the commit is 77d149e8614c381458e07808a7930ce3fb92cdc3 and the date is Wed Jun 8 18:06:24 2016 +0200.

According to the documentation at https://www.gnupg.org/documentation/manuals/gpgme/Exporting-Keys.html#Exporting-Keys, GPGME_EXPORT_MODE_EXTERN of gpgme_op_export() sends keys to the default keyserver via "--send-keys" GPG option.

To send keys to a non default keyserver, what I need to do is support "--keyserver" GPG option along with "--send-keys" GPG option in GPGME.

For this purpose, I've modified export_common() in engine-gpg.c:1821 to have a keyserver via an environment variable named "GPG_KEYSERVER" as follows. I was wondering if using environment variables is the right way to support more GPG options in GPGME than currently GPGME supports.

diff --git a/src/engine-gpg.c b/src/engine-gpg.c
index 9fa9994..c2ad3e9 100644
--- a/src/engine-gpg.c
+++ b/src/engine-gpg.c
@@ -1835,6 +1835,15 @@ export_common (engine_gpg_t gpg, gpgme_export_mode_t mode,
     ;
   else if ((mode & GPGME_EXPORT_MODE_EXTERN))
     {
+      char *tmp;
+      _gpgme_getenv ("GPG_KEYSERVER", &tmp);
+      if (tmp)
+        {
+          err = add_arg (gpg, "--keyserver");
+          if (!err)
+           add_arg (gpg, tmp);
+          free(tmp);
+        }
       err = add_arg (gpg, "--send-keys");
     }
   else

Thank you
Seiya


More information about the Gnupg-devel mailing list