Fix more spelling
* NEWS, acinclude.m4, agent/command-ssh.c, agent/command.c,
agent/gpg-agent.c, agent/keyformat.txt, agent/protect-tool.c,
common/asshelp.c, common/b64enc.c, common/recsel.c, doc/DETAILS,
doc/HACKING, doc/Notes, doc/TRANSLATE, doc/dirmngr.texi,
doc/faq.org, doc/gpg-agent.texi, doc/gpg.texi, doc/gpgsm.texi,
doc/instguide.texi, g10/armor.c, g10/gpg.c, g10/keyedit.c,
g10/mainproc.c, g10/pkclist.c, g10/tofu.c, g13/sh-cmd.c,
g13/sh-dmcrypt.c, kbx/keybox-init.c, m4/pkg.m4, sm/call-dirmngr.c,
sm/gpgsm.c, tests/Makefile.am, tests/gpgscm/Manual.txt,
tests/gpgscm/scheme.c, tests/openpgp/gpgv-forged-keyring.scm,
tests/openpgp/multisig.test, tests/openpgp/verify.scm,
tests/pkits/README, tools/applygnupgdefaults,
tools/gpg-connect-agent.c, tools/mime-maker.c, tools/mime-parser.c:
minor spelling cleanup.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-09-15 20:21:15 +02:00
|
|
|
/* keybox-init.c - Initialization of the library
|
2003-06-05 09:14:21 +02:00
|
|
|
* Copyright (C) 2001 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-04 21:49:40 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-05 09:14:21 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-11-05 12:02:19 +01:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2003-06-05 09:14:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "keybox-defs.h"
|
2020-10-20 10:43:55 +02:00
|
|
|
#include "../common/sysutils.h"
|
2015-11-27 18:10:31 +01:00
|
|
|
#include "../common/mischelp.h"
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2023-05-08 13:09:27 +02:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
# define DEFAULT_LL_BUFFER_SIZE 128
|
|
|
|
#else
|
|
|
|
# define DEFAULT_LL_BUFFER_SIZE 64
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static unsigned int ll_buffer_size = DEFAULT_LL_BUFFER_SIZE;
|
2023-05-08 09:16:35 +02:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
static KB_NAME kb_names;
|
|
|
|
|
2023-05-08 09:16:35 +02:00
|
|
|
/* This object is used to mahe setvbuf buffers. We use a short arary
|
|
|
|
* to be able to reuse already allocated buffers. */
|
|
|
|
struct stream_buffer_s
|
|
|
|
{
|
|
|
|
int inuse; /* True if used by a stream. */
|
|
|
|
size_t bufsize;
|
|
|
|
char *buf;
|
|
|
|
};
|
|
|
|
static struct stream_buffer_s stream_buffers[5];
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2016-01-13 09:29:39 +01:00
|
|
|
/* 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)
|
2003-06-05 09:14:21 +02:00
|
|
|
{
|
|
|
|
KB_NAME kr;
|
|
|
|
|
2016-01-13 09:29:39 +01:00
|
|
|
*r_token = NULL;
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
for (kr=kb_names; kr; kr = kr->next)
|
|
|
|
{
|
2007-08-24 11:34:39 +02:00
|
|
|
if (same_file_p (kr->fname, fname) )
|
2016-01-13 09:29:39 +01:00
|
|
|
{
|
|
|
|
*r_token = kr;
|
|
|
|
return gpg_error (GPG_ERR_EEXIST); /* Already registered. */
|
|
|
|
}
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
kr = xtrymalloc (sizeof *kr + strlen (fname));
|
|
|
|
if (!kr)
|
2016-01-13 09:29:39 +01:00
|
|
|
return gpg_error_from_syserror ();
|
2003-06-05 09:14:21 +02:00
|
|
|
strcpy (kr->fname, fname);
|
|
|
|
kr->secret = !!secret;
|
2008-04-01 17:08:57 +02:00
|
|
|
|
|
|
|
kr->handle_table = NULL;
|
|
|
|
kr->handle_table_size = 0;
|
|
|
|
|
2016-01-13 10:16:27 +01:00
|
|
|
kr->lockhd = NULL;
|
2003-06-05 09:14:21 +02:00
|
|
|
kr->is_locked = 0;
|
|
|
|
kr->did_full_scan = 0;
|
|
|
|
/* keep a list of all issued pointers */
|
|
|
|
kr->next = kb_names;
|
|
|
|
kb_names = kr;
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
/* create the offset table the first time a function here is used */
|
|
|
|
/* if (!kb_offtbl) */
|
|
|
|
/* kb_offtbl = new_offset_hash_table (); */
|
|
|
|
|
2016-01-13 09:29:39 +01:00
|
|
|
*r_token = kr;
|
|
|
|
return 0;
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
keybox_is_writable (void *token)
|
|
|
|
{
|
|
|
|
KB_NAME r = token;
|
|
|
|
|
2020-10-20 10:43:55 +02:00
|
|
|
return r? !gnupg_access (r->fname, W_OK) : 0;
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
|
2024-05-13 00:09:23 +02:00
|
|
|
/* Change the default buffering to KBYTES KiB; using 0 uses the system
|
2023-05-08 09:16:35 +02:00
|
|
|
* buffers. This function must be called early. */
|
|
|
|
void
|
|
|
|
keybox_set_buffersize (unsigned int kbytes, int reserved)
|
|
|
|
{
|
|
|
|
(void)reserved;
|
|
|
|
/* Round down to 8k multiples. */
|
|
|
|
ll_buffer_size = (kbytes + 7)/8 * 8;
|
|
|
|
}
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
|
2014-10-09 19:10:32 +02:00
|
|
|
static KEYBOX_HANDLE
|
|
|
|
do_keybox_new (KB_NAME resource, int secret, int for_openpgp)
|
2003-06-05 09:14:21 +02:00
|
|
|
{
|
|
|
|
KEYBOX_HANDLE hd;
|
2008-04-01 17:08:57 +02:00
|
|
|
int idx;
|
2003-06-05 09:14:21 +02:00
|
|
|
|
|
|
|
assert (resource && !resource->secret == !secret);
|
|
|
|
hd = xtrycalloc (1, sizeof *hd);
|
|
|
|
if (hd)
|
|
|
|
{
|
|
|
|
hd->kb = resource;
|
|
|
|
hd->secret = !!secret;
|
2014-10-09 19:10:32 +02:00
|
|
|
hd->for_openpgp = for_openpgp;
|
2008-04-01 17:08:57 +02:00
|
|
|
if (!resource->handle_table)
|
|
|
|
{
|
|
|
|
resource->handle_table_size = 3;
|
|
|
|
resource->handle_table = xtrycalloc (resource->handle_table_size,
|
|
|
|
sizeof *resource->handle_table);
|
|
|
|
if (!resource->handle_table)
|
|
|
|
{
|
|
|
|
resource->handle_table_size = 0;
|
|
|
|
xfree (hd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (idx=0; idx < resource->handle_table_size; idx++)
|
|
|
|
if (!resource->handle_table[idx])
|
|
|
|
{
|
|
|
|
resource->handle_table[idx] = hd;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!(idx < resource->handle_table_size))
|
|
|
|
{
|
|
|
|
KEYBOX_HANDLE *tmptbl;
|
|
|
|
size_t newsize;
|
|
|
|
|
|
|
|
newsize = resource->handle_table_size + 5;
|
2011-02-04 12:57:53 +01:00
|
|
|
tmptbl = xtryrealloc (resource->handle_table,
|
2008-04-01 17:08:57 +02:00
|
|
|
newsize * sizeof (*tmptbl));
|
|
|
|
if (!tmptbl)
|
|
|
|
{
|
|
|
|
xfree (hd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
resource->handle_table = tmptbl;
|
|
|
|
resource->handle_table_size = newsize;
|
|
|
|
resource->handle_table[idx] = hd;
|
|
|
|
for (idx++; idx < resource->handle_table_size; idx++)
|
|
|
|
resource->handle_table[idx] = NULL;
|
|
|
|
}
|
2003-06-05 09:14:21 +02:00
|
|
|
}
|
|
|
|
return hd;
|
|
|
|
}
|
|
|
|
|
2014-10-09 19:10:32 +02:00
|
|
|
|
|
|
|
/* Create a new handle for the resource associated with TOKEN. SECRET
|
|
|
|
is just a cross-check. This is the OpenPGP version. The returned
|
|
|
|
handle must be released using keybox_release. */
|
|
|
|
KEYBOX_HANDLE
|
|
|
|
keybox_new_openpgp (void *token, int secret)
|
|
|
|
{
|
|
|
|
KB_NAME resource = token;
|
|
|
|
|
|
|
|
return do_keybox_new (resource, secret, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new handle for the resource associated with TOKEN. SECRET
|
|
|
|
is just a cross-check. This is the X.509 version. The returned
|
|
|
|
handle must be released using keybox_release. */
|
|
|
|
KEYBOX_HANDLE
|
|
|
|
keybox_new_x509 (void *token, int secret)
|
|
|
|
{
|
|
|
|
KB_NAME resource = token;
|
|
|
|
|
|
|
|
return do_keybox_new (resource, secret, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
void
|
2003-06-05 09:14:21 +02:00
|
|
|
keybox_release (KEYBOX_HANDLE hd)
|
|
|
|
{
|
|
|
|
if (!hd)
|
|
|
|
return;
|
2008-04-01 17:08:57 +02:00
|
|
|
if (hd->kb->handle_table)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
for (idx=0; idx < hd->kb->handle_table_size; idx++)
|
|
|
|
if (hd->kb->handle_table[idx] == hd)
|
|
|
|
hd->kb->handle_table[idx] = NULL;
|
|
|
|
}
|
2003-06-05 09:14:21 +02:00
|
|
|
_keybox_release_blob (hd->found.blob);
|
2014-06-02 15:55:00 +02:00
|
|
|
_keybox_release_blob (hd->saved_found.blob);
|
2004-12-07 19:07:30 +01:00
|
|
|
if (hd->fp)
|
|
|
|
{
|
2023-05-05 11:37:44 +02:00
|
|
|
_keybox_ll_close (hd->fp);
|
2004-12-07 19:07:30 +01:00
|
|
|
hd->fp = NULL;
|
|
|
|
}
|
2003-06-05 09:14:21 +02:00
|
|
|
xfree (hd->word_match.name);
|
|
|
|
xfree (hd->word_match.pattern);
|
|
|
|
xfree (hd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-02 15:55:00 +02:00
|
|
|
/* Save the current found state in HD for later retrieval by
|
|
|
|
keybox_restore_found_state. Only one state may be saved. */
|
|
|
|
void
|
|
|
|
keybox_push_found_state (KEYBOX_HANDLE hd)
|
|
|
|
{
|
|
|
|
if (hd->saved_found.blob)
|
|
|
|
{
|
|
|
|
_keybox_release_blob (hd->saved_found.blob);
|
|
|
|
hd->saved_found.blob = NULL;
|
|
|
|
}
|
|
|
|
hd->saved_found = hd->found;
|
|
|
|
hd->found.blob = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Restore the saved found state in HD. */
|
|
|
|
void
|
|
|
|
keybox_pop_found_state (KEYBOX_HANDLE hd)
|
|
|
|
{
|
|
|
|
if (hd->found.blob)
|
|
|
|
{
|
|
|
|
_keybox_release_blob (hd->found.blob);
|
|
|
|
hd->found.blob = NULL;
|
|
|
|
}
|
|
|
|
hd->found = hd->saved_found;
|
|
|
|
hd->saved_found.blob = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-05 09:14:21 +02:00
|
|
|
const char *
|
|
|
|
keybox_get_resource_name (KEYBOX_HANDLE hd)
|
|
|
|
{
|
|
|
|
if (!hd || !hd->kb)
|
|
|
|
return NULL;
|
|
|
|
return hd->kb->fname;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
keybox_set_ephemeral (KEYBOX_HANDLE hd, int yes)
|
|
|
|
{
|
|
|
|
if (!hd)
|
2011-02-04 12:57:53 +01:00
|
|
|
return gpg_error (GPG_ERR_INV_HANDLE);
|
2003-06-05 09:14:21 +02:00
|
|
|
hd->ephemeral = yes;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-01 17:08:57 +02:00
|
|
|
|
2023-05-05 11:37:44 +02:00
|
|
|
/* Low-level open function to be used for keybox files. This function
|
|
|
|
* also manages custom buffering. On success 0 is returned and a new
|
|
|
|
* file pointer stored at RFP; on error an error code is returned and
|
|
|
|
* NULL is stored at RFP. MODE is one of
|
|
|
|
* KEYBOX_LL_OPEN_READ(0) := fopen mode is "rb"
|
|
|
|
* KEYBOX_LL_OPEN_UPDATE := fopen mode is "r+b"
|
|
|
|
* KEYBOX_LL_OPEN_CREATE := fopen mode is "wb"
|
|
|
|
*/
|
|
|
|
gpg_error_t
|
|
|
|
_keybox_ll_open (estream_t *rfp, const char *fname, unsigned int mode)
|
|
|
|
{
|
|
|
|
estream_t fp;
|
2023-05-08 09:16:35 +02:00
|
|
|
int i;
|
|
|
|
size_t bufsize;
|
2023-05-05 11:37:44 +02:00
|
|
|
|
|
|
|
*rfp = NULL;
|
|
|
|
|
|
|
|
fp = es_fopen (fname,
|
|
|
|
mode == KEYBOX_LL_OPEN_CREATE
|
|
|
|
? "wb,sysopen,sequential" :
|
|
|
|
mode == KEYBOX_LL_OPEN_UPDATE
|
|
|
|
? "r+b,sysopen,sequential" :
|
|
|
|
"rb,sysopen,sequential");
|
|
|
|
if (!fp)
|
|
|
|
return gpg_error_from_syserror ();
|
|
|
|
|
2023-05-08 09:16:35 +02:00
|
|
|
if (ll_buffer_size)
|
|
|
|
{
|
|
|
|
for (i=0; i < DIM (stream_buffers); i++)
|
|
|
|
if (!stream_buffers[i].inuse)
|
|
|
|
{
|
|
|
|
/* There is a free slot - we can use a larger buffer. */
|
|
|
|
stream_buffers[i].inuse = 1;
|
|
|
|
if (!stream_buffers[i].buf)
|
|
|
|
{
|
|
|
|
bufsize = ll_buffer_size * 1024;
|
|
|
|
stream_buffers[i].buf = xtrymalloc (bufsize);
|
|
|
|
if (stream_buffers[i].buf)
|
|
|
|
stream_buffers[i].bufsize = bufsize;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log_info ("can't allocate a large buffer for a kbx file;"
|
|
|
|
" using default\n");
|
|
|
|
stream_buffers[i].inuse = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream_buffers[i].buf)
|
|
|
|
{
|
|
|
|
es_setvbuf (fp, stream_buffers[i].buf, _IOFBF,
|
|
|
|
stream_buffers[i].bufsize);
|
|
|
|
es_opaque_set (fp, stream_buffers + i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 11:37:44 +02:00
|
|
|
*rfp = fp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Wrapper around es_fclose to be used for file opened with
|
|
|
|
* _keybox_ll_open. */
|
|
|
|
gpg_error_t
|
|
|
|
_keybox_ll_close (estream_t fp)
|
|
|
|
{
|
2023-05-08 09:16:35 +02:00
|
|
|
gpg_error_t err;
|
|
|
|
struct stream_buffer_s *sbuf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!fp)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sbuf = ll_buffer_size? es_opaque_get (fp) : NULL;
|
|
|
|
if (es_fclose (fp))
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
else
|
|
|
|
err = 0;
|
|
|
|
if (sbuf)
|
|
|
|
{
|
|
|
|
for (i=0; i < DIM (stream_buffers); i++)
|
|
|
|
if (stream_buffers + i == sbuf)
|
|
|
|
break;
|
|
|
|
log_assert (i < DIM (stream_buffers));
|
|
|
|
stream_buffers[i].inuse = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return err;
|
2023-05-05 11:37:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-01 17:08:57 +02:00
|
|
|
/* Close the file of the resource identified by HD. For consistent
|
2015-11-16 12:41:46 +01:00
|
|
|
results this function closes the files of all handles pointing to
|
2008-04-01 17:08:57 +02:00
|
|
|
the resource identified by HD. */
|
2011-02-04 12:57:53 +01:00
|
|
|
void
|
2008-04-01 17:08:57 +02:00
|
|
|
_keybox_close_file (KEYBOX_HANDLE hd)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
KEYBOX_HANDLE roverhd;
|
|
|
|
|
|
|
|
if (!hd || !hd->kb || !hd->kb->handle_table)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (idx=0; idx < hd->kb->handle_table_size; idx++)
|
|
|
|
if ((roverhd = hd->kb->handle_table[idx]))
|
|
|
|
{
|
|
|
|
if (roverhd->fp)
|
|
|
|
{
|
2023-05-05 11:37:44 +02:00
|
|
|
_keybox_ll_close (roverhd->fp);
|
2008-04-01 17:08:57 +02:00
|
|
|
roverhd->fp = NULL;
|
|
|
|
}
|
|
|
|
}
|
2020-10-20 11:52:16 +02:00
|
|
|
log_assert (!hd->fp);
|
2008-04-01 17:08:57 +02:00
|
|
|
}
|
2012-12-27 15:04:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2019-05-14 13:36:08 +02:00
|
|
|
* Lock the keybox at handle HD, or unlock if YES is false. TIMEOUT
|
|
|
|
* is the value used for dotlock_take. In general -1 should be used
|
|
|
|
* when taking a lock; use 0 when releasing a lock.
|
2012-12-27 15:04:29 +01:00
|
|
|
*/
|
2016-01-13 10:16:27 +01:00
|
|
|
gpg_error_t
|
2019-05-14 13:36:08 +02:00
|
|
|
keybox_lock (KEYBOX_HANDLE hd, int yes, long timeout)
|
2012-12-27 15:04:29 +01:00
|
|
|
{
|
2016-01-13 14:47:06 +01:00
|
|
|
gpg_error_t err = 0;
|
2016-01-13 10:16:27 +01:00
|
|
|
KB_NAME kb = hd->kb;
|
2012-12-27 15:04:29 +01:00
|
|
|
|
2016-01-13 14:47:06 +01:00
|
|
|
if (!keybox_is_writable (kb))
|
2016-01-13 10:16:27 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Make sure the lock handle has been created. */
|
|
|
|
if (!kb->lockhd)
|
|
|
|
{
|
|
|
|
kb->lockhd = dotlock_create (kb->fname, 0);
|
|
|
|
if (!kb->lockhd)
|
|
|
|
{
|
2016-01-13 14:47:06 +01:00
|
|
|
err = gpg_error_from_syserror ();
|
2016-01-13 10:16:27 +01:00
|
|
|
log_info ("can't allocate lock for '%s'\n", kb->fname );
|
2016-01-13 14:47:06 +01:00
|
|
|
return err;
|
2016-01-13 10:16:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yes) /* Take the lock. */
|
|
|
|
{
|
2016-01-14 20:45:33 +01:00
|
|
|
if (!kb->is_locked)
|
2016-01-13 10:16:27 +01:00
|
|
|
{
|
2016-01-14 20:45:33 +01:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
2019-05-14 19:05:58 +02:00
|
|
|
/* Under Windows we need to close the file before we try
|
|
|
|
* to lock it. This is because another process might have
|
|
|
|
* taken the lock and is using keybox_file_rename to
|
|
|
|
* rename the base file. Now if our dotlock_take below is
|
|
|
|
* waiting for the lock but we have the base file still
|
|
|
|
* open, keybox_file_rename will never succeed as we are
|
|
|
|
* in a deadlock. */
|
|
|
|
_keybox_close_file (hd);
|
2016-01-14 20:45:33 +01:00
|
|
|
#endif /*HAVE_W32_SYSTEM*/
|
2019-05-14 13:36:08 +02:00
|
|
|
if (dotlock_take (kb->lockhd, timeout))
|
2016-01-14 20:45:33 +01:00
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
2019-05-14 13:36:08 +02:00
|
|
|
if (!timeout && gpg_err_code (err) == GPG_ERR_EACCES)
|
|
|
|
; /* No diagnostic if we only tried to lock. */
|
|
|
|
else
|
|
|
|
log_info ("can't lock '%s'\n", kb->fname );
|
2016-01-14 20:45:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
kb->is_locked = 1;
|
2016-01-13 10:16:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* Release the lock. */
|
|
|
|
{
|
2016-01-14 20:45:33 +01:00
|
|
|
if (kb->is_locked)
|
2016-01-13 10:16:27 +01:00
|
|
|
{
|
2016-01-14 20:45:33 +01:00
|
|
|
if (dotlock_release (kb->lockhd))
|
|
|
|
{
|
|
|
|
err = gpg_error_from_syserror ();
|
|
|
|
log_info ("can't unlock '%s'\n", kb->fname );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
kb->is_locked = 0;
|
2016-01-13 10:16:27 +01:00
|
|
|
}
|
2016-01-13 14:47:06 +01:00
|
|
|
}
|
2016-01-13 10:16:27 +01:00
|
|
|
|
|
|
|
return err;
|
2012-12-27 15:04:29 +01:00
|
|
|
}
|