1 /* gpgconf.c - Configuration utility for GnuPG
2 * Copyright (C) 2003, 2007 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
29 /* Constants to identify the commands and options. */
30 enum cmd_and_opt_values
53 /* The list of commands and options. */
54 static ARGPARSE_OPTS opts
[] =
56 { 300, NULL
, 0, N_("@Commands:\n ") },
58 { aListComponents
, "list-components", 256, N_("list all components") },
59 { aCheckPrograms
, "check-programs", 256, N_("check all programs") },
60 { aListOptions
, "list-options", 256, N_("|COMPONENT|list options") },
61 { aChangeOptions
, "change-options", 256, N_("|COMPONENT|change options") },
62 { aApplyDefaults
, "apply-defaults", 256,
63 N_("apply global default values") },
64 { aListConfig
, "list-config", 256,
65 N_("list global configuration file") },
66 { aCheckConfig
, "check-config", 256,
67 N_("check global configuration file") },
69 { 301, NULL
, 0, N_("@\nOptions:\n ") },
71 { oOutput
, "output", 2, N_("use as output file") },
72 { oVerbose
, "verbose", 0, N_("verbose") },
73 { oQuiet
, "quiet", 0, N_("quiet") },
74 { oDryRun
, "dry-run", 0, N_("do not make any changes") },
75 { oRuntime
, "runtime", 0, N_("activate changes at runtime, if possible") },
77 { oNoVerbose
, "no-verbose", 0, "@"},
82 /* Print usage information and and provide strings for help. */
84 my_strusage( int level
)
90 case 11: p
= "gpgconf (GnuPG)";
92 case 13: p
= VERSION
; break;
93 case 17: p
= PRINTABLE_OS_NAME
; break;
94 case 19: p
= _("Please report bugs to <" PACKAGE_BUGREPORT
">.\n");
97 case 40: p
= _("Usage: gpgconf [options] (-h for help)");
100 p
= _("Syntax: gpgconf [options]\n"
101 "Manage configuration options for tools of the GnuPG system\n");
104 default: p
= NULL
; break;
110 /* Return the fp for the output. This is usually stdout unless
111 --output has been used. In the latter case this function opens
114 get_outfp (FILE **fp
)
120 *fp
= fopen (opt
.outfile
, "w");
122 gc_error (1, errno
, "can not open `%s'", opt
.outfile
);
133 main (int argc
, char **argv
)
137 int no_more_options
= 0;
138 enum cmd_and_opt_values cmd
= 0;
141 set_strusage (my_strusage
);
142 log_set_prefix ("gpgconf", 1);
144 /* Make sure that our subsystems are ready. */
145 init_common_subsystems ();
149 /* Parse the command line. */
152 pargs
.flags
= 1; /* Do not remove the args. */
153 while (!no_more_options
&& optfile_parse (NULL
, NULL
, NULL
, &pargs
, opts
))
157 case oOutput
: opt
.outfile
= pargs
.r
.ret_str
; break;
158 case oQuiet
: opt
.quiet
= 1; break;
159 case oDryRun
: opt
.dry_run
= 1; break;
163 case oVerbose
: opt
.verbose
++; break;
164 case oNoVerbose
: opt
.verbose
= 0; break;
166 case aListComponents
:
176 default: pargs
.err
= 2; break;
180 if (log_get_errorcount (0))
183 fname
= argc
? *argv
: NULL
;
187 case aListComponents
:
189 /* List all components. */
190 gc_component_list_components (get_outfp (&outfp
));
194 /* Check all programs. */
195 gc_component_check_programs (get_outfp (&outfp
));
202 fputs (_("usage: gpgconf [options] "), stderr
);
204 fputs (_("Need one component argument"), stderr
);
210 int idx
= gc_component_find (fname
);
213 fputs (_("Component not found"), stderr
);
217 gc_component_retrieve_options (idx
);
218 if (gc_process_gpgconf_conf (NULL
, 1, 0, NULL
))
220 if (cmd
== aListOptions
)
221 gc_component_list_options (idx
, get_outfp (&outfp
));
223 gc_component_change_options (idx
, stdin
);
228 if (gc_process_gpgconf_conf (fname
, 0, 0, get_outfp (&outfp
)))
233 if (gc_process_gpgconf_conf (fname
, 0, 0, NULL
))
240 fputs (_("usage: gpgconf [options] "), stderr
);
242 fputs (_("No argument allowed"), stderr
);
246 gc_component_retrieve_options (-1);
247 if (gc_process_gpgconf_conf (NULL
, 1, 1, NULL
))
252 if (outfp
&& outfp
!= stdout
)
254 gc_error (1, errno
, "error closing `%s'", opt
.outfile
);