2004-01-05 10:28:27 +01:00
|
|
|
/* gpgconf.c - Configuration utility for GnuPG
|
|
|
|
* Copyright (C) 2003 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
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gpgconf.h"
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
/* Constants to identify the commands and options. */
|
|
|
|
enum cmd_and_opt_values
|
|
|
|
{
|
|
|
|
aNull = 0,
|
|
|
|
oDryRun = 'n',
|
|
|
|
oOutput = 'o',
|
2004-01-29 00:58:18 +01:00
|
|
|
oQuiet = 'q',
|
2004-01-05 10:28:27 +01:00
|
|
|
oVerbose = 'v',
|
2004-02-23 21:31:35 +01:00
|
|
|
oRuntime = 'r',
|
2004-01-29 00:58:18 +01:00
|
|
|
oComponent = 'c',
|
2004-01-05 10:28:27 +01:00
|
|
|
oNoVerbose = 500,
|
|
|
|
oHomedir,
|
2004-01-29 00:58:18 +01:00
|
|
|
|
|
|
|
aListComponents,
|
|
|
|
aListOptions,
|
|
|
|
aChangeOptions,
|
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* The list of commands and options. */
|
|
|
|
static ARGPARSE_OPTS opts[] =
|
|
|
|
{
|
|
|
|
{ 300, NULL, 0, N_("@Commands:\n ") },
|
|
|
|
|
2004-01-29 00:58:18 +01:00
|
|
|
{ aListComponents, "list-components", 256, N_("list all components") },
|
|
|
|
{ aListOptions, "list-options", 256, N_("|COMPONENT|list options") },
|
|
|
|
{ aChangeOptions, "change-options", 256, N_("|COMPONENT|change options") },
|
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
{ 301, NULL, 0, N_("@\nOptions:\n ") },
|
|
|
|
|
2004-01-29 00:58:18 +01:00
|
|
|
{ oOutput, "output", 2, N_("use as output file") },
|
2004-01-05 10:28:27 +01:00
|
|
|
{ oVerbose, "verbose", 0, N_("verbose") },
|
2004-01-29 00:58:18 +01:00
|
|
|
{ oQuiet, "quiet", 0, N_("quiet") },
|
2004-01-05 10:28:27 +01:00
|
|
|
{ oDryRun, "dry-run", 0, N_("do not make any changes") },
|
2004-02-23 21:31:35 +01:00
|
|
|
{ oRuntime, "runtime", 0, N_("activate changes at runtime, if possible") },
|
2004-01-29 00:58:18 +01:00
|
|
|
|
2004-01-05 10:28:27 +01: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;
|
|
|
|
case 19: p = _("Please report bugs to <" PACKAGE_BUGREPORT ">.\n");
|
|
|
|
break;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize the gettext system. */
|
|
|
|
static void
|
|
|
|
i18n_init(void)
|
|
|
|
{
|
|
|
|
#ifdef USE_SIMPLE_GETTEXT
|
2004-04-06 12:01:04 +02:00
|
|
|
set_gettext_file (PACKAGE_GT);
|
2004-01-05 10:28:27 +01:00
|
|
|
#else
|
|
|
|
# ifdef ENABLE_NLS
|
|
|
|
# ifdef HAVE_LC_MESSAGES
|
|
|
|
setlocale (LC_TIME, "");
|
|
|
|
setlocale (LC_MESSAGES, "");
|
|
|
|
# else
|
|
|
|
setlocale (LC_ALL, "" );
|
|
|
|
# endif
|
2004-04-06 12:01:04 +02:00
|
|
|
bindtextdomain (PACKAGE_GT, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE_GT);
|
2004-01-05 10:28:27 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
set_strusage (my_strusage);
|
|
|
|
log_set_prefix ("gpgconf", 1);
|
|
|
|
|
|
|
|
i18n_init();
|
|
|
|
|
2004-02-23 21:31:35 +01:00
|
|
|
/* Parse the command line. */
|
2004-01-05 10:28:27 +01:00
|
|
|
pargs.argc = &argc;
|
|
|
|
pargs.argv = &argv;
|
2004-02-23 21:31:35 +01:00
|
|
|
pargs.flags = 1; /* Do not remove the args. */
|
2004-01-05 10:28:27 +01: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-29 00:58:18 +01:00
|
|
|
case oQuiet: opt.quiet = 1; break;
|
2004-01-05 10:28:27 +01:00
|
|
|
case oDryRun: opt.dry_run = 1; break;
|
2004-02-23 21:31:35 +01:00
|
|
|
case oRuntime:
|
|
|
|
opt.runtime = 1;
|
|
|
|
break;
|
2004-01-05 10:28:27 +01:00
|
|
|
case oVerbose: opt.verbose++; break;
|
|
|
|
case oNoVerbose: opt.verbose = 0; break;
|
|
|
|
|
2004-01-29 00:58:18 +01:00
|
|
|
case aListComponents:
|
|
|
|
case aListOptions:
|
|
|
|
case aChangeOptions:
|
|
|
|
cmd = pargs.r_opt;
|
|
|
|
break;
|
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
default: pargs.err = 2; break;
|
|
|
|
}
|
|
|
|
}
|
2004-02-23 21:31:35 +01:00
|
|
|
|
2004-01-05 10:28:27 +01:00
|
|
|
if (log_get_errorcount (0))
|
|
|
|
exit (2);
|
|
|
|
|
2004-01-29 00:58:18 +01:00
|
|
|
fname = argc ? *argv : NULL;
|
2004-01-05 10:28:27 +01:00
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
2004-01-29 00:58:18 +01:00
|
|
|
case aListComponents:
|
2004-01-05 10:28:27 +01:00
|
|
|
default:
|
2004-01-29 00:58:18 +01:00
|
|
|
/* List all components. */
|
|
|
|
gc_component_list_components (stdout);
|
2004-01-05 10:28:27 +01:00
|
|
|
break;
|
2004-01-29 00:58:18 +01:00
|
|
|
|
|
|
|
case aListOptions:
|
|
|
|
case aChangeOptions:
|
|
|
|
if (!fname)
|
|
|
|
{
|
|
|
|
fputs (N_("usage: gpgconf [options] "), stderr);
|
|
|
|
fputs (N_("Need one component argument"), stderr);
|
|
|
|
putc ('\n',stderr);
|
|
|
|
exit (2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int idx = gc_component_find (fname);
|
|
|
|
if (idx < 0)
|
|
|
|
{
|
|
|
|
fputs (N_("Component not found"), stderr);
|
|
|
|
putc ('\n', stderr);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
gc_component_retrieve_options (idx);
|
|
|
|
if (cmd == aListOptions)
|
|
|
|
gc_component_list_options (idx, stdout);
|
|
|
|
else
|
|
|
|
gc_component_change_options (idx, stdin);
|
|
|
|
}
|
2004-01-05 10:28:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|