From 7d6ad2866722aaa27b33338d0fbb33c7b6b94808 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 17 Apr 2024 12:16:20 +0200 Subject: [PATCH] gpg: Mark disabled keys and add show-ownertrust list option. * g10/options.h (LIST_SHOW_OWNERTRUST): New. * g10/keylist.c (print_key_line): Show wonertrust and always show whether a key is disabled. * g10/gpg.c (parse_list_options): Add "show-ownertrust". * g10/gpgv.c (get_ownertrust_string): Add stub. * g10/test-stubs.c (get_ownertrust_string): Add stub. -- Note that in a --with-colons listing the ownertrust has always been emitted and the disabled state is marked in that listing with a special 'D' usage. --- doc/gpg.texi | 5 +++++ g10/gpg.c | 2 ++ g10/gpgv.c | 8 ++++++++ g10/keylist.c | 18 ++++++++---------- g10/options.h | 1 + g10/test-stubs.c | 9 +++++++++ 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/doc/gpg.texi b/doc/gpg.texi index 2fe6a8448..10a1937f6 100644 --- a/doc/gpg.texi +++ b/doc/gpg.texi @@ -1403,6 +1403,11 @@ give the opposite meaning. The options are: key (@code{E}=encryption, @code{S}=signing, @code{C}=certification, @code{A}=authentication). Defaults to yes. + @item show-ownertrust + @opindex list-options:show-ownertrust + Show the ownertrust value for keys also in the standard key + listing. Defaults to no. + @item show-policy-urls @opindex list-options:show-policy-urls Show policy URLs in the @option{--check-signatures} diff --git a/g10/gpg.c b/g10/gpg.c index 7cb83c443..658fb7cf1 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -2113,6 +2113,8 @@ parse_list_options(char *str) N_("show preferences")}, {"show-pref-verbose", LIST_SHOW_PREF_VERBOSE, NULL, N_("show preferences")}, + {"show-ownertrust", LIST_SHOW_OWNERTRUST, NULL, + N_("show ownertrust")}, {"show-only-fpr-mbox",LIST_SHOW_ONLY_FPR_MBOX, NULL, NULL}, {"sort-sigs", LIST_SORT_SIGS, NULL, diff --git a/g10/gpgv.c b/g10/gpgv.c index c3b09f752..50ec3917a 100644 --- a/g10/gpgv.c +++ b/g10/gpgv.c @@ -426,6 +426,14 @@ get_ownertrust (ctrl_t ctrl, PKT_public_key *pk) return TRUST_UNKNOWN; } +const char * +get_ownertrust_string (ctrl_t ctrl, PKT_public_key *pk, int no_create) +{ + (void)ctrl; + (void)pk; + (void)no_create; + return ""; +} /* Stubs: * Because we only work with trusted keys, it does not make sense to diff --git a/g10/keylist.c b/g10/keylist.c index 7fb5eff72..7717ca563 100644 --- a/g10/keylist.c +++ b/g10/keylist.c @@ -2600,6 +2600,11 @@ print_key_line (ctrl_t ctrl, estream_t fp, PKT_public_key *pk, int secret) tty_fprintf (fp, " [%s]", usagestr_from_pk (pk, 0)); } + if (pk->flags.primary && (opt.list_options & LIST_SHOW_OWNERTRUST)) + { + tty_fprintf (fp, " [%s]", get_ownertrust_string (ctrl, pk, 0)); + } + if (pk->flags.revoked) { tty_fprintf (fp, " ["); @@ -2619,21 +2624,14 @@ print_key_line (ctrl_t ctrl, estream_t fp, PKT_public_key *pk, int secret) tty_fprintf (fp, "]"); } -#if 0 - /* I need to think about this some more. It's easy enough to - include, but it looks sort of confusing in the listing... */ - if (opt.list_options & LIST_SHOW_VALIDITY) - { - int validity = get_validity (ctrl, pk, NULL, NULL, 0); - tty_fprintf (fp, " [%s]", trust_value_to_string (validity)); - } -#endif - if (pk->pubkey_algo >= 100) tty_fprintf (fp, " [experimental algorithm %d]", pk->pubkey_algo); tty_fprintf (fp, "\n"); + if (pk->flags.primary && pk_is_disabled (pk)) + es_fprintf (es_stdout, " *** %s\n", _("This key has been disabled")); + /* if the user hasn't explicitly asked for human-readable fingerprints, show compact fpr of primary key: */ if (pk->flags.primary && diff --git a/g10/options.h b/g10/options.h index e810adfb9..2fe4f5bbf 100644 --- a/g10/options.h +++ b/g10/options.h @@ -445,6 +445,7 @@ EXTERN_UNLESS_MAIN_MODULE int memory_stat_debug_mode; #define LIST_SHOW_UNUSABLE_SIGS (1<<16) #define LIST_SHOW_X509_NOTATIONS (1<<17) #define LIST_STORE_X509_NOTATIONS (1<<18) +#define LIST_SHOW_OWNERTRUST (1<<19) #define VERIFY_SHOW_PHOTOS (1<<0) #define VERIFY_SHOW_POLICY_URLS (1<<1) diff --git a/g10/test-stubs.c b/g10/test-stubs.c index d9bead754..00145c12b 100644 --- a/g10/test-stubs.c +++ b/g10/test-stubs.c @@ -155,6 +155,15 @@ get_ownertrust_info (ctrl_t ctrl, PKT_public_key *pk, int no_create) return '?'; } +const char * +get_ownertrust_string (ctrl_t ctrl, PKT_public_key *pk, int no_create) +{ + (void)ctrl; + (void)pk; + (void)no_create; + return ""; +} + unsigned int get_ownertrust (ctrl_t ctrl, PKT_public_key *pk) {