diff options
author | Werner Koch <wk@gnupg.org> | 2007-10-23 20:13:27 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2007-10-23 20:13:27 +0200 |
commit | fca02368da72f42f84e328ecbef04c40b2bfa4fb (patch) | |
tree | 5e79b188e8c6860497169c8a894405b0bc0c4930 /tools | |
parent | Fixed wrong entry in the gpg-agent table. (diff) | |
download | gnupg2-fca02368da72f42f84e328ecbef04c40b2bfa4fb.tar.xz gnupg2-fca02368da72f42f84e328ecbef04c40b2bfa4fb.zip |
New option --list-config for gpgconf.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/ChangeLog | 9 | ||||
-rw-r--r-- | tools/gpgconf-comp.c | 55 | ||||
-rw-r--r-- | tools/gpgconf.c | 52 | ||||
-rw-r--r-- | tools/gpgconf.h | 5 |
4 files changed, 98 insertions, 23 deletions
diff --git a/tools/ChangeLog b/tools/ChangeLog index 37652eb84..69a24302b 100644 --- a/tools/ChangeLog +++ b/tools/ChangeLog @@ -1,6 +1,13 @@ 2007-10-23 Werner Koch <wk@g10code.com> - * gpgconf-comp.c (gc_options_gpg_agent): Repalce accidently used + * gpgconf-comp.c (gc_process_gpgconf_conf): Add arg + LISTFP. Changed all callers. + * gpgconf.h: Add gc_error. + * gpgconf.c: Add command --list-config. + (get_outfp): New. + (main): Make --output work. + + * gpgconf-comp.c (gc_options_gpg_agent): Replace accidently used GC_BACKEND_SCDAEMON. We should consider to create these tables from plain files. diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c index 6e1d604e9..3cde74574 100644 --- a/tools/gpgconf-comp.c +++ b/tools/gpgconf-comp.c @@ -337,7 +337,7 @@ static struct argument value. */ #define GC_OPT_FLAG_LIST (1UL << 2) /* The NO_CHANGE flag for an option indicates that the user should not - be allowed to chnage this option using the standard gpgconf method. + be allowed to change this option using the standard gpgconf method. Frontends using gpgconf should grey out such options, so that only the current value is displayed. */ #define GC_OPT_FLAG_NO_CHANGE (1UL <<7) @@ -522,7 +522,7 @@ static gc_option_t gc_options_gpg_agent[] = { "Passphrase policy", GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED, "gnupg", N_("Options enforcing a passphrase policy") }, - { "enforce-passphrases-constraints", GC_OPT_FLAG_RUNTIME, + { "enforce-passphrase-constraints", GC_OPT_FLAG_RUNTIME, GC_LEVEL_EXPERT, "gnupg", N_("do not allow to bypass the passphrase policy"), GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT }, @@ -542,7 +542,7 @@ static gc_option_t gc_options_gpg_agent[] = GC_LEVEL_EXPERT, "gnupg", N_("|N|expire the passphrase after N days"), GC_ARG_TYPE_UINT32, GC_BACKEND_GPG_AGENT }, - { "enable-passphrases-history", GC_OPT_FLAG_RUNTIME, + { "enable-passphrase-history", GC_OPT_FLAG_RUNTIME, GC_LEVEL_EXPERT, "gnupg", N_("do not allow the reuse of old passphrases"), GC_ARG_TYPE_NONE, GC_BACKEND_GPG_AGENT }, @@ -3094,12 +3094,14 @@ key_matches_user_or_group (char *user) default name will be used. With UPDATE set to true the internal tables are actually updated; if not set, only a syntax check is done. If DEFAULTS is true the global options are written to the - configuration files. + configuration files. If LISTFP is set, no changes are done but the + configuration file is printed to LISTFP in a colon separated format. Returns 0 on success or if the config file is not present; -1 is returned on error. */ int -gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults) +gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults, + FILE *listfp) { int result = 0; char *line = NULL; @@ -3112,9 +3114,11 @@ gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults) int runtime[GC_BACKEND_NR]; int used_components[GC_COMPONENT_NR]; int backend_id, component_id; - char *fname = (char *) fname_arg; + char *fname; - if (!fname) + if (fname_arg) + fname = xstrdup (fname_arg); + else fname = make_filename (gnupg_sysconfdir (), "gpgconf.conf", NULL); for (backend_id = 0; backend_id < GC_BACKEND_NR; backend_id++) @@ -3126,7 +3130,7 @@ gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults) if (!config) { /* Do not print an error if the file is not available, except - when runnign in syntax check mode. */ + when running in syntax check mode. */ if (errno != ENOENT || !update) { gc_error (0, errno, "can not open global config file `%s'", fname); @@ -3295,12 +3299,41 @@ gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults) fname, lineno); result = -1; } - + + /* In list mode we print out all records. */ + if (listfp && !result) + { + /* If this is a new ruleset, print a key record. */ + if (!is_continuation) + { + char *group = strchr (key, ':'); + if (group) + { + *group++ = 0; + if ((p = strchr (group, ':'))) + *p = 0; /* We better strip any extra stuff. */ + } + + fprintf (listfp, "k:%s:", my_percent_escape (key)); + fprintf (listfp, "%s:\n", group? my_percent_escape (group):""); + } + + /* All other lines are rule records. */ + fprintf (listfp, "r:::%s:%s:%s:", + gc_component[component_id].name, + option_info->name? option_info->name : "", + flags? flags : ""); + if (value != empty) + fprintf (listfp, "\"%s", my_percent_escape (value)); + putc (':', listfp); + putc ('\n', listfp); + } + /* Check whether the key matches but do this only if we are not running in syntax check mode. */ if ( update - && !result + && !result && !listfp && (got_match || (key && key_matches_user_or_group (key))) ) { int newflags = 0; @@ -3348,7 +3381,7 @@ gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults) xfree (line); /* If it all worked, process the options. */ - if (!result && update && defaults) + if (!result && update && defaults && !listfp) { /* We need to switch off the runtime update, so that we can do it later all at once. */ diff --git a/tools/gpgconf.c b/tools/gpgconf.c index 3d81f0169..9c1c77a2d 100644 --- a/tools/gpgconf.c +++ b/tools/gpgconf.c @@ -44,6 +44,7 @@ enum cmd_and_opt_values aListOptions, aChangeOptions, aApplyDefaults, + aListConfig, aCheckConfig }; @@ -60,6 +61,8 @@ static ARGPARSE_OPTS opts[] = { aChangeOptions, "change-options", 256, N_("|COMPONENT|change options") }, { aApplyDefaults, "apply-defaults", 256, N_("apply global default values") }, + { aListConfig, "list-config", 256, + N_("list global configuration file") }, { aCheckConfig, "check-config", 256, N_("check global configuration file") }, @@ -104,6 +107,27 @@ my_strusage( int level ) } +/* Return the fp for the output. This is usually stdout unless + --output has been used. In the latter case this function opens + that file. */ +static FILE * +get_outfp (FILE **fp) +{ + if (!*fp) + { + if (opt.outfile) + { + *fp = fopen (opt.outfile, "w"); + if (!*fp) + gc_error (1, errno, "can not open `%s'", opt.outfile); + } + else + *fp = stdout; + } + return *fp; +} + + /* gpgconf main. */ int main (int argc, char **argv) @@ -112,6 +136,7 @@ main (int argc, char **argv) const char *fname; int no_more_options = 0; enum cmd_and_opt_values cmd = 0; + FILE *outfp = NULL; set_strusage (my_strusage); log_set_prefix ("gpgconf", 1); @@ -143,6 +168,7 @@ main (int argc, char **argv) case aListOptions: case aChangeOptions: case aApplyDefaults: + case aListConfig: case aCheckConfig: cmd = pargs.r_opt; break; @@ -161,12 +187,12 @@ main (int argc, char **argv) case aListComponents: default: /* List all components. */ - gc_component_list_components (stdout); + gc_component_list_components (get_outfp (&outfp)); break; case aCheckPrograms: /* Check all programs. */ - gc_component_check_programs (stdout); + gc_component_check_programs (get_outfp (&outfp)); break; case aListOptions: @@ -189,17 +215,22 @@ main (int argc, char **argv) exit (1); } gc_component_retrieve_options (idx); - if (gc_process_gpgconf_conf (NULL, 1, 0)) + if (gc_process_gpgconf_conf (NULL, 1, 0, NULL)) exit (1); if (cmd == aListOptions) - gc_component_list_options (idx, stdout); + gc_component_list_options (idx, get_outfp (&outfp)); else gc_component_change_options (idx, stdin); } break; + case aListConfig: + if (gc_process_gpgconf_conf (fname, 0, 0, get_outfp (&outfp))) + exit (1); + break; + case aCheckConfig: - if (gc_process_gpgconf_conf (fname, 0, 0)) + if (gc_process_gpgconf_conf (fname, 0, 0, NULL)) exit (1); break; @@ -213,14 +244,15 @@ main (int argc, char **argv) exit (2); } gc_component_retrieve_options (-1); - if (gc_process_gpgconf_conf (NULL, 1, 1)) + if (gc_process_gpgconf_conf (NULL, 1, 1, NULL)) exit (1); break; - } - - return 0; -} + if (outfp && outfp != stdout) + if (fclose (outfp)) + gc_error (1, errno, "error closing `%s'", opt.outfile); + return 0; +} diff --git a/tools/gpgconf.h b/tools/gpgconf.h index f0d3c599d..2f4bd5216 100644 --- a/tools/gpgconf.h +++ b/tools/gpgconf.h @@ -37,6 +37,8 @@ struct /*-- gpgconf-comp.c --*/ +void gc_error (int status, int errnum, const char *fmt, ...); + /* List all components that are available. */ void gc_component_list_components (FILE *out); @@ -58,7 +60,8 @@ void gc_component_list_options (int component, FILE *out); void gc_component_change_options (int component, FILE *in); /* Process global configuration file. */ -int gc_process_gpgconf_conf (const char *fname, int update, int defaults); +int gc_process_gpgconf_conf (const char *fname, int update, int defaults, + FILE *listfp); #endif /*GPGCONF_H*/ |