1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-17 15:44:34 +02:00

* options.h, import.c, keyserver-internal.h, g10.c, mainproc.c,

keyserver.c (parse_keyserver_uri): Parse keyserver URI into a structure.
Cleanup for new "guess my keyserver" functionality, as well as refreshing
via a preferred keyserver subpacket.
This commit is contained in:
David Shaw 2004-04-14 21:33:45 +00:00
parent 2286674b9e
commit a9b00b06d1
7 changed files with 80 additions and 53 deletions

View File

@ -1,5 +1,10 @@
2004-04-14 David Shaw <dshaw@jabberwocky.com> 2004-04-14 David Shaw <dshaw@jabberwocky.com>
* options.h, import.c, keyserver-internal.h, g10.c, mainproc.c,
keyserver.c (parse_keyserver_uri): Parse keyserver URI into a
structure. Cleanup for new "guess my keyserver" functionality, as
well as refreshing via a preferred keyserver subpacket.
* options.h: Encapsulate keyserver details. Change all callers. * options.h: Encapsulate keyserver details. Change all callers.
2004-03-27 David Shaw <dshaw@jabberwocky.com> 2004-03-27 David Shaw <dshaw@jabberwocky.com>

View File

@ -2074,8 +2074,9 @@ main( int argc, char **argv )
#endif /* __riscos__ */ #endif /* __riscos__ */
break; break;
case oKeyServer: case oKeyServer:
opt.keyserver.uri=m_strdup(pargs.r.ret_str); opt.keyserver=parse_keyserver_uri(pargs.r.ret_str,
if(parse_keyserver_uri(pargs.r.ret_str,configname,configlineno)) configname,configlineno);
if(!opt.keyserver)
log_error(_("could not parse keyserver URI\n")); log_error(_("could not parse keyserver URI\n"));
break; break;
case oKeyServerOptions: case oKeyServerOptions:

View File

