1
1
/* gpgkeys_finger.c - fetch a key via finger
2
* Copyright (C) 2004 Free Software Foundation, Inc.
2
* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4
4
* This file is part of GnuPG.
6
6
* GnuPG is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
8
* the Free Software Foundation; either version 3 of the License, or
9
9
* (at your option) any later version.
11
11
* GnuPG is distributed in the hope that it will be useful,
14
14
* GNU General Public License for more details.
16
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
17
* along with this program; if not, see <http://www.gnu.org/licenses/>.
21
20
#include <config.h>
55
55
extern char *optarg;
62
static char path[1024];
63
static FILE *input, *output, *console;
65
#define BEGIN "-----BEGIN PGP PUBLIC KEY BLOCK-----"
66
#define END "-----END PGP PUBLIC KEY BLOCK-----"
58
static FILE *input,*output,*console;
59
static struct ks_options *opt;
121
114
/* Win32 gethostbyname doesn't handle IP addresses internally, so we
122
115
try inet_addr first on that platform only. */
123
if ((l = inet_addr (server)) != SOCKET_ERROR)
116
if ((l = inet_addr (server)) != INADDR_NONE)
124
117
memcpy (&addr.sin_addr, &l, sizeof l);
125
118
else if ((hp = gethostbyname (server)))
306
299
indicated the requested key anyway. */
307
300
fprintf(output,"KEY 0x%s BEGIN\n",getkey);
309
rc = send_request (path, &sock);
302
rc=send_request(opt->opaque,&sock);
312
305
fprintf(output,"KEY 0x%s FAILED %d\n",getkey, rc);
333
fputs (line, output);
334
if (!strncmp(line,END,strlen(END)))
326
print_nocr(output, (const char*)line);
327
if (!strncmp((char*)line,END,strlen(END)))
337
else if(!strncmp(line,BEGIN,strlen(BEGIN)))
330
else if(!strncmp((char*)line,BEGIN,strlen(BEGIN)))
332
print_nocr(output, (const char*)line);
345
338
fprintf (output,"KEY 0x%s END\n", getkey);
348
fprintf (console,"gpgkeys: key %s not found on keyserver\n",getkey);
349
fprintf (output,"KEY 0x%s FAILED %d\n",
350
getkey,KEYSERVER_KEY_NOT_FOUND);
341
fprintf(console,"gpgkeys: no key data found for finger:%s\n",
343
fprintf(output,"KEY 0x%s FAILED %d\n",getkey,KEYSERVER_KEY_NOT_FOUND);
354
347
iobuf_close (fp_read);
356
349
return KEYSERVER_OK;
369
362
main(int argc,char *argv[])
371
int arg,action=-1,ret=KEYSERVER_INTERNAL_ERROR;
364
int arg,ret=KEYSERVER_INTERNAL_ERROR;
372
365
char line[MAX_LINE];
373
366
char *thekey=NULL;
374
unsigned int timeout=DEFAULT_KEYSERVER_TIMEOUT;
378
370
/* Kludge to implement standard GNU options. */
379
371
if (argc > 1 && !strcmp (argv[1], "--version"))
381
fputs ("gpgkeys_ldap (GnuPG) " VERSION"\n", stdout);
373
fputs ("gpgkeys_finger (GnuPG) " VERSION"\n", stdout);
384
376
else if (argc > 1 && !strcmp (argv[1], "--help"))
423
opt=init_ks_options();
425
return KEYSERVER_NO_MEMORY;
431
427
/* Get the command and info block */
433
429
while(fgets(line,MAX_LINE,input)!=NULL)
440
433
if(line[0]=='\n')
443
if(sscanf(line,"%c",&hash)==1 && hash=='#')
436
err=parse_ks_options(line,opt);
446
if(sscanf(line,"COMMAND %6s\n",commandstr)==1)
450
if(strcasecmp(commandstr,"get")==0)
456
if(strncmp(line,"HOST ",5)==0)
458
fprintf(console,"gpgkeys: finger://relay/user syntax is not"
459
" supported. Use finger:user instead.\n");
460
ret=KEYSERVER_NOT_SUPPORTED;
464
if(sscanf(line,"OPAQUE %1023s\n",path)==1)
470
if(sscanf(line,"VERSION %d\n",&version)==1)
472
if(version!=KEYSERVER_PROTO_VERSION)
474
ret=KEYSERVER_VERSION_ERROR;
481
if(sscanf(line,"OPTION %255s\n",optionstr)==1)
484
char *start=&optionstr[0];
488
if(strncasecmp(optionstr,"no-",3)==0)
494
if(strcasecmp(start,"verbose")==0)
501
else if(strncasecmp(start,"timeout",7)==0)
505
else if(start[7]=='=')
506
timeout=atoi(&start[8]);
507
else if(start[7]=='\0')
508
timeout=DEFAULT_KEYSERVER_TIMEOUT;
515
if(timeout && register_timeout()==-1)
448
fprintf(console,"gpgkeys: finger://relay/user syntax is not"
449
" supported. Use finger:user instead.\n");
450
ret=KEYSERVER_NOT_SUPPORTED;
454
if(opt->timeout && register_timeout()==-1)
517
456
fprintf(console,"gpgkeys: unable to register timeout handler\n");
518
457
return KEYSERVER_INTERNAL_ERROR;
568
507
fprintf(output,"VERSION %d\n",KEYSERVER_PROTO_VERSION);
569
508
fprintf(output,"PROGRAM %s\n\n",VERSION);
574
fprintf(console,"Path:\t\t%s\n",path);
512
fprintf(console,"User:\t\t%s\n",opt->opaque);
575
513
fprintf(console,"Command:\tGET\n");
578
set_timeout(timeout);
516
set_timeout(opt->timeout);
580
ret = get_key(thekey);