diff --git a/keyserver/ChangeLog b/keyserver/ChangeLog index ad33db0eb..462d3b666 100644 --- a/keyserver/ChangeLog +++ b/keyserver/ChangeLog @@ -1,3 +1,13 @@ +2005-08-25 David Shaw <dshaw@jabberwocky.com> + + * ksutil.h, ksutil.c (parse_ks_options): Remove exact-name and + exact-email. + (classify_ks_search): Mimic the gpg search modes instead with *, + =, <, and @. + + * gpgkeys_ldap.c (search_key), gpgkeys_hkp.c (search_key): Call + them here. Suggested by Jason Harris. + 2005-08-18 David Shaw <dshaw@jabberwocky.com> * ksutil.h, ksutil.c (parse_ks_options): New keyserver-option diff --git a/keyserver/gpgkeys_hkp.c b/keyserver/gpgkeys_hkp.c index a0ea31081..dc05a619e 100644 --- a/keyserver/gpgkeys_hkp.c +++ b/keyserver/gpgkeys_hkp.c @@ -283,54 +283,22 @@ get_key(char *getkey) return KEYSERVER_OK; } -int -search_key(char *searchkey) +static int +search_key(const char *searchkey) { CURLcode res; char *request=NULL; char *searchkey_encoded=NULL; int ret=KEYSERVER_INTERNAL_ERROR; + enum ks_search_type search_type; - if(opt->flags.exact_name) - { - char *bracketed; + search_type=classify_ks_search(&searchkey); - bracketed=malloc(strlen(searchkey)+2+1); - if(!bracketed) - { - fprintf(console,"gpgkeys: out of memory\n"); - ret=KEYSERVER_NO_MEMORY; - goto fail; - } - - strcpy(bracketed,searchkey); - strcat(bracketed," <"); - - searchkey_encoded=curl_escape(bracketed,0); - free(bracketed); - } - else if(opt->flags.exact_email) - { - char *bracketed; - - bracketed=malloc(1+strlen(searchkey)+1+1); - if(!bracketed) - { - fprintf(console,"gpgkeys: out of memory\n"); - ret=KEYSERVER_NO_MEMORY; - goto fail; - } - - strcpy(bracketed,"<"); - strcat(bracketed,searchkey); - strcat(bracketed,">"); - - searchkey_encoded=curl_escape(bracketed,0); - free(bracketed); - } - else - searchkey_encoded=curl_escape(searchkey,0); + if(opt->debug) + fprintf(console,"gpgkeys: search type is %d, and key is \"%s\"\n", + search_type,searchkey); + searchkey_encoded=curl_escape(searchkey,0); if(!searchkey_encoded) { fprintf(console,"gpgkeys: out of memory\n"); @@ -359,7 +327,7 @@ search_key(char *searchkey) append_path(request,"/pks/lookup?op=index&options=mr&search="); strcat(request,searchkey_encoded); - if(opt->flags.exact_name || opt->flags.exact_email) + if(search_type!=KS_SEARCH_SUBSTR) strcat(request,"&exact=on"); if(opt->verbose>2) diff --git a/keyserver/gpgkeys_ldap.c b/keyserver/gpgkeys_ldap.c index a64d460c8..a483e2760 100644 --- a/keyserver/gpgkeys_ldap.c +++ b/keyserver/gpgkeys_ldap.c @@ -1167,7 +1167,7 @@ ldap_quote(char *buffer,const char *string) /* Returns 0 on success and -1 on error. Note that key-not-found is not an error! */ static int -search_key(char *searchkey) +search_key(const char *searchkey) { char **vals; LDAPMessage *res,*each; @@ -1176,13 +1176,20 @@ search_key(char *searchkey) /* The maximum size of the search, including the optional stuff and the trailing \0 */ char *expanded_search; - char search[2+12+1+1+MAX_LINE+1+2+2+15+14+1+1]; + char search[2+11+3+MAX_LINE+2+15+14+1+1+20]; char *attrs[]={"pgpcertid","pgpuserid","pgprevoked","pgpdisabled", "pgpkeycreatetime","pgpkeyexpiretime","modifytimestamp", "pgpkeysize","pgpkeytype",NULL}; + enum ks_search_type search_type; fprintf(output,"SEARCH %s BEGIN\n",searchkey); + search_type=classify_ks_search(&searchkey); + + if(opt->debug) + fprintf(console,"search type is %d, and key is \"%s\"\n", + search_type,searchkey); + expanded_search=malloc(ldap_quote(NULL,searchkey)+1); if(!expanded_search) { @@ -1190,18 +1197,19 @@ search_key(char *searchkey) fprintf(console,"Out of memory when quoting LDAP search string\n"); return KEYSERVER_NO_MEMORY; } - + ldap_quote(expanded_search,searchkey); /* Build the search string */ - sprintf(search,"%s(pgpuserid=%s%s%s%s%s*)%s%s%s", + sprintf(search,"%s(pgpuserid=%s%s%s)%s%s%s", (!(opt->flags.include_disabled&&opt->flags.include_revoked))?"(&":"", - opt->flags.exact_name?"":"*", - opt->flags.exact_email?"<":"", + (search_type==KS_SEARCH_EXACT)?"": + (search_type==KS_SEARCH_MAILSUB)?"*<*":"*", expanded_search, - opt->flags.exact_email?">":"", - opt->flags.exact_name?" <":"", + (search_type==KS_SEARCH_EXACT + || search_type==KS_SEARCH_MAIL)?"": + (search_type==KS_SEARCH_MAILSUB)?"*>":"*", opt->flags.include_disabled?"":"(pgpdisabled=0)", opt->flags.include_revoked?"":"(pgprevoked=0)", !(opt->flags.include_disabled&&opt->flags.include_revoked)?")":""); diff --git a/keyserver/ksutil.c b/keyserver/ksutil.c index 287f50224..595637756 100644 --- a/keyserver/ksutil.c +++ b/keyserver/ksutil.c @@ -298,27 +298,6 @@ parse_ks_options(char *line,struct ks_options *opt) return KEYSERVER_NO_MEMORY; } } - else if(strcasecmp(start,"exact-email")==0 - || strcasecmp(start,"exact-mail")==0) - { - if(no) - opt->flags.exact_email=0; - else - { - opt->flags.exact_email=1; - opt->flags.exact_name=0; - } - } - else if(strcasecmp(start,"exact-name")==0) - { - if(no) - opt->flags.exact_name=0; - else - { - opt->flags.exact_name=1; - opt->flags.exact_email=0; - } - } } return -1; @@ -356,6 +335,27 @@ print_nocr(FILE *stream,const char *str) } } +enum ks_search_type +classify_ks_search(const char **search) +{ + switch(**search) + { + default: + return KS_SEARCH_SUBSTR; + case '*': + (*search)++; + return KS_SEARCH_SUBSTR; + case '=': + (*search)++; + return KS_SEARCH_EXACT; + case '<': + return KS_SEARCH_MAIL; + case '@': + (*search)++; + return KS_SEARCH_MAILSUB; + } +} + #if defined (HAVE_LIBCURL) || defined (FAKE_CURL) int curl_err_to_gpg_err(CURLcode error) diff --git a/keyserver/ksutil.h b/keyserver/ksutil.h index e9d875f06..8e00e7902 100644 --- a/keyserver/ksutil.h +++ b/keyserver/ksutil.h @@ -74,6 +74,9 @@ int register_timeout(void); enum ks_action {KS_UNKNOWN=0,KS_GET,KS_SEND,KS_SEARCH}; +enum ks_search_type {KS_SEARCH_SUBSTR,KS_SEARCH_EXACT, + KS_SEARCH_MAIL,KS_SEARCH_MAILSUB}; + struct ks_options { enum ks_action action; @@ -89,8 +92,6 @@ struct ks_options unsigned int include_revoked:1; unsigned int include_subkeys:1; unsigned int check_cert:1; - unsigned int exact_name:1; - unsigned int exact_email:1; } flags; unsigned int verbose; unsigned int debug; @@ -103,6 +104,7 @@ void free_ks_options(struct ks_options *opt); int parse_ks_options(char *line,struct ks_options *opt); const char *ks_action_to_string(enum ks_action action); void print_nocr(FILE *stream,const char *str); +enum ks_search_type classify_ks_search(const char **search); #if defined (HAVE_LIBCURL) || defined (FAKE_CURL) int curl_err_to_gpg_err(CURLcode error);