mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
tools: Integrate the dotlock tool into gpgconf.
* tools/gpgconf.c (dotlock_tool): New. (main): Add --lock and --unlock commands. -- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
1f04993cd0
commit
93b5ba38dc
@ -34,6 +34,7 @@
|
|||||||
#include "../common/init.h"
|
#include "../common/init.h"
|
||||||
#include "../common/status.h"
|
#include "../common/status.h"
|
||||||
#include "../common/exechelp.h"
|
#include "../common/exechelp.h"
|
||||||
|
#include "../common/dotlock.h"
|
||||||
|
|
||||||
#ifdef HAVE_W32_SYSTEM
|
#ifdef HAVE_W32_SYSTEM
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@ -76,7 +77,9 @@ enum cmd_and_opt_values
|
|||||||
aCreateSocketDir,
|
aCreateSocketDir,
|
||||||
aRemoveSocketDir,
|
aRemoveSocketDir,
|
||||||
aApplyProfile,
|
aApplyProfile,
|
||||||
aShowCodepages
|
aShowCodepages,
|
||||||
|
aDotlockLock,
|
||||||
|
aDotlockUnlock
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -109,7 +112,10 @@ static gpgrt_opt_t opts[] =
|
|||||||
{ aRemoveSocketDir, "remove-socketdir", 256, "@"},
|
{ aRemoveSocketDir, "remove-socketdir", 256, "@"},
|
||||||
ARGPARSE_c (aShowVersions, "show-versions", ""),
|
ARGPARSE_c (aShowVersions, "show-versions", ""),
|
||||||
ARGPARSE_c (aShowConfigs, "show-configs", ""),
|
ARGPARSE_c (aShowConfigs, "show-configs", ""),
|
||||||
|
/* hidden commands: for debugging */
|
||||||
ARGPARSE_c (aShowCodepages, "show-codepages", "@"),
|
ARGPARSE_c (aShowCodepages, "show-codepages", "@"),
|
||||||
|
ARGPARSE_c (aDotlockLock, "lock", "@"),
|
||||||
|
ARGPARSE_c (aDotlockUnlock, "unlock", "@"),
|
||||||
|
|
||||||
{ 301, NULL, 0, N_("@\nOptions:\n ") },
|
{ 301, NULL, 0, N_("@\nOptions:\n ") },
|
||||||
|
|
||||||
@ -604,6 +610,41 @@ query_swdb (estream_t out, const char *name, const char *current_version)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(HAVE_W32_SYSTEM)
|
||||||
|
/* dotlock tool to handle dotlock by command line
|
||||||
|
DO_LOCK: 1 for to lock, 0 for unlock
|
||||||
|
FILENAME: filename for the dotlock */
|
||||||
|
static void
|
||||||
|
dotlock_tool (int do_lock, const char *filename)
|
||||||
|
{
|
||||||
|
dotlock_t h;
|
||||||
|
unsigned int flags = DOTLOCK_LOCK_BY_PARENT;
|
||||||
|
|
||||||
|
if (!do_lock)
|
||||||
|
flags |= DOTLOCK_LOCKED;
|
||||||
|
|
||||||
|
h = dotlock_create (filename, flags);
|
||||||
|
if (!h)
|
||||||
|
{
|
||||||
|
if (do_lock)
|
||||||
|
log_error ("error creating the lock file\n");
|
||||||
|
else
|
||||||
|
log_error ("no lock file found\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (do_lock)
|
||||||
|
{
|
||||||
|
if (dotlock_take (h, 0))
|
||||||
|
log_error ("error taking the lock\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dotlock_release (h);
|
||||||
|
|
||||||
|
dotlock_destroy (h);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* gpgconf main. */
|
/* gpgconf main. */
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
@ -669,6 +710,8 @@ main (int argc, char **argv)
|
|||||||
case aShowVersions:
|
case aShowVersions:
|
||||||
case aShowConfigs:
|
case aShowConfigs:
|
||||||
case aShowCodepages:
|
case aShowCodepages:
|
||||||
|
case aDotlockLock:
|
||||||
|
case aDotlockUnlock:
|
||||||
cmd = pargs.r_opt;
|
cmd = pargs.r_opt;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1024,7 +1067,32 @@ main (int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case aDotlockLock:
|
||||||
|
case aDotlockUnlock:
|
||||||
|
#if !defined(HAVE_W32_SYSTEM)
|
||||||
|
if (!fname)
|
||||||
|
{
|
||||||
|
es_fprintf (es_stderr, "usage: %s [options] lock|unlock NAME",
|
||||||
|
GPGCONF_NAME);
|
||||||
|
es_putc ('\n', es_stderr);
|
||||||
|
es_fputs (_("Need one NAME argument"), es_stderr);
|
||||||
|
es_putc ('\n', es_stderr);
|
||||||
|
gpgconf_failure (GPG_ERR_USER_2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
/* Keybox pubring.db lock is under public-keys.d. */
|
||||||
|
if (!strcmp (fname, "pubring.db"))
|
||||||
|
fname = "public-keys.d/pubring.db";
|
||||||
|
|
||||||
|
filename = make_absfilename (gnupg_homedir (), fname, NULL);
|
||||||
|
dotlock_tool (cmd == aDotlockLock, filename);
|
||||||
|
xfree (filename);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outfp != es_stdout)
|
if (outfp != es_stdout)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user