* http.h, http.c (send_request): Pass in srvtag and make its presence
[gnupg.git] / keyserver / gpgkeys_hkp.c
blob0764fe2acacf13a534f644b21b31ece2bf9c4cfa
1 /* gpgkeys_hkp.c - talk to an HKP keyserver
2 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 * 2009 Free Software Foundation, Inc.
5 * This file is part of GnuPG.
7 * GnuPG is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuPG is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 * In addition, as a special exception, the Free Software Foundation
21 * gives permission to link the code of the keyserver helper tools:
22 * gpgkeys_ldap, gpgkeys_curl and gpgkeys_hkp with the OpenSSL
23 * project's "OpenSSL" library (or with modified versions of it that
24 * use the same license as the "OpenSSL" library), and distribute the
25 * linked executables. You must obey the GNU General Public License
26 * in all respects for all of the code used other than "OpenSSL". If
27 * you modify this file, you may extend this exception to your version
28 * of the file, but you are not obligated to do so. If you do not
29 * wish to do so, delete this exception statement from your version.
32 #include <config.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <stdlib.h>
36 #include <errno.h>
37 #include <unistd.h>
38 #ifdef HAVE_GETOPT_H
39 #include <getopt.h>
40 #endif
41 #ifdef HAVE_LIBCURL
42 #include <curl/curl.h>
43 #else
44 #include "curl-shim.h"
45 #endif
46 #ifdef USE_DNS_SRV
47 #include "srv.h"
48 #endif
49 #include "keyserver.h"
50 #include "ksutil.h"
52 extern char *optarg;
53 extern int optind;
55 static FILE *input,*output,*console;
56 static CURL *curl;
57 static struct ks_options *opt;
58 static char errorbuffer[CURL_ERROR_SIZE];
59 static char *proto,*port;
61 static size_t
62 curl_mrindex_writer(const void *ptr,size_t size,size_t nmemb,void *stream)
64 static int checked=0,swallow=0;
66 if(!checked)
68 /* If the document begins with a '<', assume it's a HTML
69 response, which we don't support. Discard the whole message
70 body. GPG can handle it, but this is an optimization to deal
71 with it on this side of the pipe. */
72 const char *buf=ptr;
73 if(buf[0]=='<')
74 swallow=1;
76 checked=1;
79 if(swallow || fwrite(ptr,size,nmemb,stream)==nmemb)
80 return size*nmemb;
81 else
82 return 0;
85 /* Append but avoid creating a double slash // in the path. */
86 static char *
87 append_path(char *dest,const char *src)
89 size_t n=strlen(dest);
91 if(src[0]=='/' && n>0 && dest[n-1]=='/')
92 dest[n-1]='\0';
94 return strcat(dest,src);
97 int
98 send_key(int *r_eof)
100 CURLcode res;
101 char request[MAX_URL+15];
102 int begin=0,end=0,ret=KEYSERVER_INTERNAL_ERROR;
103 char keyid[17],state[6];
104 char line[MAX_LINE];
105 char *key=NULL,*encoded_key=NULL;
106 size_t keylen=0,keymax=0;
108 /* Read and throw away input until we see the BEGIN */
110 while(fgets(line,MAX_LINE,input)!=NULL)
111 if(sscanf(line,"KEY%*[ ]%16s%*[ ]%5s\n",keyid,state)==2
112 && strcmp(state,"BEGIN")==0)
114 begin=1;
115 break;
118 if(!begin)
120 /* i.e. eof before the KEY BEGIN was found. This isn't an
121 error. */
122 *r_eof=1;
123 ret=KEYSERVER_OK;
124 goto fail;
127 /* Now slurp up everything until we see the END */
129 while(fgets(line,MAX_LINE,input))
130 if(sscanf(line,"KEY%*[ ]%16s%*[ ]%3s\n",keyid,state)==2
131 && strcmp(state,"END")==0)
133 end=1;
134 break;
136 else
138 if(strlen(line)+keylen>keymax)
140 char *tmp;
142 keymax+=200;
143 tmp=realloc(key,keymax+1);
144 if(!tmp)
146 free(key);
147 fprintf(console,"gpgkeys: out of memory\n");
148 ret=KEYSERVER_NO_MEMORY;
149 goto fail;
152 key=tmp;
155 strcpy(&key[keylen],line);
156 keylen+=strlen(line);
159 if(!end)
161 fprintf(console,"gpgkeys: no KEY %s END found\n",keyid);
162 *r_eof=1;
163 ret=KEYSERVER_KEY_INCOMPLETE;
164 goto fail;
167 encoded_key=curl_escape(key,keylen);
168 if(!encoded_key)
170 fprintf(console,"gpgkeys: out of memory\n");
171 ret=KEYSERVER_NO_MEMORY;
172 goto fail;
175 free(key);
177 key=malloc(8+strlen(encoded_key)+1);
178 if(!key)
180 fprintf(console,"gpgkeys: out of memory\n");
181 ret=KEYSERVER_NO_MEMORY;
182 goto fail;
185 strcpy(key,"keytext=");
186 strcat(key,encoded_key);
188 strcpy(request,proto);
189 strcat(request,"://");
190 strcat(request,opt->host);
191 strcat(request,":");
192 strcat(request,port);
193 strcat(request,opt->path);
194 /* request is MAX_URL+15 bytes long - MAX_URL covers the whole URL,
195 including any supplied path. The 15 covers /pks/add. */
196 append_path(request,"/pks/add");
198 if(opt->verbose>2)
199 fprintf(console,"gpgkeys: HTTP URL is `%s'\n",request);
201 curl_easy_setopt(curl,CURLOPT_URL,request);
202 curl_easy_setopt(curl,CURLOPT_POST,1L);
203 curl_easy_setopt(curl,CURLOPT_POSTFIELDS,key);
204 curl_easy_setopt(curl,CURLOPT_FAILONERROR,1L);
206 res=curl_easy_perform(curl);
207 if(res!=0)
209 fprintf(console,"gpgkeys: HTTP post error %d: %s\n",res,errorbuffer);
210 ret=curl_err_to_gpg_err(res);
211 goto fail;
213 else
214 fprintf(output,"\nKEY %s SENT\n",keyid);
216 ret=KEYSERVER_OK;
218 fail:
219 free(key);
220 curl_free(encoded_key);
222 if(ret!=0 && begin)
223 fprintf(output,"KEY %s FAILED %d\n",keyid,ret);
225 return ret;
228 static int
229 get_key(char *getkey)
231 CURLcode res;
232 char request[MAX_URL+60];
233 char *offset;
234 struct curl_writer_ctx ctx;
236 memset(&ctx,0,sizeof(ctx));
238 /* Build the search string. HKP only uses the short key IDs. */
240 if(strncmp(getkey,"0x",2)==0)
241 getkey+=2;
243 fprintf(output,"KEY 0x%s BEGIN\n",getkey);
245 if(strlen(getkey)==32)
247 fprintf(console,
248 "gpgkeys: HKP keyservers do not support v3 fingerprints\n");
249 fprintf(output,"KEY 0x%s FAILED %d\n",getkey,KEYSERVER_NOT_SUPPORTED);
250 return KEYSERVER_NOT_SUPPORTED;
253 strcpy(request,proto);
254 strcat(request,"://");
255 strcat(request,opt->host);
256 strcat(request,":");
257 strcat(request,port);
258 strcat(request,opt->path);
259 /* request is MAX_URL+55 bytes long - MAX_URL covers the whole URL,
260 including any supplied path. The 60 overcovers this /pks/... etc
261 string plus the 8 bytes of key id */
262 append_path(request,"/pks/lookup?op=get&options=mr&search=0x");
264 /* fingerprint or long key id. Take the last 8 characters and treat
265 it like a short key id */
266 if(strlen(getkey)>8)
267 offset=&getkey[strlen(getkey)-8];
268 else
269 offset=getkey;
271 strcat(request,offset);
273 if(opt->verbose>2)
274 fprintf(console,"gpgkeys: HTTP URL is `%s'\n",request);
276 curl_easy_setopt(curl,CURLOPT_URL,request);
277 curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,curl_writer);
278 ctx.stream=output;
279 curl_easy_setopt(curl,CURLOPT_FILE,&ctx);
281 res=curl_easy_perform(curl);
282 if(res!=CURLE_OK)
284 fprintf(console,"gpgkeys: HTTP fetch error %d: %s\n",res,errorbuffer);
285 fprintf(output,"\nKEY 0x%s FAILED %d\n",getkey,curl_err_to_gpg_err(res));
287 else
289 curl_writer_finalize(&ctx);
290 if(!ctx.flags.done)
292 fprintf(console,"gpgkeys: key %s not found on keyserver\n",getkey);
293 fprintf(output,"\nKEY 0x%s FAILED %d\n",
294 getkey,KEYSERVER_KEY_NOT_FOUND);
296 else
297 fprintf(output,"\nKEY 0x%s END\n",getkey);
300 return KEYSERVER_OK;
303 static int
304 get_name(const char *getkey)
306 CURLcode res;
307 char *request=NULL;
308 char *searchkey_encoded;
309 int ret=KEYSERVER_INTERNAL_ERROR;
310 struct curl_writer_ctx ctx;
312 memset(&ctx,0,sizeof(ctx));
314 searchkey_encoded=curl_escape((char *)getkey,0);
315 if(!searchkey_encoded)
317 fprintf(console,"gpgkeys: out of memory\n");
318 ret=KEYSERVER_NO_MEMORY;
319 goto fail;
322 request=malloc(MAX_URL+60+strlen(searchkey_encoded));
323 if(!request)
325 fprintf(console,"gpgkeys: out of memory\n");
326 ret=KEYSERVER_NO_MEMORY;
327 goto fail;
330 fprintf(output,"NAME %s BEGIN\n",getkey);
332 strcpy(request,proto);
333 strcat(request,"://");
334 strcat(request,opt->host);
335 strcat(request,":");
336 strcat(request,port);
337 strcat(request,opt->path);
338 append_path(request,"/pks/lookup?op=get&options=mr&search=");
339 strcat(request,searchkey_encoded);
341 if(opt->action==KS_GETNAME)
342 strcat(request,"&exact=on");
344 if(opt->verbose>2)
345 fprintf(console,"gpgkeys: HTTP URL is `%s'\n",request);
347 curl_easy_setopt(curl,CURLOPT_URL,request);
348 curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,curl_writer);
349 ctx.stream=output;
350 curl_easy_setopt(curl,CURLOPT_FILE,&ctx);
352 res=curl_easy_perform(curl);
353 if(res!=CURLE_OK)
355 fprintf(console,"gpgkeys: HTTP fetch error %d: %s\n",res,errorbuffer);
356 ret=curl_err_to_gpg_err(res);
358 else
360 curl_writer_finalize(&ctx);
361 if(!ctx.flags.done)
363 fprintf(console,"gpgkeys: key %s not found on keyserver\n",getkey);
364 ret=KEYSERVER_KEY_NOT_FOUND;
366 else
368 fprintf(output,"\nNAME %s END\n",getkey);
369 ret=KEYSERVER_OK;
373 fail:
374 curl_free(searchkey_encoded);
375 free(request);
377 if(ret!=KEYSERVER_OK)
378 fprintf(output,"\nNAME %s FAILED %d\n",getkey,ret);
380 return ret;
383 static int
384 search_key(const char *searchkey)
386 CURLcode res;
387 char *request=NULL;
388 char *searchkey_encoded;
389 int ret=KEYSERVER_INTERNAL_ERROR;
390 enum ks_search_type search_type;
392 search_type=classify_ks_search(&searchkey);
394 if(opt->debug)
395 fprintf(console,"gpgkeys: search type is %d, and key is \"%s\"\n",
396 search_type,searchkey);
398 searchkey_encoded=curl_escape((char *)searchkey,0);
399 if(!searchkey_encoded)
401 fprintf(console,"gpgkeys: out of memory\n");
402 ret=KEYSERVER_NO_MEMORY;
403 goto fail;
406 request=malloc(MAX_URL+60+strlen(searchkey_encoded));
407 if(!request)
409 fprintf(console,"gpgkeys: out of memory\n");
410 ret=KEYSERVER_NO_MEMORY;
411 goto fail;
414 fprintf(output,"SEARCH %s BEGIN\n",searchkey);
416 strcpy(request,proto);
417 strcat(request,"://");
418 strcat(request,opt->host);
419 strcat(request,":");
420 strcat(request,port);
421 strcat(request,opt->path);
422 append_path(request,"/pks/lookup?op=index&options=mr&search=");
424 /* HKP keyservers like the 0x to be present when searching by
425 keyid */
426 if(search_type==KS_SEARCH_KEYID_SHORT || search_type==KS_SEARCH_KEYID_LONG)
427 strcat(request,"0x");
429 strcat(request,searchkey_encoded);
431 if(search_type!=KS_SEARCH_SUBSTR)
432 strcat(request,"&exact=on");
434 if(opt->verbose>2)
435 fprintf(console,"gpgkeys: HTTP URL is `%s'\n",request);
437 curl_easy_setopt(curl,CURLOPT_URL,request);
438 curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,curl_mrindex_writer);
439 curl_easy_setopt(curl,CURLOPT_FILE,output);
441 res=curl_easy_perform(curl);
442 if(res!=0)
444 fprintf(console,"gpgkeys: HTTP search error %d: %s\n",res,errorbuffer);
445 ret=curl_err_to_gpg_err(res);
447 else
449 fprintf(output,"\nSEARCH %s END\n",searchkey);
450 ret=KEYSERVER_OK;
453 fail:
455 curl_free(searchkey_encoded);
456 free(request);
458 if(ret!=KEYSERVER_OK)
459 fprintf(output,"\nSEARCH %s FAILED %d\n",searchkey,ret);
461 return ret;
464 void
465 fail_all(struct keylist *keylist,int err)
467 if(!keylist)
468 return;
470 if(opt->action==KS_SEARCH)
472 fprintf(output,"SEARCH ");
473 while(keylist)
475 fprintf(output,"%s ",keylist->str);
476 keylist=keylist->next;
478 fprintf(output,"FAILED %d\n",err);
480 else
481 while(keylist)
483 fprintf(output,"KEY %s FAILED %d\n",keylist->str,err);
484 keylist=keylist->next;
488 #ifdef HAVE_LIBCURL
489 /* If there is a SRV record, take the highest ranked possibility.
490 This is a hack, as we don't proceed downwards. */
491 static void
492 srv_replace(void)
494 #ifdef USE_DNS_SRV
495 struct srventry *srvlist=NULL;
496 int srvcount;
498 if(1+strlen(opt->scheme)+6+strlen(opt->host)+1<=MAXDNAME)
500 char srvname[MAXDNAME];
502 strcpy(srvname,"_");
503 strcat(srvname,opt->scheme);
504 strcat(srvname,"._tcp.");
505 strcat(srvname,opt->host);
506 srvcount=getsrv(srvname,&srvlist);
509 if(srvlist)
511 char *newname,*newport;
513 newname=strdup(srvlist->target);
514 newport=malloc(MAX_PORT);
515 if(newname && newport)
517 free(opt->host);
518 free(opt->port);
519 opt->host=newname;
520 snprintf(newport,MAX_PORT,"%u",srvlist->port);
521 opt->port=newport;
523 else
525 free(newname);
526 free(newport);
529 #endif
531 #endif
533 static void
534 show_help (FILE *fp)
536 fprintf (fp,"-h, --help\thelp\n");
537 fprintf (fp,"-V\t\tmachine readable version\n");
538 fprintf (fp,"--version\thuman readable version\n");
539 fprintf (fp,"-o\t\toutput to this file\n");
543 main(int argc,char *argv[])
545 int arg,ret=KEYSERVER_INTERNAL_ERROR,try_srv=1;
546 char line[MAX_LINE];
547 int failed=0;
548 struct keylist *keylist=NULL,*keyptr=NULL;
549 char *proxy=NULL;
551 console=stderr;
553 /* Kludge to implement standard GNU options. */
554 if (argc > 1 && !strcmp (argv[1], "--version"))
556 printf ("gpgkeys_hkp (GnuPG) %s\n", VERSION);
557 printf ("Uses: %s\n", curl_version());
558 return 0;
560 else if (argc > 1 && !strcmp (argv[1], "--help"))
562 show_help (stdout);
563 return 0;
566 while((arg=getopt(argc,argv,"hVo:"))!=-1)
567 switch(arg)
569 default:
570 case 'h':
571 show_help (console);
572 return KEYSERVER_OK;
574 case 'V':
575 fprintf(stdout,"%d\n%s\n",KEYSERVER_PROTO_VERSION,VERSION);
576 return KEYSERVER_OK;
578 case 'o':
579 output=fopen(optarg,"w");
580 if(output==NULL)
582 fprintf(console,"gpgkeys: Cannot open output file `%s': %s\n",
583 optarg,strerror(errno));
584 return KEYSERVER_INTERNAL_ERROR;
587 break;
590 if(argc>optind)
592 input=fopen(argv[optind],"r");
593 if(input==NULL)
595 fprintf(console,"gpgkeys: Cannot open input file `%s': %s\n",
596 argv[optind],strerror(errno));
597 return KEYSERVER_INTERNAL_ERROR;
601 if(input==NULL)
602 input=stdin;
604 if(output==NULL)
605 output=stdout;
607 opt=init_ks_options();
608 if(!opt)
609 return KEYSERVER_NO_MEMORY;
611 /* Get the command and info block */
613 while(fgets(line,MAX_LINE,input)!=NULL)
615 int err;
616 char option[MAX_OPTION+1];
618 if(line[0]=='\n')
619 break;
621 err=parse_ks_options(line,opt);
622 if(err>0)
624 ret=err;
625 goto fail;
627 else if(err==0)
628 continue;
630 if(sscanf(line,"OPTION %" MKSTRING(MAX_OPTION) "s\n",option)==1)
632 int no=0;
633 char *start=&option[0];
635 option[MAX_OPTION]='\0';
637 if(strncasecmp(option,"no-",3)==0)
639 no=1;
640 start=&option[3];
643 if(strncasecmp(start,"http-proxy",10)==0)
645 if(no)
647 free(proxy);
648 proxy=strdup("");
650 else if(start[10]=='=')
652 if(strlen(&start[11])<MAX_PROXY)
654 free(proxy);
655 proxy=strdup(&start[11]);
659 else if(strcasecmp(start,"try-dns-srv")==0)
661 if(no)
662 try_srv=0;
663 else
664 try_srv=1;
667 continue;
671 if(!opt->scheme)
673 fprintf(console,"gpgkeys: no scheme supplied!\n");
674 ret=KEYSERVER_SCHEME_NOT_FOUND;
675 goto fail;
678 if(ks_strcasecmp(opt->scheme,"hkps")==0)
680 proto="https";
681 port="443";
683 else
685 proto="http";
686 port="11371";
689 if(!opt->host)
691 fprintf(console,"gpgkeys: no keyserver host provided\n");
692 goto fail;
695 if(opt->timeout && register_timeout()==-1)
697 fprintf(console,"gpgkeys: unable to register timeout handler\n");
698 return KEYSERVER_INTERNAL_ERROR;
701 curl_global_init(CURL_GLOBAL_DEFAULT);
702 curl=curl_easy_init();
703 if(!curl)
705 fprintf(console,"gpgkeys: unable to initialize curl\n");
706 ret=KEYSERVER_INTERNAL_ERROR;
707 goto fail;
710 /* If the user gives a :port, then disable SRV. The semantics of a
711 specified port and SRV do not play well together. */
712 if(opt->port)
713 port=opt->port;
714 else if(try_srv)
716 #ifdef HAVE_LIBCURL
717 /* We're using libcurl, so fake SRV support via our wrapper.
718 This isn't as good as true SRV support, as we do not try all
719 possible targets at one particular level and work our way
720 down the list, but it's better than nothing. */
721 srv_replace();
722 #else
723 /* We're using our internal curl shim, so we can use its (true)
724 SRV support. Obviously, CURLOPT_SRVTAG_GPG_HACK isn't a real
725 libcurl option. It's specific to our shim. */
726 curl_easy_setopt(curl,CURLOPT_SRVTAG_GPG_HACK,opt->scheme);
727 #endif
730 curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,errorbuffer);
732 if(opt->auth)
733 curl_easy_setopt(curl,CURLOPT_USERPWD,opt->auth);
735 if(opt->debug)
737 fprintf(console,"gpgkeys: curl version = %s\n",curl_version());
738 curl_easy_setopt(curl,CURLOPT_STDERR,console);
739 curl_easy_setopt(curl,CURLOPT_VERBOSE,1L);
742 curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,(long)opt->flags.check_cert);
743 curl_easy_setopt(curl,CURLOPT_CAINFO,opt->ca_cert_file);
745 if(proxy)
746 curl_easy_setopt(curl,CURLOPT_PROXY,proxy);
748 /* If it's a GET or a SEARCH, the next thing to come in is the
749 keyids. If it's a SEND, then there are no keyids. */
751 if(opt->action==KS_SEND)
752 while(fgets(line,MAX_LINE,input)!=NULL && line[0]!='\n');
753 else if(opt->action==KS_GET
754 || opt->action==KS_GETNAME || opt->action==KS_SEARCH)
756 for(;;)
758 struct keylist *work;
760 if(fgets(line,MAX_LINE,input)==NULL)
761 break;
762 else
764 if(line[0]=='\n' || line[0]=='\0')
765 break;
767 work=malloc(sizeof(struct keylist));
768 if(work==NULL)
770 fprintf(console,"gpgkeys: out of memory while "
771 "building key list\n");
772 ret=KEYSERVER_NO_MEMORY;
773 goto fail;
776 strcpy(work->str,line);
778 /* Trim the trailing \n */
779 work->str[strlen(line)-1]='\0';
781 work->next=NULL;
783 /* Always attach at the end to keep the list in proper
784 order for searching */
785 if(keylist==NULL)
786 keylist=work;
787 else
788 keyptr->next=work;
790 keyptr=work;
794 else
796 fprintf(console,"gpgkeys: no keyserver command specified\n");
797 goto fail;
800 /* Send the response */
802 fprintf(output,"VERSION %d\n",KEYSERVER_PROTO_VERSION);
803 fprintf(output,"PROGRAM %s\n\n",VERSION);
805 if(opt->verbose>1)
807 fprintf(console,"Host:\t\t%s\n",opt->host);
808 if(opt->port)
809 fprintf(console,"Port:\t\t%s\n",opt->port);
810 if(strcmp(opt->path,"/")!=0)
811 fprintf(console,"Path:\t\t%s\n",opt->path);
812 fprintf(console,"Command:\t%s\n",ks_action_to_string(opt->action));
815 if(opt->action==KS_GET)
817 keyptr=keylist;
819 while(keyptr!=NULL)
821 set_timeout(opt->timeout);
823 if(get_key(keyptr->str)!=KEYSERVER_OK)
824 failed++;
826 keyptr=keyptr->next;
829 else if(opt->action==KS_GETNAME)
831 keyptr=keylist;
833 while(keyptr!=NULL)
835 set_timeout(opt->timeout);
837 if(get_name(keyptr->str)!=KEYSERVER_OK)
838 failed++;
840 keyptr=keyptr->next;
843 else if(opt->action==KS_SEND)
845 int myeof=0;
849 set_timeout(opt->timeout);
851 if(send_key(&myeof)!=KEYSERVER_OK)
852 failed++;
854 while(!myeof);
856 else if(opt->action==KS_SEARCH)
858 char *searchkey=NULL;
859 int len=0;
861 set_timeout(opt->timeout);
863 /* To search, we stick a space in between each key to search
864 for. */
866 keyptr=keylist;
867 while(keyptr!=NULL)
869 len+=strlen(keyptr->str)+1;
870 keyptr=keyptr->next;
873 searchkey=malloc(len+1);
874 if(searchkey==NULL)
876 ret=KEYSERVER_NO_MEMORY;
877 fail_all(keylist,KEYSERVER_NO_MEMORY);
878 goto fail;
881 searchkey[0]='\0';
883 keyptr=keylist;
884 while(keyptr!=NULL)
886 strcat(searchkey,keyptr->str);
887 strcat(searchkey," ");
888 keyptr=keyptr->next;
891 /* Nail that last space */
892 if(*searchkey)
893 searchkey[strlen(searchkey)-1]='\0';
895 if(search_key(searchkey)!=KEYSERVER_OK)
896 failed++;
898 free(searchkey);
900 else
901 abort();
903 if(!failed)
904 ret=KEYSERVER_OK;
906 fail:
907 while(keylist!=NULL)
909 struct keylist *current=keylist;
910 keylist=keylist->next;
911 free(current);
914 if(input!=stdin)
915 fclose(input);
917 if(output!=stdout)
918 fclose(output);
920 free_ks_options(opt);
922 if(curl)
923 curl_easy_cleanup(curl);
925 free(proxy);
927 return ret;