1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

New command --check-programs for gpgconf.

This commit is contained in:
Werner Koch 2007-08-29 09:51:37 +00:00
parent f268889b8f
commit b13587ef16
17 changed files with 267 additions and 25 deletions

View file

@ -1,3 +1,12 @@
2007-08-29 Werner Koch <wk@g10code.com>
* gpgconf.c: New comamnd --check-programs.
* gpgconf-comp.c (gc_component_check_programs): New.
(gc_backend): Add member MODULE_NAME and add these module names.
(retrieve_options_from_program): Use module name so that we use an
absolute file name and don't rely on $PATH.
* no-libgcrypt.c (gcry_control): New.
2007-08-28 Werner Koch <wk@g10code.com>
* gpgconf-comp.c <gpg-agent>: Add options --max-passphrase-days
@ -713,7 +722,7 @@
* watchgnupg.c: New.
Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
Copyright 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
This file is free software; as a special exception the author gives
unlimited permission to copy and/or distribute it, with or without

View file

@ -43,6 +43,7 @@
#define JNLIB_NEED_LOG_LOGV
#include "util.h"
#include "i18n.h"
#include "exechelp.h"
#include "gc-opt-flags.h"
#include "gpgconf.h"
@ -153,6 +154,12 @@ static struct
GPGConf. In this case, PROGRAM is NULL. */
char *program;
/* The module name (GNUPG_MODULE_NAME_foo) as defined by
../common/util.h. This value is used to get the actual installed
path of the program. 0 is used if no backedn program is
available. */
char module_name;
/* The runtime change callback. */
void (*runtime_change) (void);
@ -168,14 +175,18 @@ static struct
} gc_backend[GC_BACKEND_NR] =
{
{ NULL }, /* GC_BACKEND_ANY dummy entry. */
{ "GnuPG", GPGNAME, NULL, "gpgconf-gpg.conf" },
{ "GPGSM", "gpgsm", NULL, "gpgconf-gpgsm.conf" },
{ "GPG Agent", "gpg-agent", gpg_agent_runtime_change,
"gpgconf-gpg-agent.conf" },
{ "SCDaemon", "scdaemon", NULL, "gpgconf-scdaemon.conf" },
{ "DirMngr", "dirmngr", NULL, "gpgconf-dirmngr.conf" },
{ "DirMngr LDAP Server List", NULL, NULL, "ldapserverlist-file",
"LDAP Server" },
{ "GnuPG", GPGNAME, GNUPG_MODULE_NAME_GPG,
NULL, "gpgconf-gpg.conf" },
{ "GPGSM", "gpgsm", GNUPG_MODULE_NAME_GPGSM,
NULL, "gpgconf-gpgsm.conf" },
{ "GPG Agent", "gpg-agent", GNUPG_MODULE_NAME_AGENT,
gpg_agent_runtime_change, "gpgconf-gpg-agent.conf" },
{ "SCDaemon", "scdaemon", GNUPG_MODULE_NAME_SCDAEMON,
NULL, "gpgconf-scdaemon.conf" },
{ "DirMngr", "dirmngr", GNUPG_MODULE_NAME_DIRMNGR,
NULL, "gpgconf-dirmngr.conf" },
{ "DirMngr LDAP Server List", NULL, 0,
NULL, "ldapserverlist-file", "LDAP Server" },
};
@ -1129,6 +1140,81 @@ gc_component_list_components (FILE *out)
}
}
/* Check all components that are available. */
void
gc_component_check_programs (FILE *out)
{
gc_component_t component;
unsigned int result;
int backend_seen[GC_BACKEND_NR];
gc_backend_t backend;
gc_option_t *option;
const char *desc;
const char *pgmname;
const char *argv[2];
pid_t pid;
int exitcode;
for (component = 0; component < GC_COMPONENT_NR; component++)
{
if (!gc_component[component].options)
continue;
for (backend = 0; backend < GC_BACKEND_NR; backend++)
backend_seen[backend] = 0;
option = gc_component[component].options;
for (; option && option->name; option++)
{
if ((option->flags & GC_OPT_FLAG_GROUP))
continue;
backend = option->backend;
if (backend_seen[backend])
continue;
backend_seen[backend] = 1;
assert (backend != GC_BACKEND_ANY);
if (!gc_backend[backend].program)
continue;
if (!gc_backend[backend].module_name)
continue;
pgmname = gnupg_module_name (gc_backend[backend].module_name);
argv[0] = "--gpgconf-test";
argv[1] = NULL;
/* Note that under Windows the spawn fucntion returns an
error if the progrom could not be executed whereas under
Unix the wait function returns an error. */
result = 0;
if (gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid))
result |= 1; /* Program could not be run. */
else if (gnupg_wait_process (pgmname, pid, &exitcode))
{
if (exitcode == -1)
result |= 1; /* Program could not be run or it
terminated abnormally. */
result |= 2; /* Program returned an error. */
}
/* If the program could not be run, we can't tell whether
the config file is good. */
if ((result&1))
result |= 2;
desc = gc_component[component].desc;
desc = my_dgettext (gc_component[component].desc_domain, desc);
fprintf (out, "%s:%s:",
gc_component[component].name, my_percent_escape (desc));
fputs (my_percent_escape (pgmname), out);
fprintf (out, ":%d:%d:\n", !(result & 1), !(result & 2));
break; /* Loop over options of this component */
}
}
}
/* Find the component with the name NAME. Returns -1 if not
found. */
@ -1362,7 +1448,10 @@ retrieve_options_from_program (gc_component_t component, gc_backend_t backend)
FILE *config;
char *config_pathname;
cmd_line = xasprintf ("%s --gpgconf-list", gc_backend[backend].program);
cmd_line = xasprintf ("%s --gpgconf-list",
gc_backend[backend].module_name ?
gnupg_module_name (gc_backend[backend].module_name) :
gc_backend[backend].program );
config = popen (cmd_line, "r");
if (!config)
@ -1663,6 +1752,8 @@ gc_component_retrieve_options (int component)
while (process_all && ++component < GC_COMPONENT_NR);
}
/* Perform a simple validity check based on the type. Return in
NEW_VALUE_NR the value of the number in NEW_VALUE if OPTION is of

View file

@ -1,5 +1,5 @@
/* gpgconf.c - Configuration utility for GnuPG
* Copyright (C) 2003 Free Software Foundation, Inc.
* Copyright (C) 2003, 2007 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -40,6 +40,7 @@ enum cmd_and_opt_values
oHomedir,
aListComponents,
aCheckPrograms,
aListOptions,
aChangeOptions,
aApplyDefaults,
@ -54,6 +55,7 @@ static ARGPARSE_OPTS opts[] =
{ 300, NULL, 0, N_("@Commands:\n ") },
{ aListComponents, "list-components", 256, N_("list all components") },
{ aCheckPrograms, "check-programs", 256, N_("check all programs") },
{ aListOptions, "list-options", 256, N_("|COMPONENT|list options") },
{ aChangeOptions, "change-options", 256, N_("|COMPONENT|change options") },
{ aApplyDefaults, "apply-defaults", 256,
@ -137,6 +139,7 @@ main (int argc, char **argv)
case oNoVerbose: opt.verbose = 0; break;
case aListComponents:
case aCheckPrograms:
case aListOptions:
case aChangeOptions:
case aApplyDefaults:
@ -161,6 +164,11 @@ main (int argc, char **argv)
gc_component_list_components (stdout);
break;
case aCheckPrograms:
/* Check all programs. */
gc_component_check_programs (stdout);
break;
case aListOptions:
case aChangeOptions:
if (!fname)

View file

@ -40,6 +40,9 @@ struct
/* List all components that are available. */
void gc_component_list_components (FILE *out);
/* List all programs along with their status. */
void gc_component_check_programs (FILE *out);
/* Find the component with the name NAME. Returns -1 if not
found. */
int gc_component_find (const char *name);

View file

@ -102,3 +102,12 @@ gcry_free (void *a)
if (a)
free (a);
}
/* We need this dummy because exechelp.c uses gcry_control to
terminate the secure memeory. */
gcry_error_t
gcry_control (enum gcry_ctl_cmds CMD, ...)
{
return 0;
}