diff --git a/doc/gpgme.texi b/doc/gpgme.texi --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -3095,6 +3095,16 @@ @code{legacy_cipher_nomdc} set. For failsafe reasons this flag is reset after each operation. +@item "auto-key-locate" +The string given in @var{value} is passed to gpg. This can be used +to change the behavior of a @code{GPGME_KEYLIST_MODE_LOCATE} keylisting. +Valid values are documented in the GnuPG manual and the gpg man page under +the option @option{--auto-key-locate}. +Requires at least GnuPG 2.0.10 to have an effect. + +Note: Keys retrieved through @code{auto-key-locate} are automatically +imported in the keyring. + @end table This function returns @code{0} on success. diff --git a/src/context.h b/src/context.h --- a/src/context.h +++ b/src/context.h @@ -155,6 +155,9 @@ /* The optional request origin. */ char *request_origin; + /* The optional auto key locate options. */ + char *auto_key_locate; + /* The locale for the pinentry. */ char *lc_ctype; char *lc_messages; diff --git a/src/engine-gpg.c b/src/engine-gpg.c --- a/src/engine-gpg.c +++ b/src/engine-gpg.c @@ -140,6 +140,7 @@ struct gpgme_io_cbs io_cbs; gpgme_pinentry_mode_t pinentry_mode; char request_origin[10]; + char auto_key_locate[100]; struct { unsigned int no_symkey_cache : 1; @@ -645,6 +646,16 @@ else *gpg->request_origin = 0; + if (ctx->auto_key_locate && have_gpg_version (gpg, "2.0.10")) + { + if (strlen (ctx->auto_key_locate) + 1 > sizeof gpg->auto_key_locate) + strcpy (gpg->auto_key_locate, "xxx"); /* Too long - force error */ + else + strcpy (gpg->auto_key_locate, ctx->auto_key_locate); + } + else + *gpg->auto_key_locate = 0; + gpg->flags.no_symkey_cache = (ctx->no_symkey_cache && have_gpg_version (gpg, "2.2.7")); gpg->flags.offline = (ctx->offline && have_gpg_version (gpg, "2.1.23")); @@ -944,6 +955,20 @@ argc++; } + if (*gpg->auto_key_locate) + { + argv[argc] = _gpgme_strconcat ("--auto-key-locate=", + gpg->auto_key_locate, NULL); + if (!argv[argc]) + { + int saved_err = gpg_error_from_syserror (); + free (fd_data_map); + free_argv (argv); + return saved_err; + } + argc++; + } + if (gpg->flags.no_symkey_cache) { argv[argc] = strdup ("--no-symkey-cache"); diff --git a/src/gpgme.c b/src/gpgme.c --- a/src/gpgme.c +++ b/src/gpgme.c @@ -249,6 +249,7 @@ free (ctx->lc_messages); free (ctx->override_session_key); free (ctx->request_origin); + free (ctx->auto_key_locate); _gpgme_engine_info_release (ctx->engine_info); ctx->engine_info = NULL; DESTROY_LOCK (ctx->lock); @@ -546,6 +547,13 @@ { ctx->ignore_mdc_error = abool; } + else if (!strcmp (name, "auto-key-locate")) + { + free (ctx->auto_key_locate); + ctx->auto_key_locate = strdup (value); + if (!ctx->auto_key_locate) + err = gpg_error_from_syserror (); + } else err = gpg_error (GPG_ERR_UNKNOWN_NAME); @@ -599,6 +607,10 @@ { return ctx->ignore_mdc_error? "1":""; } + else if (!strcmp (name, "auto-key-locate")) + { + return ctx->auto_key_locate? ctx->auto_key_locate : ""; + } else return NULL; } diff --git a/tests/run-keylist.c b/tests/run-keylist.c --- a/tests/run-keylist.c +++ b/tests/run-keylist.c @@ -57,6 +57,7 @@ " --import import all keys\n" " --offline use offline mode\n" " --from-file list all keys in the given file\n" + " --from-wkd list key from a web key directory\n" " --require-gnupg required at least the given GnuPG version\n" , stderr); exit (ex); @@ -100,6 +101,7 @@ int only_secret = 0; int offline = 0; int from_file = 0; + int from_wkd = 0; gpgme_data_t data = NULL; @@ -194,6 +196,12 @@ gpgme_set_global_flag ("require-gnupg", *argv); argc--; argv++; } + else if (!strcmp (*argv, "--from-wkd")) + { + argc--; argv++; + mode |= GPGME_KEYLIST_MODE_LOCATE; + from_wkd = 1; + } else if (!strncmp (*argv, "--", 2)) show_usage (1); } @@ -213,6 +221,13 @@ gpgme_set_offline (ctx, offline); + if (from_wkd) + { + err = gpgme_set_ctx_flag (ctx, "auto-key-locate", + "clear,nodefault,wkd"); + fail_if_err (err); + } + if (from_file) { err = gpgme_data_new_from_file (&data, *argv, 1);