1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-28 02:12:46 +02:00

* options.h: Encapsulate keyserver details. Change all callers.

This commit is contained in:
David Shaw 2004-04-14 17:56:23 +00:00
parent 975b83d9d0
commit 2286674b9e
6 changed files with 57 additions and 48 deletions

View File

@ -1,3 +1,7 @@
2004-04-14 David Shaw <dshaw@jabberwocky.com>
* options.h: Encapsulate keyserver details. Change all callers.
2004-03-27 David Shaw <dshaw@jabberwocky.com> 2004-03-27 David Shaw <dshaw@jabberwocky.com>
* keyedit.c (keyedit_menu): Request a trustdb update when adding a * keyedit.c (keyedit_menu): Request a trustdb update when adding a

View File

@ -2074,7 +2074,7 @@ 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.uri=m_strdup(pargs.r.ret_str);
if(parse_keyserver_uri(pargs.r.ret_str,configname,configlineno)) if(parse_keyserver_uri(pargs.r.ret_str,configname,configlineno))
log_error(_("could not parse keyserver URI\n")); log_error(_("could not parse keyserver URI\n"));
break; break;

View File

@ -1691,7 +1691,7 @@ 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.scheme &&
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:"

View File

@ -153,42 +153,42 @@ parse_keyserver_uri(char *uri,const char *configname,unsigned int configlineno)
assert(uri!=NULL); assert(uri!=NULL);
opt.keyserver_host=NULL; opt.keyserver.host=NULL;
opt.keyserver_port=NULL; opt.keyserver.port=NULL;
opt.keyserver_opaque=NULL; opt.keyserver.opaque=NULL;
/* Get the scheme */ /* Get the scheme */
opt.keyserver_scheme=strsep(&uri,":"); opt.keyserver.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=opt.keyserver.scheme;
opt.keyserver_scheme="hkp"; opt.keyserver.scheme="hkp";
} }
else else
{ {
/* Force to lowercase */ /* Force to lowercase */
char *i; char *i;
for(i=opt.keyserver_scheme;*i!='\0';i++) for(i=opt.keyserver.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(opt.keyserver.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"; opt.keyserver.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(opt.keyserver.scheme,"x-hkp")==0
|| ascii_strcasecmp(opt.keyserver_scheme,"http")==0) || ascii_strcasecmp(opt.keyserver.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"; opt.keyserver.scheme="hkp";
} }
if(assume_hkp || (uri[0]=='/' && uri[1]=='/')) if(assume_hkp || (uri[0]=='/' && uri[1]=='/'))
@ -200,21 +200,21 @@ 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,":/"); opt.keyserver.host=strsep(&uri,":/");
if(opt.keyserver_host[0]=='\0') if(opt.keyserver.host[0]=='\0')
return G10ERR_BAD_URI; return G10ERR_BAD_URI;
if(uri==NULL || uri[0]=='\0') if(uri==NULL || uri[0]=='\0')
opt.keyserver_port=NULL; opt.keyserver.port=NULL;
else else
{ {
char *ch; char *ch;
/* Get the port */ /* Get the port */
opt.keyserver_port=strsep(&uri,"/"); opt.keyserver.port=strsep(&uri,"/");
/* Ports are digits only */ /* Ports are digits only */
ch=opt.keyserver_port; ch=opt.keyserver.port;
while(*ch!='\0') while(*ch!='\0')
{ {
if(!digitp(ch)) if(!digitp(ch))
@ -236,7 +236,7 @@ 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; opt.keyserver.opaque=uri;
return 0; return 0;
} }
else else
@ -246,7 +246,7 @@ parse_keyserver_uri(char *uri,const char *configname,unsigned int configlineno)
return G10ERR_BAD_URI; return G10ERR_BAD_URI;
} }
if(opt.keyserver_scheme[0]=='\0') if(opt.keyserver.scheme[0]=='\0')
return G10ERR_BAD_URI; return G10ERR_BAD_URI;
return 0; return 0;
@ -718,9 +718,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 +748,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 +1112,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.scheme==NULL)
{ {
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 +1133,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 +1141,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 +1403,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.scheme &&
(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 +1414,13 @@ keyserver_refresh(STRLIST users)
if(count>0) if(count>0)
{ {
if(opt.keyserver_uri) if(opt.keyserver.uri)
{ {
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,10 +1345,12 @@ 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 && opt.keyserver_options.auto_key_retrieve) { if( rc == G10ERR_NO_PUBKEY && opt.keyserver.scheme
&& opt.keyserver_options.auto_key_retrieve)
{
if( keyserver_import_keyid ( sig->keyid )==0 ) if( keyserver_import_keyid ( sig->keyid )==0 )
rc = do_check_sig(c, node, NULL, &is_expkey, &is_revkey ); rc = do_check_sig(c, node, NULL, &is_expkey, &is_revkey );
} }
/* If the key still isn't found, try to inform the user where it /* If the key still isn't found, try to inform the user where it
can be found. */ can be found. */

View File

@ -125,11 +125,14 @@ struct
int not_dash_escaped; int not_dash_escaped;
int escape_from; int escape_from;
int lock_once; int lock_once;
char *keyserver_uri; struct keyserver_spec
char *keyserver_scheme; {
char *keyserver_host; char *uri;
char *keyserver_port; char *scheme;
char *keyserver_opaque; char *host;
char *port;
char *opaque;
} keyserver;
struct struct
{ {
int verbose; int verbose;