diff --git a/g10/ChangeLog b/g10/ChangeLog index d6bf03c2c..b1154458b 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,13 @@ +2005-12-07 David Shaw + + * keyserver.c (keyserver_spawn): Don't print "searching for key + 00000000" when fetching a URI. + + * keyserver-internal.h, keyserver.c (keyserver_fetch): New. Fetch + an arbitrary URI using the keyserver helpers. + + * gpg.c (main): Call it from here for --fetch-keys. + 2005-11-20 David Shaw * main.h, keylist.c (print_revokers): New. Print the "rvk" diff --git a/g10/gpg.c b/g10/gpg.c index 1080f9992..81bf454c2 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -127,6 +127,8 @@ enum cmd_and_opt_values aSendKeys, aRecvKeys, aSearchKeys, + aRefreshKeys, + aFetchKeys, aExport, aExportSecret, aExportSecretSub, @@ -149,7 +151,6 @@ enum cmd_and_opt_values aGenRandom, aPipeMode, aRebuildKeydbCaches, - aRefreshKeys, aCardStatus, aCardEdit, aChangePIN, @@ -399,6 +400,7 @@ static ARGPARSE_OPTS opts[] = { N_("search for keys on a key server") }, { aRefreshKeys, "refresh-keys", 256, N_("update all keys from a keyserver")}, + { aFetchKeys, "fetch-keys" , 256, "@" }, { aExportSecret, "export-secret-keys" , 256, "@" }, { aExportSecretSub, "export-secret-subkeys" , 256, "@" }, { aImport, "import", 256 , N_("import/merge keys")}, @@ -1901,6 +1903,7 @@ main (int argc, char **argv ) case aRecvKeys: case aSearchKeys: case aRefreshKeys: + case aFetchKeys: case aExport: set_cmd (&cmd, pargs.r_opt); break; @@ -3389,6 +3392,16 @@ main (int argc, char **argv ) free_strlist(sl); break; + case aFetchKeys: + sl = NULL; + for( ; argc; argc--, argv++ ) + add_to_strlist2( &sl, *argv, utf8_strings ); + rc=keyserver_fetch(sl); + if(rc) + log_error("key fetch failed: %s\n",g10_errstr(rc)); + free_strlist(sl); + break; + case aExportSecret: sl = NULL; for( ; argc; argc--, argv++ ) diff --git a/g10/keyserver-internal.h b/g10/keyserver-internal.h index 2ead5a067..d64269030 100644 --- a/g10/keyserver-internal.h +++ b/g10/keyserver-internal.h @@ -40,5 +40,6 @@ int keyserver_import_fprint(const byte *fprint,size_t fprint_len, int keyserver_import_keyid(u32 *keyid,struct keyserver_spec *keyserver); int keyserver_refresh(STRLIST users); int keyserver_search(STRLIST tokens); +int keyserver_fetch(STRLIST urilist); #endif /* !_KEYSERVER_INTERNAL_H_ */ diff --git a/g10/keyserver.c b/g10/keyserver.c index b9c96e8ac..69391ec82 100644 --- a/g10/keyserver.c +++ b/g10/keyserver.c @@ -883,7 +883,7 @@ static int keyserver_spawn(int action,STRLIST list,KEYDB_SEARCH_DESC *desc, int count,int *prog,struct keyserver_spec *keyserver) { - int ret=0,i,gotversion=0,outofband=0; + int ret=0,i,gotversion=0,outofband=0,quiet=0; STRLIST temp; unsigned int maxlen,buflen; char *command,*end,*searchstr=NULL; @@ -1047,18 +1047,26 @@ keyserver_spawn(int action,STRLIST list,KEYDB_SEARCH_DESC *desc, else if(desc[i].mode==KEYDB_SEARCH_MODE_SHORT_KID) fprintf(spawn->tochild,"0x%08lX\n", (ulong)desc[i].u.kid[1]); + else if(desc[i].mode==KEYDB_SEARCH_MODE_EXACT) + { + fprintf(spawn->tochild,"0x0000000000000000\n"); + quiet=1; + } else if(desc[i].mode==KEYDB_SEARCH_MODE_NONE) continue; else BUG(); - if(keyserver->host) - log_info(_("requesting key %s from %s server %s\n"), - keystr_from_desc(&desc[i]), - keyserver->scheme,keyserver->host); - else - log_info(_("requesting key %s from %s\n"), - keystr_from_desc(&desc[i]),keyserver->uri); + if(!quiet) + { + if(keyserver->host) + log_info(_("requesting key %s from %s server %s\n"), + keystr_from_desc(&desc[i]), + keyserver->scheme,keyserver->host); + else + log_info(_("requesting key %s from %s\n"), + keystr_from_desc(&desc[i]),keyserver->uri); + } } fprintf(spawn->tochild,"\n"); @@ -1705,7 +1713,7 @@ keyidlist(STRLIST users,KEYDB_SEARCH_DESC **klist,int *count,int fakev3) /* Note this is different than the original HKP refresh. It allows usernames to refresh only part of the keyring. */ -int +int keyserver_refresh(STRLIST users) { int rc,count,numdesc,fakev3=0; @@ -1802,3 +1810,34 @@ keyserver_search(STRLIST tokens) else return 0; } + +int +keyserver_fetch(STRLIST urilist) +{ + KEYDB_SEARCH_DESC desc; + STRLIST sl; + + /* A dummy desc since we're not actually fetching a particular key + ID */ + memset(&desc,0,sizeof(desc)); + desc.mode=KEYDB_SEARCH_MODE_EXACT; + + for(sl=urilist;sl;sl=sl->next) + { + struct keyserver_spec *spec; + + spec=parse_keyserver_uri(sl->d,1,NULL,0); + if(spec) + { + int rc=keyserver_work(GET,NULL,&desc,1,spec); + if(rc) + log_info("WARNING: unable to fetch URI %s: %s\n", + sl->d,g10_errstr(rc)); + free_keyserver_spec(spec); + } + else + log_info("WARNING: unable to parse URI %s\n",sl->d); + } + + return 0; +}