* ksutil.h, ksutil.c (classify_ks_search): Add KS_SEARCH_KEYID_SHORT

and KS_SEARCH_KEYID_LONG to search for a key ID.

* gpgkeys_ldap.c (search_key): Use it here to flip from pgpUserID
searches to pgpKeyID or pgpCertID.
This commit is contained in:
David Shaw 2006-04-11 03:00:50 +00:00
parent 1bf02666fb
commit 3011a39284
4 changed files with 108 additions and 15 deletions

View File

@ -1,3 +1,12 @@
2006-04-10 David Shaw <dshaw@jabberwocky.com>
* ksutil.h, ksutil.c (classify_ks_search): Add
KS_SEARCH_KEYID_SHORT and KS_SEARCH_KEYID_LONG to search for a key
ID.
* gpgkeys_ldap.c (search_key): Use it here to flip from pgpUserID
searches to pgpKeyID or pgpCertID.
2006-03-27 David Shaw <dshaw@jabberwocky.com>
* gpgkeys_ldap.c: #define LDAP_DEPRECATED for newer OpenLDAPs so

View File

@ -1291,7 +1291,7 @@ search_key(const char *searchkey)
char *expanded_search;
/* The maximum size of the search, including the optional stuff and
the trailing \0 */
char search[2+11+3+MAX_LINE+2+15+14+1+1+20];
char search[2+1+9+1+3+(MAX_LINE*3)+3+1+15+1+1];
char *attrs[]={"pgpcertid","pgpuserid","pgprevoked","pgpdisabled",
"pgpkeycreatetime","pgpkeyexpiretime","modifytimestamp",
"pgpkeysize","pgpkeytype",NULL};
@ -1317,17 +1317,82 @@ search_key(const char *searchkey)
/* Build the search string */
sprintf(search,"%s(pgpuserid=%s%s%s)%s%s%s",
(!(opt->flags.include_disabled&&opt->flags.include_revoked))?"(&":"",
(search_type==KS_SEARCH_EXACT)?"":
(search_type==KS_SEARCH_MAILSUB)?"*<*":"*",
expanded_search,
(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)?")":"");
search[0]='\0';
if(!opt->flags.include_disabled || !opt->flags.include_revoked)
strcat(search,"(&");
strcat(search,"(");
switch(search_type)
{
case KS_SEARCH_KEYID_SHORT:
strcat(search,"pgpKeyID");
break;
case KS_SEARCH_KEYID_LONG:
strcat(search,"pgpCertID");
break;
default:
strcat(search,"pgpUserID");
break;
}
strcat(search,"=");
switch(search_type)
{
case KS_SEARCH_SUBSTR:
strcat(search,"*");
break;
case KS_SEARCH_MAIL:
strcat(search,"*<");
break;
case KS_SEARCH_MAILSUB:
strcat(search,"*<*");
break;
case KS_SEARCH_EXACT:
case KS_SEARCH_KEYID_LONG:
case KS_SEARCH_KEYID_SHORT:
break;
}
strcat(search,expanded_search);
switch(search_type)
{
case KS_SEARCH_SUBSTR:
strcat(search,"*");
break;
case KS_SEARCH_MAIL:
strcat(search,">*");
break;
case KS_SEARCH_MAILSUB:
strcat(search,"*>*");
break;
case KS_SEARCH_EXACT:
case KS_SEARCH_KEYID_LONG:
case KS_SEARCH_KEYID_SHORT:
break;
}
strcat(search,")");
if(!opt->flags.include_disabled)
strcat(search,"(pgpDisabled=0)");
if(!opt->flags.include_revoked)
strcat(search,"(pgpRevoked=0)");
if(!opt->flags.include_disabled || !opt->flags.include_revoked)
strcat(search,")");
free(expanded_search);

View File

@ -346,8 +346,6 @@ classify_ks_search(const char **search)
{
switch(**search)
{
default:
return KS_SEARCH_SUBSTR;
case '*':
(*search)++;
return KS_SEARCH_SUBSTR;
@ -355,10 +353,30 @@ classify_ks_search(const char **search)
(*search)++;
return KS_SEARCH_EXACT;
case '<':
(*search)++;
return KS_SEARCH_MAIL;
case '@':
(*search)++;
return KS_SEARCH_MAILSUB;
case '0':
if((*search)[1]=='x')
{
if(strlen(*search)==10
&& strspn(*search,"abcdefABCDEF1234567890x")==10)
{
(*search)+=2;
return KS_SEARCH_KEYID_SHORT;
}
else if(strlen(*search)==18
&& strspn(*search,"abcdefABCDEF1234567890x")==18)
{
(*search)+=2;
return KS_SEARCH_KEYID_LONG;
}
}
/* fall through */
default:
return KS_SEARCH_SUBSTR;
}
}

View File

@ -75,7 +75,8 @@ int register_timeout(void);
enum ks_action {KS_UNKNOWN=0,KS_GET,KS_GETNAME,KS_SEND,KS_SEARCH};
enum ks_search_type {KS_SEARCH_SUBSTR,KS_SEARCH_EXACT,
KS_SEARCH_MAIL,KS_SEARCH_MAILSUB};
KS_SEARCH_MAIL,KS_SEARCH_MAILSUB,
KS_SEARCH_KEYID_LONG,KS_SEARCH_KEYID_SHORT};
struct ks_options
{