mirror of
git://git.gnupg.org/gnupg.git
synced 2025-05-19 09:02:22 +02:00
* 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.
This commit is contained in:
parent
a21fedf555
commit
aec65a94d8
@ -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>
|
2005-08-18 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
* ksutil.h, ksutil.c (parse_ks_options): New keyserver-option
|
* ksutil.h, ksutil.c (parse_ks_options): New keyserver-option
|
||||||
|
@ -283,54 +283,22 @@ get_key(char *getkey)
|
|||||||
return KEYSERVER_OK;
|
return KEYSERVER_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
search_key(char *searchkey)
|
search_key(const char *searchkey)
|
||||||
{
|
{
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
char *request=NULL;
|
char *request=NULL;
|
||||||
char *searchkey_encoded=NULL;
|
char *searchkey_encoded=NULL;
|
||||||
int ret=KEYSERVER_INTERNAL_ERROR;
|
int ret=KEYSERVER_INTERNAL_ERROR;
|
||||||
|
enum ks_search_type search_type;
|
||||||
|
|
||||||
if(opt->flags.exact_name)
|
search_type=classify_ks_search(&searchkey);
|
||||||
{
|
|
||||||
char *bracketed;
|
|
||||||
|
|
||||||
bracketed=malloc(strlen(searchkey)+2+1);
|
if(opt->debug)
|
||||||
if(!bracketed)
|
fprintf(console,"gpgkeys: search type is %d, and key is \"%s\"\n",
|
||||||
{
|
search_type,searchkey);
|
||||||
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);
|
searchkey_encoded=curl_escape(searchkey,0);
|
||||||
|
|
||||||
if(!searchkey_encoded)
|
if(!searchkey_encoded)
|
||||||
{
|
{
|
||||||
fprintf(console,"gpgkeys: out of memory\n");
|
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=");
|
append_path(request,"/pks/lookup?op=index&options=mr&search=");
|
||||||
strcat(request,searchkey_encoded);
|
strcat(request,searchkey_encoded);
|
||||||
|
|
||||||
if(opt->flags.exact_name || opt->flags.exact_email)
|
if(search_type!=KS_SEARCH_SUBSTR)
|
||||||
strcat(request,"&exact=on");
|
strcat(request,"&exact=on");
|
||||||
|
|
||||||
if(opt->verbose>2)
|
if(opt->verbose>2)
|
||||||
|
@ -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
|
/* Returns 0 on success and -1 on error. Note that key-not-found is
|
||||||
not an error! */
|
not an error! */
|
||||||
static int
|
static int
|
||||||
search_key(char *searchkey)
|
search_key(const char *searchkey)
|
||||||
{
|
{
|
||||||
char **vals;
|
char **vals;
|
||||||
LDAPMessage *res,*each;
|
LDAPMessage *res,*each;
|
||||||
@ -1176,13 +1176,20 @@ search_key(char *searchkey)
|
|||||||
/* The maximum size of the search, including the optional stuff and
|
/* The maximum size of the search, including the optional stuff and
|
||||||
the trailing \0 */
|
the trailing \0 */
|
||||||
char *expanded_search;
|
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",
|
char *attrs[]={"pgpcertid","pgpuserid","pgprevoked","pgpdisabled",
|
||||||
"pgpkeycreatetime","pgpkeyexpiretime","modifytimestamp",
|
"pgpkeycreatetime","pgpkeyexpiretime","modifytimestamp",
|
||||||
"pgpkeysize","pgpkeytype",NULL};
|
"pgpkeysize","pgpkeytype",NULL};
|
||||||
|
enum ks_search_type search_type;
|
||||||
|
|
||||||
fprintf(output,"SEARCH %s BEGIN\n",searchkey);
|
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);
|
expanded_search=malloc(ldap_quote(NULL,searchkey)+1);
|
||||||
if(!expanded_search)
|
if(!expanded_search)
|
||||||
{
|
{
|
||||||
@ -1195,13 +1202,14 @@ search_key(char *searchkey)
|
|||||||
|
|
||||||
/* Build the search string */
|
/* 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.include_disabled&&opt->flags.include_revoked))?"(&":"",
|
||||||
opt->flags.exact_name?"":"*",
|
(search_type==KS_SEARCH_EXACT)?"":
|
||||||
opt->flags.exact_email?"<":"",
|
(search_type==KS_SEARCH_MAILSUB)?"*<*":"*",
|
||||||
expanded_search,
|
expanded_search,
|
||||||
opt->flags.exact_email?">":"",
|
(search_type==KS_SEARCH_EXACT
|
||||||
opt->flags.exact_name?" <":"",
|
|| search_type==KS_SEARCH_MAIL)?"":
|
||||||
|
(search_type==KS_SEARCH_MAILSUB)?"*>":"*",
|
||||||
opt->flags.include_disabled?"":"(pgpdisabled=0)",
|
opt->flags.include_disabled?"":"(pgpdisabled=0)",
|
||||||
opt->flags.include_revoked?"":"(pgprevoked=0)",
|
opt->flags.include_revoked?"":"(pgprevoked=0)",
|
||||||
!(opt->flags.include_disabled&&opt->flags.include_revoked)?")":"");
|
!(opt->flags.include_disabled&&opt->flags.include_revoked)?")":"");
|
||||||
|
@ -298,27 +298,6 @@ parse_ks_options(char *line,struct ks_options *opt)
|
|||||||
return KEYSERVER_NO_MEMORY;
|
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;
|
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)
|
#if defined (HAVE_LIBCURL) || defined (FAKE_CURL)
|
||||||
int
|
int
|
||||||
curl_err_to_gpg_err(CURLcode error)
|
curl_err_to_gpg_err(CURLcode error)
|
||||||
|
@ -74,6 +74,9 @@ int register_timeout(void);
|
|||||||
|
|
||||||
enum ks_action {KS_UNKNOWN=0,KS_GET,KS_SEND,KS_SEARCH};
|
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
|
struct ks_options
|
||||||
{
|
{
|
||||||
enum ks_action action;
|
enum ks_action action;
|
||||||
@ -89,8 +92,6 @@ struct ks_options
|
|||||||
unsigned int include_revoked:1;
|
unsigned int include_revoked:1;
|
||||||
unsigned int include_subkeys:1;
|
unsigned int include_subkeys:1;
|
||||||
unsigned int check_cert:1;
|
unsigned int check_cert:1;
|
||||||
unsigned int exact_name:1;
|
|
||||||
unsigned int exact_email:1;
|
|
||||||
} flags;
|
} flags;
|
||||||
unsigned int verbose;
|
unsigned int verbose;
|
||||||
unsigned int debug;
|
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);
|
int parse_ks_options(char *line,struct ks_options *opt);
|
||||||
const char *ks_action_to_string(enum ks_action action);
|
const char *ks_action_to_string(enum ks_action action);
|
||||||
void print_nocr(FILE *stream,const char *str);
|
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)
|
#if defined (HAVE_LIBCURL) || defined (FAKE_CURL)
|
||||||
int curl_err_to_gpg_err(CURLcode error);
|
int curl_err_to_gpg_err(CURLcode error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user