2001-12-06 21:54:04 +00:00
|
|
|
/* keyserver.c - generic keyserver code
|
|
|
|
* Copyright (C) 2001 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2001-12-25 18:04:09 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
2001-12-06 21:54:04 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2001-12-25 18:04:09 +00:00
|
|
|
|
|
|
|
#include "filter.h"
|
2001-12-06 21:54:04 +00:00
|
|
|
#include "keydb.h"
|
|
|
|
#include "status.h"
|
2001-12-21 23:06:02 +00:00
|
|
|
#include "exec.h"
|
2001-12-06 21:54:04 +00:00
|
|
|
#include "main.h"
|
2001-12-25 18:04:09 +00:00
|
|
|
#include "i18n.h"
|
2001-12-06 21:54:04 +00:00
|
|
|
#include "hkp.h"
|
2001-12-25 18:04:09 +00:00
|
|
|
#include "iobuf.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "packet.h"
|
|
|
|
#include "keyserver-internal.h"
|
2002-01-02 17:51:34 +00:00
|
|
|
#include "util.h"
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
#define KEYSERVER_PROTO_VERSION 0
|
|
|
|
|
|
|
|
#define GET 0
|
|
|
|
#define SEND 1
|
|
|
|
#define SEARCH 2
|
|
|
|
|
2001-12-15 18:27:13 +00:00
|
|
|
void
|
|
|
|
parse_keyserver_options(char *options)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
|
|
|
char *tok="";
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2002-04-19 22:38:20 +00:00
|
|
|
if(strcasecmp(tok,"include-revoked")==0)
|
2001-12-06 21:54:04 +00:00
|
|
|
opt.keyserver_options.include_revoked=1;
|
|
|
|
else if(strcasecmp(tok,"no-include-revoked")==0)
|
|
|
|
opt.keyserver_options.include_revoked=0;
|
|
|
|
else if(strcasecmp(tok,"include-disabled")==0)
|
|
|
|
opt.keyserver_options.include_disabled=1;
|
|
|
|
else if(strcasecmp(tok,"no-include-disabled")==0)
|
|
|
|
opt.keyserver_options.include_disabled=0;
|
2001-12-21 23:06:02 +00:00
|
|
|
#ifdef EXEC_TEMPFILE_ONLY
|
2001-12-06 21:54:04 +00:00
|
|
|
else if(strcasecmp(tok,"use-temp-files")==0 ||
|
|
|
|
strcasecmp(tok,"no-use-temp-files")==0)
|
|
|
|
log_info(_("Warning: keyserver option \"%s\" is not used "
|
|
|
|
"on this platform\n"),tok);
|
|
|
|
#else
|
|
|
|
else if(strcasecmp(tok,"use-temp-files")==0)
|
|
|
|
opt.keyserver_options.use_temp_files=1;
|
|
|
|
else if(strcasecmp(tok,"no-use-temp-files")==0)
|
|
|
|
opt.keyserver_options.use_temp_files=0;
|
|
|
|
#endif
|
|
|
|
else if(strcasecmp(tok,"keep-temp-files")==0)
|
|
|
|
opt.keyserver_options.keep_temp_files=1;
|
|
|
|
else if(strcasecmp(tok,"no-keep-temp-files")==0)
|
|
|
|
opt.keyserver_options.keep_temp_files=0;
|
|
|
|
else if(strcasecmp(tok,"verbose")==0)
|
|
|
|
opt.keyserver_options.verbose++;
|
|
|
|
else if(strcasecmp(tok,"no-verbose")==0)
|
|
|
|
opt.keyserver_options.verbose--;
|
|
|
|
else if(strcasecmp(tok,"honor-http-proxy")==0)
|
|
|
|
opt.honor_http_proxy=1;
|
|
|
|
else if(strcasecmp(tok,"no-honor-http-proxy")==0)
|
|
|
|
opt.honor_http_proxy=0;
|
2002-02-04 21:49:08 +00:00
|
|
|
else if(strcasecmp(tok,"refresh-add-fake-v3-keyids")==0)
|
|
|
|
opt.keyserver_options.refresh_add_fake_v3_keyids=1;
|
|
|
|
else if(strcasecmp(tok,"no-refresh-add-fake-v3-keyids")==0)
|
|
|
|
opt.keyserver_options.refresh_add_fake_v3_keyids=0;
|
2002-03-07 19:44:57 +00:00
|
|
|
else if(strcasecmp(tok,"auto-key-retrieve")==0)
|
2002-04-04 03:45:50 +00:00
|
|
|
opt.keyserver_options.auto_key_retrieve=1;
|
2002-03-07 19:44:57 +00:00
|
|
|
else if(strcasecmp(tok,"no-auto-key-retrieve")==0)
|
2002-04-04 03:45:50 +00:00
|
|
|
opt.keyserver_options.auto_key_retrieve=0;
|
2001-12-06 21:54:04 +00:00
|
|
|
else if(strlen(tok)>0)
|
|
|
|
add_to_strlist(&opt.keyserver_options.other,tok);
|
|
|
|
|
|
|
|
tok=strsep(&options," ,");
|
|
|
|
}
|
|
|
|
while(tok!=NULL);
|
|
|
|
}
|
|
|
|
|
2001-12-15 18:27:13 +00:00
|
|
|
int
|
|
|
|
parse_keyserver_uri(char *uri)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
|
|
|
/* Get the scheme */
|
|
|
|
|
|
|
|
opt.keyserver_scheme=strsep(&uri,":");
|
|
|
|
if(uri==NULL)
|
|
|
|
{
|
|
|
|
uri=opt.keyserver_scheme;
|
|
|
|
opt.keyserver_scheme="x-hkp";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip the "//", if any */
|
|
|
|
if(strlen(uri)>2 && uri[0]=='/' && uri[1]=='/')
|
|
|
|
uri+=2;
|
|
|
|
|
|
|
|
/* Get the host */
|
|
|
|
opt.keyserver_host=strsep(&uri,":/");
|
|
|
|
if(uri==NULL)
|
|
|
|
opt.keyserver_port="0";
|
|
|
|
else
|
|
|
|
{
|
2001-12-20 05:02:30 +00:00
|
|
|
char *ch;
|
2001-12-18 23:10:46 +00:00
|
|
|
|
2001-12-06 21:54:04 +00:00
|
|
|
/* Get the port */
|
|
|
|
opt.keyserver_port=strsep(&uri,"/");
|
2001-12-18 23:10:46 +00:00
|
|
|
|
|
|
|
/* Ports are digits only */
|
|
|
|
ch=opt.keyserver_port;
|
|
|
|
while(*ch!='\0')
|
|
|
|
{
|
|
|
|
if(!isdigit(*ch))
|
|
|
|
return G10ERR_BAD_URI;
|
|
|
|
|
|
|
|
ch++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strlen(opt.keyserver_port)==0 ||
|
|
|
|
atoi(opt.keyserver_port)<1 || atoi(opt.keyserver_port)>65535)
|
|
|
|
return G10ERR_BAD_URI;
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
|
|
|
|
2002-03-31 23:51:33 +00:00
|
|
|
/* (any path part of the URI is discarded for now as no keyserver
|
|
|
|
uses it) */
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
if(opt.keyserver_scheme[0]=='\0' || opt.keyserver_host[0]=='\0')
|
|
|
|
return G10ERR_BAD_URI;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-31 23:51:33 +00:00
|
|
|
/* Unquote only the delimiter character and backslashes (\x5C) */
|
2001-12-15 18:27:13 +00:00
|
|
|
static void
|
|
|
|
printunquoted(char *string,char delim)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
|
|
|
char *ch=string;
|
|
|
|
|
|
|
|
while(*ch)
|
|
|
|
{
|
|
|
|
if(*ch=='\\')
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2002-03-29 16:58:07 +00:00
|
|
|
sscanf(ch,"\\x%02x",&c);
|
2001-12-06 21:54:04 +00:00
|
|
|
if(c==delim)
|
|
|
|
{
|
|
|
|
printf("%c",c);
|
|
|
|
ch+=3;
|
|
|
|
}
|
2002-03-29 16:58:07 +00:00
|
|
|
else if(c=='\\')
|
|
|
|
{
|
|
|
|
fputc('\\',stdout);
|
|
|
|
ch+=3;
|
|
|
|
}
|
2001-12-06 21:54:04 +00:00
|
|
|
else
|
|
|
|
fputc(*ch,stdout);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fputc(*ch,stdout);
|
|
|
|
|
|
|
|
ch++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-15 18:27:13 +00:00
|
|
|
static int
|
2002-02-26 01:00:12 +00:00
|
|
|
print_keyinfo(int count,char *keystring,KEYDB_SEARCH_DESC *desc)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
|
|
|
char *certid,*userid,*keytype,*tok;
|
|
|
|
int flags,keysize=0;
|
|
|
|
time_t createtime=0,expiretime=0,modifytime=0;
|
|
|
|
|
|
|
|
if((certid=strsep(&keystring,":"))==NULL)
|
|
|
|
return -1;
|
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
classify_user_id (certid, desc);
|
|
|
|
if(desc->mode!=KEYDB_SEARCH_MODE_SHORT_KID &&
|
|
|
|
desc->mode!=KEYDB_SEARCH_MODE_LONG_KID &&
|
|
|
|
desc->mode!=KEYDB_SEARCH_MODE_FPR16 &&
|
|
|
|
desc->mode!=KEYDB_SEARCH_MODE_FPR20)
|
|
|
|
return -1;
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
userid=utf8_to_native(tok,strlen(tok),0);
|
|
|
|
|
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
flags=atoi(tok);
|
|
|
|
|
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
createtime=atoi(tok);
|
|
|
|
|
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
expiretime=atoi(tok);
|
|
|
|
|
|
|
|
if((tok=strsep(&keystring,":"))==NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
modifytime=atoi(tok);
|
|
|
|
|
|
|
|
if((keytype=strsep(&keystring,":"))==NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* The last one */
|
|
|
|
if(keystring!=NULL)
|
|
|
|
keysize=atoi(keystring);
|
|
|
|
|
|
|
|
printf("(%d)\t",count);
|
|
|
|
|
2001-12-17 23:10:07 +00:00
|
|
|
/* No need to check for control characters, as utf8_to_native does
|
|
|
|
this for us. */
|
2001-12-06 21:54:04 +00:00
|
|
|
printunquoted(userid,':');
|
|
|
|
|
|
|
|
if(flags&1)
|
|
|
|
printf(" (revoked)");
|
|
|
|
if(flags&2)
|
|
|
|
printf(" (disabled)");
|
|
|
|
|
|
|
|
if(keytype[0])
|
|
|
|
printf(" %s",keytype);
|
|
|
|
|
|
|
|
if(keysize>0)
|
|
|
|
printf(" %d",keysize);
|
|
|
|
|
|
|
|
printf("\n\t created %s,",strtimestamp(createtime));
|
|
|
|
|
|
|
|
if(expiretime>0)
|
|
|
|
printf(" expires %s,",strtimestamp(expiretime));
|
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
printf(" key %s\n",certid);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
#define KEYSERVER_ARGS_KEEP " -o \"%O\" \"%I\""
|
|
|
|
#define KEYSERVER_ARGS_NOKEEP " -o \"%o\" \"%i\""
|
2001-12-15 18:27:13 +00:00
|
|
|
|
|
|
|
static int
|
2002-02-26 01:00:12 +00:00
|
|
|
keyserver_spawn(int action,STRLIST list,
|
|
|
|
KEYDB_SEARCH_DESC *desc,int count,int *prog)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2001-12-28 16:34:01 +00:00
|
|
|
int ret=0,i,gotversion=0,outofband=0;
|
2001-12-06 21:54:04 +00:00
|
|
|
STRLIST temp;
|
|
|
|
unsigned int maxlen=256,buflen;
|
2001-12-21 23:06:02 +00:00
|
|
|
char *command=NULL,*searchstr=NULL;
|
2001-12-06 21:54:04 +00:00
|
|
|
byte *line=NULL;
|
2001-12-21 23:06:02 +00:00
|
|
|
struct exec_info *spawn;
|
2001-12-20 05:02:30 +00:00
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
#ifdef EXEC_TEMPFILE_ONLY
|
|
|
|
opt.keyserver_options.use_temp_files=1;
|
|
|
|
#endif
|
2001-12-20 05:02:30 +00:00
|
|
|
|
2001-12-06 21:54:04 +00:00
|
|
|
/* Build the filename for the helper to execute */
|
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
command=m_alloc(strlen("gpgkeys_")+strlen(opt.keyserver_scheme)+1);
|
|
|
|
strcpy(command,"gpgkeys_");
|
|
|
|
strcat(command,opt.keyserver_scheme);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
if(opt.keyserver_options.use_temp_files)
|
|
|
|
{
|
2001-12-21 23:06:02 +00:00
|
|
|
if(opt.keyserver_options.keep_temp_files)
|
2001-12-20 05:02:30 +00:00
|
|
|
{
|
2001-12-21 23:06:02 +00:00
|
|
|
command=m_realloc(command,strlen(command)+
|
|
|
|
strlen(KEYSERVER_ARGS_KEEP)+1);
|
|
|
|
strcat(command,KEYSERVER_ARGS_KEEP);
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
2001-12-21 23:06:02 +00:00
|
|
|
else
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2001-12-21 23:06:02 +00:00
|
|
|
command=m_realloc(command,strlen(command)+
|
|
|
|
strlen(KEYSERVER_ARGS_NOKEEP)+1);
|
|
|
|
strcat(command,KEYSERVER_ARGS_NOKEEP);
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
2001-12-21 23:06:02 +00:00
|
|
|
|
|
|
|
ret=exec_write(&spawn,NULL,command,0,0);
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
|
|
|
else
|
2001-12-21 23:06:02 +00:00
|
|
|
ret=exec_write(&spawn,command,NULL,0,0);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
if(ret)
|
2001-12-29 04:43:11 +00:00
|
|
|
return ret;
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"# This is a gpg keyserver communications file\n");
|
|
|
|
fprintf(spawn->tochild,"VERSION %d\n",KEYSERVER_PROTO_VERSION);
|
|
|
|
fprintf(spawn->tochild,"PROGRAM %s\n",VERSION);
|
|
|
|
fprintf(spawn->tochild,"HOST %s\n",opt.keyserver_host);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
if(atoi(opt.keyserver_port)>0)
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"PORT %s\n",opt.keyserver_port);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
/* Write options */
|
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"OPTION %sinclude-revoked\n",
|
2001-12-06 21:54:04 +00:00
|
|
|
opt.keyserver_options.include_revoked?"":"no-");
|
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"OPTION %sinclude-disabled\n",
|
2001-12-06 21:54:04 +00:00
|
|
|
opt.keyserver_options.include_disabled?"":"no-");
|
|
|
|
|
|
|
|
for(i=0;i<opt.keyserver_options.verbose;i++)
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"OPTION verbose\n");
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
temp=opt.keyserver_options.other;
|
|
|
|
|
|
|
|
for(;temp;temp=temp->next)
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"OPTION %s\n",temp->d);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
switch(action)
|
|
|
|
{
|
|
|
|
case GET:
|
|
|
|
{
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"COMMAND GET\n\n");
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
/* Which keys do we want? */
|
|
|
|
|
|
|
|
for(i=0;i<count;i++)
|
2002-02-26 01:00:12 +00:00
|
|
|
{
|
|
|
|
if(desc[i].mode==KEYDB_SEARCH_MODE_FPR20)
|
|
|
|
{
|
|
|
|
int f;
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"0x");
|
|
|
|
|
|
|
|
for(f=0;f<MAX_FINGERPRINT_LEN;f++)
|
|
|
|
fprintf(spawn->tochild,"%02X",(byte)desc[i].u.fpr[f]);
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"\n");
|
|
|
|
}
|
|
|
|
else if(desc[i].mode==KEYDB_SEARCH_MODE_FPR16)
|
|
|
|
{
|
|
|
|
int f;
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"0x");
|
|
|
|
|
|
|
|
for(f=0;f<16;f++)
|
|
|
|
fprintf(spawn->tochild,"%02X",(byte)desc[i].u.fpr[f]);
|
|
|
|
|
|
|
|
fprintf(spawn->tochild,"\n");
|
|
|
|
}
|
|
|
|
else if(desc[i].mode==KEYDB_SEARCH_MODE_LONG_KID)
|
|
|
|
fprintf(spawn->tochild,"0x%08lX%08lX\n",
|
|
|
|
(ulong)desc[i].u.kid[0],
|
|
|
|
(ulong)desc[i].u.kid[1]);
|
|
|
|
else
|
|
|
|
fprintf(spawn->tochild,"0x%08lX\n",
|
|
|
|
(ulong)desc[i].u.kid[1]);
|
|
|
|
}
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"\n");
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SEND:
|
|
|
|
{
|
2001-12-22 13:04:24 +00:00
|
|
|
STRLIST key;
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
/* Note the extra \n here to send an empty keylist block */
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"COMMAND SEND\n\n\n");
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
for(key=list;key!=NULL;key=key->next)
|
|
|
|
{
|
|
|
|
armor_filter_context_t afx;
|
|
|
|
IOBUF buffer=iobuf_temp();
|
|
|
|
|
|
|
|
temp=NULL;
|
|
|
|
add_to_strlist(&temp,key->d);
|
|
|
|
|
|
|
|
memset(&afx,0,sizeof(afx));
|
|
|
|
afx.what=1;
|
|
|
|
iobuf_push_filter(buffer,armor_filter,&afx);
|
|
|
|
|
2002-02-04 05:19:24 +00:00
|
|
|
if(export_pubkeys_stream(buffer,temp,1)==-1)
|
2001-12-06 21:54:04 +00:00
|
|
|
iobuf_close(buffer);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iobuf_flush_temp(buffer);
|
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"KEY %s BEGIN\n",key->d);
|
2001-12-06 21:54:04 +00:00
|
|
|
fwrite(iobuf_get_temp_buffer(buffer),
|
2001-12-21 23:06:02 +00:00
|
|
|
iobuf_get_temp_length(buffer),1,spawn->tochild);
|
|
|
|
fprintf(spawn->tochild,"KEY %s END\n",key->d);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
iobuf_close(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_strlist(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SEARCH:
|
|
|
|
{
|
|
|
|
STRLIST key;
|
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"COMMAND SEARCH\n\n");
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
/* Which keys do we want? Remember that the gpgkeys_ program
|
|
|
|
is going to lump these together into a search string. */
|
|
|
|
|
|
|
|
for(key=list;key!=NULL;key=key->next)
|
|
|
|
{
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"%s\n",key->d);
|
2001-12-06 21:54:04 +00:00
|
|
|
if(key!=list)
|
|
|
|
{
|
|
|
|
searchstr=m_realloc(searchstr,
|
|
|
|
strlen(searchstr)+strlen(key->d)+2);
|
|
|
|
strcat(searchstr," ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
searchstr=m_alloc(strlen(key->d)+1);
|
|
|
|
searchstr[0]='\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat(searchstr,key->d);
|
|
|
|
}
|
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
fprintf(spawn->tochild,"\n");
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
log_fatal(_("no keyserver action!\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-21 23:06:02 +00:00
|
|
|
/* Done sending, so start reading. */
|
|
|
|
ret=exec_read(spawn);
|
|
|
|
if(ret)
|
|
|
|
goto fail;
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
/* Now handle the response */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2001-12-21 23:06:02 +00:00
|
|
|
if(iobuf_read_line(spawn->fromchild,&line,&buflen,&maxlen)==0)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
|
|
|
ret=G10ERR_READ_FILE;
|
|
|
|
goto fail; /* i.e. EOF */
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strncasecmp(line,"VERSION ",8)==0)
|
|
|
|
{
|
|
|
|
gotversion=1;
|
|
|
|
|
|
|
|
if(atoi(&line[8])!=KEYSERVER_PROTO_VERSION)
|
|
|
|
{
|
2001-12-17 22:48:52 +00:00
|
|
|
log_error(_("invalid keyserver protocol (us %d!=handler %d)\n"),
|
2001-12-06 21:54:04 +00:00
|
|
|
KEYSERVER_PROTO_VERSION,atoi(&line[8]));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strncasecmp(line,"PROGRAM ",8)==0)
|
|
|
|
{
|
|
|
|
line[strlen(line)-1]='\0';
|
|
|
|
if(strcasecmp(&line[8],VERSION)!=0)
|
|
|
|
log_info(_("Warning: keyserver handler from a different "
|
|
|
|
"version of GnuPG (%s)\n"),&line[8]);
|
|
|
|
}
|
2001-12-28 16:34:01 +00:00
|
|
|
|
|
|
|
/* Currently the only OPTION */
|
|
|
|
if(strncasecmp(line,"OPTION OUTOFBAND",16)==0)
|
|
|
|
outofband=1;
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
|
|
|
while(line[0]!='\n');
|
|
|
|
|
|
|
|
if(!gotversion)
|
|
|
|
{
|
2001-12-27 20:48:05 +00:00
|
|
|
log_error(_("keyserver did not send VERSION\n"));
|
2001-12-06 21:54:04 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2001-12-28 16:34:01 +00:00
|
|
|
if(!outofband)
|
|
|
|
switch(action)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2001-12-28 16:34:01 +00:00
|
|
|
case GET:
|
|
|
|
{
|
|
|
|
void *stats_handle;
|
|
|
|
|
|
|
|
stats_handle=import_new_stats_handle();
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2001-12-28 16:34:01 +00:00
|
|
|
/* Slurp up all the key data. In the future, it might be nice
|
|
|
|
to look for KEY foo OUTOFBAND and FAILED indicators. It's
|
|
|
|
harmless to ignore them, but ignoring them does make gpg
|
|
|
|
complain about "no valid OpenPGP data found". One way to
|
|
|
|
do this could be to continue parsing this line-by-line and
|
|
|
|
make a temp iobuf for each key. */
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2002-04-19 22:38:20 +00:00
|
|
|
import_keys_stream(spawn->fromchild,0,stats_handle);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2001-12-28 16:34:01 +00:00
|
|
|
import_print_stats(stats_handle);
|
|
|
|
import_release_stats_handle(stats_handle);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2001-12-28 16:34:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2001-12-28 16:34:01 +00:00
|
|
|
/* Nothing to do here */
|
|
|
|
case SEND:
|
2001-12-06 21:54:04 +00:00
|
|
|
break;
|
|
|
|
|
2001-12-28 16:34:01 +00:00
|
|
|
case SEARCH:
|
|
|
|
{
|
|
|
|
line=NULL;
|
|
|
|
buflen = 0;
|
|
|
|
maxlen = 80;
|
|
|
|
/* Look for the COUNT line */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if(iobuf_read_line(spawn->fromchild,&line,&buflen,&maxlen)==0)
|
|
|
|
{
|
|
|
|
ret=G10ERR_READ_FILE;
|
|
|
|
goto fail; /* i.e. EOF */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(sscanf(line,"COUNT %d\n",&i)!=1);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2001-12-28 16:34:01 +00:00
|
|
|
keyserver_search_prompt(spawn->fromchild,i,searchstr);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2001-12-28 16:34:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2001-12-28 16:34:01 +00:00
|
|
|
default:
|
|
|
|
log_fatal(_("no keyserver action!\n"));
|
2001-12-06 21:54:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
2001-12-27 20:48:05 +00:00
|
|
|
*prog=exec_finish(spawn);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-12-15 18:27:13 +00:00
|
|
|
static int
|
2002-02-26 01:00:12 +00:00
|
|
|
keyserver_work(int action,STRLIST list,KEYDB_SEARCH_DESC *desc,int count)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2001-12-21 23:06:02 +00:00
|
|
|
int rc=0,ret=0;
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
if(opt.keyserver_scheme==NULL ||
|
|
|
|
opt.keyserver_host==NULL ||
|
|
|
|
opt.keyserver_port==NULL)
|
|
|
|
{
|
|
|
|
log_error(_("no keyserver known (use option --keyserver)\n"));
|
|
|
|
return G10ERR_BAD_URI;
|
|
|
|
}
|
|
|
|
|
2002-02-19 23:10:32 +00:00
|
|
|
#ifndef USE_EXTERNAL_HKP
|
2001-12-06 21:54:04 +00:00
|
|
|
/* Use the internal HKP code */
|
|
|
|
if(strcasecmp(opt.keyserver_scheme,"x-hkp")==0 ||
|
|
|
|
strcasecmp(opt.keyserver_scheme,"hkp")==0 ||
|
|
|
|
strcasecmp(opt.keyserver_scheme,"x-broken-hkp")==0)
|
|
|
|
{
|
|
|
|
void *stats_handle = import_new_stats_handle ();
|
|
|
|
|
|
|
|
switch(action)
|
|
|
|
{
|
|
|
|
case GET:
|
|
|
|
for(count--;count>=0;count--)
|
2002-02-26 01:00:12 +00:00
|
|
|
if(hkp_ask_import(&desc[count],stats_handle))
|
2001-12-06 21:54:04 +00:00
|
|
|
log_inc_errorcount();
|
|
|
|
break;
|
|
|
|
case SEND:
|
|
|
|
return hkp_export(list);
|
|
|
|
case SEARCH:
|
|
|
|
return hkp_search(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
import_print_stats (stats_handle);
|
|
|
|
import_release_stats_handle (stats_handle);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2002-02-19 23:10:32 +00:00
|
|
|
#endif
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
/* It's not the internal HKP code, so try and spawn a handler for it */
|
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
rc=keyserver_spawn(action,list,desc,count,&ret);
|
2001-12-27 20:48:05 +00:00
|
|
|
if(ret)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2001-12-21 23:06:02 +00:00
|
|
|
switch(ret)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
|
|
|
case KEYSERVER_SCHEME_NOT_FOUND:
|
2001-12-17 22:48:52 +00:00
|
|
|
log_error(_("no handler for keyserver scheme \"%s\"\n"),
|
2001-12-06 21:54:04 +00:00
|
|
|
opt.keyserver_scheme);
|
|
|
|
break;
|
|
|
|
|
2002-02-19 23:10:32 +00:00
|
|
|
case KEYSERVER_NOT_SUPPORTED:
|
|
|
|
log_error(_("action \"%s\" not supported with keyserver "
|
|
|
|
"scheme \"%s\"\n"),
|
|
|
|
action==GET?"get":action==SEND?"send":
|
|
|
|
action==SEARCH?"search":"unknown",
|
|
|
|
opt.keyserver_scheme);
|
|
|
|
|
2001-12-06 21:54:04 +00:00
|
|
|
case KEYSERVER_INTERNAL_ERROR:
|
|
|
|
default:
|
2001-12-17 22:48:52 +00:00
|
|
|
log_error(_("keyserver internal error\n"));
|
2001-12-06 21:54:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-27 20:48:05 +00:00
|
|
|
return G10ERR_KEYSERVER;
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
2001-12-27 20:48:05 +00:00
|
|
|
|
|
|
|
if(rc)
|
2001-12-21 23:06:02 +00:00
|
|
|
{
|
2001-12-27 20:48:05 +00:00
|
|
|
log_error(_("keyserver communications error: %s\n"),g10_errstr(rc));
|
2001-12-21 23:06:02 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-15 18:27:13 +00:00
|
|
|
int
|
|
|
|
keyserver_export(STRLIST users)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
|
|
|
return keyserver_work(SEND,users,NULL,0);
|
|
|
|
}
|
|
|
|
|
2001-12-15 18:27:13 +00:00
|
|
|
int
|
|
|
|
keyserver_import(STRLIST users)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2002-02-26 01:00:12 +00:00
|
|
|
KEYDB_SEARCH_DESC *desc;
|
2001-12-06 21:54:04 +00:00
|
|
|
int num=100,count=0;
|
|
|
|
int rc=0;
|
|
|
|
|
|
|
|
/* Build a list of key ids */
|
2002-02-26 01:00:12 +00:00
|
|
|
desc=m_alloc(sizeof(KEYDB_SEARCH_DESC)*num);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
for(;users;users=users->next)
|
|
|
|
{
|
2002-02-26 01:00:12 +00:00
|
|
|
classify_user_id (users->d, &desc[count]);
|
|
|
|
if(desc[count].mode!=KEYDB_SEARCH_MODE_SHORT_KID &&
|
|
|
|
desc[count].mode!=KEYDB_SEARCH_MODE_LONG_KID &&
|
|
|
|
desc[count].mode!=KEYDB_SEARCH_MODE_FPR16 &&
|
|
|
|
desc[count].mode!=KEYDB_SEARCH_MODE_FPR20)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2002-02-26 01:00:12 +00:00
|
|
|
log_error(_("skipping invalid key ID \"%s\"\n"),users->d);
|
|
|
|
continue;
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
2002-02-26 01:00:12 +00:00
|
|
|
|
|
|
|
count++;
|
|
|
|
if(count==num)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2002-02-26 01:00:12 +00:00
|
|
|
num+=100;
|
|
|
|
desc=m_realloc(desc,sizeof(KEYDB_SEARCH_DESC)*num);
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count>0)
|
2002-02-26 01:00:12 +00:00
|
|
|
rc=keyserver_work(GET,NULL,desc,count);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
m_free(desc);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2002-03-07 19:44:57 +00:00
|
|
|
int
|
|
|
|
keyserver_import_fprint(const byte *fprint,size_t fprint_len)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2002-03-07 19:44:57 +00:00
|
|
|
KEYDB_SEARCH_DESC desc;
|
|
|
|
|
|
|
|
memset(&desc,0,sizeof(desc));
|
|
|
|
|
|
|
|
if(fprint_len==16)
|
|
|
|
desc.mode=KEYDB_SEARCH_MODE_FPR16;
|
|
|
|
else if(fprint_len==20)
|
|
|
|
desc.mode=KEYDB_SEARCH_MODE_FPR20;
|
|
|
|
else
|
|
|
|
return -1;
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2002-03-07 19:44:57 +00:00
|
|
|
memcpy(desc.u.fpr,fprint,fprint_len);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2002-03-07 19:44:57 +00:00
|
|
|
return keyserver_work(GET,NULL,&desc,1);
|
|
|
|
}
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2002-03-07 19:44:57 +00:00
|
|
|
int
|
|
|
|
keyserver_import_keyid(u32 *keyid)
|
|
|
|
{
|
|
|
|
KEYDB_SEARCH_DESC desc;
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2002-03-07 19:44:57 +00:00
|
|
|
memset(&desc,0,sizeof(desc));
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2002-03-07 19:44:57 +00:00
|
|
|
desc.mode=KEYDB_SEARCH_MODE_LONG_KID;
|
|
|
|
desc.u.kid[0]=keyid[0];
|
|
|
|
desc.u.kid[1]=keyid[1];
|
|
|
|
|
|
|
|
return keyserver_work(GET,NULL,&desc,1);
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* code mostly stolen from do_export_stream */
|
2001-12-15 18:27:13 +00:00
|
|
|
static int
|
2002-02-26 01:00:12 +00:00
|
|
|
keyidlist(STRLIST users,KEYDB_SEARCH_DESC **klist,int *count,int fakev3)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
|
|
|
int rc=0,ndesc,num=100;
|
|
|
|
KBNODE keyblock=NULL,node;
|
|
|
|
KEYDB_HANDLE kdbhd;
|
|
|
|
KEYDB_SEARCH_DESC *desc;
|
|
|
|
STRLIST sl;
|
|
|
|
|
|
|
|
*count=0;
|
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
*klist=m_alloc(sizeof(KEYDB_SEARCH_DESC)*num);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
kdbhd=keydb_new(0);
|
|
|
|
|
|
|
|
if(!users)
|
|
|
|
{
|
|
|
|
ndesc = 1;
|
|
|
|
desc = m_alloc_clear ( ndesc * sizeof *desc);
|
|
|
|
desc[0].mode = KEYDB_SEARCH_MODE_FIRST;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (ndesc=0, sl=users; sl; sl = sl->next, ndesc++)
|
|
|
|
;
|
|
|
|
desc = m_alloc ( ndesc * sizeof *desc);
|
|
|
|
|
|
|
|
for (ndesc=0, sl=users; sl; sl = sl->next)
|
|
|
|
{
|
|
|
|
if(classify_user_id (sl->d, desc+ndesc))
|
|
|
|
ndesc++;
|
|
|
|
else
|
|
|
|
log_error (_("key `%s' not found: %s\n"),
|
|
|
|
sl->d, g10_errstr (G10ERR_INV_USER_ID));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!(rc = keydb_search (kdbhd, desc, ndesc)))
|
|
|
|
{
|
|
|
|
if (!users)
|
|
|
|
desc[0].mode = KEYDB_SEARCH_MODE_NEXT;
|
|
|
|
|
|
|
|
/* read the keyblock */
|
|
|
|
rc = keydb_get_keyblock (kdbhd, &keyblock );
|
|
|
|
if( rc )
|
|
|
|
{
|
|
|
|
log_error (_("error reading keyblock: %s\n"), g10_errstr(rc) );
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((node=find_kbnode(keyblock,PKT_PUBLIC_KEY)))
|
|
|
|
{
|
2002-02-04 21:49:08 +00:00
|
|
|
/* This is to work around a bug in some keyservers (pksd and
|
|
|
|
OKS) that calculate v4 RSA keyids as if they were v3 RSA.
|
|
|
|
The answer is to refresh both the correct v4 keyid
|
|
|
|
(e.g. 99242560) and the fake v3 keyid (e.g. 68FDDBC7).
|
|
|
|
This only happens for key refresh using the HKP scheme
|
|
|
|
and if the refresh-add-fake-v3-keyids keyserver option is
|
|
|
|
set. */
|
|
|
|
if(fakev3 && is_RSA(node->pkt->pkt.public_key->pubkey_algo) &&
|
|
|
|
node->pkt->pkt.public_key->version>=4)
|
|
|
|
{
|
2002-02-26 01:00:12 +00:00
|
|
|
(*klist)[*count].mode=KEYDB_SEARCH_MODE_LONG_KID;
|
2002-02-04 21:49:08 +00:00
|
|
|
mpi_get_keyid(node->pkt->pkt.public_key->pkey[0],
|
2002-02-26 01:00:12 +00:00
|
|
|
(*klist)[*count].u.kid);
|
2002-02-04 21:49:08 +00:00
|
|
|
(*count)++;
|
|
|
|
|
|
|
|
if(*count==num)
|
|
|
|
{
|
|
|
|
num+=100;
|
2002-02-26 01:00:12 +00:00
|
|
|
*klist=m_realloc(*klist,sizeof(KEYDB_SEARCH_DESC)*num);
|
2002-02-04 21:49:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
/* v4 keys get full fingerprints. v3 keys get long keyids.
|
|
|
|
This is because it's easy to calculate any sort of key id
|
|
|
|
from a v4 fingerprint, but not a v3 fingerprint. */
|
|
|
|
|
|
|
|
if(node->pkt->pkt.public_key->version<4)
|
|
|
|
{
|
|
|
|
(*klist)[*count].mode=KEYDB_SEARCH_MODE_LONG_KID;
|
|
|
|
keyid_from_pk(node->pkt->pkt.public_key,
|
|
|
|
(*klist)[*count].u.kid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t dummy;
|
|
|
|
|
|
|
|
(*klist)[*count].mode=KEYDB_SEARCH_MODE_FPR20;
|
|
|
|
fingerprint_from_pk(node->pkt->pkt.public_key,
|
|
|
|
(*klist)[*count].u.fpr,&dummy);
|
|
|
|
}
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
(*count)++;
|
|
|
|
|
|
|
|
if(*count==num)
|
|
|
|
{
|
|
|
|
num+=100;
|
2002-02-26 01:00:12 +00:00
|
|
|
*klist=m_realloc(*klist,sizeof(KEYDB_SEARCH_DESC)*num);
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
if(rc==-1)
|
|
|
|
rc=0;
|
|
|
|
|
|
|
|
leave:
|
|
|
|
m_free(desc);
|
|
|
|
keydb_release(kdbhd);
|
|
|
|
release_kbnode(keyblock);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
return rc;
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note this is different than the original HKP refresh. It allows
|
|
|
|
usernames to refresh only part of the keyring. */
|
|
|
|
|
2001-12-15 18:27:13 +00:00
|
|
|
int
|
|
|
|
keyserver_refresh(STRLIST users)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2002-02-04 21:49:08 +00:00
|
|
|
int rc,count,fakev3=0;
|
2002-02-26 01:00:12 +00:00
|
|
|
KEYDB_SEARCH_DESC *desc;
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2002-02-04 21:49:08 +00:00
|
|
|
/* If refresh_add_fake_v3_keyids is on and it's a HKP scheme, then
|
|
|
|
enable fake v3 keyid generation. */
|
|
|
|
if(opt.keyserver_options.refresh_add_fake_v3_keyids &&
|
|
|
|
opt.keyserver_scheme &&
|
|
|
|
(strcasecmp(opt.keyserver_scheme,"x-hkp")==0 ||
|
|
|
|
strcasecmp(opt.keyserver_scheme,"hkp")==0 ||
|
|
|
|
strcasecmp(opt.keyserver_scheme,"x-broken-hkp")==0))
|
|
|
|
fakev3=1;
|
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
rc=keyidlist(users,&desc,&count,fakev3);
|
2001-12-06 21:54:04 +00:00
|
|
|
if(rc)
|
|
|
|
return rc;
|
|
|
|
|
2001-12-17 22:48:52 +00:00
|
|
|
if(count==1)
|
|
|
|
log_info(_("%d key to refresh\n"),count);
|
|
|
|
else
|
|
|
|
log_info(_("%d keys to refresh\n"),count);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
if(count>0)
|
2002-02-26 01:00:12 +00:00
|
|
|
rc=keyserver_work(GET,NULL,desc,count);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
m_free(desc);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-15 18:27:13 +00:00
|
|
|
int
|
|
|
|
keyserver_search(STRLIST tokens)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
|
|
|
if(tokens)
|
|
|
|
return keyserver_work(SEARCH,tokens,NULL,0);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-02-22 03:11:15 +00:00
|
|
|
/* Count and searchstr are just for cosmetics. If the count is too
|
|
|
|
small, it will grow safely. If negative it disables the "Key x-y
|
|
|
|
of z" messages. */
|
2001-12-15 18:27:13 +00:00
|
|
|
void
|
|
|
|
keyserver_search_prompt(IOBUF buffer,int count,const char *searchstr)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
|
|
|
int i=0,validcount=1;
|
|
|
|
unsigned int maxlen=256,buflen=0;
|
2002-02-26 01:00:12 +00:00
|
|
|
KEYDB_SEARCH_DESC *desc;
|
2001-12-06 21:54:04 +00:00
|
|
|
byte *line=NULL;
|
|
|
|
char *answer;
|
|
|
|
|
|
|
|
if(count==0)
|
2002-02-22 03:11:15 +00:00
|
|
|
goto notfound;
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
if(count<0)
|
|
|
|
{
|
|
|
|
validcount=0;
|
2002-03-19 04:35:45 +00:00
|
|
|
count=10;
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
desc=m_alloc(count*sizeof(KEYDB_SEARCH_DESC));
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
/* Read each line and show it to the user */
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
int rl;
|
|
|
|
|
2002-03-19 04:35:45 +00:00
|
|
|
if(validcount && i%10==0)
|
2001-12-06 21:54:04 +00:00
|
|
|
{
|
2002-03-19 04:35:45 +00:00
|
|
|
printf("Keys %d-%d of %d",i+1,(i+10<count)?i+10:count,count);
|
2002-02-22 03:11:15 +00:00
|
|
|
if(searchstr)
|
|
|
|
printf(" for \"%s\"",searchstr);
|
2001-12-06 21:54:04 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
maxlen=1024;
|
|
|
|
rl=iobuf_read_line(buffer,&line,&buflen,&maxlen);
|
|
|
|
if(rl>0)
|
|
|
|
{
|
2002-03-19 04:35:45 +00:00
|
|
|
if(print_keyinfo(i+1,line,&desc[i])==0)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if(i==count)
|
|
|
|
{
|
|
|
|
count+=10;
|
|
|
|
desc=m_realloc(desc,count*sizeof(KEYDB_SEARCH_DESC));
|
|
|
|
validcount=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2001-12-06 21:54:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-03-19 04:35:45 +00:00
|
|
|
if(rl==0 && i==0)
|
2002-02-22 03:11:15 +00:00
|
|
|
{
|
|
|
|
count=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-06 21:54:04 +00:00
|
|
|
if(i%10==0 || rl==0)
|
|
|
|
{
|
|
|
|
answer=cpr_get_no_help("keysearch.prompt",
|
|
|
|
_("Enter number(s), N)ext, or Q)uit > "));
|
2002-03-31 23:51:33 +00:00
|
|
|
/* control-d */
|
|
|
|
if(answer[0]=='\x04')
|
|
|
|
{
|
|
|
|
printf("Q\n");
|
|
|
|
answer[0]='q';
|
|
|
|
}
|
|
|
|
|
2001-12-06 21:54:04 +00:00
|
|
|
if(answer[0]=='q' || answer[0]=='Q')
|
|
|
|
{
|
|
|
|
m_free(answer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(atoi(answer)>=1 && atoi(answer)<=i)
|
|
|
|
{
|
|
|
|
char *split=answer,*num;
|
|
|
|
|
|
|
|
while((num=strsep(&split," ,"))!=NULL)
|
|
|
|
if(atoi(num)>=1 && atoi(num)<=i)
|
2002-02-26 01:00:12 +00:00
|
|
|
keyserver_work(GET,NULL,&desc[atoi(num)-1],1);
|
2001-12-06 21:54:04 +00:00
|
|
|
|
|
|
|
m_free(answer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-26 01:00:12 +00:00
|
|
|
m_free(desc);
|
2001-12-06 21:54:04 +00:00
|
|
|
m_free(line);
|
2002-02-22 03:11:15 +00:00
|
|
|
|
|
|
|
notfound:
|
|
|
|
if(count==0)
|
|
|
|
{
|
|
|
|
if(searchstr)
|
|
|
|
log_info(_("key \"%s\" not found on keyserver\n"),searchstr);
|
|
|
|
else
|
|
|
|
log_info(_("key not found on keyserver\n"));
|
|
|
|
return;
|
|
|
|
}
|
2001-12-06 21:54:04 +00:00
|
|
|
}
|