1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-02-07 17:33:02 +01:00

* keydb.h, getkey.c (release_akl), gpg.c (main): Add

--no-auto-key-locate.

* options.h, gpg.c (main): Keep track of each keyserver registered so
we can match on them later.

* keyserver-internal.h, keyserver.c (cmp_keyserver_spec,
keyserver_match), gpgv.c: New.  Find a keyserver that matches ours and
return its spec.

* getkey.c (get_pubkey_byname): Use it here to get the per-keyserver
options from an earlier keyserver.
This commit is contained in:
David Shaw 2006-02-24 14:27:22 +00:00
parent 4139587267
commit f4f5ea43e7
8 changed files with 114 additions and 27 deletions

View File

@ -1,3 +1,18 @@
2006-02-24 David Shaw <dshaw@jabberwocky.com>
* keydb.h, getkey.c (release_akl), gpg.c (main): Add
--no-auto-key-locate.
* options.h, gpg.c (main): Keep track of each keyserver registered
so we can match on them later.
* keyserver-internal.h, keyserver.c (cmp_keyserver_spec,
keyserver_match), gpgv.c: New. Find a keyserver that matches ours
and return its spec.
* getkey.c (get_pubkey_byname): Use it here to get the
per-keyserver options from an earlier keyserver.
2006-02-23 David Shaw <dshaw@jabberwocky.com> 2006-02-23 David Shaw <dshaw@jabberwocky.com>
* keyserver.c (parse_keyserver_options): Only change max_cert if * keyserver.c (parse_keyserver_options): Only change max_cert if

View File

@ -1,6 +1,6 @@
/* getkey.c - Get a key from the database /* getkey.c - Get a key from the database
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
* 2005 Free Software Foundation, Inc. * 2006 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -989,13 +989,18 @@ get_pubkey_byname (PKT_public_key *pk,
break; break;
case AKL_SPEC: case AKL_SPEC:
glo_ctrl.in_auto_key_retrieve++; {
res=keyserver_import_name(name,akl->spec); struct keyserver_spec *keyserver;
glo_ctrl.in_auto_key_retrieve--;
if(res==0) keyserver=keyserver_match(akl->spec);
log_info(_("Automatically retrieved `%s' via %s\n"), glo_ctrl.in_auto_key_retrieve++;
name,akl->spec->uri); res=keyserver_import_name(name,keyserver);
glo_ctrl.in_auto_key_retrieve--;
if(res==0)
log_info(_("Automatically retrieved `%s' via %s\n"),
name,akl->spec->uri);
}
break; break;
} }
@ -2898,6 +2903,17 @@ free_akl(struct akl *akl)
xfree(akl); xfree(akl);
} }
void
release_akl(void)
{
while(opt.auto_key_locate)
{
struct akl *akl2=opt.auto_key_locate;
opt.auto_key_locate=opt.auto_key_locate->next;
free_akl(akl2);
}
}
int int
parse_auto_key_locate(char *options) parse_auto_key_locate(char *options)
{ {

View File

@ -1,6 +1,6 @@
/* gpg.c - The GnuPG utility (main for gpg) /* gpg.c - The GnuPG utility (main for gpg)
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
* 2005 Free Software Foundation, Inc. * 2006 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -361,6 +361,7 @@ enum cmd_and_opt_values
oRequireBacksigs, oRequireBacksigs,
oNoRequireBacksigs, oNoRequireBacksigs,
oAutoKeyLocate, oAutoKeyLocate,
oNoAutoKeyLocate,
oNoop oNoop
}; };
@ -698,15 +699,16 @@ static ARGPARSE_OPTS opts[] = {
#if defined(ENABLE_CARD_SUPPORT) && defined(HAVE_LIBUSB) #if defined(ENABLE_CARD_SUPPORT) && defined(HAVE_LIBUSB)
{ oDebugCCIDDriver, "debug-ccid-driver", 0, "@"}, { oDebugCCIDDriver, "debug-ccid-driver", 0, "@"},
#endif #endif
/* These are aliases to help users of the PGP command line product /* These two are aliases to help users of the PGP command line
use gpg with minimal pain. Many commands are common already as product use gpg with minimal pain. Many commands are common
they seem to have borrowed commands from us. Now I'm returning already as they seem to have borrowed commands from us. Now
the favor. */ I'm returning the favor. */
{ oLocalUser, "sign-with", 2, "@" }, { oLocalUser, "sign-with", 2, "@" },
{ oRecipient, "user", 2, "@" }, { oRecipient, "user", 2, "@" },
{ oRequireBacksigs, "require-backsigs", 0, "@"}, { oRequireBacksigs, "require-backsigs", 0, "@"},
{ oNoRequireBacksigs, "no-require-backsigs", 0, "@"}, { oNoRequireBacksigs, "no-require-backsigs", 0, "@"},
{ oAutoKeyLocate, "auto-key-locate", 2, "@"}, { oAutoKeyLocate, "auto-key-locate", 2, "@"},
{ oNoAutoKeyLocate, "no-auto-key-locate", 0, "@"},
{0,NULL,0,NULL} {0,NULL,0,NULL}
}; };
@ -2416,10 +2418,18 @@ main (int argc, char **argv )
#endif /* __riscos__ */ #endif /* __riscos__ */
break; break;
case oKeyServer: case oKeyServer:
opt.keyserver=parse_keyserver_uri(pargs.r.ret_str,0, {
configname,configlineno); struct keyserver_spec *keyserver;
if(!opt.keyserver) keyserver=parse_keyserver_uri(pargs.r.ret_str,0,
log_error(_("could not parse keyserver URL\n")); configname,configlineno);
if(!keyserver)
log_error(_("could not parse keyserver URL\n"));
else
{
keyserver->next=opt.keyserver;
opt.keyserver=keyserver;
}
}
break; break;
case oKeyServerOptions: case oKeyServerOptions:
if(!parse_keyserver_options(pargs.r.ret_str)) if(!parse_keyserver_options(pargs.r.ret_str))
@ -2655,6 +2665,9 @@ main (int argc, char **argv )
log_error(_("invalid auto-key-locate list\n")); log_error(_("invalid auto-key-locate list\n"));
} }
break; break;
case oNoAutoKeyLocate:
release_akl();
break;
case oNoop: break; case oNoop: break;

