mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-09 12:54:23 +01:00
* keyring.h, keyring.c (keyring_register_filename): Return the pointer if
a given keyring is registered twice. * keydb.h, keydb.c (keydb_add_resource): Use flags to indicate a default keyring. (keydb_locate_writable): Prefer the default keyring if possible. * g10.c (main): Add --default-keyring option.
This commit is contained in:
parent
bf4a893586
commit
7911a5ed86
@ -1,3 +1,14 @@
|
|||||||
|
2002-11-07 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
|
* keyring.h, keyring.c (keyring_register_filename): Return the
|
||||||
|
pointer if a given keyring is registered twice.
|
||||||
|
|
||||||
|
* keydb.h, keydb.c (keydb_add_resource): Use flags to indicate a
|
||||||
|
default keyring.
|
||||||
|
(keydb_locate_writable): Prefer the default keyring if possible.
|
||||||
|
|
||||||
|
* g10.c (main): Add --default-keyring option.
|
||||||
|
|
||||||
2002-11-06 David Shaw <dshaw@jabberwocky.com>
|
2002-11-06 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
* options.h, g10.c (main), trustdb.c (ask_ownertrust): Add
|
* options.h, g10.c (main), trustdb.c (ask_ownertrust): Add
|
||||||
|
@ -141,6 +141,7 @@ enum cmd_and_opt_values { aNull = 0,
|
|||||||
oAnswerNo,
|
oAnswerNo,
|
||||||
oDefCertCheckLevel,
|
oDefCertCheckLevel,
|
||||||
oKeyring,
|
oKeyring,
|
||||||
|
oDefaultKeyring,
|
||||||
oSecretKeyring,
|
oSecretKeyring,
|
||||||
oShowKeyring,
|
oShowKeyring,
|
||||||
oDefaultKey,
|
oDefaultKey,
|
||||||
@ -420,6 +421,7 @@ static ARGPARSE_OPTS opts[] = {
|
|||||||
{ oAnswerYes, "yes", 0, N_("assume yes on most questions")},
|
{ oAnswerYes, "yes", 0, N_("assume yes on most questions")},
|
||||||
{ oAnswerNo, "no", 0, N_("assume no on most questions")},
|
{ oAnswerNo, "no", 0, N_("assume no on most questions")},
|
||||||
{ oKeyring, "keyring" ,2, N_("add this keyring to the list of keyrings")},
|
{ oKeyring, "keyring" ,2, N_("add this keyring to the list of keyrings")},
|
||||||
|
{ oDefaultKeyring, "default-keyring",2, "@" },
|
||||||
{ oSecretKeyring, "secret-keyring" ,2, N_("add this secret keyring to the list")},
|
{ oSecretKeyring, "secret-keyring" ,2, N_("add this secret keyring to the list")},
|
||||||
{ oShowKeyring, "show-keyring", 0, N_("show which keyring a listed key is on")},
|
{ oShowKeyring, "show-keyring", 0, N_("show which keyring a listed key is on")},
|
||||||
{ oDefaultKey, "default-key" ,2, N_("|NAME|use NAME as default secret key")},
|
{ oDefaultKey, "default-key" ,2, N_("|NAME|use NAME as default secret key")},
|
||||||
@ -1368,6 +1370,10 @@ main( int argc, char **argv )
|
|||||||
case oAnswerYes: opt.answer_yes = 1; break;
|
case oAnswerYes: opt.answer_yes = 1; break;
|
||||||
case oAnswerNo: opt.answer_no = 1; break;
|
case oAnswerNo: opt.answer_no = 1; break;
|
||||||
case oKeyring: append_to_strlist( &nrings, pargs.r.ret_str); break;
|
case oKeyring: append_to_strlist( &nrings, pargs.r.ret_str); break;
|
||||||
|
case oDefaultKeyring:
|
||||||
|
sl=append_to_strlist( &nrings, pargs.r.ret_str);
|
||||||
|
sl->flags=2;
|
||||||
|
break;
|
||||||
case oShowKeyring: opt.show_keyring = 1; break;
|
case oShowKeyring: opt.show_keyring = 1; break;
|
||||||
case oDebug: opt.debug |= pargs.r.ret_ulong; break;
|
case oDebug: opt.debug |= pargs.r.ret_ulong; break;
|
||||||
case oDebugAll: opt.debug = ~0; break;
|
case oDebugAll: opt.debug = ~0; break;
|
||||||
@ -2052,7 +2058,7 @@ main( int argc, char **argv )
|
|||||||
if( !nrings || default_keyring ) /* add default ring */
|
if( !nrings || default_keyring ) /* add default ring */
|
||||||
keydb_add_resource ("pubring" EXTSEP_S "gpg", 0, 0);
|
keydb_add_resource ("pubring" EXTSEP_S "gpg", 0, 0);
|
||||||
for(sl = nrings; sl; sl = sl->next )
|
for(sl = nrings; sl; sl = sl->next )
|
||||||
keydb_add_resource ( sl->d, 0, 0 );
|
keydb_add_resource ( sl->d, sl->flags, 0 );
|
||||||
}
|
}
|
||||||
FREE_STRLIST(nrings);
|
FREE_STRLIST(nrings);
|
||||||
FREE_STRLIST(sec_nrings);
|
FREE_STRLIST(sec_nrings);
|
||||||
|
43
g10/keydb.c
43
g10/keydb.c
@ -55,6 +55,7 @@ struct resource_item {
|
|||||||
|
|
||||||
static struct resource_item all_resources[MAX_KEYDB_RESOURCES];
|
static struct resource_item all_resources[MAX_KEYDB_RESOURCES];
|
||||||
static int used_resources;
|
static int used_resources;
|
||||||
|
static void *default_keyring=NULL;
|
||||||
|
|
||||||
struct keydb_handle {
|
struct keydb_handle {
|
||||||
int locked;
|
int locked;
|
||||||
@ -75,14 +76,17 @@ static void unlock_all (KEYDB_HANDLE hd);
|
|||||||
* created if it does not exist.
|
* created if it does not exist.
|
||||||
* Note: this function may be called before secure memory is
|
* Note: this function may be called before secure memory is
|
||||||
* available.
|
* available.
|
||||||
|
* Flag 1 == force
|
||||||
|
* Flag 2 == default
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
keydb_add_resource (const char *url, int force, int secret)
|
keydb_add_resource (const char *url, int flags, int secret)
|
||||||
{
|
{
|
||||||
static int any_secret, any_public;
|
static int any_secret, any_public;
|
||||||
const char *resname = url;
|
const char *resname = url;
|
||||||
IOBUF iobuf = NULL;
|
IOBUF iobuf = NULL;
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
|
int force=(flags&1);
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
KeydbResourceType rt = KEYDB_RESOURCE_TYPE_NONE;
|
KeydbResourceType rt = KEYDB_RESOURCE_TYPE_NONE;
|
||||||
void *token;
|
void *token;
|
||||||
@ -189,19 +193,29 @@ keydb_add_resource (const char *url, int force, int secret)
|
|||||||
iobuf_ioctl (NULL, 2, 0, (char*)filename);
|
iobuf_ioctl (NULL, 2, 0, (char*)filename);
|
||||||
} /* end file creation */
|
} /* end file creation */
|
||||||
|
|
||||||
token = keyring_register_filename (filename, secret);
|
if(keyring_register_filename (filename, secret, &token))
|
||||||
if (!token)
|
{
|
||||||
; /* already registered - ignore it */
|
if (used_resources >= MAX_KEYDB_RESOURCES)
|
||||||
else if (used_resources >= MAX_KEYDB_RESOURCES)
|
|
||||||
rc = G10ERR_RESOURCE_LIMIT;
|
rc = G10ERR_RESOURCE_LIMIT;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if(flags&2)
|
||||||
|
default_keyring=token;
|
||||||
all_resources[used_resources].type = rt;
|
all_resources[used_resources].type = rt;
|
||||||
all_resources[used_resources].u.kr = NULL; /* Not used here */
|
all_resources[used_resources].u.kr = NULL; /* Not used here */
|
||||||
all_resources[used_resources].token = token;
|
all_resources[used_resources].token = token;
|
||||||
all_resources[used_resources].secret = secret;
|
all_resources[used_resources].secret = secret;
|
||||||
used_resources++;
|
used_resources++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* This keyring was already registered, so ignore it.
|
||||||
|
However, we can still mark it as default even if it was
|
||||||
|
already registered. */
|
||||||
|
if(flags&2)
|
||||||
|
default_keyring=token;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -536,6 +550,25 @@ keydb_locate_writable (KEYDB_HANDLE hd, const char *reserved)
|
|||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
/* If we have a default set, try that one first */
|
||||||
|
if(default_keyring)
|
||||||
|
{
|
||||||
|
for ( ; hd->current >= 0 && hd->current < hd->used; hd->current++)
|
||||||
|
{
|
||||||
|
if(hd->active[hd->current].token==default_keyring)
|
||||||
|
{
|
||||||
|
if(keyring_is_writable (hd->active[hd->current].token))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = keydb_search_reset (hd); /* this does reset hd->current */
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
for ( ; hd->current >= 0 && hd->current < hd->used; hd->current++)
|
for ( ; hd->current >= 0 && hd->current < hd->used; hd->current++)
|
||||||
{
|
{
|
||||||
switch (hd->active[hd->current].type)
|
switch (hd->active[hd->current].type)
|
||||||
|
@ -143,7 +143,12 @@ struct keydb_search_desc {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*-- keydb.c --*/
|
/*-- keydb.c --*/
|
||||||
int keydb_add_resource (const char *url, int force, int secret);
|
|
||||||
|
/*
|
||||||
|
Flag 1 == force
|
||||||
|
Flag 2 == default
|
||||||
|
*/
|
||||||
|
int keydb_add_resource (const char *url, int flags, int secret);
|
||||||
KEYDB_HANDLE keydb_new (int secret);
|
KEYDB_HANDLE keydb_new (int secret);
|
||||||
void keydb_release (KEYDB_HANDLE hd);
|
void keydb_release (KEYDB_HANDLE hd);
|
||||||
const char *keydb_get_resource_name (KEYDB_HANDLE hd);
|
const char *keydb_get_resource_name (KEYDB_HANDLE hd);
|
||||||
|
@ -190,24 +190,27 @@ update_offset_hash_table_from_kb (OffsetHashTable tbl, KBNODE node, off_t off)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register a filename for plain keyring files. Returns a pointer to
|
* Register a filename for plain keyring files. ptr is set to a
|
||||||
* be used to create a handles etc or NULL to indicate that it has
|
* pointer to be used to create a handles etc, or the already-issued
|
||||||
* already been registered */
|
* pointer if it has already been registered. The function returns 1
|
||||||
void *
|
* if a new keyring was registered.
|
||||||
keyring_register_filename (const char *fname, int secret)
|
*/
|
||||||
|
int
|
||||||
|
keyring_register_filename (const char *fname, int secret, void **ptr)
|
||||||
{
|
{
|
||||||
KR_NAME kr;
|
KR_NAME kr;
|
||||||
|
|
||||||
if (active_handles)
|
if (active_handles)
|
||||||
BUG (); /* We don't allow that */
|
BUG (); /* We don't allow that */
|
||||||
|
|
||||||
for (kr=kr_names; kr; kr = kr->next) {
|
for (kr=kr_names; kr; kr = kr->next)
|
||||||
|
{
|
||||||
if ( !compare_filenames (kr->fname, fname) )
|
if ( !compare_filenames (kr->fname, fname) )
|
||||||
return NULL; /* already registered */
|
{
|
||||||
|
*ptr=kr;
|
||||||
|
return 0; /* already registered */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kr = m_alloc (sizeof *kr + strlen (fname));
|
kr = m_alloc (sizeof *kr + strlen (fname));
|
||||||
@ -224,7 +227,9 @@ keyring_register_filename (const char *fname, int secret)
|
|||||||
if (!kr_offtbl)
|
if (!kr_offtbl)
|
||||||
kr_offtbl = new_offset_hash_table ();
|
kr_offtbl = new_offset_hash_table ();
|
||||||
|
|
||||||
return kr;
|
*ptr=kr;
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
typedef struct keyring_handle *KEYRING_HANDLE;
|
typedef struct keyring_handle *KEYRING_HANDLE;
|
||||||
|
|
||||||
void *keyring_register_filename (const char *fname, int secret);
|
int keyring_register_filename (const char *fname, int secret, void **ptr);
|
||||||
int keyring_is_writable (void *token);
|
int keyring_is_writable (void *token);
|
||||||
|
|
||||||
KEYRING_HANDLE keyring_new (void *token, int secret);
|
KEYRING_HANDLE keyring_new (void *token, int secret);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user