summaryrefslogtreecommitdiffstats
path: root/g10/keydb.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2016-11-10 17:01:19 +0100
committerWerner Koch <wk@gnupg.org>2016-11-10 17:07:28 +0100
commit5d13581f4737c18430f6572dd4ef486d1ad80dd1 (patch)
treed90f1618778b7534bb195aa7c09060cb631484dd /g10/keydb.c
parentsm: Remove unused arg SECRET from keydb functions. (diff)
downloadgnupg2-5d13581f4737c18430f6572dd4ef486d1ad80dd1.tar.xz
gnupg2-5d13581f4737c18430f6572dd4ef486d1ad80dd1.zip
gpg,sm: Add STATUS_ERROR keydb_search and keydb_add-resource.
* g10/keydb.c (keydb_add_resource): Make ANY_REGISTERED file-global. Write a STATUS_ERROR. (maybe_create_keyring_or_box): Check for non-accessible but existant file. (keydb_search): Write a STATUS_ERROR if no keyring has been registered but continue to return NOT_FOUND. * sm/keydb.c (keydb_add_resource): Rename ANY_PUBLIC to ANY_REGISTERED and make file-global. Write a STATUS_ERROR. (keydb_search): Write a STATUS_ERROR if no keyring has been registered but continue to return NOT_FOUND. Also add new arg CTRL and change all callers to pass it down. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'g10/keydb.c')
-rw-r--r--g10/keydb.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/g10/keydb.c b/g10/keydb.c
index 76850f963..1467b2d53 100644
--- a/g10/keydb.c
+++ b/g10/keydb.c
@@ -64,6 +64,8 @@ static int used_resources;
to the struct resource_item's TOKEN. */
static void *primary_keydb;
+/* Whether we have successfully registered any resource. */
+static int any_registered;
/* This is a simple cache used to return the last result of a
successful fingerprint search. This works only for keybox resources
@@ -277,7 +279,7 @@ maybe_create_keyring_or_box (char *filename, int is_box, int force_create)
/* A quick test whether the filename already exists. */
if (!access (filename, F_OK))
- return 0;
+ return !access (filename, R_OK)? 0 : gpg_error (GPG_ERR_EACCES);
/* If we don't want to create a new file at all, there is no need to
go any further - bail out right here. */
@@ -616,8 +618,6 @@ keydb_search_desc_dump (struct keydb_search_desc *desc)
gpg_error_t
keydb_add_resource (const char *url, unsigned int flags)
{
- /* Whether we have successfully registered a resource. */
- static int any_registered;
/* The file named by the URL (i.e., without the prototype). */
const char *resname = url;
@@ -819,7 +819,11 @@ keydb_add_resource (const char *url, unsigned int flags)
leave:
if (err)
- log_error (_("keyblock resource '%s': %s\n"), filename, gpg_strerror (err));
+ {
+ log_error (_("keyblock resource '%s': %s\n"),
+ filename, gpg_strerror (err));
+ write_status_error ("add_keyblock_resource", err);
+ }
else
any_registered = 1;
xfree (filename);
@@ -1875,6 +1879,12 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
if (!hd)
return gpg_error (GPG_ERR_INV_ARG);
+ if (!any_registered)
+ {
+ write_status_error ("keydb_search", gpg_error (GPG_ERR_KEYRING_OPEN));
+ return gpg_error (GPG_ERR_NOT_FOUND);
+ }
+
if (DBG_CLOCK)
log_clock ("keydb_search enter");