diff options
author | David Shaw <[email protected]> | 2004-04-14 21:33:45 +0000 |
---|---|---|
committer | David Shaw <[email protected]> | 2004-04-14 21:33:45 +0000 |
commit | a9b00b06d1161cff6f9278f35e913b2db25538c0 (patch) | |
tree | 1bbd69cb819df80a17d0bcf8c551cb31838db306 | |
parent | * options.h: Encapsulate keyserver details. Change all callers. (diff) | |
download | gnupg-a9b00b06d1161cff6f9278f35e913b2db25538c0.tar.gz gnupg-a9b00b06d1161cff6f9278f35e913b2db25538c0.zip |
* 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.
-rw-r--r-- | g10/ChangeLog | 5 | ||||
-rw-r--r-- | g10/g10.c | 5 | ||||
-rw-r--r-- | g10/import.c | 4 | ||||
-rw-r--r-- | g10/keyserver-internal.h | 5 | ||||
-rw-r--r-- | g10/keyserver.c | 110 | ||||
-rw-r--r-- | g10/mainproc.c | 2 | ||||
-rw-r--r-- | g10/options.h | 2 |
7 files changed, 80 insertions, 53 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog index 032fdbcc2..e6a0ab2df 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,5 +1,10 @@ 2004-04-14 David Shaw <[email protected]> + * 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. 2004-03-27 David Shaw <[email protected]> @@ -2074,8 +2074,9 @@ main( int argc, char **argv ) #endif /* __riscos__ */ break; case oKeyServer: - opt.keyserver.uri=m_strdup(pargs.r.ret_str); - if(parse_keyserver_uri(pargs.r.ret_str,configname,configlineno)) + opt.keyserver=parse_keyserver_uri(pargs.r.ret_str, + configname,configlineno); + if(!opt.keyserver) log_error(_("could not parse keyserver URI\n")); break; case oKeyServerOptions: diff --git a/g10/import.c b/g10/import.c index 89e95dda7..bbe590afa 100644 --- a/g10/import.c +++ b/g10/import.c @@ -1691,8 +1691,8 @@ revocation_present(KBNODE keyblock) char *tempkeystr=m_strdup(keystr_from_pk(pk)); /* No, so try and get it */ - if(opt.keyserver.scheme && - opt.keyserver_options.auto_key_retrieve) + if(opt.keyserver + && opt.keyserver_options.auto_key_retrieve) { log_info(_("WARNING: key %s may be revoked:" " fetching revocation key %s\n"), diff --git a/g10/keyserver-internal.h b/g10/keyserver-internal.h index c341578fa..b1f22be32 100644 --- a/g10/keyserver-internal.h +++ b/g10/keyserver-internal.h @@ -9,8 +9,9 @@ #include "types.h" void parse_keyserver_options(char *options); -int parse_keyserver_uri(char *uri, - const char *configname,unsigned int configlineno); +struct keyserver_spec *parse_keyserver_uri(char *uri, + const char *configname, + unsigned int configlineno); int keyserver_export(STRLIST users); int keyserver_import(STRLIST users); int keyserver_import_fprint(const byte *fprint,size_t fprint_len); diff --git a/g10/keyserver.c b/g10/keyserver.c index 6a58b918a..ae513e4e6 100644 --- a/g10/keyserver.c +++ b/g10/keyserver.c @@ -146,53 +146,62 @@ parse_keyserver_options(char *options) } } -int +struct keyserver_spec * parse_keyserver_uri(char *uri,const char *configname,unsigned int configlineno) { int assume_hkp=0; + struct keyserver_spec *keyserver; + char *scheme; assert(uri!=NULL); - opt.keyserver.host=NULL; - opt.keyserver.port=NULL; - opt.keyserver.opaque=NULL; + keyserver=m_alloc_clear(sizeof(struct keyserver_spec)); + + keyserver->uri=m_strdup(uri); /* Get the scheme */ - opt.keyserver.scheme=strsep(&uri,":"); + scheme=strsep(&uri,":"); if(uri==NULL) { /* Assume HKP if there is no scheme */ assume_hkp=1; - uri=opt.keyserver.scheme; - opt.keyserver.scheme="hkp"; + uri=scheme; + scheme="hkp"; } else { /* Force to lowercase */ char *i; - for(i=opt.keyserver.scheme;*i!='\0';i++) + for(i=scheme;*i!='\0';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", "--keyserver-options ","broken-http-proxy"); - opt.keyserver.scheme="hkp"; + scheme="hkp"; add_to_strlist(&opt.keyserver_options.other,"broken-http-proxy"); } - else if(ascii_strcasecmp(opt.keyserver.scheme,"x-hkp")==0 - || ascii_strcasecmp(opt.keyserver.scheme,"http")==0) + else if(ascii_strcasecmp(scheme,"x-hkp")==0 + || ascii_strcasecmp(scheme,"http")==0) { /* Canonicalize this to "hkp" so it works with both the internal 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]=='/')) { + char *host,*port; + /* Two slashes means network path. */ /* Skip over the "//", if any */ @@ -200,25 +209,27 @@ parse_keyserver_uri(char *uri,const char *configname,unsigned int configlineno) uri+=2; /* Get the host */ - opt.keyserver.host=strsep(&uri,":/"); - if(opt.keyserver.host[0]=='\0') - return G10ERR_BAD_URI; + host=strsep(&uri,":/"); + if(host[0]=='\0') + goto fail; + + keyserver->host=m_strdup(host); if(uri==NULL || uri[0]=='\0') - opt.keyserver.port=NULL; + port=NULL; else { char *ch; /* Get the port */ - opt.keyserver.port=strsep(&uri,"/"); + port=strsep(&uri,"/"); /* Ports are digits only */ - ch=opt.keyserver.port; + ch=port; while(*ch!='\0') { if(!digitp(ch)) - return G10ERR_BAD_URI; + goto fail; 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 imply there is no limit. Of course, the real world has limits. */ + + keyserver->port=m_strdup(port); } /* (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 out. */ - opt.keyserver.opaque=uri; - return 0; + keyserver->opaque=m_strdup(uri); } else { /* One slash means absolute path. We don't need to support that yet. */ - return G10ERR_BAD_URI; + goto fail; } - if(opt.keyserver.scheme[0]=='\0') - return G10ERR_BAD_URI; + return keyserver; - 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 @@ -705,6 +723,8 @@ keyserver_spawn(int action,STRLIST list, struct kopts *kopts; struct exec_info *spawn; + assert(opt.keyserver); + #ifdef EXEC_TEMPFILE_ONLY opt.keyserver_options.use_temp_files=1; #endif @@ -718,9 +738,9 @@ keyserver_spawn(int action,STRLIST list, #endif /* 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_"); - strcat(command,opt.keyserver.scheme); + strcat(command,opt.keyserver->scheme); 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,"VERSION %d\n",KEYSERVER_PROTO_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) - fprintf(spawn->tochild,"OPAQUE %s\n",opt.keyserver.opaque); + if(opt.keyserver->opaque) + fprintf(spawn->tochild,"OPAQUE %s\n",opt.keyserver->opaque); else { - if(opt.keyserver.host) - fprintf(spawn->tochild,"HOST %s\n",opt.keyserver.host); + if(opt.keyserver->host) + fprintf(spawn->tochild,"HOST %s\n",opt.keyserver->host); - if(opt.keyserver.port) - fprintf(spawn->tochild,"PORT %s\n",opt.keyserver.port); + if(opt.keyserver->port) + fprintf(spawn->tochild,"PORT %s\n",opt.keyserver->port); } /* Write options */ @@ -1112,7 +1132,7 @@ keyserver_work(int action,STRLIST list,KEYDB_SEARCH_DESC *desc,int count) { int rc=0,ret=0; - if(opt.keyserver.scheme==NULL) + if(!opt.keyserver) { log_error(_("no keyserver known (use option --keyserver)\n")); 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: log_error(_("no handler for keyserver scheme \"%s\"\n"), - opt.keyserver.scheme); + opt.keyserver->scheme); break; case KEYSERVER_NOT_SUPPORTED: @@ -1141,12 +1161,12 @@ keyserver_work(int action,STRLIST list,KEYDB_SEARCH_DESC *desc,int count) "scheme \"%s\"\n"), action==GET?"get":action==SEND?"send": action==SEARCH?"search":"unknown", - opt.keyserver.scheme); + opt.keyserver->scheme); break; case KEYSERVER_VERSION_ERROR: log_error(_("gpgkeys_%s does not support handler version %d\n"), - opt.keyserver.scheme,KEYSERVER_PROTO_VERSION); + opt.keyserver->scheme,KEYSERVER_PROTO_VERSION); break; 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 scheme, then enable fake v3 keyid generation. */ - if(opt.keyserver_options.fake_v3_keyids && opt.keyserver.scheme && - (ascii_strcasecmp(opt.keyserver.scheme,"hkp")==0 || - ascii_strcasecmp(opt.keyserver.scheme,"mailto")==0)) + if(opt.keyserver_options.fake_v3_keyids && opt.keyserver + && (ascii_strcasecmp(opt.keyserver->scheme,"hkp")==0 || + ascii_strcasecmp(opt.keyserver->scheme,"mailto")==0)) fakev3=1; rc=keyidlist(users,&desc,&count,fakev3); @@ -1414,13 +1434,13 @@ keyserver_refresh(STRLIST users) if(count>0) { - if(opt.keyserver.uri) + if(opt.keyserver) { 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 log_info(_("refreshing %d keys from %s\n"), - count,opt.keyserver.uri); + count,opt.keyserver->uri); } rc=keyserver_work(GET,NULL,desc,count); diff --git a/g10/mainproc.c b/g10/mainproc.c index c6a44f196..0d2066a0f 100644 --- a/g10/mainproc.c +++ b/g10/mainproc.c @@ -1345,7 +1345,7 @@ check_sig_and_print( CTX c, KBNODE node ) keystr(sig->keyid)); 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) { if( keyserver_import_keyid ( sig->keyid )==0 ) diff --git a/g10/options.h b/g10/options.h index 7a405233b..06fd6ba89 100644 --- a/g10/options.h +++ b/g10/options.h @@ -132,7 +132,7 @@ struct char *host; char *port; char *opaque; - } keyserver; + } *keyserver; struct { int verbose; |