aboutsummaryrefslogtreecommitdiffstats
path: root/g10/getkey.c
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2005-12-23 21:33:32 +0000
committerDavid Shaw <[email protected]>2005-12-23 21:33:32 +0000
commit8b9c16ed0aa9e9002af78a9f7739ae9c218d3431 (patch)
tree1cd08d3e65e3155b6ba7c7ff76287ee3f82c7286 /g10/getkey.c
parent* ksutil.h, ksutil.c (parse_ks_options): New keyserver command "getname". (diff)
downloadgnupg-8b9c16ed0aa9e9002af78a9f7739ae9c218d3431.tar.gz
gnupg-8b9c16ed0aa9e9002af78a9f7739ae9c218d3431.zip
* gpgv.c: Stub.
* keyserver-internal.h, keyserver.c (keyserver_spawn, keyserver_work, keygerver_getname): New keyserver_getname function to fetch keys by name. * getkey.c (get_pubkey_byname): Call it here to enable locating keys by full mailbox from a keyserver a la PKA. Try PKA first, though, as it is likely to be faster.
Diffstat (limited to 'g10/getkey.c')
-rw-r--r--g10/getkey.c74
1 files changed, 46 insertions, 28 deletions
diff --git a/g10/getkey.c b/g10/getkey.c
index e66b57cdd..ebd1345fd 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -905,42 +905,60 @@ get_pubkey_byname (PKT_public_key *pk,
KEYDB_HANDLE *ret_kdbhd, int include_unusable )
{
int rc;
- int again = 0;
+ int tried_ks=0, tried_pka=0;
STRLIST namelist = NULL;
add_to_strlist( &namelist, name );
retry:
rc = key_byname( NULL, namelist, pk, NULL, 0,
include_unusable, ret_keyblock, ret_kdbhd);
- if (rc == G10ERR_NO_PUBKEY
- && !again
- && opt.allow_pka_lookup
- && (opt.keyserver_options.options&KEYSERVER_AUTO_PKA_RETRIEVE)
- && is_valid_mailbox (name))
+
+ if (rc == G10ERR_NO_PUBKEY && is_valid_mailbox(name))
{
- /* If the requested name resembles a valid mailbox and
- automatic retrieval via PKA records has been enabled, we
- try to import the key via the URI and try again. */
- unsigned char fpr[MAX_FINGERPRINT_LEN];
- char *uri;
- struct keyserver_spec *spec;
+ if(!tried_pka
+ && opt.allow_pka_lookup
+ && (opt.keyserver_options.options&KEYSERVER_AUTO_PKA_RETRIEVE))
+ {
+ /* If the requested name resembles a valid mailbox and
+ automatic retrieval via PKA records has been enabled, we
+ try to import the key via the URI and try again. */
+ unsigned char fpr[MAX_FINGERPRINT_LEN];
+ char *uri;
+ struct keyserver_spec *spec;
+ int try=1;
+
+ tried_pka=1;
- uri = get_pka_info (name, fpr);
- if (uri)
- {
- spec = parse_keyserver_uri (uri, 0, NULL, 0);
- if (spec)
- {
- glo_ctrl.in_auto_key_retrieve++;
- if (!keyserver_import_fprint (fpr, 20, spec))
- again = 1;
- glo_ctrl.in_auto_key_retrieve--;
- free_keyserver_spec (spec);
- }
- xfree (uri);
- }
- if (again)
- goto retry;
+ uri = get_pka_info (name, fpr);
+ if (uri)
+ {
+ spec = parse_keyserver_uri (uri, 0, NULL, 0);
+ if (spec)
+ {
+ glo_ctrl.in_auto_key_retrieve++;
+ try=keyserver_import_fprint (fpr, 20, spec);
+ glo_ctrl.in_auto_key_retrieve--;
+ free_keyserver_spec (spec);
+ }
+ xfree (uri);
+ }
+ if (try==0)
+ goto retry;
+ }
+
+ /* Try keyserver last as it is likely to be the slowest.
+ Strictly speaking, we don't need to only use a valid mailbox
+ for the getname search, but it helps cut down on a problem
+ with searching for something like "john" and getting a lot of
+ keys back. */
+ if(!tried_ks
+ && (opt.keyserver_options.options&KEYSERVER_AUTO_KEY_RETRIEVE))
+ {
+ tried_ks=1;
+
+ if(keyserver_getname(name)==0)
+ goto retry;
+ }
}
free_strlist( namelist );