From c69c51bce0f07bf1becdb944a422bdc563705dae Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 30 Dec 2021 10:18:23 +0100 Subject: [PATCH] gpgconf: Do not list ignored options and mark forced options as r/o. * tools/gpgconf-comp.c (list_one_option): Skip ignored options and set the no_change flag for forced options. (retrieve_options_from_program): Put the attributes into the option table. -- (cherry picked from commit 42785d7c8a524129d9fe1a5afae553ff73f8e25b) This commit also marks the end of the back port as requested by GnuPG-bug-id: 5732 --- tools/gpgconf-comp.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c index ba21bf423..7f5eafa4d 100644 --- a/tools/gpgconf-comp.c +++ b/tools/gpgconf-comp.c @@ -1316,6 +1316,10 @@ list_one_option (gc_component_id_t component, unsigned long flags; const char *desc_domain = gc_component[component].desc_domain; + /* Don't show options with the ignore attribute. */ + if (option->attr_ignore && !option->attr_force) + return; + if (option->desc) { desc = my_dgettext (desc_domain, option->desc); @@ -1352,6 +1356,7 @@ list_one_option (gc_component_id_t component, if (option->def_in_desc) flags |= GC_OPT_FLAG_DEF_DESC; if (option->no_arg_desc) flags |= GC_OPT_FLAG_NO_ARG_DESC; if (option->no_change) flags |= GC_OPT_FLAG_NO_CHANGE; + if (option->attr_force) flags |= GC_OPT_FLAG_NO_CHANGE; es_fprintf (out, ":%lu", flags); if (opt.verbose) { @@ -1835,11 +1840,6 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed) { char *opt_value; - if (pargs.r_type & ARGPARSE_OPT_IGNORE) - { - /* log_debug ("ignored\n"); */ - continue; - } if (pargs.r_opt == ARGPARSE_CONFFILE) { /* log_debug ("current conffile='%s'\n", */ @@ -1861,8 +1861,18 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed) if (!option) continue; /* We don't want to handle this option. */ - option->attr_ignore = !!(pargs.r_type & ARGPARSE_ATTR_IGNORE); - option->attr_force = !!(pargs.r_type & ARGPARSE_ATTR_FORCE); + /* Set the force and ignore attributes. The idea is that there + * is no way to clear them again, thus we set them when first + * encountered. */ + if ((pargs.r_type & ARGPARSE_ATTR_FORCE)) + option->attr_force = 1; + if ((pargs.r_type & ARGPARSE_ATTR_IGNORE)) + option->attr_ignore = 1; + + /* If an option has been ignored, there is no need to return + * that option with gpgconf --list-options. */ + if (option->attr_ignore) + continue; switch ((pargs.r_type & ARGPARSE_TYPE_MASK)) {