mirror of
git://git.gnupg.org/gnupg.git
synced 2025-03-12 23:01:14 +01:00
* gpgkeys_hkp.c: Overall cleanup from iobuf conversion. Be consistent in
m_alloc and malloc usage. Remove include-disabled (meaningless on HKP). RISC OS tweak.
This commit is contained in:
parent
813fa3f98b
commit
43ba6d43d7
@ -1,3 +1,9 @@
|
|||||||
|
2002-08-28 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
|
* gpgkeys_hkp.c: Overall cleanup from iobuf conversion. Be
|
||||||
|
consistent in m_alloc and malloc usage. Remove include-disabled
|
||||||
|
(meaningless on HKP). RISC OS tweak.
|
||||||
|
|
||||||
2002-08-27 David Shaw <dshaw@jabberwocky.com>
|
2002-08-27 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
* gpgkeys_hkp.c, Makefile.am: Convert over to using iobufs.
|
* gpgkeys_hkp.c, Makefile.am: Convert over to using iobufs.
|
||||||
|
@ -25,10 +25,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "iobuf.h"
|
#define INCLUDED_BY_MAIN_MODULE 1
|
||||||
#include "http.h"
|
|
||||||
#include "memory.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "http.h"
|
||||||
#include "keyserver.h"
|
#include "keyserver.h"
|
||||||
|
|
||||||
#define GET 0
|
#define GET 0
|
||||||
@ -36,11 +35,10 @@
|
|||||||
#define SEARCH 2
|
#define SEARCH 2
|
||||||
#define MAX_LINE 80
|
#define MAX_LINE 80
|
||||||
|
|
||||||
int verbose=0,include_disabled=0,include_revoked=0;
|
int verbose=0,include_revoked=0;
|
||||||
unsigned int http_flags=0;
|
unsigned int http_flags=0;
|
||||||
char host[80]={'\0'};
|
char host[80]={'\0'},port[10]={'\0'};
|
||||||
char portstr[10]={'\0'};
|
FILE *input=NULL,*output=NULL,*console=NULL;
|
||||||
FILE *input=NULL,*output=NULL,*console=NULL,*server=NULL;
|
|
||||||
|
|
||||||
struct keylist
|
struct keylist
|
||||||
{
|
{
|
||||||
@ -85,11 +83,11 @@ int send_key(void)
|
|||||||
IOBUF temp = iobuf_temp();
|
IOBUF temp = iobuf_temp();
|
||||||
char line[MAX_LINE];
|
char line[MAX_LINE];
|
||||||
|
|
||||||
request=m_alloc(strlen(host)+100);
|
request=malloc(strlen(host)+100);
|
||||||
|
|
||||||
iobuf_push_filter(temp,urlencode_filter,NULL);
|
iobuf_push_filter(temp,urlencode_filter,NULL);
|
||||||
|
|
||||||
/* Read and throw away stdin until we see the BEGIN */
|
/* Read and throw away input until we see the BEGIN */
|
||||||
|
|
||||||
while(fgets(line,MAX_LINE,input)!=NULL)
|
while(fgets(line,MAX_LINE,input)!=NULL)
|
||||||
if(sscanf(line,"KEY %16s BEGIN\n",keyid)==1)
|
if(sscanf(line,"KEY %16s BEGIN\n",keyid)==1)
|
||||||
@ -116,9 +114,11 @@ int send_key(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
if(iobuf_writestr(temp,line))
|
||||||
iobuf_writestr(temp,line);
|
{
|
||||||
}
|
fprintf(console,"gpgkeys: internal iobuf error\n");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
if(!gotit)
|
if(!gotit)
|
||||||
{
|
{
|
||||||
@ -129,7 +129,10 @@ int send_key(void)
|
|||||||
iobuf_flush_temp(temp);
|
iobuf_flush_temp(temp);
|
||||||
|
|
||||||
sprintf(request,"x-hkp://%s%s%s/pks/add",
|
sprintf(request,"x-hkp://%s%s%s/pks/add",
|
||||||
host,portstr[0]?":":"",portstr[0]?portstr:"");
|
host,port[0]?":":"",port[0]?port:"");
|
||||||
|
|
||||||
|
if(verbose>2)
|
||||||
|
fprintf(console,"gpgkeys: HTTP URL is \"%s\"\n",request);
|
||||||
|
|
||||||
rc=http_open(&hd,HTTP_REQ_POST,request,http_flags);
|
rc=http_open(&hd,HTTP_REQ_POST,request,http_flags);
|
||||||
if(rc)
|
if(rc)
|
||||||
@ -167,7 +170,7 @@ int send_key(void)
|
|||||||
ret=0;
|
ret=0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
m_free(request);
|
free(request);
|
||||||
iobuf_close(temp);
|
iobuf_close(temp);
|
||||||
http_close(&hd);
|
http_close(&hd);
|
||||||
|
|
||||||
@ -215,21 +218,17 @@ int get_key(char *getkey)
|
|||||||
|
|
||||||
fprintf(output,"KEY 0x%s BEGIN\n",getkey);
|
fprintf(output,"KEY 0x%s BEGIN\n",getkey);
|
||||||
|
|
||||||
if(verbose>2)
|
|
||||||
fprintf(console,"gpgkeys: HKP fetch for: %s\n",search);
|
|
||||||
|
|
||||||
if(verbose)
|
if(verbose)
|
||||||
fprintf(console,"gpgkeys: requesting key 0x%s from hkp://%s%s%s\n",
|
fprintf(console,"gpgkeys: requesting key 0x%s from hkp://%s%s%s\n",
|
||||||
getkey,host,portstr[0]?":":"",portstr[0]?portstr:"");
|
getkey,host,port[0]?":":"",port[0]?port:"");
|
||||||
|
|
||||||
request=m_alloc(strlen(host)+100);
|
request=malloc(strlen(host)+100);
|
||||||
|
|
||||||
sprintf(request,"x-hkp://%s%s%s/pks/lookup?op=get&search=%s",
|
sprintf(request,"x-hkp://%s%s%s/pks/lookup?op=get&search=%s",
|
||||||
host,
|
host,port[0]?":":"",port[0]?port:"", search);
|
||||||
portstr[0]?":":"",
|
|
||||||
portstr[0]?portstr:"", search);
|
|
||||||
|
|
||||||
fprintf(console,"request is \"%s\"\n",request);
|
if(verbose>2)
|
||||||
|
fprintf(console,"gpgkeys: HTTP URL is \"%s\"\n",request);
|
||||||
|
|
||||||
rc=http_open_document(&hd,request,http_flags);
|
rc=http_open_document(&hd,request,http_flags);
|
||||||
if(rc!=0)
|
if(rc!=0)
|
||||||
@ -261,7 +260,8 @@ int get_key(char *getkey)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_free(request);
|
m_free(line);
|
||||||
|
free(request);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -401,9 +401,9 @@ parse_hkp_index(IOBUF buffer,char *line)
|
|||||||
ascii_memcasecmp(line,"pub ",4)!=0 &&
|
ascii_memcasecmp(line,"pub ",4)!=0 &&
|
||||||
ascii_memcasecmp(line," ",4)!=0)
|
ascii_memcasecmp(line," ",4)!=0)
|
||||||
{
|
{
|
||||||
m_free(key);
|
free(key);
|
||||||
m_free(uid);
|
free(uid);
|
||||||
fprintf(console,"gpgkeys: this keyserver is not fully HKP compatible\n");
|
fprintf(console,"gpgkeys: this keyserver does not support searching\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,8 +438,8 @@ parse_hkp_index(IOBUF buffer,char *line)
|
|||||||
if(strncmp(line," ",4)!=0)
|
if(strncmp(line," ",4)!=0)
|
||||||
{
|
{
|
||||||
revoked=0;
|
revoked=0;
|
||||||
m_free(key);
|
free(key);
|
||||||
m_free(uid);
|
free(uid);
|
||||||
uid=NULL;
|
uid=NULL;
|
||||||
open=0;
|
open=0;
|
||||||
}
|
}
|
||||||
@ -470,7 +470,7 @@ parse_hkp_index(IOBUF buffer,char *line)
|
|||||||
if(tok==NULL)
|
if(tok==NULL)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
key=m_strdup(tok);
|
key=strdup(tok);
|
||||||
|
|
||||||
tok=strsep(&line," ");
|
tok=strsep(&line," ");
|
||||||
if(tok==NULL)
|
if(tok==NULL)
|
||||||
@ -493,7 +493,7 @@ parse_hkp_index(IOBUF buffer,char *line)
|
|||||||
{
|
{
|
||||||
if(line==NULL)
|
if(line==NULL)
|
||||||
{
|
{
|
||||||
uid=m_strdup("Key index corrupted");
|
uid=strdup("Key index corrupted");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -509,7 +509,7 @@ parse_hkp_index(IOBUF buffer,char *line)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
uid=m_strdup(line);
|
uid=strdup(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -549,17 +549,17 @@ int search_key(char *searchkey)
|
|||||||
|
|
||||||
search[len]='\0';
|
search[len]='\0';
|
||||||
|
|
||||||
request=m_alloc(strlen(host)+100+strlen(search));
|
|
||||||
|
|
||||||
sprintf(request,"x-hkp://%s%s%s/pks/lookup?op=index&search=%s",
|
|
||||||
host,portstr[0]?":":"",portstr[0]?portstr:"",search);
|
|
||||||
|
|
||||||
if(verbose>2)
|
|
||||||
fprintf(console,"gpgkeys: HKP search for: %s\n",search);
|
|
||||||
|
|
||||||
fprintf(console,("gpgkeys: searching for \"%s\" from HKP server %s\n"),
|
fprintf(console,("gpgkeys: searching for \"%s\" from HKP server %s\n"),
|
||||||
searchkey,host);
|
searchkey,host);
|
||||||
|
|
||||||
|
request=malloc(strlen(host)+100+strlen(search));
|
||||||
|
|
||||||
|
sprintf(request,"x-hkp://%s%s%s/pks/lookup?op=index&search=%s",
|
||||||
|
host,port[0]?":":"",port[0]?port:"",search);
|
||||||
|
|
||||||
|
if(verbose>2)
|
||||||
|
fprintf(console,"gpgkeys: HTTP URL is \"%s\"\n",request);
|
||||||
|
|
||||||
rc=http_open_document(&hd,request,http_flags);
|
rc=http_open_document(&hd,request,http_flags);
|
||||||
if(rc)
|
if(rc)
|
||||||
{
|
{
|
||||||
@ -570,7 +570,6 @@ int search_key(char *searchkey)
|
|||||||
{
|
{
|
||||||
unsigned int maxlen=1024,buflen=0;
|
unsigned int maxlen=1024,buflen=0;
|
||||||
int count=1;
|
int count=1;
|
||||||
int ret;
|
|
||||||
IOBUF buffer;
|
IOBUF buffer;
|
||||||
|
|
||||||
buffer=iobuf_temp();
|
buffer=iobuf_temp();
|
||||||
@ -612,7 +611,7 @@ int search_key(char *searchkey)
|
|||||||
ret=0;
|
ret=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_free(request);
|
free(request);
|
||||||
free(search);
|
free(search);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -620,9 +619,9 @@ int search_key(char *searchkey)
|
|||||||
|
|
||||||
int main(int argc,char *argv[])
|
int main(int argc,char *argv[])
|
||||||
{
|
{
|
||||||
int port=0,arg,action=-1,ret=KEYSERVER_INTERNAL_ERROR;
|
int arg,action=-1,ret=KEYSERVER_INTERNAL_ERROR;
|
||||||
char line[MAX_LINE];
|
char line[MAX_LINE];
|
||||||
int version,failed=0;
|
int failed=0;
|
||||||
struct keylist *keylist=NULL,*keyptr=NULL;
|
struct keylist *keylist=NULL,*keyptr=NULL;
|
||||||
|
|
||||||
console=stderr;
|
console=stderr;
|
||||||
@ -672,6 +671,7 @@ int main(int argc,char *argv[])
|
|||||||
|
|
||||||
while(fgets(line,MAX_LINE,input)!=NULL)
|
while(fgets(line,MAX_LINE,input)!=NULL)
|
||||||
{
|
{
|
||||||
|
int version;
|
||||||
char commandstr[7];
|
char commandstr[7];
|
||||||
char optionstr[30];
|
char optionstr[30];
|
||||||
char hash;
|
char hash;
|
||||||
@ -702,10 +702,9 @@ int main(int argc,char *argv[])
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sscanf(line,"PORT %9s\n",portstr)==1)
|
if(sscanf(line,"PORT %9s\n",port)==1)
|
||||||
{
|
{
|
||||||
portstr[9]='\0';
|
port[9]='\0';
|
||||||
port=atoi(portstr);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -740,13 +739,6 @@ int main(int argc,char *argv[])
|
|||||||
else
|
else
|
||||||
verbose++;
|
verbose++;
|
||||||
}
|
}
|
||||||
else if(strcasecmp(start,"include-disabled")==0)
|
|
||||||
{
|
|
||||||
if(no)
|
|
||||||
include_disabled=0;
|
|
||||||
else
|
|
||||||
include_disabled=1;
|
|
||||||
}
|
|
||||||
else if(strcasecmp(start,"include-revoked")==0)
|
else if(strcasecmp(start,"include-revoked")==0)
|
||||||
{
|
{
|
||||||
if(no)
|
if(no)
|
||||||
@ -832,8 +824,8 @@ int main(int argc,char *argv[])
|
|||||||
if(verbose>1)
|
if(verbose>1)
|
||||||
{
|
{
|
||||||
fprintf(console,"Host:\t\t%s\n",host);
|
fprintf(console,"Host:\t\t%s\n",host);
|
||||||
if(port)
|
if(port[0])
|
||||||
fprintf(console,"Port:\t\t%d\n",port);
|
fprintf(console,"Port:\t\t%s\n",port);
|
||||||
fprintf(console,"Command:\t%s\n",action==GET?"GET":
|
fprintf(console,"Command:\t%s\n",action==GET?"GET":
|
||||||
action==SEND?"SEND":"SEARCH");
|
action==SEND?"SEND":"SEARCH");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user