View File

@ -1,6 +1,6 @@
/* gpgv.c - The GnuPG signature verify utility /* gpgv.c - The GnuPG signature verify utility
* Copyright (C) 1998, 1999, 2000, 2001, 2002, * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005,
* 2005 Free Software Foundation, Inc. * 2006 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -274,6 +274,10 @@ get_ownertrust (PKT_public_key *pk)
* Because we only work with trusted keys, it does not make sense to * Because we only work with trusted keys, it does not make sense to
* get them from a keyserver * get them from a keyserver
*/ */
struct keyserver_spec *
keyserver_match(struct keyserver_spec *spec) { return NULL; }
int int
keyserver_import_keyid( u32 *keyid, void *dummy ) keyserver_import_keyid( u32 *keyid, void *dummy )
{ {

View File

@ -1,6 +1,6 @@
/* keydb.h - Key database /* keydb.h - Key database
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
* 2005 Free Software Foundation, Inc. * 2006 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -258,6 +258,7 @@ char*get_long_user_id_string( u32 *keyid );
char*get_user_id( u32 *keyid, size_t *rn ); char*get_user_id( u32 *keyid, size_t *rn );
char*get_user_id_native( u32 *keyid ); char*get_user_id_native( u32 *keyid );
KEYDB_HANDLE get_ctx_handle(GETKEY_CTX ctx); KEYDB_HANDLE get_ctx_handle(GETKEY_CTX ctx);
void release_akl(void);
int parse_auto_key_locate(char *options); int parse_auto_key_locate(char *options);
/*-- keyid.c --*/ /*-- keyid.c --*/

View File

@ -1,5 +1,5 @@
/* keyserver-internal.h - Keyserver internals /* keyserver-internal.h - Keyserver internals
* Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. * Copyright (C) 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -29,6 +29,7 @@
int parse_keyserver_options(char *options); int parse_keyserver_options(char *options);
void free_keyserver_spec(struct keyserver_spec *keyserver); void free_keyserver_spec(struct keyserver_spec *keyserver);
struct keyserver_spec *keyserver_match(struct keyserver_spec *spec);
struct keyserver_spec *parse_keyserver_uri(const char *string, struct keyserver_spec *parse_keyserver_uri(const char *string,
int require_scheme, int require_scheme,
const char *configname, const char *configname,

View File

@ -1,5 +1,6 @@
/* keyserver.c - generic keyserver code /* keyserver.c - generic keyserver code
* Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. * Copyright (C) 2001, 2002, 2003, 2004, 2005,
* 2006 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -196,6 +197,41 @@ free_keyserver_spec(struct keyserver_spec *keyserver)
xfree(keyserver); xfree(keyserver);
} }
/* Return 0 for match */
static int
cmp_keyserver_spec(struct keyserver_spec *one,struct keyserver_spec *two)
{
if(ascii_strcasecmp(one->scheme,two->scheme)==0)
{
if(one->host && two->host && ascii_strcasecmp(one->host,two->host)==0)
{
if((one->port && two->port
&& ascii_strcasecmp(one->port,two->port)==0)
|| (!one->port && !two->port))
return 0;
}
else if(one->opaque && two->opaque
&& ascii_strcasecmp(one->opaque,two->opaque)==0)
return 0;
}
return 1;
}
/* Try and match one of our keyservers. If we can, return that. If
we can't, return our input. */
struct keyserver_spec *
keyserver_match(struct keyserver_spec *spec)
{
struct keyserver_spec *ks;
for(ks=opt.keyserver;ks;ks=ks->next)
if(cmp_keyserver_spec(spec,ks)==0)
return ks;
return spec;
}
/* TODO: once we cut over to an all-curl world, we don't need this /* TODO: once we cut over to an all-curl world, we don't need this
parser any longer so it can be removed, or at least moved to parser any longer so it can be removed, or at least moved to
keyserver/ksutil.c for limited use in gpgkeys_ldap or the like. */ keyserver/ksutil.c for limited use in gpgkeys_ldap or the like. */
@ -1050,7 +1086,7 @@ keyserver_spawn(enum ks_action action,STRLIST list,KEYDB_SEARCH_DESC *desc,
/* Write per-keyserver options */ /* Write per-keyserver options */
for(temp=opt.keyserver->options;temp;temp=temp->next) for(temp=keyserver->options;temp;temp=temp->next)
fprintf(spawn->tochild,"OPTION %s\n",temp->d); fprintf(spawn->tochild,"OPTION %s\n",temp->d);
switch(action) switch(action)

View File

@ -1,6 +1,6 @@
/* options.h /* options.h
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
* 2005 Free Software Foundation, Inc. * 2006 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -141,6 +141,7 @@ struct
{ {
unsigned int direct_uri:1; unsigned int direct_uri:1;
} flags; } flags;
struct keyserver_spec *next;
} *keyserver; } *keyserver;
struct struct
{ {