diff options
author | David Shaw <[email protected]> | 2002-11-08 03:31:21 +0000 |
---|---|---|
committer | David Shaw <[email protected]> | 2002-11-08 03:31:21 +0000 |
commit | 7911a5ed86925eb24ce2df962965ee3ee51c47ff (patch) | |
tree | 48d3b2dd2a040e006f23ca40e001a5605706e5ed /g10/keydb.c | |
parent | * options.h, g10.c (main), trustdb.c (ask_ownertrust): Add (diff) | |
download | gnupg-7911a5ed86925eb24ce2df962965ee3ee51c47ff.tar.gz gnupg-7911a5ed86925eb24ce2df962965ee3ee51c47ff.zip |
* 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.
Diffstat (limited to 'g10/keydb.c')
-rw-r--r-- | g10/keydb.c | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/g10/keydb.c b/g10/keydb.c index d8dd83fe6..7b31e2dd0 100644 --- a/g10/keydb.c +++ b/g10/keydb.c @@ -55,6 +55,7 @@ struct resource_item { static struct resource_item all_resources[MAX_KEYDB_RESOURCES]; static int used_resources; +static void *default_keyring=NULL; struct keydb_handle { int locked; @@ -75,14 +76,17 @@ static void unlock_all (KEYDB_HANDLE hd); * created if it does not exist. * Note: this function may be called before secure memory is * available. + * Flag 1 == force + * Flag 2 == default */ 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; const char *resname = url; IOBUF iobuf = NULL; char *filename = NULL; + int force=(flags&1); int rc = 0; KeydbResourceType rt = KEYDB_RESOURCE_TYPE_NONE; void *token; @@ -189,19 +193,29 @@ keydb_add_resource (const char *url, int force, int secret) iobuf_ioctl (NULL, 2, 0, (char*)filename); } /* end file creation */ - token = keyring_register_filename (filename, secret); - if (!token) - ; /* already registered - ignore it */ - else if (used_resources >= MAX_KEYDB_RESOURCES) - rc = G10ERR_RESOURCE_LIMIT; - else - { - all_resources[used_resources].type = rt; - all_resources[used_resources].u.kr = NULL; /* Not used here */ - all_resources[used_resources].token = token; - all_resources[used_resources].secret = secret; - used_resources++; - } + if(keyring_register_filename (filename, secret, &token)) + { + if (used_resources >= MAX_KEYDB_RESOURCES) + rc = G10ERR_RESOURCE_LIMIT; + else + { + if(flags&2) + default_keyring=token; + all_resources[used_resources].type = rt; + all_resources[used_resources].u.kr = NULL; /* Not used here */ + all_resources[used_resources].token = token; + all_resources[used_resources].secret = secret; + 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; default: @@ -536,6 +550,25 @@ keydb_locate_writable (KEYDB_HANDLE hd, const char *reserved) if (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++) { switch (hd->active[hd->current].type) |