1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
From: Werner Koch <wk@gnupg.org>
Date: Thu, 15 Nov 2018 18:24:56 -0500
Subject: gpg: Avoid superfluous sig check info during import.
* g10/key-check.c (print_info): New.
(key_check_all_keysigs): Print sig checking results only in debug
mode. Prettify the stats info and suppress them in quiet mode.
--
This also makes usable stats by prefixing them with the key and the
program name.
GnuPG-bug-id: 3397
Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry-picked/backported from upstream
84af859e391a757877c9a1d78e35face983e6d23 by dkg)
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
---
g10/keyedit.c | 133 +++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 95 insertions(+), 38 deletions(-)
diff --git a/g10/keyedit.c b/g10/keyedit.c
index 3d6c5d4c4..bdeb251f9 100644
--- a/g10/keyedit.c
+++ b/g10/keyedit.c
@@ -329,6 +329,26 @@ print_and_check_one_sig (KBNODE keyblock, KBNODE node,
}
+/* Print PREFIX followed by TEXT. With mode > 0 use log_info, with
+ * mode < 0 use ttyio, else print to stdout. If TEXT is not NULL, it
+ * may be modified by this function. */
+static void
+print_info (int mode, const char *prefix, char *text)
+{
+ char *p;
+
+ if (!text)
+ text = "";
+ else if ((p = strchr (text,'\n')))
+ *p = 0; /* Strip LF. */
+
+ if (mode > 0)
+ log_info ("%s %s\n", prefix, text);
+ else
+ tty_fprintf (mode? NULL:es_stdout, "%s %s\n", prefix, text);
+}
+
+
/* Order two signatures. The actual ordering isn't important. Our
goal is to ensure that identical signatures occur together. */
@@ -766,8 +786,9 @@ check_all_keysigs (KBNODE kb, int only_selected, int only_selfsigs)
has_selfsig = 1;
}
- if ((n2 && n2 != last_printed_component)
- || (! n2 && last_printed_component != current_component))
+ if (DBG_PACKET
+ && ((n2 && n2 != last_printed_component)
+ || (! n2 && last_printed_component != current_component)))
{
int is_reordered = n2 && n2 != current_component;
if (n2)
@@ -779,31 +800,32 @@ check_all_keysigs (KBNODE kb, int only_selected, int only_selfsigs)
;
else if (last_printed_component->pkt->pkttype == PKT_USER_ID)
{
- tty_printf ("uid ");
- tty_print_utf8_string (last_printed_component
- ->pkt->pkt.user_id->name,
- last_printed_component
- ->pkt->pkt.user_id->len);
+ log_debug ("uid ");
+ print_utf8_buffer (log_get_stream (),
+ last_printed_component
+ ->pkt->pkt.user_id->name,
+ last_printed_component
+ ->pkt->pkt.user_id->len);
+ log_flush ();
}
else if (last_printed_component->pkt->pkttype
== PKT_PUBLIC_KEY)
- tty_printf ("pub %s",
- pk_keyid_str (last_printed_component
- ->pkt->pkt.public_key));
+ log_debug ("pub %s",
+ pk_keyid_str (last_printed_component
+ ->pkt->pkt.public_key));
else
- tty_printf ("sub %s",
- pk_keyid_str (last_printed_component
- ->pkt->pkt.public_key));
+ log_debug ("sub %s",
+ pk_keyid_str (last_printed_component
+ ->pkt->pkt.public_key));
if (modified)
{
if (is_reordered)
- tty_printf (_(" (reordered signatures follow)"));
- tty_printf ("\n");
+ log_debug ("%s\n", _(" (reordered signatures follow)"));
}
}
- if (modified)
+ if (DBG_PACKET && modified)
print_one_sig (rc, kb, n, NULL, NULL, NULL, has_selfsig,
0, only_selfsigs);
}
@@ -910,28 +932,63 @@ check_all_keysigs (KBNODE kb, int only_selected, int only_selfsigs)
}
}
- if (dups || missing_issuer || bad_signature || reordered)
- tty_printf (_("key %s:\n"), pk_keyid_str (pk));
-
- if (dups)
- tty_printf (ngettext ("%d duplicate signature removed\n",
- "%d duplicate signatures removed\n", dups), dups);
- if (missing_issuer)
- tty_printf (ngettext ("%d signature not checked due to a missing key\n",
- "%d signatures not checked due to missing keys\n",
- missing_issuer), missing_issuer);
- if (bad_signature)
- tty_printf (ngettext ("%d bad signature\n",
- "%d bad signatures\n",
- bad_signature), bad_signature);
- if (reordered)
- tty_printf (ngettext ("%d signature reordered\n",
- "%d signatures reordered\n",
- reordered), reordered);
-
- if (only_selfsigs && (bad_signature || reordered))
- tty_printf (_("Warning: errors found and only checked self-signatures,"
- " run '%s' to check all signatures.\n"), "check");
+ if (!opt.quiet)
+ {
+ char prefix[100];
+ char *p;
+ int mode = 1;
+
+ /* To avoid string changes in 2.2 we strip the LF here. */
+ snprintf (prefix, sizeof prefix, _("key %s:\n"), pk_keyid_str (pk));
+ p = strrchr (prefix, '\n');
+ if (p)
+ *p = 0;
+
+ if (dups)
+ {
+ p = xtryasprintf
+ (ngettext ("%d duplicate signature removed\n",
+ "%d duplicate signatures removed\n", dups), dups);
+ print_info (mode, prefix, p);
+ xfree (p);
+ }
+
+ if (missing_issuer)
+ {
+ p = xtryasprintf
+ (ngettext ("%d signature not checked due to a missing key\n",
+ "%d signatures not checked due to missing keys\n",
+ missing_issuer), missing_issuer);
+ print_info (mode, prefix, p);
+ xfree (p);
+ }
+ if (bad_signature)
+ {
+ p = xtryasprintf (ngettext ("%d bad signature\n",
+ "%d bad signatures\n",
+ bad_signature), bad_signature);
+ print_info (mode, prefix, p);
+ xfree (p);
+ }
+
+ if (reordered)
+ {
+ p = xtryasprintf (ngettext ("%d signature reordered\n",
+ "%d signatures reordered\n",
+ reordered), reordered);
+ print_info (mode, prefix, p);
+ xfree (p);
+ }
+
+ if (only_selfsigs && (bad_signature || reordered))
+ {
+ p = xtryasprintf
+ (_("Warning: errors found and only checked self-signatures,"
+ " run '%s' to check all signatures.\n"), "check");
+ print_info (mode, prefix, p);
+ xfree (p);
+ }
+ }
return modified;
}
|