@ -1691,8 +1691,8 @@ revocation_present(KBNODE keyblock)
char *tempkeystr=m_strdup(keystr_from_pk(pk)); char *tempkeystr=m_strdup(keystr_from_pk(pk));
/* No, so try and get it */ /* No, so try and get it */
if(opt.keyserver.scheme && if(opt.keyserver
opt.keyserver_options.auto_key_retrieve) && opt.keyserver_options.auto_key_retrieve)
{ {
log_info(_("WARNING: key %s may be revoked:" log_info(_("WARNING: key %s may be revoked:"
" fetching revocation key %s\n"), " fetching revocation key %s\n"),

View File

@ -9,8 +9,9 @@
#include "types.h" #include "types.h"
void parse_keyserver_options(char *options); void parse_keyserver_options(char *options);
int parse_keyserver_uri(char *uri, struct keyserver_spec *parse_keyserver_uri(char *uri,
const char *configname,unsigned int configlineno); const char *configname,
unsigned int configlineno);
int keyserver_export(STRLIST users); int keyserver_export(STRLIST users);
int keyserver_import(STRLIST users); int keyserver_import(STRLIST users);
int keyserver_import_fprint(const byte *fprint,size_t fprint_len); int keyserver_import_fprint(const byte *fprint,size_t fprint_len);

View File

@ -146,53 +146,62 @@ parse_keyserver_options(char *options)
} }
} }
int struct keyserver_spec *
parse_keyserver_uri(char *uri,const char *configname,unsigned int configlineno) parse_keyserver_uri(char *uri,const char *configname,unsigned int configlineno)
{ {
int assume_hkp=0; int assume_hkp=0;
struct keyserver_spec *keyserver;
char *scheme;
assert(uri!=NULL); assert(uri!=NULL);
opt.keyserver.host=NULL; keyserver=m_alloc_clear(sizeof(struct keyserver_spec));
opt.keyserver.port=NULL;
opt.keyserver.opaque=NULL; keyserver->uri=m_strdup(uri);
/* Get the scheme */ /* Get the scheme */
opt.keyserver.scheme=strsep(&uri,":"); scheme=strsep(&uri,":");
if(uri==NULL) if(uri==NULL)
{ {
/* Assume HKP if there is no scheme */ /* Assume HKP if there is no scheme */
assume_hkp=1; assume_hkp=1;
uri=opt.keyserver.scheme; uri=scheme;
opt.keyserver.scheme="hkp"; scheme="hkp";
} }
else else
{ {
/* Force to lowercase */ /* Force to lowercase */
char *i; char *i;
for(i=opt.keyserver.scheme;*i!='\0';i++) for(i=scheme;*i!='\0';i++)
*i=ascii_tolower(*i); *i=ascii_tolower(*i);
} }
if(ascii_strcasecmp(opt.keyserver.scheme,"x-broken-hkp")==0) if(ascii_strcasecmp(scheme,"x-broken-hkp")==0)
{ {
deprecated_warning(configname,configlineno,"x-broken-hkp", deprecated_warning(configname,configlineno,"x-broken-hkp",
"--keyserver-options ","broken-http-proxy"); "--keyserver-options ","broken-http-proxy");
opt.keyserver.scheme="hkp"; scheme="hkp";
add_to_strlist(&opt.keyserver_options.other,"broken-http-proxy"); add_to_strlist(&opt.keyserver_options.other,"broken-http-proxy");
} }
else if(ascii_strcasecmp(opt.keyserver.scheme,"x-hkp")==0 else if(ascii_strcasecmp(scheme,"x-hkp")==0
|| ascii_strcasecmp(opt.keyserver.scheme,"http")==0) || ascii_strcasecmp(scheme,"http")==0)
{ {
/* Canonicalize this to "hkp" so it works with both the internal /* Canonicalize this to "hkp" so it works with both the internal
and external keyserver interface. */ and external keyserver interface. */
opt.keyserver.scheme="hkp"; scheme="hkp";
} }
if(scheme[0]=='\0')
goto fail;
keyserver->scheme=m_strdup(scheme);
if(assume_hkp || (uri[0]=='/' && uri[1]=='/')) if(assume_hkp || (uri[0]=='/' && uri[1]=='/'))
{ {
char *host,*port;
/* Two slashes means network path. */ /* Two slashes means network path. */
/* Skip over the "//", if any */ /* Skip over the "//", if any */
@ -200,25 +209,27 @@ parse_keyserver_uri(char *uri,const char *configname,unsigned int configlineno)
uri+=2; uri+=2;
/* Get the host */ /* Get the host */
opt.keyserver.host=strsep(&uri,":/"); host=strsep(&uri,":/");
if(opt.keyserver.host[0]=='\0') if(host[0]=='\0')
return G10ERR_BAD_URI; goto fail;
keyserver->host=m_strdup(host);
if(uri==NULL || uri[0]=='\0') if(uri==NULL || uri[0]=='\0')
opt.keyserver.port=NULL; port=NULL;
else else
{ {
char *ch; char *ch;
/* Get the port */ /* Get the port */
opt.keyserver.port=strsep(&uri,"/"); port=strsep(&uri,"/");
/* Ports are digits only */ /* Ports are digits only */
ch=opt.keyserver.port; ch=port;
while(*ch!='\0') while(*ch!='\0')
{ {
if(!digitp(ch)) if(!digitp(ch))
return G10ERR_BAD_URI; goto fail;
ch++; ch++;
} }
@ -227,6 +238,8 @@ parse_keyserver_uri(char *uri,const char *configname,unsigned int configlineno)
ports to values between 1-65535, but RFC 1738 and 1808 ports to values between 1-65535, but RFC 1738 and 1808
imply there is no limit. Of course, the real world has imply there is no limit. Of course, the real world has
limits. */ limits. */
keyserver->port=m_strdup(port);
} }
/* (any path part of the URI is discarded for now as no keyserver /* (any path part of the URI is discarded for now as no keyserver
@ -236,20 +249,25 @@ parse_keyserver_uri(char *uri,const char *configname,unsigned int configlineno)
{ {
/* No slash means opaque. Just record the opaque blob and get /* No slash means opaque. Just record the opaque blob and get
out. */ out. */
opt.keyserver.opaque=uri; keyserver->opaque=m_strdup(uri);
return 0;
} }
else else
{ {
/* One slash means absolute path. We don't need to support that /* One slash means absolute path. We don't need to support that
yet. */ yet. */
return G10ERR_BAD_URI; goto fail;
} }
if(opt.keyserver.scheme[0]=='\0') return keyserver;
return G10ERR_BAD_URI;
return 0; fail:
m_free(keyserver->uri);
m_free(keyserver->host);
m_free(keyserver->port);
m_free(keyserver->opaque);
m_free(keyserver);
return NULL;
} }
static void static void
@ -705,6 +723,8 @@ keyserver_spawn(int action,STRLIST list,
struct kopts *kopts; struct kopts *kopts;
struct exec_info *spawn; struct exec_info *spawn;
assert(opt.keyserver);
#ifdef EXEC_TEMPFILE_ONLY #ifdef EXEC_TEMPFILE_ONLY
opt.keyserver_options.use_temp_files=1; opt.keyserver_options.use_temp_files=1;
#endif #endif
@ -718,9 +738,9 @@ keyserver_spawn(int action,STRLIST list,
#endif #endif
/* Build the filename for the helper to execute */ /* Build the filename for the helper to execute */
command=m_alloc(strlen("gpgkeys_")+strlen(opt.keyserver.scheme)+1); command=m_alloc(strlen("gpgkeys_")+strlen(opt.keyserver->scheme)+1);
strcpy(command,"gpgkeys_"); strcpy(command,"gpgkeys_");
strcat(command,opt.keyserver.scheme); strcat(command,opt.keyserver->scheme);
if(opt.keyserver_options.use_temp_files) if(opt.keyserver_options.use_temp_files)
{ {
@ -748,17 +768,17 @@ keyserver_spawn(int action,STRLIST list,
fprintf(spawn->tochild,"# This is a gpg keyserver communications file\n"); fprintf(spawn->tochild,"# This is a gpg keyserver communications file\n");
fprintf(spawn->tochild,"VERSION %d\n",KEYSERVER_PROTO_VERSION); fprintf(spawn->tochild,"VERSION %d\n",KEYSERVER_PROTO_VERSION);
fprintf(spawn->tochild,"PROGRAM %s\n",VERSION); fprintf(spawn->tochild,"PROGRAM %s\n",VERSION);
fprintf(spawn->tochild,"SCHEME %s\n",opt.keyserver.scheme); fprintf(spawn->tochild,"SCHEME %s\n",opt.keyserver->scheme);
if(opt.keyserver.opaque) if(opt.keyserver->opaque)
fprintf(spawn->tochild,"OPAQUE %s\n",opt.keyserver.opaque); fprintf(spawn->tochild,"OPAQUE %s\n",opt.keyserver->opaque);
else else
{ {
if(opt.keyserver.host) if(opt.keyserver->host)
fprintf(spawn->tochild,"HOST %s\n",opt.keyserver.host); fprintf(spawn->tochild,"HOST %s\n",opt.keyserver->host);
if(opt.keyserver.port) if(opt.keyserver->port)
fprintf(spawn->tochild,"PORT %s\n",opt.keyserver.port); fprintf(spawn->tochild,"PORT %s\n",opt.keyserver->port);
} }
/* Write options */ /* Write options */
@ -1112,7 +1132,7 @@ keyserver_work(int action,STRLIST list,KEYDB_SEARCH_DESC *desc,int count)
{ {
int rc=0,ret=0; int rc=0,ret=0;
if(opt.keyserver.scheme==NULL) if(!opt.keyserver)
{ {
log_error(_("no keyserver known (use option --keyserver)\n")); log_error(_("no keyserver known (use option --keyserver)\n"));
return G10ERR_BAD_URI; return G10ERR_BAD_URI;
@ -1133,7 +1153,7 @@ keyserver_work(int action,STRLIST list,KEYDB_SEARCH_DESC *desc,int count)
{ {
case KEYSERVER_SCHEME_NOT_FOUND: case KEYSERVER_SCHEME_NOT_FOUND:
log_error(_("no handler for keyserver scheme \"%s\"\n"), log_error(_("no handler for keyserver scheme \"%s\"\n"),
opt.keyserver.scheme); opt.keyserver->scheme);
break; break;
case KEYSERVER_NOT_SUPPORTED: case KEYSERVER_NOT_SUPPORTED:
@ -1141,12 +1161,12 @@ keyserver_work(int action,STRLIST list,KEYDB_SEARCH_DESC *desc,int count)
"scheme \"%s\"\n"), "scheme \"%s\"\n"),
action==GET?"get":action==SEND?"send": action==GET?"get":action==SEND?"send":
action==SEARCH?"search":"unknown", action==SEARCH?"search":"unknown",
opt.keyserver.scheme); opt.keyserver->scheme);
break; break;
case KEYSERVER_VERSION_ERROR: case KEYSERVER_VERSION_ERROR:
log_error(_("gpgkeys_%s does not support handler version %d\n"), log_error(_("gpgkeys_%s does not support handler version %d\n"),
opt.keyserver.scheme,KEYSERVER_PROTO_VERSION); opt.keyserver->scheme,KEYSERVER_PROTO_VERSION);
break; break;
case KEYSERVER_INTERNAL_ERROR: case KEYSERVER_INTERNAL_ERROR:
@ -1403,9 +1423,9 @@ keyserver_refresh(STRLIST users)
/* If refresh_add_fake_v3_keyids is on and it's a HKP or MAILTO /* If refresh_add_fake_v3_keyids is on and it's a HKP or MAILTO
scheme, then enable fake v3 keyid generation. */ scheme, then enable fake v3 keyid generation. */
if(opt.keyserver_options.fake_v3_keyids && opt.keyserver.scheme && if(opt.keyserver_options.fake_v3_keyids && opt.keyserver
(ascii_strcasecmp(opt.keyserver.scheme,"hkp")==0 || && (ascii_strcasecmp(opt.keyserver->scheme,"hkp")==0 ||
ascii_strcasecmp(opt.keyserver.scheme,"mailto")==0)) ascii_strcasecmp(opt.keyserver->scheme,"mailto")==0))
fakev3=1; fakev3=1;
rc=keyidlist(users,&desc,&count,fakev3); rc=keyidlist(users,&desc,&count,fakev3);
@ -1414,13 +1434,13 @@ keyserver_refresh(STRLIST users)
if(count>0) if(count>0)
{ {
if(opt.keyserver.uri) if(opt.keyserver)
{ {
if(count==1) if(count==1)
log_info(_("refreshing 1 key from %s\n"),opt.keyserver.uri); log_info(_("refreshing 1 key from %s\n"),opt.keyserver->uri);
else else
log_info(_("refreshing %d keys from %s\n"), log_info(_("refreshing %d keys from %s\n"),
count,opt.keyserver.uri); count,opt.keyserver->uri);
} }
rc=keyserver_work(GET,NULL,desc,count); rc=keyserver_work(GET,NULL,desc,count);

View File

@ -1345,7 +1345,7 @@ check_sig_and_print( CTX c, KBNODE node )
keystr(sig->keyid)); keystr(sig->keyid));
rc = do_check_sig(c, node, NULL, &is_expkey, &is_revkey ); rc = do_check_sig(c, node, NULL, &is_expkey, &is_revkey );
if( rc == G10ERR_NO_PUBKEY && opt.keyserver.scheme if( rc == G10ERR_NO_PUBKEY && opt.keyserver
&& opt.keyserver_options.auto_key_retrieve) && opt.keyserver_options.auto_key_retrieve)
{ {
if( keyserver_import_keyid ( sig->keyid )==0 ) if( keyserver_import_keyid ( sig->keyid )==0 )

View File

@ -132,7 +132,7 @@ struct
char *host; char *host;
char *port; char *port;
char *opaque; char *opaque;
} keyserver; } *keyserver;
struct struct
{ {
int verbose; int verbose;