diff options
Diffstat (limited to 'g10')
-rw-r--r-- | g10/ChangeLog | 5 | ||||
-rw-r--r-- | g10/call-dirmngr.c | 61 | ||||
-rw-r--r-- | g10/keyserver.c | 49 |
3 files changed, 89 insertions, 26 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog index 8d850a65f..8594110f5 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,8 @@ +2011-02-08 Werner Koch <[email protected]> + + * call-dirmngr.c (gpg_dirmngr_ks_fetch): New. + * keyserver.c (keyserver_fetch): Rewrite to use dirmngr. + 2011-02-07 Werner Koch <[email protected]> * seskey.c (encode_md_value): Truncate to MDLEN and not to QBYTES diff --git a/g10/call-dirmngr.c b/g10/call-dirmngr.c index 10c0e568c..09ade4eb9 100644 --- a/g10/call-dirmngr.c +++ b/g10/call-dirmngr.c @@ -354,7 +354,7 @@ gpg_dirmngr_ks_search (ctrl_t ctrl, const char *searchstr, -/* Data callback for the KS_GET command. */ +/* Data callback for the KS_GET and KS_FETCH commands. */ static gpg_error_t ks_get_data_cb (void *opaque, const void *data, size_t datalen) { @@ -448,6 +448,65 @@ gpg_dirmngr_ks_get (ctrl_t ctrl, char **pattern, estream_t *r_fp) } +/* Run the KS_FETCH and pass URL as argument. On success an estream + object is returned to retrieve the keys. On error an error code is + returned and NULL stored at R_FP. + + The url is expected to point to a small set of keys; in many cases + only to one key. However, schemes like finger may return several + keys. Note that the configured keyservers are ignored by the + KS_FETCH command. */ +gpg_error_t +gpg_dirmngr_ks_fetch (ctrl_t ctrl, const char *url, estream_t *r_fp) +{ + gpg_error_t err; + assuan_context_t ctx; + struct ks_get_parm_s parm; + char *line = NULL; + + memset (&parm, 0, sizeof parm); + + *r_fp = NULL; + + err = open_context (ctrl, &ctx); + if (err) + return err; + + line = strconcat ("KS_FETCH -- ", url, NULL); + if (!line) + { + err = gpg_error_from_syserror (); + goto leave; + } + if (strlen (line) + 2 >= ASSUAN_LINELENGTH) + { + err = gpg_error (GPG_ERR_TOO_LARGE); + goto leave; + } + + parm.memfp = es_fopenmem (0, "rwb"); + if (!parm.memfp) + { + err = gpg_error_from_syserror (); + goto leave; + } + err = assuan_transact (ctx, line, ks_get_data_cb, &parm, + NULL, NULL, NULL, NULL); + if (err) + goto leave; + + es_rewind (parm.memfp); + *r_fp = parm.memfp; + parm.memfp = NULL; + + leave: + es_fclose (parm.memfp); + xfree (line); + close_context (ctrl, ctx); + return err; +} + + /* Handle the KS_PUT inquiries. */ static gpg_error_t diff --git a/g10/keyserver.c b/g10/keyserver.c index 2f055ada5..be0049a18 100644 --- a/g10/keyserver.c +++ b/g10/keyserver.c @@ -1641,54 +1641,53 @@ keyserver_put (ctrl_t ctrl, strlist_t keyspecs, } - int keyserver_fetch (ctrl_t ctrl, strlist_t urilist) { - KEYDB_SEARCH_DESC desc; + gpg_error_t err; strlist_t sl; - unsigned int options=opt.keyserver_options.import_options; + estream_t datastream; + unsigned int options = opt.keyserver_options.import_options; /* Switch on fast-import, since fetch can handle more than one import and we don't want each set to rebuild the trustdb. Instead we do it once at the end. */ - opt.keyserver_options.import_options|=IMPORT_FAST; - - /* A dummy desc since we're not actually fetching a particular key - ID */ - memset(&desc,0,sizeof(desc)); - desc.mode=KEYDB_SEARCH_MODE_EXACT; + opt.keyserver_options.import_options |= IMPORT_FAST; - for(sl=urilist;sl;sl=sl->next) + for (sl=urilist; sl; sl=sl->next) { - struct keyserver_spec *spec; + if (!opt.quiet) + log_info (_("requesting key from `%s'\n"), sl->d); - spec=parse_keyserver_uri(sl->d,1,NULL,0); - if(spec) - { - int rc; + err = gpg_dirmngr_ks_fetch (ctrl, sl->d, &datastream); + if (!err) + { + void *stats_handle; - rc = keyserver_get (ctrl, &desc, 1, spec); - if(rc) - log_info (_("WARNING: unable to fetch URI %s: %s\n"), - sl->d,g10_errstr(rc)); + stats_handle = import_new_stats_handle(); + import_keys_es_stream (ctrl, datastream, stats_handle, NULL, NULL, + opt.keyserver_options.import_options); - free_keyserver_spec(spec); - } + import_print_stats (stats_handle); + import_release_stats_handle (stats_handle); + } else - log_info (_("WARNING: unable to parse URI %s\n"),sl->d); + log_info (_("WARNING: unable to fetch URI %s: %s\n"), + sl->d, gpg_strerror (err)); + es_fclose (datastream); } - opt.keyserver_options.import_options=options; + opt.keyserver_options.import_options = options; /* If the original options didn't have fast import, and the trustdb is dirty, rebuild. */ - if(!(opt.keyserver_options.import_options&IMPORT_FAST)) - trustdb_check_or_update(); + if (!(opt.keyserver_options.import_options&IMPORT_FAST)) + trustdb_check_or_update (); return 0; } + /* Import key in a CERT or pointed to by a CERT */ int keyserver_import_cert (ctrl_t ctrl, |