From 3b9815bd8ad723445128ae99883be0072ae389a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Wed, 12 Jun 2024 10:45:11 +0200 Subject: core: Allow setting import options when importing keys * src/context.h (struct gpgme_context): New field import_options. * src/engine-backend.h (struct engine_ops): Add arg import_options to field 'import'. * src/engine-gpg.c (gpg_import): Add arg import_options and pass option --import-options with argument value to gpg. * src/engine-gpgsm.c (gpgsm_import): Add dummy arg import_options. * src/engine.c (_gpgme_engine_op_import): Add arg import_options and pass option to import function of engine. * src/engine.h (_gpgme_engine_op_import): Add arg import_options. * src/gpgme.c (gpgme_release): Free 'import_options'. (gpgme_set_ctx_flag, gpgme_get_ctx_flag): New flag "import-options". * src/import.c (_gpgme_op_import_start, _gpgme_op_import_keys_start, _gpgme_op_receive_keys_start): Pass import options stored in context to _gpgme_engine_op_import. * tests/run-import.c (show_usage, main): Add option --import-options. -- This makes the --import-options option available in the GPGME API for key imports. GnuPG-bug-id: 7152 --- tests/run-import.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') 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); -- cgit v1.2.3