diff --git a/NEWS b/NEWS index b7309454..7335e198 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ Noteworthy changes in version 1.24.0 (unrelease) * Add information about designated revocation keys. [T7118] + * New context flag "import-options". [#7152] + * cpp: Provide information about designated revocation keys for a Key. [T7118] @@ -24,6 +26,7 @@ Noteworthy changes in version 1.24.0 (unrelease) GPGME_SIG_MODE_FILE NEW. gpgme_key_t EXTENDED: New field 'revkeys'. gpgme_revocation_key_t NEW. + gpgme_set_ctx_flag EXTENDED: New flag 'import-options'. cpp: Context::EncryptFile NEW. cpp: SignatureMode::SignFile NEW. cpp: RevocationKey NEW. diff --git a/doc/gpgme.texi b/doc/gpgme.texi index 45dc9e9b..b2bf6f8c 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -3279,6 +3279,12 @@ The string given in @var{value} is passed to the GnuPG engine to use as filter when importing keys. Valid values are documented in the GnuPG manual and the gpg man page under the option @option{--import-filter}. +@item "import-options" +@since{1.24.0} +The string given in @var{value} is passed to the GnuPG engine to use as +options when importing keys. Valid values are documented in the GnuPG +manual and the gpg man page under the option @option{--import-options}. + @item "no-auto-check-trustdb" @since{1.19.0} Setting the @var{value} to "1" forces the GPG backend to disable the diff --git a/src/context.h b/src/context.h index 7a1b9ada..454625e7 100644 --- a/src/context.h +++ b/src/context.h @@ -186,6 +186,9 @@ struct gpgme_context /* The optional import filter. */ char *import_filter; + /* The optional import options. */ + char *import_options; + /* The operation data hooked into the context. */ ctx_op_data_t op_data; diff --git a/src/engine-backend.h b/src/engine-backend.h index 850ffaa9..8c98e5a3 100644 --- a/src/engine-backend.h +++ b/src/engine-backend.h @@ -98,6 +98,7 @@ struct engine_ops gpgme_key_t *keyarray, const char *keyids[], const char *import_filter, + const char *import_options, const char *key_origin); gpgme_error_t (*keylist) (void *engine, const char *pattern, int secret_only, gpgme_keylist_mode_t mode); diff --git a/src/engine-gpg.c b/src/engine-gpg.c index fd7064b5..376dad0a 100644 --- a/src/engine-gpg.c +++ b/src/engine-gpg.c @@ -3075,7 +3075,7 @@ string_from_data (gpgme_data_t data, int delim, static gpgme_error_t gpg_import (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray, const char *keyids[], const char *import_filter, - const char *key_origin) + const char *import_options, const char *key_origin) { engine_gpg_t gpg = engine; gpgme_error_t err; @@ -3090,6 +3090,12 @@ gpg_import (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray, if (keyids) { err = add_arg (gpg, "--recv-keys"); + if (!err && import_options) + { + err = add_arg (gpg, "--import-options"); + if (!err) + err = add_arg (gpg, import_options); + } if (!err && import_filter && have_gpg_version (gpg, "2.1.14")) { err = add_arg (gpg, "--import-filter"); @@ -3104,6 +3110,12 @@ gpg_import (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray, else if (keyarray) { err = add_arg (gpg, "--recv-keys"); + if (!err && import_options) + { + err = add_arg (gpg, "--import-options"); + if (!err) + err = add_arg (gpg, import_options); + } if (!err && import_filter && have_gpg_version (gpg, "2.1.14")) { err = add_arg (gpg, "--import-filter"); @@ -3141,6 +3153,12 @@ gpg_import (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray, should use an option to gpg to modify such commands (ala --multifile). */ err = add_arg (gpg, "--fetch-keys"); + if (!err && import_options) + { + err = add_arg (gpg, "--import-options"); + if (!err) + err = add_arg (gpg, import_options); + } if (!err && import_filter && have_gpg_version (gpg, "2.1.14")) { err = add_arg (gpg, "--import-filter"); @@ -3165,6 +3183,12 @@ gpg_import (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray, else { err = add_arg (gpg, "--import"); + if (!err && import_options) + { + err = add_arg (gpg, "--import-options"); + if (!err) + err = add_arg (gpg, import_options); + } if (!err && import_filter && have_gpg_version (gpg, "2.1.14")) { err = add_arg (gpg, "--import-filter"); diff --git a/src/engine-gpgsm.c b/src/engine-gpgsm.c index fa89ae3f..8ee29de8 100644 --- a/src/engine-gpgsm.c +++ b/src/engine-gpgsm.c @@ -1795,7 +1795,7 @@ gpgsm_genkey (void *engine, static gpgme_error_t gpgsm_import (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray, const char *keyids[], const char *import_filter, - const char *key_origin) + const char *import_options, const char *key_origin) { engine_gpgsm_t gpgsm = engine; gpgme_error_t err; @@ -1803,6 +1803,7 @@ gpgsm_import (void *engine, gpgme_data_t keydata, gpgme_key_t *keyarray, int idx; (void)import_filter; + (void)import_options; (void)key_origin; if (!gpgsm) diff --git a/src/engine.c b/src/engine.c index 252d8805..f1efdf34 100644 --- a/src/engine.c +++ b/src/engine.c @@ -858,7 +858,8 @@ _gpgme_engine_op_tofu_policy (engine_t engine, gpgme_error_t _gpgme_engine_op_import (engine_t engine, gpgme_data_t keydata, gpgme_key_t *keyarray, const char *keyids[], - const char *import_filter, const char *key_origin) + const char *import_filter, const char *import_options, + const char *key_origin) { if (!engine) return gpg_error (GPG_ERR_INV_VALUE); @@ -867,7 +868,7 @@ _gpgme_engine_op_import (engine_t engine, gpgme_data_t keydata, return gpg_error (GPG_ERR_NOT_IMPLEMENTED); return (*engine->ops->import) (engine->engine, keydata, keyarray, keyids, - import_filter, key_origin); + import_filter, import_options, key_origin); } diff --git a/src/engine.h b/src/engine.h index 654deddf..ae57cbed 100644 --- a/src/engine.h +++ b/src/engine.h @@ -144,6 +144,7 @@ gpgme_error_t _gpgme_engine_op_import (engine_t engine, gpgme_key_t *keyarray, const char *keyids[], const char *import_filter, + const char *import_options, const char *key_origin); gpgme_error_t _gpgme_engine_op_keylist (engine_t engine, const char *pattern, diff --git a/src/gpgme.c b/src/gpgme.c index 135a75a7..f6d7f38d 100644 --- a/src/gpgme.c +++ b/src/gpgme.c @@ -261,6 +261,7 @@ gpgme_release (gpgme_ctx_t ctx) free (ctx->cert_expire); free (ctx->key_origin); free (ctx->import_filter); + free (ctx->import_options); _gpgme_engine_info_release (ctx->engine_info); ctx->engine_info = NULL; DESTROY_LOCK (ctx->lock); @@ -607,6 +608,13 @@ gpgme_set_ctx_flag (gpgme_ctx_t ctx, const char *name, const char *value) if (!ctx->import_filter) err = gpg_error_from_syserror (); } + else if (!strcmp (name, "import-options")) + { + free (ctx->import_options); + ctx->import_options = strdup (value); + if (!ctx->import_options) + err = gpg_error_from_syserror (); + } else if (!strcmp (name, "no-auto-check-trustdb")) { ctx->no_auto_check_trustdb = abool; @@ -692,6 +700,10 @@ gpgme_get_ctx_flag (gpgme_ctx_t ctx, const char *name) { return ctx->import_filter? ctx->import_filter : ""; } + else if (!strcmp (name, "import-options")) + { + return ctx->import_options? ctx->import_options : ""; + } else if (!strcmp (name, "no-auto-check-trustdb")) { return ctx->no_auto_check_trustdb? "1":""; diff --git a/src/import.c b/src/import.c index f288a811..d8c9adcb 100644 --- a/src/import.c +++ b/src/import.c @@ -368,7 +368,8 @@ _gpgme_op_import_start (gpgme_ctx_t ctx, int synchronous, gpgme_data_t keydata) ctx); return _gpgme_engine_op_import (ctx->engine, keydata, NULL, NULL, - ctx->import_filter, ctx->key_origin); + ctx->import_filter, ctx->import_options, + ctx->key_origin); } @@ -448,7 +449,8 @@ _gpgme_op_import_keys_start (gpgme_ctx_t ctx, int synchronous, ctx); return _gpgme_engine_op_import (ctx->engine, NULL, keys, NULL, - ctx->import_filter, ctx->key_origin); + ctx->import_filter, ctx->import_options, + ctx->key_origin); } @@ -541,7 +543,8 @@ _gpgme_op_receive_keys_start (gpgme_ctx_t ctx, int synchronous, const char *keyi ctx); return _gpgme_engine_op_import (ctx->engine, NULL, NULL, keyids, - ctx->import_filter, ctx->key_origin); + ctx->import_filter, ctx->import_options, + ctx->key_origin); } diff --git a/tests/run-import.c b/tests/run-import.c index b0320ef8..0e9a300f 100644 --- a/tests/run-import.c +++ b/tests/run-import.c @@ -48,6 +48,7 @@ show_usage (int ex) " --cms use the CMS protocol\n" " --offline use offline mode\n" " --key-origin use the specified key origin\n" + " --import-options use the specified import options\n" " --url import from given URLs\n" " -0 URLs are delimited by a nul\n" , stderr); @@ -65,6 +66,7 @@ main (int argc, char **argv) gpgme_import_result_t impres; gpgme_data_t data; gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP; + char *import_options = NULL; char *import_filter = NULL; char *key_origin = NULL; int offline = 0; @@ -106,6 +108,14 @@ main (int argc, char **argv) protocol = GPGME_PROTOCOL_CMS; argc--; argv++; } + else if (!strcmp (*argv, "--import-options")) + { + argc--; argv++; + if (!argc) + show_usage (1); + import_options = strdup (*argv); + argc--; argv++; + } else if (!strcmp (*argv, "--import-filter")) { argc--; argv++; @@ -143,6 +153,11 @@ main (int argc, char **argv) gpgme_set_offline (ctx, offline); + if (import_options) + { + err = gpgme_set_ctx_flag (ctx, "import-options", import_options); + fail_if_err (err); + } if (import_filter) { err = gpgme_set_ctx_flag (ctx, "import-filter", import_filter);