mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-01 16:33:02 +01:00
* gpgkeys_hkp.c (send_key, get_key, search_key, main): Some minor error
reporting enhancements for use with GPA.
This commit is contained in:
parent
5835a80426
commit
e0512b187c
@ -1,3 +1,8 @@
|
|||||||
|
2002-09-24 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
|
* gpgkeys_hkp.c (send_key, get_key, search_key, main): Some minor
|
||||||
|
error reporting enhancements for use with GPA.
|
||||||
|
|
||||||
2002-09-20 Werner Koch <wk@gnupg.org>
|
2002-09-20 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
* gpgkeys_hkp.c (handle_old_hkp_index): s/input/inp/ to avoid
|
* gpgkeys_hkp.c (handle_old_hkp_index): s/input/inp/ to avoid
|
||||||
|
@ -76,11 +76,10 @@ urlencode_filter( void *opaque, int control,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns 0 on success, -1 on failure, and 1 on eof */
|
|
||||||
int
|
int
|
||||||
send_key(void)
|
send_key(int *eof)
|
||||||
{
|
{
|
||||||
int rc,gotit=0,ret=-1;
|
int rc,gotit=0,ret=KEYSERVER_INTERNAL_ERROR;
|
||||||
char keyid[17];
|
char keyid[17];
|
||||||
char *request;
|
char *request;
|
||||||
struct http_context hd;
|
struct http_context hd;
|
||||||
@ -92,7 +91,7 @@ send_key(void)
|
|||||||
if(!request)
|
if(!request)
|
||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: out of memory\n");
|
fprintf(console,"gpgkeys: out of memory\n");
|
||||||
return -1;
|
return KEYSERVER_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
iobuf_push_filter(temp,urlencode_filter,NULL);
|
iobuf_push_filter(temp,urlencode_filter,NULL);
|
||||||
@ -108,8 +107,10 @@ send_key(void)
|
|||||||
|
|
||||||
if(!gotit)
|
if(!gotit)
|
||||||
{
|
{
|
||||||
/* i.e. eof before the KEY BEGIN was found */
|
/* i.e. eof before the KEY BEGIN was found. This isn't an
|
||||||
ret=1;
|
error. */
|
||||||
|
*eof=1;
|
||||||
|
ret=KEYSERVER_OK;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +134,8 @@ send_key(void)
|
|||||||
if(!gotit)
|
if(!gotit)
|
||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: no KEY %s END found\n",keyid);
|
fprintf(console,"gpgkeys: no KEY %s END found\n",keyid);
|
||||||
|
*eof=1;
|
||||||
|
ret=KEYSERVER_KEY_INCOMPLETE;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,11 +176,13 @@ send_key(void)
|
|||||||
if((status/100)!=2)
|
if((status/100)!=2)
|
||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: remote server returned error %d\n",status);
|
fprintf(console,"gpgkeys: remote server returned error %d\n",status);
|
||||||
fprintf(output,"KEY %s FAILED\n",keyid);
|
fprintf(output,"KEY %s FAILED %d\n",keyid,ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret=0;
|
fprintf(output,"KEY %s SENT\n",keyid);
|
||||||
|
|
||||||
|
ret=KEYSERVER_OK;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
free(request);
|
free(request);
|
||||||
@ -205,8 +210,8 @@ get_key(char *getkey)
|
|||||||
fprintf(console,
|
fprintf(console,
|
||||||
"gpgkeys: HKP keyservers do not support v3 fingerprints\n");
|
"gpgkeys: HKP keyservers do not support v3 fingerprints\n");
|
||||||
fprintf(output,"KEY 0x%s BEGIN\n",getkey);
|
fprintf(output,"KEY 0x%s BEGIN\n",getkey);
|
||||||
fprintf(output,"KEY 0x%s FAILED\n",getkey);
|
fprintf(output,"KEY 0x%s FAILED %d\n",getkey,KEYSERVER_NOT_SUPPORTED);
|
||||||
return -1;
|
return KEYSERVER_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen(getkey)>8)
|
if(strlen(getkey)>8)
|
||||||
@ -235,7 +240,7 @@ get_key(char *getkey)
|
|||||||
if(!request)
|
if(!request)
|
||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: out of memory\n");
|
fprintf(console,"gpgkeys: out of memory\n");
|
||||||
return -1;
|
return KEYSERVER_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
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",
|
||||||
@ -249,7 +254,7 @@ get_key(char *getkey)
|
|||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: HKP fetch error: %s\n",
|
fprintf(console,"gpgkeys: HKP fetch error: %s\n",
|
||||||
rc==G10ERR_NETWORK?strerror(errno):g10_errstr(rc));
|
rc==G10ERR_NETWORK?strerror(errno):g10_errstr(rc));
|
||||||
fprintf(output,"KEY 0x%s FAILED\n",getkey);
|
fprintf(output,"KEY 0x%s FAILED %d\n",getkey,KEYSERVER_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -279,7 +284,8 @@ get_key(char *getkey)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: key %s not found on keyserver\n",getkey);
|
fprintf(console,"gpgkeys: key %s not found on keyserver\n",getkey);
|
||||||
fprintf(output,"KEY 0x%s FAILED\n",getkey);
|
fprintf(output,"KEY 0x%s FAILED %d\n",
|
||||||
|
getkey,KEYSERVER_KEY_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_free(line);
|
m_free(line);
|
||||||
@ -287,7 +293,7 @@ get_key(char *getkey)
|
|||||||
|
|
||||||
free(request);
|
free(request);
|
||||||
|
|
||||||
return 0;
|
return KEYSERVER_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove anything <between brackets> and de-urlencode in place. Note
|
/* Remove anything <between brackets> and de-urlencode in place. Note
|
||||||
@ -576,15 +582,15 @@ handle_old_hkp_index(IOBUF inp)
|
|||||||
int
|
int
|
||||||
search_key(char *searchkey)
|
search_key(char *searchkey)
|
||||||
{
|
{
|
||||||
int max=0,len=0,ret=-1,rc;
|
int max=0,len=0,ret=KEYSERVER_INTERNAL_ERROR,rc;
|
||||||
struct http_context hd;
|
struct http_context hd;
|
||||||
char *search=NULL,*request=searchkey;
|
char *search=NULL,*request=NULL,*skey=searchkey;
|
||||||
|
|
||||||
fprintf(output,"SEARCH %s BEGIN\n",searchkey);
|
fprintf(output,"SEARCH %s BEGIN\n",searchkey);
|
||||||
|
|
||||||
/* Build the search string. It's going to need url-encoding. */
|
/* Build the search string. It's going to need url-encoding. */
|
||||||
|
|
||||||
while(*request!='\0')
|
while(*skey!='\0')
|
||||||
{
|
{
|
||||||
if(max-len<3)
|
if(max-len<3)
|
||||||
{
|
{
|
||||||
@ -593,21 +599,22 @@ search_key(char *searchkey)
|
|||||||
if (!search)
|
if (!search)
|
||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: out of memory\n");
|
fprintf(console,"gpgkeys: out of memory\n");
|
||||||
return -1;
|
ret=KEYSERVER_NO_MEMORY;
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isalnum(*request) || *request=='-')
|
if(isalnum(*skey) || *skey=='-')
|
||||||
search[len++]=*request;
|
search[len++]=*skey;
|
||||||
else if(*request==' ')
|
else if(*skey==' ')
|
||||||
search[len++]='+';
|
search[len++]='+';
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf(&search[len],"%%%02X",*request);
|
sprintf(&search[len],"%%%02X",*skey);
|
||||||
len+=3;
|
len+=3;
|
||||||
}
|
}
|
||||||
|
|
||||||
request++;
|
skey++;
|
||||||
}
|
}
|
||||||
|
|
||||||
search[len]='\0';
|
search[len]='\0';
|
||||||
@ -619,7 +626,8 @@ search_key(char *searchkey)
|
|||||||
if(!request)
|
if(!request)
|
||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: out of memory\n");
|
fprintf(console,"gpgkeys: out of memory\n");
|
||||||
return -1;
|
ret=KEYSERVER_NO_MEMORY;
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(request,"x-hkp://%s%s%s/pks/lookup?op=index&options=mr&search=%s",
|
sprintf(request,"x-hkp://%s%s%s/pks/lookup?op=index&options=mr&search=%s",
|
||||||
@ -660,12 +668,17 @@ search_key(char *searchkey)
|
|||||||
|
|
||||||
fprintf(output,"SEARCH %s END\n",searchkey);
|
fprintf(output,"SEARCH %s END\n",searchkey);
|
||||||
|
|
||||||
ret=0;
|
ret=KEYSERVER_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fail:
|
||||||
|
|
||||||
free(request);
|
free(request);
|
||||||
free(search);
|
free(search);
|
||||||
|
|
||||||
|
if(ret!=KEYSERVER_OK)
|
||||||
|
fprintf(output,"SEARCH %s FAILED %d\n",searchkey,ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -910,7 +923,7 @@ main(int argc,char *argv[])
|
|||||||
|
|
||||||
while(keyptr!=NULL)
|
while(keyptr!=NULL)
|
||||||
{
|
{
|
||||||
if(get_key(keyptr->str)==-1)
|
if(get_key(keyptr->str)!=KEYSERVER_OK)
|
||||||
failed++;
|
failed++;
|
||||||
|
|
||||||
keyptr=keyptr->next;
|
keyptr=keyptr->next;
|
||||||
@ -919,15 +932,14 @@ main(int argc,char *argv[])
|
|||||||
|
|
||||||
case SEND:
|
case SEND:
|
||||||
{
|
{
|
||||||
int ret2;
|
int eof=0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ret2=send_key();
|
if(send_key(&eof)!=KEYSERVER_OK)
|
||||||
if(ret2==-1)
|
|
||||||
failed++;
|
failed++;
|
||||||
}
|
}
|
||||||
while(ret2!=1);
|
while(!eof);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -963,11 +975,8 @@ main(int argc,char *argv[])
|
|||||||
/* Nail that last space */
|
/* Nail that last space */
|
||||||
searchkey[strlen(searchkey)-1]='\0';
|
searchkey[strlen(searchkey)-1]='\0';
|
||||||
|
|
||||||
if(search_key(searchkey)==-1)
|
if(search_key(searchkey)!=KEYSERVER_OK)
|
||||||
{
|
|
||||||
fprintf(output,"SEARCH %s FAILED\n",searchkey);
|
|
||||||
failed++;
|
failed++;
|
||||||
}
|
|
||||||
|
|
||||||
free(searchkey);
|
free(searchkey);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user