From d058d80ed0d5edeff6d85108054b1dfd45ddad7d Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 23 Aug 2019 13:22:15 +0200 Subject: [PATCH] gpg: Allow --locate-external-key even with --no-auto-key-locate. * g10/getkey.c (akl_empty_or_only_local): New. * g10/gpg.c (DEFAULT_AKL_LIST): New. (main): Use it here. (main) : Set default AKL if none is set. -- This better matches the expectations of the user. The used list in this case is the default list ("local,wkd") with local ignored by the command anyway. GnuPG-bug-id: 4662 Signed-off-by: Werner Koch --- g10/getkey.c | 20 ++++++++++++++++++++ g10/gpg.c | 15 ++++++++++++++- g10/keydb.h | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/g10/getkey.c b/g10/getkey.c index 57617a0a9..dc3dc4844 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -3922,6 +3922,26 @@ release_akl (void) } } + +/* Returns true if the AKL is empty or has only the local method + * active. */ +int +akl_empty_or_only_local (void) +{ + struct akl *akl; + int any = 0; + + for (akl = opt.auto_key_locate; akl; akl = akl->next) + if (akl->type != AKL_NODEFAULT && akl->type != AKL_LOCAL) + { + any = 1; + break; + } + + return !any; +} + + /* Returns false on error. */ int parse_auto_key_locate (const char *options_arg) diff --git a/g10/gpg.c b/g10/gpg.c index 0b7788971..6da36c2d4 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -961,6 +961,9 @@ static struct debug_flags_s debug_flags [] = #define ALWAYS_ADD_KEYRINGS 0 #endif +/* The list of the default AKL methods. */ +#define DEFAULT_AKL_LIST "local,wkd" + int g10_errors_seen = 0; @@ -2535,7 +2538,7 @@ main (int argc, char **argv) /* Set default options which require that malloc stuff is ready. */ additional_weak_digest ("MD5"); - parse_auto_key_locate ("local,wkd"); + parse_auto_key_locate (DEFAULT_AKL_LIST); /* Try for a version specific config file first */ default_configname = get_default_configname (); @@ -4544,7 +4547,17 @@ main (int argc, char **argv) sl = NULL; for (; argc; argc--, argv++) add_to_strlist2( &sl, *argv, utf8_strings ); + if (cmd == aLocateExtKeys && akl_empty_or_only_local ()) + { + /* This is a kludge to let --locate-external-keys even + * work if the config file has --no-auto-key-locate. This + * better matches the expectations of the user. */ + release_akl (); + parse_auto_key_locate (DEFAULT_AKL_LIST); + } public_key_list (ctrl, sl, 1, cmd == aLocateExtKeys); + + free_strlist (sl); break; diff --git a/g10/keydb.h b/g10/keydb.h index 6ad8dce4c..6b719ad44 100644 --- a/g10/keydb.h +++ b/g10/keydb.h @@ -448,6 +448,7 @@ char *get_user_id_native (ctrl_t ctrl, u32 *keyid); char *get_user_id_byfpr_native (ctrl_t ctrl, const byte *fpr, size_t fprlen); void release_akl(void); +int akl_empty_or_only_local (void); int parse_auto_key_locate(const char *options); int parse_key_origin (char *string); const char *key_origin_string (int origin);