diff options
author | Werner Koch <[email protected]> | 2014-03-27 11:59:55 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2014-03-27 11:59:55 +0000 |
commit | 4f50ec98ddd57253cae66e2321f0cc98ee189a09 (patch) | |
tree | feb4dc9662cfd4a2833cfdcb8587d47939b49fd4 | |
parent | agent: Replace es_mopen by es_fopenmem for ssh. (diff) | |
download | gnupg-4f50ec98ddd57253cae66e2321f0cc98ee189a09.tar.gz gnupg-4f50ec98ddd57253cae66e2321f0cc98ee189a09.zip |
Change some keyedit functions to allow printing to arbitrary streams.
* common/ttyio.c (tty_print_string): Add optional arg FP. Change all
callers.
(tty_print_utf8_string2): Ditto.
* g10/keyedit.c (show_prefs): Ditto.
(show_key_with_all_names_colon): Ditto.
(show_names): Ditto.
* g10/keylist.c (print_revokers): Ditto.
(print_fingerprint): Ditto.
-rw-r--r-- | common/ttyio.c | 115 | ||||
-rw-r--r-- | common/ttyio.h | 5 | ||||
-rw-r--r-- | g10/card-util.c | 6 | ||||
-rw-r--r-- | g10/keyedit.c | 245 | ||||
-rw-r--r-- | g10/keylist.c | 35 | ||||
-rw-r--r-- | g10/main.h | 4 | ||||
-rw-r--r-- | g10/mainproc.c | 6 | ||||
-rw-r--r-- | g10/pkclist.c | 18 |
8 files changed, 251 insertions, 183 deletions
diff --git a/common/ttyio.c b/common/ttyio.c index 66ca98401..dee11cb8f 100644 --- a/common/ttyio.c +++ b/common/ttyio.c @@ -310,53 +310,101 @@ tty_fprintf (estream_t fp, const char *fmt, ... ) /**************** - * Print a string, but filter all control characters out. + * Print a string, but filter all control characters out. If FP is + * not NULL print to that stream instead to the tty. */ void -tty_print_string ( const byte *p, size_t n ) +tty_print_string (estream_t fp, const byte *p, size_t n ) { - if (no_terminal) + if (no_terminal && !fp) return; - if( !initialized ) + if( !initialized & !fp) init_ttyfp(); #ifdef USE_W32_CONSOLE /* not so effective, change it if you want */ - for( ; n; n--, p++ ) - if( iscntrl( *p ) ) { - if( *p == '\n' ) - tty_printf("\\n"); - else if( !*p ) - tty_printf("\\0"); - else - tty_printf("\\x%02x", *p); - } - else - tty_printf("%c", *p); + if (fp) + { + for( ; n; n--, p++ ) + { + if( iscntrl( *p ) ) + { + if( *p == '\n' ) + tty_fprintf (fp, "\\n"); + else if( !*p ) + tty_fprintf (fp, "\\0"); + else + tty_fprintf (fp, "\\x%02x", *p); + } + else + tty_fprintf (fp, "%c", *p); + } + } + else + { + for( ; n; n--, p++ ) + { + if( iscntrl( *p ) ) + { + if( *p == '\n' ) + tty_printf ("\\n"); + else if( !*p ) + tty_printf ("\\0"); + else + tty_printf ("\\x%02x", *p); + } + else + tty_printf ("%c", *p); + } + } #else - for( ; n; n--, p++ ) - if( iscntrl( *p ) ) { - putc('\\', ttyfp); - if( *p == '\n' ) - putc('n', ttyfp); - else if( !*p ) - putc('0', ttyfp); - else - fprintf(ttyfp, "x%02x", *p ); - } - else - putc(*p, ttyfp); + if (fp) + { + for( ; n; n--, p++ ) + { + if (iscntrl (*p)) + { + es_putc ('\\', fp); + if ( *p == '\n' ) + es_putc ('n', fp); + else if ( !*p ) + es_putc ('0', fp); + else + es_fprintf (fp, "x%02x", *p); + } + else + es_putc (*p, fp); + } + } + else + { + for (; n; n--, p++) + { + if (iscntrl (*p)) + { + putc ('\\', ttyfp); + if ( *p == '\n' ) + putc ('n', ttyfp); + else if ( !*p ) + putc ('0', ttyfp); + else + fprintf (ttyfp, "x%02x", *p ); + } + else + putc (*p, ttyfp); + } + } #endif } void -tty_print_utf8_string2( const byte *p, size_t n, size_t max_n ) +tty_print_utf8_string2 (estream_t fp, const byte *p, size_t n, size_t max_n) { size_t i; char *buf; - if (no_terminal) + if (no_terminal && !fp) return; /* we can handle plain ascii simpler, so check for it first */ @@ -370,21 +418,22 @@ tty_print_utf8_string2( const byte *p, size_t n, size_t max_n ) buf[max_n] = 0; } /*(utf8 conversion already does the control character quoting)*/ - tty_printf("%s", buf ); - xfree( buf ); + tty_fprintf (fp, "%s", buf); + xfree (buf); } else { if( max_n && (n > max_n) ) { n = max_n; } - tty_print_string( p, n ); + tty_print_string (fp, p, n ); } } + void tty_print_utf8_string( const byte *p, size_t n ) { - tty_print_utf8_string2( p, n, 0 ); + tty_print_utf8_string2 (NULL, p, n, 0); } diff --git a/common/ttyio.h b/common/ttyio.h index 5c810b8a5..0a66d8654 100644 --- a/common/ttyio.h +++ b/common/ttyio.h @@ -47,9 +47,10 @@ void tty_printf (const char *fmt, ... ); void tty_fprintf (estream_t fp, const char *fmt, ... ); char *tty_getf (const char *promptfmt, ... ); #endif -void tty_print_string (const unsigned char *p, size_t n); +void tty_print_string (estream_t fp, const unsigned char *p, size_t n); void tty_print_utf8_string (const unsigned char *p, size_t n); -void tty_print_utf8_string2 (const unsigned char *p, size_t n, size_t max_n); +void tty_print_utf8_string2 (estream_t fp, + const unsigned char *p, size_t n, size_t max_n); char *tty_get (const char *prompt); char *tty_get_hidden (const char *prompt); void tty_kill_prompt (void); diff --git a/g10/card-util.c b/g10/card-util.c index c043b3e29..411a4d482 100644 --- a/g10/card-util.c +++ b/g10/card-util.c @@ -269,7 +269,7 @@ print_name (estream_t fp, const char *text, const char *name) if (fp) print_utf8_buffer2 (fp, name, strlen (name), '\n'); else - tty_print_utf8_string2 (name, strlen (name), 0); + tty_print_utf8_string2 (NULL, name, strlen (name), 0); } else tty_fprintf (fp, _("[not set]")); @@ -302,7 +302,7 @@ print_isoname (estream_t fp, const char *text, else if (fp) print_utf8_buffer2 (fp, given, strlen (given), '\n'); else - tty_print_utf8_string2 (given, strlen (given), 0); + tty_print_utf8_string2 (NULL, given, strlen (given), 0); if (opt.with_colons) es_putc (':', fp); @@ -315,7 +315,7 @@ print_isoname (estream_t fp, const char *text, else if (fp) print_utf8_buffer2 (fp, buf, strlen (buf), '\n'); else - tty_print_utf8_string2 (buf, strlen (buf), 0); + tty_print_utf8_string2 (NULL, buf, strlen (buf), 0); xfree (buf); } else diff --git a/g10/keyedit.c b/g10/keyedit.c index 47a223409..b7f7ad66b 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -1,6 +1,7 @@ /* keyedit.c - keyedit stuff * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, * 2008, 2009, 2010 Free Software Foundation, Inc. + * Copyright (C) 2013, 2014 Werner Koch * * This file is part of GnuPG. * @@ -50,9 +51,10 @@ static void show_prefs (PKT_user_id * uid, PKT_signature * selfsig, int verbose); -static void show_names (KBNODE keyblock, PKT_public_key * pk, +static void show_names (estream_t fp, KBNODE keyblock, PKT_public_key * pk, unsigned int flag, int with_prefs); -static void show_key_with_all_names (KBNODE keyblock, int only_marked, +static void show_key_with_all_names (estream_t fp, + KBNODE keyblock, int only_marked, int with_revoker, int with_fpr, int with_subkeys, int with_prefs); static void show_key_and_fingerprint (KBNODE keyblock); @@ -252,7 +254,7 @@ print_and_check_one_sig (KBNODE keyblock, KBNODE node, { size_t n; char *p = get_user_id (sig->keyid, &n); - tty_print_utf8_string2 (p, n, + tty_print_utf8_string2 (NULL, p, n, opt.screen_columns - keystrlen () - 26 - ((opt. list_options & LIST_SHOW_SIG_EXPIRE) ? 11 @@ -815,7 +817,7 @@ sign_uids (KBNODE keyblock, strlist_t locusr, int *ret_modified, /* Ask whether we really should sign these user id(s). */ tty_printf ("\n"); - show_key_with_all_names (keyblock, 1, 0, 1, 0, 0); + show_key_with_all_names (NULL, keyblock, 1, 0, 1, 0, 0); tty_printf ("\n"); if (primary_pk->expiredate && !selfsig) @@ -1542,7 +1544,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr, if (redisplay && !quiet) { - show_key_with_all_names (keyblock, 0, 1, 0, 1, 0); + show_key_with_all_names (NULL, keyblock, 0, 1, 0, 1, 0); tty_printf ("\n"); redisplay = 0; } @@ -2081,7 +2083,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr, break; } - show_key_with_all_names (keyblock, 0, 0, 0, 1, 0); + show_key_with_all_names (NULL, keyblock, 0, 0, 0, 1, 0); tty_printf ("\n"); if (edit_ownertrust (find_kbnode (keyblock, PKT_PUBLIC_KEY)->pkt->pkt. @@ -2100,7 +2102,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr, { int count = count_selected_uids (keyblock); assert (keyblock->pkt->pkttype == PKT_PUBLIC_KEY); - show_names (keyblock, keyblock->pkt->pkt.public_key, + show_names (NULL, keyblock, keyblock->pkt->pkt.public_key, count ? NODFLG_SELUID : 0, 1); } break; @@ -2109,7 +2111,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr, { int count = count_selected_uids (keyblock); assert (keyblock->pkt->pkttype == PKT_PUBLIC_KEY); - show_names (keyblock, keyblock->pkt->pkt.public_key, + show_names (NULL, keyblock, keyblock->pkt->pkt.public_key, count ? NODFLG_SELUID : 0, 2); } break; @@ -2482,13 +2484,16 @@ show_prefs (PKT_user_id * uid, PKT_signature * selfsig, int verbose) opt.with_colons is used. It prints all available data in a easy to parse format and does not translate utf8 */ static void -show_key_with_all_names_colon (KBNODE keyblock) +show_key_with_all_names_colon (estream_t fp, kbnode_t keyblock) { KBNODE node; int i, j, ulti_hack = 0; byte pk_version = 0; PKT_public_key *primary = NULL; + if (!fp) + fp = es_stdout; + /* the keys */ for (node = keyblock; node; node = node->next) { @@ -2506,46 +2511,46 @@ show_key_with_all_names_colon (KBNODE keyblock) keyid_from_pk (pk, keyid); - fputs (node->pkt->pkttype == PKT_PUBLIC_KEY ? "pub:" : "sub:", - stdout); + es_fputs (node->pkt->pkttype == PKT_PUBLIC_KEY ? "pub:" : "sub:", + fp); if (!pk->flags.valid) - putchar ('i'); + es_putc ('i', fp); else if (pk->flags.revoked) - putchar ('r'); + es_putc ('r', fp); else if (pk->has_expired) - putchar ('e'); + es_putc ('e', fp); else if (!(opt.fast_list_mode || opt.no_expensive_trust_checks)) { int trust = get_validity_info (pk, NULL); if (trust == 'u') ulti_hack = 1; - putchar (trust); + es_putc (trust, fp); } - printf (":%u:%d:%08lX%08lX:%lu:%lu::", - nbits_from_pk (pk), - pk->pubkey_algo, - (ulong) keyid[0], (ulong) keyid[1], - (ulong) pk->timestamp, (ulong) pk->expiredate); + es_fprintf (fp, ":%u:%d:%08lX%08lX:%lu:%lu::", + nbits_from_pk (pk), + pk->pubkey_algo, + (ulong) keyid[0], (ulong) keyid[1], + (ulong) pk->timestamp, (ulong) pk->expiredate); if (node->pkt->pkttype == PKT_PUBLIC_KEY && !(opt.fast_list_mode || opt.no_expensive_trust_checks)) - putchar (get_ownertrust_info (pk)); - putchar (':'); - putchar (':'); - putchar (':'); + es_putc (get_ownertrust_info (pk), fp); + es_putc (':', fp); + es_putc (':', fp); + es_putc (':', fp); /* Print capabilities. */ if ((pk->pubkey_usage & PUBKEY_USAGE_ENC)) - putchar ('e'); + es_putc ('e', fp); if ((pk->pubkey_usage & PUBKEY_USAGE_SIG)) - putchar ('s'); + es_putc ('s', fp); if ((pk->pubkey_usage & PUBKEY_USAGE_CERT)) - putchar ('c'); + es_putc ('c', fp); if ((pk->pubkey_usage & PUBKEY_USAGE_AUTH)) - putchar ('a'); - putchar ('\n'); + es_putc ('a', fp); + es_putc ('\n', fp); - print_fingerprint (pk, 0); - print_revokers (pk); + print_fingerprint (fp, pk, 0); + print_revokers (fp, pk); } } @@ -2560,16 +2565,16 @@ show_key_with_all_names_colon (KBNODE keyblock) ++i; if (uid->attrib_data) - printf ("uat:"); + es_fputs ("uat:", fp); else - printf ("uid:"); + es_fputs ("uid:", fp); if (uid->is_revoked) - printf ("r::::::::"); + es_fputs ("r::::::::", fp); else if (uid->is_expired) - printf ("e::::::::"); + es_fputs ("e::::::::", fp); else if (opt.fast_list_mode || opt.no_expensive_trust_checks) - printf ("::::::::"); + es_fputs ("::::::::", fp); else { int uid_validity; @@ -2578,19 +2583,19 @@ show_key_with_all_names_colon (KBNODE keyblock) uid_validity = get_validity_info (primary, uid); else uid_validity = 'u'; - printf ("%c::::::::", uid_validity); + es_fprintf (fp, "%c::::::::", uid_validity); } if (uid->attrib_data) - printf ("%u %lu", uid->numattribs, uid->attrib_len); + es_fprintf (fp, "%u %lu", uid->numattribs, uid->attrib_len); else - es_write_sanitized (es_stdout, uid->name, uid->len, ":", NULL); + es_write_sanitized (fp, uid->name, uid->len, ":", NULL); - putchar (':'); + es_putc (':', fp); /* signature class */ - putchar (':'); + es_putc (':', fp); /* capabilities */ - putchar (':'); + es_putc (':', fp); /* preferences */ if (pk_version > 3 || uid->selfsigversion > 3) { @@ -2599,38 +2604,41 @@ show_key_with_all_names_colon (KBNODE keyblock) for (j = 0; prefs && prefs[j].type; j++) { if (j) - putchar (' '); - printf ("%c%d", prefs[j].type == PREFTYPE_SYM ? 'S' : - prefs[j].type == PREFTYPE_HASH ? 'H' : - prefs[j].type == PREFTYPE_ZIP ? 'Z' : '?', - prefs[j].value); + es_putc (' ', fp); + es_fprintf (fp, + "%c%d", prefs[j].type == PREFTYPE_SYM ? 'S' : + prefs[j].type == PREFTYPE_HASH ? 'H' : + prefs[j].type == PREFTYPE_ZIP ? 'Z' : '?', + prefs[j].value); } if (uid->flags.mdc) - printf (",mdc"); + es_fputs (",mdc", fp); if (!uid->flags.ks_modify) - printf (",no-ks-modify"); + es_fputs (",no-ks-modify", fp); } - putchar (':'); + es_putc (':', fp); /* flags */ - printf ("%d,", i); + es_fprintf (fp, "%d,", i); if (uid->is_primary) - putchar ('p'); + es_putc ('p', fp); if (uid->is_revoked) - putchar ('r'); + es_putc ('r', fp); if (uid->is_expired) - putchar ('e'); + es_putc ('e', fp); if ((node->flag & NODFLG_SELUID)) - putchar ('s'); + es_putc ('s', fp); if ((node->flag & NODFLG_MARK_A)) - putchar ('m'); - putchar (':'); - putchar ('\n'); + es_putc ('m', fp); + es_putc (':', fp); + es_putc ('\n', fp); } } } + static void -show_names (KBNODE keyblock, PKT_public_key * pk, unsigned int flag, +show_names (estream_t fp, + KBNODE keyblock, PKT_public_key * pk, unsigned int flag, int with_prefs) { KBNODE node; @@ -2645,18 +2653,18 @@ show_names (KBNODE keyblock, PKT_public_key * pk, unsigned int flag, if (!flag || (flag && (node->flag & flag))) { if (!(flag & NODFLG_MARK_A) && pk) - tty_printf ("%s ", uid_trust_string_fixed (pk, uid)); + tty_fprintf (fp, "%s ", uid_trust_string_fixed (pk, uid)); if (flag & NODFLG_MARK_A) - tty_printf (" "); + tty_fprintf (fp, " "); else if (node->flag & NODFLG_SELUID) - tty_printf ("(%d)* ", i); + tty_fprintf (fp, "(%d)* ", i); else if (uid->is_primary) - tty_printf ("(%d). ", i); + tty_fprintf (fp, "(%d). ", i); else - tty_printf ("(%d) ", i); - tty_print_utf8_string (uid->name, uid->len); - tty_printf ("\n"); + tty_fprintf (fp, "(%d) ", i); + tty_print_utf8_string2 (fp, uid->name, uid->len, 0); + tty_fprintf (fp, "\n"); if (with_prefs && pk) { if (pk->version > 3 || uid->selfsigversion > 3) @@ -2679,8 +2687,8 @@ show_names (KBNODE keyblock, PKT_public_key * pk, unsigned int flag, show_prefs (uid, selfsig, with_prefs == 2); } else - tty_printf (_("There are no preferences on a" - " PGP 2.x-style user ID.\n")); + tty_fprintf (fp, _("There are no preferences on a" + " PGP 2.x-style user ID.\n")); } } } @@ -2689,11 +2697,14 @@ show_names (KBNODE keyblock, PKT_public_key * pk, unsigned int flag, /* - * Display the key a the user ids, if only_marked is true, do only - * so for user ids with mark A flag set and dont display the index number + * Display the key a the user ids, if only_marked is true, do only so + * for user ids with mark A flag set and do not display the index + * number. If FP is not NULL print to the given stream and not to the + * tty (ignored in with-colons mode). */ static void -show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, +show_key_with_all_names (estream_t fp, + KBNODE keyblock, int only_marked, int with_revoker, int with_fpr, int with_subkeys, int with_prefs) { KBNODE node; @@ -2704,7 +2715,7 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, if (opt.with_colons) { - show_key_with_all_names_colon (keyblock); + show_key_with_all_names_colon (fp, keyblock); return; } @@ -2716,7 +2727,8 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, && !is_deleted_kbnode (node))) { PKT_public_key *pk = node->pkt->pkt.public_key; - const char *otrust = "err", *trust = "err"; + const char *otrust = "err"; + const char *trust = "err"; if (node->pkt->pkttype == PKT_PUBLIC_KEY) { @@ -2741,7 +2753,8 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, if (pk->flags.revoked) { char *user = get_user_id_string_native (pk->revoked.keyid); - tty_printf (_("The following key was revoked on" + tty_fprintf (fp, + _("The following key was revoked on" " %s by %s key %s\n"), revokestr_from_pk (pk), gcry_pk_algo_name (pk->revoked.algo), user); @@ -2764,22 +2777,23 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, MAX_FINGERPRINT_LEN, r_keyid); user = get_user_id_string_native (r_keyid); - tty_printf (_("This key may be revoked by %s key %s"), - algo ? algo : "?", user); + tty_fprintf (fp, + _("This key may be revoked by %s key %s"), + algo ? algo : "?", user); if (pk->revkey[i].class & 0x40) { - tty_printf (" "); - tty_printf (_("(sensitive)")); + tty_fprintf (fp, " "); + tty_fprintf (fp, _("(sensitive)")); } - tty_printf ("\n"); + tty_fprintf (fp, "\n"); xfree (user); } } keyid_from_pk (pk, NULL); - tty_printf ("%s%c %s/%s", + tty_fprintf (fp, "%s%c %s/%s", node->pkt->pkttype == PKT_PUBLIC_KEY ? "pub" : node->pkt->pkttype == PKT_PUBLIC_SUBKEY ? "sub" : node->pkt->pkttype == PKT_SECRET_KEY ? "sec" : "ssb", @@ -2788,28 +2802,28 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, keystr (pk->keyid)); if (opt.legacy_list_mode) - tty_printf (" "); + tty_fprintf (fp, " "); else - tty_printf ("\n "); + tty_fprintf (fp, "\n "); - tty_printf (_("created: %s"), datestr_from_pk (pk)); - tty_printf (" "); + tty_fprintf (fp, _("created: %s"), datestr_from_pk (pk)); + tty_fprintf (fp, " "); if (pk->flags.revoked) - tty_printf (_("revoked: %s"), revokestr_from_pk (pk)); + tty_fprintf (fp, _("revoked: %s"), revokestr_from_pk (pk)); else if (pk->has_expired) - tty_printf (_("expired: %s"), expirestr_from_pk (pk)); + tty_fprintf (fp, _("expired: %s"), expirestr_from_pk (pk)); else - tty_printf (_("expires: %s"), expirestr_from_pk (pk)); - tty_printf (" "); - tty_printf (_("usage: %s"), usagestr_from_pk (pk)); - tty_printf ("\n"); + tty_fprintf (fp, _("expires: %s"), expirestr_from_pk (pk)); + tty_fprintf (fp, " "); + tty_fprintf (fp, _("usage: %s"), usagestr_from_pk (pk)); + tty_fprintf (fp, "\n"); if (pk->seckey_info && pk->seckey_info->is_protected && pk->seckey_info->s2k.mode == 1002) { - tty_printf ("%*s%s", opt.legacy_list_mode? 21:5, "", - _("card-no: ")); + tty_fprintf (fp, "%*s%s", opt.legacy_list_mode? 21:5, "", + _("card-no: ")); if (pk->seckey_info->ivlen == 16 && !memcmp (pk->seckey_info->iv, "\xD2\x76\x00\x01\x24\x01", 6)) @@ -2818,17 +2832,17 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, for (i = 8; i < 14; i++) { if (i == 10) - tty_printf (" "); - tty_printf ("%02X", pk->seckey_info->iv[i]); + tty_fprintf (fp, " "); + tty_fprintf (fp, "%02X", pk->seckey_info->iv[i]); } } else { /* Unknown card: Print all. */ for (i = 0; i < pk->seckey_info->ivlen; i++) - tty_printf ("%02X", pk->seckey_info->iv[i]); + tty_fprintf (fp, "%02X", pk->seckey_info->iv[i]); } - tty_printf ("\n"); + tty_fprintf (fp, "\n"); } if (node->pkt->pkttype == PKT_PUBLIC_KEY @@ -2836,9 +2850,9 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, { if (opt.trust_model != TM_ALWAYS) { - tty_printf ("%*s", - opt.legacy_list_mode? - ((int) keystrlen () + 13):5, ""); + tty_fprintf (fp, "%*s", + opt.legacy_list_mode? + ((int) keystrlen () + 13):5, ""); /* Ownertrust is only meaningful for the PGP or classic trust models */ if (opt.trust_model == TM_PGP @@ -2847,37 +2861,38 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker, int width = 14 - strlen (otrust); if (width <= 0) width = 1; - tty_printf (_("trust: %s"), otrust); - tty_printf ("%*s", width, ""); + tty_fprintf (fp, _("trust: %s"), otrust); + tty_fprintf (fp, "%*s", width, ""); } - tty_printf (_("validity: %s"), trust); - tty_printf ("\n"); + tty_fprintf (fp, _("validity: %s"), trust); + tty_fprintf (fp, "\n"); } if (node->pkt->pkttype == PKT_PUBLIC_KEY && (get_ownertrust (pk) & TRUST_FLAG_DISABLED)) { - tty_printf ("*** "); - tty_printf (_("This key has been disabled")); - tty_printf ("\n"); + tty_fprintf (fp, "*** "); + tty_fprintf (fp, _("This key has been disabled")); + tty_fprintf (fp, "\n"); } } if ((node->pkt->pkttype == PKT_PUBLIC_KEY || node->pkt->pkttype == PKT_SECRET_KEY) && with_fpr) { - print_fingerprint (pk, 2); - tty_printf ("\n"); + print_fingerprint (fp, pk, 2); + tty_fprintf (fp, "\n"); } } } - show_names (keyblock, primary, only_marked ? NODFLG_MARK_A : 0, with_prefs); + show_names (fp, + keyblock, primary, only_marked ? NODFLG_MARK_A : 0, with_prefs); if (do_warn) - tty_printf (_("Please note that the shown key validity" - " is not necessarily correct\n" - "unless you restart the program.\n")); + tty_fprintf (fp, _("Please note that the shown key validity" + " is not necessarily correct\n" + "unless you restart the program.\n")); } @@ -2912,7 +2927,7 @@ show_basic_key_info (KBNODE keyblock) tty_printf (" "); tty_printf (_("expires: %s"), expirestr_from_pk (pk)); tty_printf ("\n"); - print_fingerprint (pk, 3); + print_fingerprint (NULL, pk, 3); tty_printf ("\n"); } } @@ -2962,7 +2977,7 @@ show_key_and_fingerprint (KBNODE keyblock) } tty_printf ("\n"); if (pk) - print_fingerprint (pk, 2); + print_fingerprint (NULL, pk, 2); } @@ -3438,7 +3453,7 @@ menu_addrevoker (ctrl_t ctrl, kbnode_t pub_keyblock, int sensitive) } print_pubkey_info (NULL, revoker_pk); - print_fingerprint (revoker_pk, 2); + print_fingerprint (NULL, revoker_pk, 2); tty_printf ("\n"); tty_printf (_("WARNING: appointing a key as a designated revoker " diff --git a/g10/keylist.c b/g10/keylist.c index 6e5ebdac9..71f72e233 100644 --- a/g10/keylist.c +++ b/g10/keylist.c @@ -866,7 +866,7 @@ list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque) es_fprintf (es_stdout, "\n"); if (fpr) - print_fingerprint (pk, 0); + print_fingerprint (NULL, pk, 0); if (opt.with_keygrip && hexgrip) es_fprintf (es_stdout, " Keygrip = %s\n", hexgrip); @@ -991,7 +991,7 @@ list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque) es_putc ('\n', es_stdout); if (fpr > 1) { - print_fingerprint (pk2, 0); + print_fingerprint (NULL, pk2, 0); if (serialno) print_card_serialno (serialno); } @@ -1112,7 +1112,7 @@ list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque) } void -print_revokers (PKT_public_key * pk) +print_revokers (estream_t fp, PKT_public_key * pk) { /* print the revoker record */ if (!pk->revkey && pk->numrevkeys) @@ -1125,12 +1125,13 @@ print_revokers (PKT_public_key * pk) { byte *p; - es_fprintf (es_stdout, "rvk:::%d::::::", pk->revkey[i].algid); + es_fprintf (fp, "rvk:::%d::::::", pk->revkey[i].algid); p = pk->revkey[i].fpr; for (j = 0; j < 20; j++, p++) - es_fprintf (es_stdout, "%02X", *p); - es_fprintf (es_stdout, ":%02x%s:\n", pk->revkey[i].class, - (pk->revkey[i].class & 0x40) ? "s" : ""); + es_fprintf (fp, "%02X", *p); + es_fprintf (fp, ":%02x%s:\n", + pk->revkey[i].class, + (pk->revkey[i].class & 0x40) ? "s" : ""); } } } @@ -1227,9 +1228,9 @@ list_keyblock_colon (KBNODE keyblock, int secret, int fpr) es_putc (':', es_stdout); /* End of field 17. */ es_putc ('\n', es_stdout); - print_revokers (pk); + print_revokers (es_stdout, pk); if (fpr) - print_fingerprint (pk, 0); + print_fingerprint (NULL, pk, 0); if (opt.with_key_data || opt.with_keygrip) { if (hexgrip) @@ -1353,7 +1354,7 @@ list_keyblock_colon (KBNODE keyblock, int secret, int fpr) es_putc (':', es_stdout); /* End of field 17. */ es_putc ('\n', es_stdout); if (fpr > 1) - print_fingerprint (pk2, 0); + print_fingerprint (NULL, pk2, 0); if (opt.with_key_data || opt.with_keygrip) { if (hexgrip) @@ -1553,10 +1554,12 @@ list_keyblock (KBNODE keyblock, int secret, int fpr, void *opaque) * 3: direct use of tty but only primary key. * * Modes 1 and 2 will try and print both subkey and primary key - * fingerprints. A MODE with bit 7 set is used internally. + * fingerprints. A MODE with bit 7 set is used internally. If + * OVERRIDE_FP is not NULL that stream will be used in 0 instead + * of es_stdout or instead of the TTY in modes 2 and 3. */ void -print_fingerprint (PKT_public_key *pk, int mode) +print_fingerprint (estream_t override_fp, PKT_public_key *pk, int mode) { byte array[MAX_FINGERPRINT_LEN], *p; size_t i, n; @@ -1581,7 +1584,7 @@ print_fingerprint (PKT_public_key *pk, int mode) { PKT_public_key *primary_pk = xmalloc_clear (sizeof (*primary_pk)); get_pubkey (primary_pk, pk->main_keyid); - print_fingerprint (primary_pk, mode | 0x80); + print_fingerprint (override_fp, primary_pk, (mode | 0x80)); free_public_key (primary_pk); } @@ -1595,7 +1598,7 @@ print_fingerprint (PKT_public_key *pk, int mode) } else if (mode == 2) { - fp = NULL; /* Use tty. */ + fp = override_fp; /* Use tty or given stream. */ if (primary) /* TRANSLATORS: this should fit into 24 bytes to that the * fingerprint data is properly aligned with the user ID */ @@ -1605,12 +1608,12 @@ print_fingerprint (PKT_public_key *pk, int mode) } else if (mode == 3) { - fp = NULL; /* Use tty. */ + fp = override_fp; /* Use tty or given stream. */ text = _(" Key fingerprint ="); } else { - fp = es_stdout; + fp = override_fp? override_fp : es_stdout; text = _(" Key fingerprint ="); } diff --git a/g10/main.h b/g10/main.h index 28115ca60..ad1a9f682 100644 --- a/g10/main.h +++ b/g10/main.h @@ -325,8 +325,8 @@ void secret_key_list (ctrl_t ctrl, strlist_t list ); void print_subpackets_colon(PKT_signature *sig); void reorder_keyblock (KBNODE keyblock); void list_keyblock( KBNODE keyblock, int secret, int fpr, void *opaque ); -void print_fingerprint (PKT_public_key *pk, int mode); -void print_revokers(PKT_public_key *pk); +void print_fingerprint (estream_t fp, PKT_public_key *pk, int mode); +void print_revokers (estream_t fp, PKT_public_key *pk); void show_policy_url(PKT_signature *sig,int indent,int mode); void show_keyserver_url(PKT_signature *sig,int indent,int mode); void show_notation(PKT_signature *sig,int indent,int mode,int which); diff --git a/g10/mainproc.c b/g10/mainproc.c index 6bd475ba3..f830eeedb 100644 --- a/g10/mainproc.c +++ b/g10/mainproc.c @@ -953,7 +953,7 @@ list_node( CTX c, KBNODE node ) if( node->next && node->next->pkt->pkttype == PKT_RING_TRUST) { putchar('\n'); any=1; if( opt.fingerprint ) - print_fingerprint (pk, 0); + print_fingerprint (NULL, pk, 0); printf("rtv:1:%u:\n", node->next->pkt->pkt.ring_trust->trustval ); } @@ -991,7 +991,7 @@ list_node( CTX c, KBNODE node ) putchar(':'); putchar('\n'); if( opt.fingerprint && !any ) - print_fingerprint ( pk, 0 ); + print_fingerprint (NULL, pk, 0 ); if( opt.with_colons && node->next && node->next->pkt->pkttype == PKT_RING_TRUST ) { @@ -1030,7 +1030,7 @@ list_node( CTX c, KBNODE node ) if( !any ) putchar('\n'); if( !mainkey && opt.fingerprint > 1 ) - print_fingerprint( pk, 0 ); + print_fingerprint (NULL, pk, 0); } else if( (mainkey = (node->pkt->pkttype == PKT_SECRET_KEY) ) || node->pkt->pkttype == PKT_SECRET_SUBKEY ) { diff --git a/g10/pkclist.c b/g10/pkclist.c index a6d687a0f..49cd30926 100644 --- a/g10/pkclist.c +++ b/g10/pkclist.c @@ -258,7 +258,7 @@ do_edit_ownertrust (PKT_public_key *pk, int mode, tty_printf(_(" aka \"%s\"\n"),p); } - print_fingerprint (pk, 2); + print_fingerprint (NULL, pk, 2); tty_printf("\n"); release_kbnode (keyblock); } @@ -470,7 +470,7 @@ do_we_trust_pre( PKT_public_key *pk, unsigned int trustlevel ) if( !opt.batch && !rc ) { print_pubkey_info(NULL,pk); - print_fingerprint (pk, 2); + print_fingerprint (NULL, pk, 2); tty_printf("\n"); tty_printf( @@ -529,7 +529,7 @@ check_signatures_trust( PKT_signature *sig ) if( !opt.quiet ) log_info(_("WARNING: Using untrusted key!\n")); if (opt.with_fingerprint) - print_fingerprint (pk, 1); + print_fingerprint (NULL, pk, 1); goto leave; } @@ -617,7 +617,7 @@ check_signatures_trust( PKT_signature *sig ) { case TRUST_EXPIRED: log_info(_("Note: This key has expired!\n")); - print_fingerprint (pk, 1); + print_fingerprint (NULL, pk, 1); break; default: @@ -631,7 +631,7 @@ check_signatures_trust( PKT_signature *sig ) " a trusted signature!\n")); log_info(_(" There is no indication that the " "signature belongs to the owner.\n" )); - print_fingerprint (pk, 1); + print_fingerprint (NULL, pk, 1); break; case TRUST_NEVER: @@ -640,7 +640,7 @@ check_signatures_trust( PKT_signature *sig ) log_info(_("WARNING: We do NOT trust this key!\n")); log_info(_(" The signature is probably a FORGERY.\n")); if (opt.with_fingerprint) - print_fingerprint (pk, 1); + print_fingerprint (NULL, pk, 1); rc = gpg_error (GPG_ERR_BAD_SIGNATURE); break; @@ -650,19 +650,19 @@ check_signatures_trust( PKT_signature *sig ) " sufficiently trusted signatures!\n")); log_info(_(" It is not certain that the" " signature belongs to the owner.\n" )); - print_fingerprint (pk, 1); + print_fingerprint (NULL, pk, 1); break; case TRUST_FULLY: write_status( STATUS_TRUST_FULLY ); if (opt.with_fingerprint) - print_fingerprint (pk, 1); + print_fingerprint (NULL, pk, 1); break; case TRUST_ULTIMATE: write_status( STATUS_TRUST_ULTIMATE ); if (opt.with_fingerprint) - print_fingerprint (pk, 1); + print_fingerprint (NULL, pk, 1); break; } |