[svn] GnuPG - r3874 - trunk/keyserver
svn author dshaw
cvs at cvs.gnupg.org
Fri Aug 26 06:24:47 CEST 2005
Author: dshaw
Date: 2005-08-26 06:24:46 +0200 (Fri, 26 Aug 2005)
New Revision: 3874
Modified:
trunk/keyserver/ChangeLog
trunk/keyserver/gpgkeys_hkp.c
trunk/keyserver/gpgkeys_ldap.c
trunk/keyserver/ksutil.c
trunk/keyserver/ksutil.h
Log:
* 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.
Modified: trunk/keyserver/ChangeLog
===================================================================
--- trunk/keyserver/ChangeLog 2005-08-23 04:42:25 UTC (rev 3873)
+++ trunk/keyserver/ChangeLog 2005-08-26 04:24:46 UTC (rev 3874)
@@ -1,3 +1,13 @@
+2005-08-25 David Shaw <dshaw at 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 at jabberwocky.com>
* ksutil.h, ksutil.c (parse_ks_options): New keyserver-option
Modified: trunk/keyserver/gpgkeys_hkp.c
===================================================================
--- trunk/keyserver/gpgkeys_hkp.c 2005-08-23 04:42:25 UTC (rev 3873)
+++ trunk/keyserver/gpgkeys_hkp.c 2005-08-26 04:24:46 UTC (rev 3874)
@@ -283,54 +283,22 @@
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;
- }
+ if(opt->debug)
+ fprintf(console,"gpgkeys: search type is %d, and key is \"%s\"\n",
+ search_type,searchkey);
- 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);
-
+ searchkey_encoded=curl_escape(searchkey,0);
if(!searchkey_encoded)
{
fprintf(console,"gpgkeys: out of memory\n");
@@ -359,7 +327,7 @@
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)
Modified: trunk/keyserver/gpgkeys_ldap.c
===================================================================
--- trunk/keyserver/gpgkeys_ldap.c 2005-08-23 04:42:25 UTC (rev 3873)
+++ trunk/keyserver/gpgkeys_ldap.c 2005-08-26 04:24:46 UTC (rev 3874)
@@ -1167,7 +1167,7 @@
/* 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 @@
/* 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 @@
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)?")":"");
Modified: trunk/keyserver/ksutil.c
===================================================================
--- trunk/keyserver/ksutil.c 2005-08-23 04:42:25 UTC (rev 3873)
+++ trunk/keyserver/ksutil.c 2005-08-26 04:24:46 UTC (rev 3874)
@@ -298,27 +298,6 @@
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 @@
}
}
+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)
Modified: trunk/keyserver/ksutil.h
===================================================================
--- trunk/keyserver/ksutil.h 2005-08-23 04:42:25 UTC (rev 3873)
+++ trunk/keyserver/ksutil.h 2005-08-26 04:24:46 UTC (rev 3874)
@@ -74,6 +74,9 @@
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 @@
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 @@
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);
More information about the Gnupg-commits
mailing list