diff options
author | Werner Koch <[email protected]> | 2016-01-13 08:29:39 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-01-13 09:43:33 +0000 |
commit | 9dc355ad3ae0026ab04c424dc984d748b8fad393 (patch) | |
tree | 31a6eb986c5a6f89cbbf8f33ed34352696b91cf2 /kbx/keybox-init.c | |
parent | Fix to support git worktree. (diff) | |
download | gnupg-9dc355ad3ae0026ab04c424dc984d748b8fad393.tar.gz gnupg-9dc355ad3ae0026ab04c424dc984d748b8fad393.zip |
gpg: Make sure to mark a duplicate registered keybox as primary.
* kbx/keybox-init.c (keybox_register_file): Change interface to return
the token even if the file has already been registered.
* g10/keydb.c (primary_keyring): Rename to primary_keydb.
(maybe_create_keyring_or_box): Change return type to gpg_error_t.
(keydb_add_resource): Ditto. s/rc/err/.
(keydb_add_resource): Mark an already registered as primary.
* sm/keydb.c (maybe_create_keybox): Change return type to gpg_error_t.
(keydb_add_resource): Ditto. s/rc/err/.
(keydb_add_resource): Adjust for changed keybox_register_file.
--
This change aligns the registering of keyboxes with those of
keyrings. This fixes a potential bug:
gpg --keyring foo.kbx --keyring bar.gpg --keyring foo.kbx
would have marked bar.gpg as primary resource and thus inserting new
keys there. The correct and now fixed behavior is to insert to
foo.kbx.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'kbx/keybox-init.c')
-rw-r--r-- | kbx/keybox-init.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/kbx/keybox-init.c b/kbx/keybox-init.c index e91911c37..3ff592eaf 100644 --- a/kbx/keybox-init.c +++ b/kbx/keybox-init.c @@ -30,23 +30,30 @@ static KB_NAME kb_names; -/* Register a filename for plain keybox files. Returns a pointer to - be used to create a handles and so on. Returns NULL to indicate - that FNAME has already been registered. */ -void * -keybox_register_file (const char *fname, int secret) +/* Register a filename for plain keybox files. Returns 0 on success, + * GPG_ERR_EEXIST if it has already been registered, or another error + * code. On success or with error code GPG_ERR_EEXIST a token usable + * to access the keybox handle is stored at R_TOKEN, NULL is stored + * for all other errors. */ +gpg_error_t +keybox_register_file (const char *fname, int secret, void **r_token) { KB_NAME kr; + *r_token = NULL; + for (kr=kb_names; kr; kr = kr->next) { if (same_file_p (kr->fname, fname) ) - return NULL; /* Already registered. */ + { + *r_token = kr; + return gpg_error (GPG_ERR_EEXIST); /* Already registered. */ + } } kr = xtrymalloc (sizeof *kr + strlen (fname)); if (!kr) - return NULL; + return gpg_error_from_syserror (); strcpy (kr->fname, fname); kr->secret = !!secret; @@ -64,7 +71,8 @@ keybox_register_file (const char *fname, int secret) /* if (!kb_offtbl) */ /* kb_offtbl = new_offset_hash_table (); */ - return kr; + *r_token = kr; + return 0; } int |