From 7f541547fc1783bb9ea119695fb76e2000bdfcf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Wed, 1 Feb 2023 09:27:12 +0100 Subject: [PATCH] core: Allow usage of gpgtar also for new enough gpg 2.2 * src/engine-gpg.c (have_usable_gpgtar): New. (start): Always pass --status-fd to the called process. (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign, gpg_sign, gpg_verify): Use have_usable_gpgtar() to check for suitable gpg. -- The version check in start() is not needed because versions of gpg that are unsuitable for the usage of gpgtar are rejected already by the callers. GnuPG-bug-id: 6342 --- src/engine-gpg.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/engine-gpg.c b/src/engine-gpg.c index 41f24d1e..e766f08e 100644 --- a/src/engine-gpg.c +++ b/src/engine-gpg.c @@ -389,6 +389,14 @@ gpg_get_req_version (void) } +static int +have_usable_gpgtar (engine_gpg_t gpg) +{ + return have_gpg_version (gpg, "2.4.1") + || (have_gpg_version (gpg, "2.2.42") && !have_gpg_version (gpg, "2.3.0")); +} + + static void free_argv (char **argv) { @@ -1669,21 +1677,17 @@ start (engine_gpg_t gpg) return rc; } - if (!gpg->flags.use_gpgtar || have_gpg_version (gpg, "2.4.1")) - { - /* Do not pass --status-fd to gpgtar for gpg < 2.4.1. */ - { - char buf[25]; - _gpgme_io_fd2str (buf, sizeof (buf), gpg->status.fd[1]); - rc = add_arg_with_locp (gpg, buf, &gpg->status.arg_loc, 1); - if (rc) - return rc; - } + { + char buf[25]; + _gpgme_io_fd2str (buf, sizeof (buf), gpg->status.fd[1]); + rc = add_arg_with_locp (gpg, buf, &gpg->status.arg_loc, 1); + if (rc) + return rc; + } - rc = add_arg_ext (gpg, "--status-fd", 1); - if (rc) - return rc; - } + rc = add_arg_ext (gpg, "--status-fd", 1); + if (rc) + return rc; if (gpg->lc_ctype) { @@ -1832,7 +1836,7 @@ gpg_decrypt (void *engine, gpg->flags.use_gpgtar = !!(flags & GPGME_DECRYPT_ARCHIVE); - if (gpg->flags.use_gpgtar && !have_gpg_version (gpg, "2.4.1")) + if (gpg->flags.use_gpgtar && !have_usable_gpgtar (gpg)) return gpg_error (GPG_ERR_NOT_SUPPORTED); if (gpg->flags.use_gpgtar && (flags & GPGME_DECRYPT_UNWRAP)) @@ -2334,7 +2338,7 @@ gpg_encrypt (void *engine, gpgme_key_t recp[], const char *recpstring, gpg->flags.use_gpgtar = !!(flags & GPGME_ENCRYPT_ARCHIVE); - if (gpg->flags.use_gpgtar && !have_gpg_version (gpg, "2.4.1")) + if (gpg->flags.use_gpgtar && !have_usable_gpgtar (gpg)) return gpg_error (GPG_ERR_NOT_SUPPORTED); if (gpg->flags.use_gpgtar && (flags & GPGME_ENCRYPT_WRAP)) @@ -2449,7 +2453,7 @@ gpg_encrypt_sign (void *engine, gpgme_key_t recp[], gpg->flags.use_gpgtar = !!(flags & GPGME_ENCRYPT_ARCHIVE); - if (gpg->flags.use_gpgtar && !have_gpg_version (gpg, "2.4.1")) + if (gpg->flags.use_gpgtar && !have_usable_gpgtar (gpg)) return gpg_error (GPG_ERR_NOT_SUPPORTED); if (recp || recpstring) @@ -3594,7 +3598,7 @@ gpg_sign (void *engine, gpgme_data_t in, gpgme_data_t out, gpg->flags.use_gpgtar = !!(flags & GPGME_SIG_MODE_ARCHIVE); - if (gpg->flags.use_gpgtar && !have_gpg_version (gpg, "2.4.1")) + if (gpg->flags.use_gpgtar && !have_usable_gpgtar (gpg)) return gpg_error (GPG_ERR_NOT_SUPPORTED); if (flags & GPGME_SIG_MODE_CLEAR) @@ -3678,7 +3682,7 @@ gpg_verify (void *engine, gpgme_verify_flags_t flags, gpgme_data_t sig, gpg->flags.use_gpgtar = !!(flags & GPGME_VERIFY_ARCHIVE); - if (gpg->flags.use_gpgtar && !have_gpg_version (gpg, "2.4.1")) + if (gpg->flags.use_gpgtar && !have_usable_gpgtar (gpg)) return gpg_error (GPG_ERR_NOT_SUPPORTED); err = append_args_from_sender (gpg, ctx);