2004-01-05 09:28:27 +00:00
|
|
|
/* gpgconf.c - Configuration utility for GnuPG
|
2011-02-23 10:15:34 +01:00
|
|
|
* Copyright (C) 2003, 2007, 2009, 2011 Free Software Foundation, Inc.
|
2004-01-05 09:28:27 +00:00
|
|
|
*
|
|
|
|
* 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 19:49:40 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-01-05 09:28:27 +00: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
|
2007-07-04 19:49:40 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2004-01-05 09:28:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gpgconf.h"
|
|
|
|
#include "i18n.h"
|
2009-06-08 08:15:34 +00:00
|
|
|
#include "sysutils.h"
|
2004-01-05 09:28:27 +00:00
|
|
|
|
|
|
|
/* Constants to identify the commands and options. */
|
|
|
|
enum cmd_and_opt_values
|
|
|
|
{
|
|
|
|
aNull = 0,
|
|
|
|
oDryRun = 'n',
|
|
|
|
oOutput = 'o',
|
2004-01-28 23:58:18 +00:00
|
|
|
oQuiet = 'q',
|
2004-01-05 09:28:27 +00:00
|
|
|
oVerbose = 'v',
|
2004-02-23 20:31:35 +00:00
|
|
|
oRuntime = 'r',
|
2004-01-28 23:58:18 +00:00
|
|
|
oComponent = 'c',
|
2004-01-05 09:28:27 +00:00
|
|
|
oNoVerbose = 500,
|
|
|
|
oHomedir,
|
2004-01-28 23:58:18 +00:00
|
|
|
|
|
|
|
aListComponents,
|
2007-08-29 09:51:37 +00:00
|
|
|
aCheckPrograms,
|
2004-01-28 23:58:18 +00:00
|
|
|
aListOptions,
|
|
|
|
aChangeOptions,
|
2008-05-19 22:46:41 +00:00
|
|
|
aCheckOptions,
|
2007-03-06 20:44:41 +00:00
|
|
|
aApplyDefaults,
|
2007-10-23 18:13:27 +00:00
|
|
|
aListConfig,
|
2008-05-26 13:43:20 +00:00
|
|
|
aCheckConfig,
|
2009-03-03 09:02:58 +00:00
|
|
|
aListDirs,
|
2011-02-23 10:15:34 +01:00
|
|
|
aKill,
|
2009-03-03 09:02:58 +00:00
|
|
|
aReload
|
2004-01-05 09:28:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* The list of commands and options. */
|
|
|
|
static ARGPARSE_OPTS opts[] =
|
|
|
|
{
|
|
|
|
{ 300, NULL, 0, N_("@Commands:\n ") },
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
{ aListComponents, "list-components", 256, N_("list all components") },
|
2007-08-29 09:51:37 +00:00
|
|
|
{ aCheckPrograms, "check-programs", 256, N_("check all programs") },
|
2004-01-28 23:58:18 +00:00
|
|
|
{ aListOptions, "list-options", 256, N_("|COMPONENT|list options") },
|
|
|
|
{ aChangeOptions, "change-options", 256, N_("|COMPONENT|change options") },
|
2008-05-19 22:46:41 +00:00
|
|
|
{ aCheckOptions, "check-options", 256, N_("|COMPONENT|check options") },
|
2007-03-06 20:44:41 +00:00
|
|
|
{ aApplyDefaults, "apply-defaults", 256,
|
|
|
|
N_("apply global default values") },
|
2008-05-26 13:43:20 +00:00
|
|
|
{ aListDirs, "list-dirs", 256,
|
|
|
|
N_("get the configuration directories for gpgconf") },
|
2007-10-23 18:13:27 +00:00
|
|
|
{ aListConfig, "list-config", 256,
|
|
|
|
N_("list global configuration file") },
|
2007-03-06 20:44:41 +00:00
|
|
|
{ aCheckConfig, "check-config", 256,
|
|
|
|
N_("check global configuration file") },
|
2010-10-14 08:32:55 +00:00
|
|
|
{ aReload, "reload", 256, N_("reload all or a given component")},
|
2011-02-23 10:15:34 +01:00
|
|
|
{ aKill, "kill", 256, N_("kill a given component")},
|
2004-01-28 23:58:18 +00:00
|
|
|
|
2004-01-05 09:28:27 +00:00
|
|
|
{ 301, NULL, 0, N_("@\nOptions:\n ") },
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
{ oOutput, "output", 2, N_("use as output file") },
|
2004-01-05 09:28:27 +00:00
|
|
|
{ oVerbose, "verbose", 0, N_("verbose") },
|
2004-01-28 23:58:18 +00:00
|
|
|
{ oQuiet, "quiet", 0, N_("quiet") },
|
2004-01-05 09:28:27 +00:00
|
|
|
{ oDryRun, "dry-run", 0, N_("do not make any changes") },
|
2004-02-23 20:31:35 +00:00
|
|
|
{ oRuntime, "runtime", 0, N_("activate changes at runtime, if possible") },
|
2004-01-05 09:28:27 +00:00
|
|
|
/* hidden options */
|
|
|
|
{ oNoVerbose, "no-verbose", 0, "@"},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Print usage information and and provide strings for help. */
|
|
|
|
static const char *
|
|
|
|
my_strusage( int level )
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
switch (level)
|
|
|
|
{
|
|
|
|
case 11: p = "gpgconf (GnuPG)";
|
|
|
|
break;
|
|
|
|
case 13: p = VERSION; break;
|
|
|
|
case 17: p = PRINTABLE_OS_NAME; break;
|
2009-07-21 14:21:05 +00:00
|
|
|
case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break;
|
|
|
|
|
2004-01-05 09:28:27 +00:00
|
|
|
case 1:
|
|
|
|
case 40: p = _("Usage: gpgconf [options] (-h for help)");
|
|
|
|
break;
|
|
|
|
case 41:
|
|
|
|
p = _("Syntax: gpgconf [options]\n"
|
|
|
|
"Manage configuration options for tools of the GnuPG system\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: p = NULL; break;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-23 18:13:27 +00:00
|
|
|
/* Return the fp for the output. This is usually stdout unless
|
|
|
|
--output has been used. In the latter case this function opens
|
|
|
|
that file. */
|
2010-08-18 19:25:15 +00:00
|
|
|
static estream_t
|
|
|
|
get_outfp (estream_t *fp)
|
2007-10-23 18:13:27 +00:00
|
|
|
{
|
|
|
|
if (!*fp)
|
|
|
|
{
|
|
|
|
if (opt.outfile)
|
|
|
|
{
|
2010-08-18 19:25:15 +00:00
|
|
|
*fp = es_fopen (opt.outfile, "w");
|
2007-10-23 18:13:27 +00:00
|
|
|
if (!*fp)
|
|
|
|
gc_error (1, errno, "can not open `%s'", opt.outfile);
|
|
|
|
}
|
|
|
|
else
|
2010-08-18 19:25:15 +00:00
|
|
|
*fp = es_stdout;
|
2007-10-23 18:13:27 +00:00
|
|
|
}
|
|
|
|
return *fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-05 09:28:27 +00:00
|
|
|
/* gpgconf main. */
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
ARGPARSE_ARGS pargs;
|
|
|
|
const char *fname;
|
|
|
|
int no_more_options = 0;
|
|
|
|
enum cmd_and_opt_values cmd = 0;
|
2010-08-18 19:25:15 +00:00
|
|
|
estream_t outfp = NULL;
|
2004-01-05 09:28:27 +00:00
|
|
|
|
2009-06-08 08:15:34 +00:00
|
|
|
gnupg_reopen_std ("gpgconf");
|
2004-01-05 09:28:27 +00:00
|
|
|
set_strusage (my_strusage);
|
|
|
|
log_set_prefix ("gpgconf", 1);
|
|
|
|
|
2007-06-14 17:05:07 +00:00
|
|
|
/* Make sure that our subsystems are ready. */
|
2004-01-05 09:28:27 +00:00
|
|
|
i18n_init();
|
2010-03-22 12:46:05 +00:00
|
|
|
init_common_subsystems (&argc, &argv);
|
2004-01-05 09:28:27 +00:00
|
|
|
|
2004-02-23 20:31:35 +00:00
|
|
|
/* Parse the command line. */
|
2004-01-05 09:28:27 +00:00
|
|
|
pargs.argc = &argc;
|
|
|
|
pargs.argv = &argv;
|
2004-02-23 20:31:35 +00:00
|
|
|
pargs.flags = 1; /* Do not remove the args. */
|
2004-01-05 09:28:27 +00:00
|
|
|
while (!no_more_options && optfile_parse (NULL, NULL, NULL, &pargs, opts))
|
|
|
|
{
|
|
|
|
switch (pargs.r_opt)
|
|
|
|
{
|
|
|
|
case oOutput: opt.outfile = pargs.r.ret_str; break;
|
2004-01-28 23:58:18 +00:00
|
|
|
case oQuiet: opt.quiet = 1; break;
|
2004-01-05 09:28:27 +00:00
|
|
|
case oDryRun: opt.dry_run = 1; break;
|
2004-02-23 20:31:35 +00:00
|
|
|
case oRuntime:
|
|
|
|
opt.runtime = 1;
|
|
|
|
break;
|
2004-01-05 09:28:27 +00:00
|
|
|
case oVerbose: opt.verbose++; break;
|
|
|
|
case oNoVerbose: opt.verbose = 0; break;
|
|
|
|
|
2008-05-26 13:43:20 +00:00
|
|
|
case aListDirs:
|
2004-01-28 23:58:18 +00:00
|
|
|
case aListComponents:
|
2007-08-29 09:51:37 +00:00
|
|
|
case aCheckPrograms:
|
2004-01-28 23:58:18 +00:00
|
|
|
case aListOptions:
|
|
|
|
case aChangeOptions:
|
2008-05-19 22:46:41 +00:00
|
|
|
case aCheckOptions:
|
2007-03-06 20:44:41 +00:00
|
|
|
case aApplyDefaults:
|
2007-10-23 18:13:27 +00:00
|
|
|
case aListConfig:
|
2007-03-06 20:44:41 +00:00
|
|
|
case aCheckConfig:
|
2009-03-03 09:02:58 +00:00
|
|
|
case aReload:
|
2011-02-23 10:15:34 +01:00
|
|
|
case aKill:
|
2004-01-28 23:58:18 +00:00
|
|
|
cmd = pargs.r_opt;
|
|
|
|
break;
|
|
|
|
|
2004-01-05 09:28:27 +00:00
|
|
|
default: pargs.err = 2; break;
|
|
|
|
}
|
|
|
|
}
|
2004-02-23 20:31:35 +00:00
|
|
|
|
2004-01-05 09:28:27 +00:00
|
|
|
if (log_get_errorcount (0))
|
|
|
|
exit (2);
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
fname = argc ? *argv : NULL;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2004-01-05 09:28:27 +00:00
|
|
|
switch (cmd)
|
|
|
|
{
|
2004-01-28 23:58:18 +00:00
|
|
|
case aListComponents:
|
2004-01-05 09:28:27 +00:00
|
|
|
default:
|
2004-01-28 23:58:18 +00:00
|
|
|
/* List all components. */
|
2007-10-23 18:13:27 +00:00
|
|
|
gc_component_list_components (get_outfp (&outfp));
|
2004-01-05 09:28:27 +00:00
|
|
|
break;
|
2004-01-28 23:58:18 +00:00
|
|
|
|
2007-08-29 09:51:37 +00:00
|
|
|
case aCheckPrograms:
|
|
|
|
/* Check all programs. */
|
2008-05-19 22:46:41 +00:00
|
|
|
gc_check_programs (get_outfp (&outfp));
|
2007-08-29 09:51:37 +00:00
|
|
|
break;
|
|
|
|
|
2004-01-28 23:58:18 +00:00
|
|
|
case aListOptions:
|
|
|
|
case aChangeOptions:
|
2008-05-19 22:46:41 +00:00
|
|
|
case aCheckOptions:
|
2004-01-28 23:58:18 +00:00
|
|
|
if (!fname)
|
|
|
|
{
|
2010-08-18 19:25:15 +00:00
|
|
|
es_fputs (_("usage: gpgconf [options] "), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
|
|
|
es_fputs (_("Need one component argument"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
2004-01-28 23:58:18 +00:00
|
|
|
exit (2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int idx = gc_component_find (fname);
|
|
|
|
if (idx < 0)
|
|
|
|
{
|
2010-08-18 19:25:15 +00:00
|
|
|
es_fputs (_("Component not found"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
2004-01-28 23:58:18 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
2010-08-20 12:18:38 +00:00
|
|
|
if (cmd == aCheckOptions)
|
2008-05-19 22:46:41 +00:00
|
|
|
gc_component_check_options (idx, get_outfp (&outfp), NULL);
|
2010-08-20 12:18:38 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gc_component_retrieve_options (idx);
|
|
|
|
if (gc_process_gpgconf_conf (NULL, 1, 0, NULL))
|
|
|
|
exit (1);
|
|
|
|
if (cmd == aListOptions)
|
|
|
|
gc_component_list_options (idx, get_outfp (&outfp));
|
|
|
|
else if (cmd == aChangeOptions)
|
|
|
|
gc_component_change_options (idx, es_stdin, get_outfp (&outfp));
|
|
|
|
}
|
2004-01-28 23:58:18 +00:00
|
|
|
}
|
2007-03-06 20:44:41 +00:00
|
|
|
break;
|
|
|
|
|
2011-02-23 10:15:34 +01:00
|
|
|
case aKill:
|
|
|
|
if (!fname)
|
|
|
|
{
|
|
|
|
es_fputs (_("usage: gpgconf [options] "), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
|
|
|
es_fputs (_("Need one component argument"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
|
|
|
exit (2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Kill a given component. */
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = gc_component_find (fname);
|
|
|
|
if (idx < 0)
|
|
|
|
{
|
|
|
|
es_fputs (_("Component not found"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gc_component_kill (idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-03-03 09:02:58 +00:00
|
|
|
case aReload:
|
|
|
|
if (!fname)
|
|
|
|
{
|
|
|
|
/* Reload all. */
|
|
|
|
gc_component_reload (-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Reload given component. */
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = gc_component_find (fname);
|
|
|
|
if (idx < 0)
|
|
|
|
{
|
2010-08-18 19:25:15 +00:00
|
|
|
es_fputs (_("Component not found"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
2009-03-03 09:02:58 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gc_component_reload (idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-10-23 18:13:27 +00:00
|
|
|
case aListConfig:
|
|
|
|
if (gc_process_gpgconf_conf (fname, 0, 0, get_outfp (&outfp)))
|
|
|
|
exit (1);
|
|
|
|
break;
|
|
|
|
|
2007-03-06 20:44:41 +00:00
|
|
|
case aCheckConfig:
|
2007-10-23 18:13:27 +00:00
|
|
|
if (gc_process_gpgconf_conf (fname, 0, 0, NULL))
|
2007-03-06 20:44:41 +00:00
|
|
|
exit (1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case aApplyDefaults:
|
|
|
|
if (fname)
|
|
|
|
{
|
2010-08-18 19:25:15 +00:00
|
|
|
es_fputs (_("usage: gpgconf [options] "), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
|
|
|
es_fputs (_("No argument allowed"), es_stderr);
|
|
|
|
es_putc ('\n', es_stderr);
|
2007-03-06 20:44:41 +00:00
|
|
|
exit (2);
|
|
|
|
}
|
|
|
|
gc_component_retrieve_options (-1);
|
2007-10-23 18:13:27 +00:00
|
|
|
if (gc_process_gpgconf_conf (NULL, 1, 1, NULL))
|
2007-03-06 20:44:41 +00:00
|
|
|
exit (1);
|
|
|
|
break;
|
2011-02-23 10:15:34 +01:00
|
|
|
|
2008-05-26 13:43:20 +00:00
|
|
|
case aListDirs:
|
2009-01-20 19:24:24 +00:00
|
|
|
/* Show the system configuration directories for gpgconf. */
|
2008-05-26 13:43:20 +00:00
|
|
|
get_outfp (&outfp);
|
2010-08-18 19:25:15 +00:00
|
|
|
es_fprintf (outfp, "sysconfdir:%s\n",
|
|
|
|
gc_percent_escape (gnupg_sysconfdir ()));
|
|
|
|
es_fprintf (outfp, "bindir:%s\n",
|
|
|
|
gc_percent_escape (gnupg_bindir ()));
|
|
|
|
es_fprintf (outfp, "libexecdir:%s\n",
|
|
|
|
gc_percent_escape (gnupg_libexecdir ()));
|
|
|
|
es_fprintf (outfp, "libdir:%s\n",
|
|
|
|
gc_percent_escape (gnupg_libdir ()));
|
|
|
|
es_fprintf (outfp, "datadir:%s\n",
|
|
|
|
gc_percent_escape (gnupg_datadir ()));
|
|
|
|
es_fprintf (outfp, "localedir:%s\n",
|
|
|
|
gc_percent_escape (gnupg_localedir ()));
|
|
|
|
es_fprintf (outfp, "dirmngr-socket:%s\n",
|
|
|
|
gc_percent_escape (dirmngr_socket_name ()));
|
2009-01-20 19:24:24 +00:00
|
|
|
{
|
|
|
|
char *infostr = getenv ("GPG_AGENT_INFO");
|
|
|
|
|
|
|
|
if (!infostr || !*infostr)
|
|
|
|
infostr = make_filename (default_homedir (), "S.gpg-agent", NULL);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
infostr = xstrdup (infostr);
|
|
|
|
tmp = strchr (infostr, PATHSEP_C);
|
|
|
|
if (!tmp || tmp == infostr)
|
|
|
|
{
|
|
|
|
xfree (infostr);
|
|
|
|
infostr = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*tmp = 0;
|
|
|
|
}
|
2010-08-18 19:25:15 +00:00
|
|
|
es_fprintf (outfp, "agent-socket:%s\n",
|
|
|
|
infostr? gc_percent_escape (infostr) : "");
|
2009-01-20 19:24:24 +00:00
|
|
|
xfree (infostr);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
/* We need to use make_filename to expand a possible "~/". */
|
|
|
|
char *tmp = make_filename (default_homedir (), NULL);
|
2010-08-18 19:25:15 +00:00
|
|
|
es_fprintf (outfp, "homedir:%s\n", gc_percent_escape (tmp));
|
2009-01-20 19:24:24 +00:00
|
|
|
xfree (tmp);
|
|
|
|
}
|
2008-05-26 13:43:20 +00:00
|
|
|
break;
|
2004-01-05 09:28:27 +00:00
|
|
|
}
|
|
|
|
|
2010-08-18 19:25:15 +00:00
|
|
|
if (outfp != es_stdout)
|
|
|
|
if (es_fclose (outfp))
|
2007-10-23 18:13:27 +00:00
|
|
|
gc_error (1, errno, "error closing `%s'", opt.outfile);
|
2004-01-05 09:28:27 +00:00
|
|
|
|
2011-02-23 10:15:34 +01:00
|
|
|
return 0;
|
2007-10-23 18:13:27 +00:00
|
|
|
}
|