1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

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.
This commit is contained in:
Werner Koch 2014-03-27 12:59:55 +01:00
parent 5c2a50cdc9
commit 4f50ec98dd
8 changed files with 251 additions and 183 deletions

View file

@ -310,21 +310,43 @@ 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 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; return;
if( !initialized ) if( !initialized & !fp)
init_ttyfp(); init_ttyfp();
#ifdef USE_W32_CONSOLE #ifdef USE_W32_CONSOLE
/* not so effective, change it if you want */ /* not so effective, change it if you want */
if (fp)
{
for( ; n; n--, p++ ) for( ; n; n--, p++ )
if( iscntrl( *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' ) if( *p == '\n' )
tty_printf ("\\n"); tty_printf ("\\n");
else if( !*p ) else if( !*p )
@ -334,9 +356,33 @@ tty_print_string ( const byte *p, size_t n )
} }
else else
tty_printf ("%c", *p); tty_printf ("%c", *p);
}
}
#else #else
if (fp)
{
for( ; n; n--, p++ ) for( ; n; n--, p++ )
if( iscntrl( *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); putc ('\\', ttyfp);
if ( *p == '\n' ) if ( *p == '\n' )
putc ('n', ttyfp); putc ('n', ttyfp);
@ -347,16 +393,18 @@ tty_print_string ( const byte *p, size_t n )
} }
else else
putc (*p, ttyfp); putc (*p, ttyfp);
}
}
#endif #endif
} }
void 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; size_t i;
char *buf; char *buf;
if (no_terminal) if (no_terminal && !fp)
return; return;
/* we can handle plain ascii simpler, so check for it first */ /* 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; buf[max_n] = 0;
} }
/*(utf8 conversion already does the control character quoting)*/ /*(utf8 conversion already does the control character quoting)*/
tty_printf("%s", buf ); tty_fprintf (fp, "%s", buf);
xfree (buf); xfree (buf);
} }
else { else {
if( max_n && (n > max_n) ) { if( max_n && (n > max_n) ) {
n = max_n; n = max_n;
} }
tty_print_string( p, n ); tty_print_string (fp, p, n );
} }
} }
void void
tty_print_utf8_string( const byte *p, size_t n ) 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);
} }

View file

@ -47,9 +47,10 @@ void tty_printf (const char *fmt, ... );
void tty_fprintf (estream_t fp, const char *fmt, ... ); void tty_fprintf (estream_t fp, const char *fmt, ... );
char *tty_getf (const char *promptfmt, ... ); char *tty_getf (const char *promptfmt, ... );
#endif #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_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 (const char *prompt);
char *tty_get_hidden (const char *prompt); char *tty_get_hidden (const char *prompt);
void tty_kill_prompt (void); void tty_kill_prompt (void);

View file

@ -269,7 +269,7 @@ print_name (estream_t fp, const char *text, const char *name)
if (fp) if (fp)
print_utf8_buffer2 (fp, name, strlen (name), '\n'); print_utf8_buffer2 (fp, name, strlen (name), '\n');
else else
tty_print_utf8_string2 (name, strlen (name), 0); tty_print_utf8_string2 (NULL, name, strlen (name), 0);
} }
else else
tty_fprintf (fp, _("[not set]")); tty_fprintf (fp, _("[not set]"));
@ -302,7 +302,7 @@ print_isoname (estream_t fp, const char *text,
else if (fp) else if (fp)
print_utf8_buffer2 (fp, given, strlen (given), '\n'); print_utf8_buffer2 (fp, given, strlen (given), '\n');
else else
tty_print_utf8_string2 (given, strlen (given), 0); tty_print_utf8_string2 (NULL, given, strlen (given), 0);
if (opt.with_colons) if (opt.with_colons)
es_putc (':', fp); es_putc (':', fp);
@ -315,7 +315,7 @@ print_isoname (estream_t fp, const char *text,
else if (fp) else if (fp)
print_utf8_buffer2 (fp, buf, strlen (buf), '\n'); print_utf8_buffer2 (fp, buf, strlen (buf), '\n');
else else
tty_print_utf8_string2 (buf, strlen (buf), 0); tty_print_utf8_string2 (NULL, buf, strlen (buf), 0);
xfree (buf); xfree (buf);
} }
else else

View file

@ -1,6 +1,7 @@
/* keyedit.c - keyedit stuff /* keyedit.c - keyedit stuff
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
* 2008, 2009, 2010 Free Software Foundation, Inc. * 2008, 2009, 2010 Free Software Foundation, Inc.
* Copyright (C) 2013, 2014 Werner Koch
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -50,9 +51,10 @@
static void show_prefs (PKT_user_id * uid, PKT_signature * selfsig, static void show_prefs (PKT_user_id * uid, PKT_signature * selfsig,
int verbose); 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); 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_revoker, int with_fpr,
int with_subkeys, int with_prefs); int with_subkeys, int with_prefs);
static void show_key_and_fingerprint (KBNODE keyblock); static void show_key_and_fingerprint (KBNODE keyblock);
@ -252,7 +254,7 @@ print_and_check_one_sig (KBNODE keyblock, KBNODE node,
{ {
size_t n; size_t n;
char *p = get_user_id (sig->keyid, &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.screen_columns - keystrlen () - 26 -
((opt. ((opt.
list_options & LIST_SHOW_SIG_EXPIRE) ? 11 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). */ /* Ask whether we really should sign these user id(s). */
tty_printf ("\n"); 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"); tty_printf ("\n");
if (primary_pk->expiredate && !selfsig) if (primary_pk->expiredate && !selfsig)
@ -1542,7 +1544,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
if (redisplay && !quiet) 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"); tty_printf ("\n");
redisplay = 0; redisplay = 0;
} }
@ -2081,7 +2083,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
break; 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"); tty_printf ("\n");
if (edit_ownertrust (find_kbnode (keyblock, if (edit_ownertrust (find_kbnode (keyblock,
PKT_PUBLIC_KEY)->pkt->pkt. 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); int count = count_selected_uids (keyblock);
assert (keyblock->pkt->pkttype == PKT_PUBLIC_KEY); 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); count ? NODFLG_SELUID : 0, 1);
} }
break; break;
@ -2109,7 +2111,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
{ {
int count = count_selected_uids (keyblock); int count = count_selected_uids (keyblock);
assert (keyblock->pkt->pkttype == PKT_PUBLIC_KEY); 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); count ? NODFLG_SELUID : 0, 2);
} }
break; 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 opt.with_colons is used. It prints all available data in a easy to
parse format and does not translate utf8 */ parse format and does not translate utf8 */
static void static void
show_key_with_all_names_colon (KBNODE keyblock) show_key_with_all_names_colon (estream_t fp, kbnode_t keyblock)
{ {
KBNODE node; KBNODE node;
int i, j, ulti_hack = 0; int i, j, ulti_hack = 0;
byte pk_version = 0; byte pk_version = 0;
PKT_public_key *primary = NULL; PKT_public_key *primary = NULL;
if (!fp)
fp = es_stdout;
/* the keys */ /* the keys */
for (node = keyblock; node; node = node->next) for (node = keyblock; node; node = node->next)
{ {
@ -2506,46 +2511,46 @@ show_key_with_all_names_colon (KBNODE keyblock)
keyid_from_pk (pk, keyid); keyid_from_pk (pk, keyid);
fputs (node->pkt->pkttype == PKT_PUBLIC_KEY ? "pub:" : "sub:", es_fputs (node->pkt->pkttype == PKT_PUBLIC_KEY ? "pub:" : "sub:",
stdout); fp);
if (!pk->flags.valid) if (!pk->flags.valid)
putchar ('i'); es_putc ('i', fp);
else if (pk->flags.revoked) else if (pk->flags.revoked)
putchar ('r'); es_putc ('r', fp);
else if (pk->has_expired) else if (pk->has_expired)
putchar ('e'); es_putc ('e', fp);
else if (!(opt.fast_list_mode || opt.no_expensive_trust_checks)) else if (!(opt.fast_list_mode || opt.no_expensive_trust_checks))
{ {
int trust = get_validity_info (pk, NULL); int trust = get_validity_info (pk, NULL);
if (trust == 'u') if (trust == 'u')
ulti_hack = 1; ulti_hack = 1;
putchar (trust); es_putc (trust, fp);
} }
printf (":%u:%d:%08lX%08lX:%lu:%lu::", es_fprintf (fp, ":%u:%d:%08lX%08lX:%lu:%lu::",
nbits_from_pk (pk), nbits_from_pk (pk),
pk->pubkey_algo, pk->pubkey_algo,
(ulong) keyid[0], (ulong) keyid[1], (ulong) keyid[0], (ulong) keyid[1],
(ulong) pk->timestamp, (ulong) pk->expiredate); (ulong) pk->timestamp, (ulong) pk->expiredate);
if (node->pkt->pkttype == PKT_PUBLIC_KEY if (node->pkt->pkttype == PKT_PUBLIC_KEY
&& !(opt.fast_list_mode || opt.no_expensive_trust_checks)) && !(opt.fast_list_mode || opt.no_expensive_trust_checks))
putchar (get_ownertrust_info (pk)); es_putc (get_ownertrust_info (pk), fp);
putchar (':'); es_putc (':', fp);
putchar (':'); es_putc (':', fp);
putchar (':'); es_putc (':', fp);
/* Print capabilities. */ /* Print capabilities. */
if ((pk->pubkey_usage & PUBKEY_USAGE_ENC)) if ((pk->pubkey_usage & PUBKEY_USAGE_ENC))
putchar ('e'); es_putc ('e', fp);
if ((pk->pubkey_usage & PUBKEY_USAGE_SIG)) if ((pk->pubkey_usage & PUBKEY_USAGE_SIG))
putchar ('s'); es_putc ('s', fp);
if ((pk->pubkey_usage & PUBKEY_USAGE_CERT)) if ((pk->pubkey_usage & PUBKEY_USAGE_CERT))
putchar ('c'); es_putc ('c', fp);
if ((pk->pubkey_usage & PUBKEY_USAGE_AUTH)) if ((pk->pubkey_usage & PUBKEY_USAGE_AUTH))
putchar ('a'); es_putc ('a', fp);
putchar ('\n'); es_putc ('\n', fp);
print_fingerprint (pk, 0); print_fingerprint (fp, pk, 0);
print_revokers (pk); print_revokers (fp, pk);
} }
} }
@ -2560,16 +2565,16 @@ show_key_with_all_names_colon (KBNODE keyblock)
++i; ++i;
if (uid->attrib_data) if (uid->attrib_data)
printf ("uat:"); es_fputs ("uat:", fp);
else else
printf ("uid:"); es_fputs ("uid:", fp);
if (uid->is_revoked) if (uid->is_revoked)
printf ("r::::::::"); es_fputs ("r::::::::", fp);
else if (uid->is_expired) else if (uid->is_expired)
printf ("e::::::::"); es_fputs ("e::::::::", fp);
else if (opt.fast_list_mode || opt.no_expensive_trust_checks) else if (opt.fast_list_mode || opt.no_expensive_trust_checks)
printf ("::::::::"); es_fputs ("::::::::", fp);
else else
{ {
int uid_validity; int uid_validity;
@ -2578,19 +2583,19 @@ show_key_with_all_names_colon (KBNODE keyblock)
uid_validity = get_validity_info (primary, uid); uid_validity = get_validity_info (primary, uid);
else else
uid_validity = 'u'; uid_validity = 'u';
printf ("%c::::::::", uid_validity); es_fprintf (fp, "%c::::::::", uid_validity);
} }
if (uid->attrib_data) if (uid->attrib_data)
printf ("%u %lu", uid->numattribs, uid->attrib_len); es_fprintf (fp, "%u %lu", uid->numattribs, uid->attrib_len);
else 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 */ /* signature class */
putchar (':'); es_putc (':', fp);
/* capabilities */ /* capabilities */
putchar (':'); es_putc (':', fp);
/* preferences */ /* preferences */
if (pk_version > 3 || uid->selfsigversion > 3) 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++) for (j = 0; prefs && prefs[j].type; j++)
{ {
if (j) if (j)
putchar (' '); es_putc (' ', fp);
printf ("%c%d", prefs[j].type == PREFTYPE_SYM ? 'S' : es_fprintf (fp,
"%c%d", prefs[j].type == PREFTYPE_SYM ? 'S' :
prefs[j].type == PREFTYPE_HASH ? 'H' : prefs[j].type == PREFTYPE_HASH ? 'H' :
prefs[j].type == PREFTYPE_ZIP ? 'Z' : '?', prefs[j].type == PREFTYPE_ZIP ? 'Z' : '?',
prefs[j].value); prefs[j].value);
} }
if (uid->flags.mdc) if (uid->flags.mdc)
printf (",mdc"); es_fputs (",mdc", fp);
if (!uid->flags.ks_modify) if (!uid->flags.ks_modify)
printf (",no-ks-modify"); es_fputs (",no-ks-modify", fp);
} }
putchar (':'); es_putc (':', fp);
/* flags */ /* flags */
printf ("%d,", i); es_fprintf (fp, "%d,", i);
if (uid->is_primary) if (uid->is_primary)
putchar ('p'); es_putc ('p', fp);
if (uid->is_revoked) if (uid->is_revoked)
putchar ('r'); es_putc ('r', fp);
if (uid->is_expired) if (uid->is_expired)
putchar ('e'); es_putc ('e', fp);
if ((node->flag & NODFLG_SELUID)) if ((node->flag & NODFLG_SELUID))
putchar ('s'); es_putc ('s', fp);
if ((node->flag & NODFLG_MARK_A)) if ((node->flag & NODFLG_MARK_A))
putchar ('m'); es_putc ('m', fp);
putchar (':'); es_putc (':', fp);
putchar ('\n'); es_putc ('\n', fp);
} }
} }
} }
static void 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) int with_prefs)
{ {
KBNODE node; 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 || (flag && (node->flag & flag)))
{ {
if (!(flag & NODFLG_MARK_A) && pk) 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) if (flag & NODFLG_MARK_A)
tty_printf (" "); tty_fprintf (fp, " ");
else if (node->flag & NODFLG_SELUID) else if (node->flag & NODFLG_SELUID)
tty_printf ("(%d)* ", i); tty_fprintf (fp, "(%d)* ", i);
else if (uid->is_primary) else if (uid->is_primary)
tty_printf ("(%d). ", i); tty_fprintf (fp, "(%d). ", i);
else else
tty_printf ("(%d) ", i); tty_fprintf (fp, "(%d) ", i);
tty_print_utf8_string (uid->name, uid->len); tty_print_utf8_string2 (fp, uid->name, uid->len, 0);
tty_printf ("\n"); tty_fprintf (fp, "\n");
if (with_prefs && pk) if (with_prefs && pk)
{ {
if (pk->version > 3 || uid->selfsigversion > 3) if (pk->version > 3 || uid->selfsigversion > 3)
@ -2679,7 +2687,7 @@ show_names (KBNODE keyblock, PKT_public_key * pk, unsigned int flag,
show_prefs (uid, selfsig, with_prefs == 2); show_prefs (uid, selfsig, with_prefs == 2);
} }
else else
tty_printf (_("There are no preferences on a" tty_fprintf (fp, _("There are no preferences on a"
" PGP 2.x-style user ID.\n")); " 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 * Display the key a the user ids, if only_marked is true, do only so
* so for user ids with mark A flag set and dont display the index number * 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 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) int with_fpr, int with_subkeys, int with_prefs)
{ {
KBNODE node; KBNODE node;
@ -2704,7 +2715,7 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker,
if (opt.with_colons) if (opt.with_colons)
{ {
show_key_with_all_names_colon (keyblock); show_key_with_all_names_colon (fp, keyblock);
return; return;
} }
@ -2716,7 +2727,8 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker,
&& !is_deleted_kbnode (node))) && !is_deleted_kbnode (node)))
{ {
PKT_public_key *pk = node->pkt->pkt.public_key; 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) 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) if (pk->flags.revoked)
{ {
char *user = get_user_id_string_native (pk->revoked.keyid); 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"), " %s by %s key %s\n"),
revokestr_from_pk (pk), revokestr_from_pk (pk),
gcry_pk_algo_name (pk->revoked.algo), user); 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); MAX_FINGERPRINT_LEN, r_keyid);
user = get_user_id_string_native (r_keyid); user = get_user_id_string_native (r_keyid);
tty_printf (_("This key may be revoked by %s key %s"), tty_fprintf (fp,
_("This key may be revoked by %s key %s"),
algo ? algo : "?", user); algo ? algo : "?", user);
if (pk->revkey[i].class & 0x40) if (pk->revkey[i].class & 0x40)
{ {
tty_printf (" "); tty_fprintf (fp, " ");
tty_printf (_("(sensitive)")); tty_fprintf (fp, _("(sensitive)"));
} }
tty_printf ("\n"); tty_fprintf (fp, "\n");
xfree (user); xfree (user);
} }
} }
keyid_from_pk (pk, NULL); 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_KEY ? "pub" :
node->pkt->pkttype == PKT_PUBLIC_SUBKEY ? "sub" : node->pkt->pkttype == PKT_PUBLIC_SUBKEY ? "sub" :
node->pkt->pkttype == PKT_SECRET_KEY ? "sec" : "ssb", node->pkt->pkttype == PKT_SECRET_KEY ? "sec" : "ssb",
@ -2788,27 +2802,27 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker,
keystr (pk->keyid)); keystr (pk->keyid));
if (opt.legacy_list_mode) if (opt.legacy_list_mode)
tty_printf (" "); tty_fprintf (fp, " ");
else else
tty_printf ("\n "); tty_fprintf (fp, "\n ");
tty_printf (_("created: %s"), datestr_from_pk (pk)); tty_fprintf (fp, _("created: %s"), datestr_from_pk (pk));
tty_printf (" "); tty_fprintf (fp, " ");
if (pk->flags.revoked) 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) else if (pk->has_expired)
tty_printf (_("expired: %s"), expirestr_from_pk (pk)); tty_fprintf (fp, _("expired: %s"), expirestr_from_pk (pk));
else else
tty_printf (_("expires: %s"), expirestr_from_pk (pk)); tty_fprintf (fp, _("expires: %s"), expirestr_from_pk (pk));
tty_printf (" "); tty_fprintf (fp, " ");
tty_printf (_("usage: %s"), usagestr_from_pk (pk)); tty_fprintf (fp, _("usage: %s"), usagestr_from_pk (pk));
tty_printf ("\n"); tty_fprintf (fp, "\n");
if (pk->seckey_info if (pk->seckey_info
&& pk->seckey_info->is_protected && pk->seckey_info->is_protected
&& pk->seckey_info->s2k.mode == 1002) && pk->seckey_info->s2k.mode == 1002)
{ {
tty_printf ("%*s%s", opt.legacy_list_mode? 21:5, "", tty_fprintf (fp, "%*s%s", opt.legacy_list_mode? 21:5, "",
_("card-no: ")); _("card-no: "));
if (pk->seckey_info->ivlen == 16 if (pk->seckey_info->ivlen == 16
&& !memcmp (pk->seckey_info->iv, && !memcmp (pk->seckey_info->iv,
@ -2818,17 +2832,17 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker,
for (i = 8; i < 14; i++) for (i = 8; i < 14; i++)
{ {
if (i == 10) if (i == 10)
tty_printf (" "); tty_fprintf (fp, " ");
tty_printf ("%02X", pk->seckey_info->iv[i]); tty_fprintf (fp, "%02X", pk->seckey_info->iv[i]);
} }
} }
else else
{ {
/* Unknown card: Print all. */ /* Unknown card: Print all. */
for (i = 0; i < pk->seckey_info->ivlen; i++) 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 if (node->pkt->pkttype == PKT_PUBLIC_KEY
@ -2836,7 +2850,7 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker,
{ {
if (opt.trust_model != TM_ALWAYS) if (opt.trust_model != TM_ALWAYS)
{ {
tty_printf ("%*s", tty_fprintf (fp, "%*s",
opt.legacy_list_mode? opt.legacy_list_mode?
((int) keystrlen () + 13):5, ""); ((int) keystrlen () + 13):5, "");
/* Ownertrust is only meaningful for the PGP or /* Ownertrust is only meaningful for the PGP or
@ -2847,35 +2861,36 @@ show_key_with_all_names (KBNODE keyblock, int only_marked, int with_revoker,
int width = 14 - strlen (otrust); int width = 14 - strlen (otrust);
if (width <= 0) if (width <= 0)
width = 1; width = 1;
tty_printf (_("trust: %s"), otrust); tty_fprintf (fp, _("trust: %s"), otrust);
tty_printf ("%*s", width, ""); tty_fprintf (fp, "%*s", width, "");
} }
tty_printf (_("validity: %s"), trust); tty_fprintf (fp, _("validity: %s"), trust);
tty_printf ("\n"); tty_fprintf (fp, "\n");
} }
if (node->pkt->pkttype == PKT_PUBLIC_KEY if (node->pkt->pkttype == PKT_PUBLIC_KEY
&& (get_ownertrust (pk) & TRUST_FLAG_DISABLED)) && (get_ownertrust (pk) & TRUST_FLAG_DISABLED))
{ {
tty_printf ("*** "); tty_fprintf (fp, "*** ");
tty_printf (_("This key has been disabled")); tty_fprintf (fp, _("This key has been disabled"));
tty_printf ("\n"); tty_fprintf (fp, "\n");
} }
} }
if ((node->pkt->pkttype == PKT_PUBLIC_KEY if ((node->pkt->pkttype == PKT_PUBLIC_KEY
|| node->pkt->pkttype == PKT_SECRET_KEY) && with_fpr) || node->pkt->pkttype == PKT_SECRET_KEY) && with_fpr)
{ {
print_fingerprint (pk, 2); print_fingerprint (fp, pk, 2);
tty_printf ("\n"); 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) if (do_warn)
tty_printf (_("Please note that the shown key validity" tty_fprintf (fp, _("Please note that the shown key validity"
" is not necessarily correct\n" " is not necessarily correct\n"
"unless you restart the program.\n")); "unless you restart the program.\n"));
} }
@ -2912,7 +2927,7 @@ show_basic_key_info (KBNODE keyblock)
tty_printf (" "); tty_printf (" ");
tty_printf (_("expires: %s"), expirestr_from_pk (pk)); tty_printf (_("expires: %s"), expirestr_from_pk (pk));
tty_printf ("\n"); tty_printf ("\n");
print_fingerprint (pk, 3); print_fingerprint (NULL, pk, 3);
tty_printf ("\n"); tty_printf ("\n");
} }
} }
@ -2962,7 +2977,7 @@ show_key_and_fingerprint (KBNODE keyblock)
} }
tty_printf ("\n"); tty_printf ("\n");
if (pk) 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_pubkey_info (NULL, revoker_pk);
print_fingerprint (revoker_pk, 2); print_fingerprint (NULL, revoker_pk, 2);
tty_printf ("\n"); tty_printf ("\n");
tty_printf (_("WARNING: appointing a key as a designated revoker " tty_printf (_("WARNING: appointing a key as a designated revoker "

View file

@ -866,7 +866,7 @@ list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque)
es_fprintf (es_stdout, "\n"); es_fprintf (es_stdout, "\n");
if (fpr) if (fpr)
print_fingerprint (pk, 0); print_fingerprint (NULL, pk, 0);
if (opt.with_keygrip && hexgrip) if (opt.with_keygrip && hexgrip)
es_fprintf (es_stdout, " Keygrip = %s\n", 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); es_putc ('\n', es_stdout);
if (fpr > 1) if (fpr > 1)
{ {
print_fingerprint (pk2, 0); print_fingerprint (NULL, pk2, 0);
if (serialno) if (serialno)
print_card_serialno (serialno); print_card_serialno (serialno);
} }
@ -1112,7 +1112,7 @@ list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque)
} }
void void
print_revokers (PKT_public_key * pk) print_revokers (estream_t fp, PKT_public_key * pk)
{ {
/* print the revoker record */ /* print the revoker record */
if (!pk->revkey && pk->numrevkeys) if (!pk->revkey && pk->numrevkeys)
@ -1125,11 +1125,12 @@ print_revokers (PKT_public_key * pk)
{ {
byte *p; 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; p = pk->revkey[i].fpr;
for (j = 0; j < 20; j++, p++) for (j = 0; j < 20; j++, p++)
es_fprintf (es_stdout, "%02X", *p); es_fprintf (fp, "%02X", *p);
es_fprintf (es_stdout, ":%02x%s:\n", pk->revkey[i].class, es_fprintf (fp, ":%02x%s:\n",
pk->revkey[i].class,
(pk->revkey[i].class & 0x40) ? "s" : ""); (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 (':', es_stdout); /* End of field 17. */
es_putc ('\n', es_stdout); es_putc ('\n', es_stdout);
print_revokers (pk); print_revokers (es_stdout, pk);
if (fpr) if (fpr)
print_fingerprint (pk, 0); print_fingerprint (NULL, pk, 0);
if (opt.with_key_data || opt.with_keygrip) if (opt.with_key_data || opt.with_keygrip)
{ {
if (hexgrip) 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 (':', es_stdout); /* End of field 17. */
es_putc ('\n', es_stdout); es_putc ('\n', es_stdout);
if (fpr > 1) if (fpr > 1)
print_fingerprint (pk2, 0); print_fingerprint (NULL, pk2, 0);
if (opt.with_key_data || opt.with_keygrip) if (opt.with_key_data || opt.with_keygrip)
{ {
if (hexgrip) 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. * 3: direct use of tty but only primary key.
* *
* Modes 1 and 2 will try and print both subkey and 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 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; byte array[MAX_FINGERPRINT_LEN], *p;
size_t i, n; 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)); PKT_public_key *primary_pk = xmalloc_clear (sizeof (*primary_pk));
get_pubkey (primary_pk, pk->main_keyid); 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); free_public_key (primary_pk);
} }
@ -1595,7 +1598,7 @@ print_fingerprint (PKT_public_key *pk, int mode)
} }
else if (mode == 2) else if (mode == 2)
{ {
fp = NULL; /* Use tty. */ fp = override_fp; /* Use tty or given stream. */
if (primary) if (primary)
/* TRANSLATORS: this should fit into 24 bytes to that the /* TRANSLATORS: this should fit into 24 bytes to that the
* fingerprint data is properly aligned with the user ID */ * 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) else if (mode == 3)
{ {
fp = NULL; /* Use tty. */ fp = override_fp; /* Use tty or given stream. */
text = _(" Key fingerprint ="); text = _(" Key fingerprint =");
} }
else else
{ {
fp = es_stdout; fp = override_fp? override_fp : es_stdout;
text = _(" Key fingerprint ="); text = _(" Key fingerprint =");
} }

View file

@ -325,8 +325,8 @@ void secret_key_list (ctrl_t ctrl, strlist_t list );
void print_subpackets_colon(PKT_signature *sig); void print_subpackets_colon(PKT_signature *sig);
void reorder_keyblock (KBNODE keyblock); void reorder_keyblock (KBNODE keyblock);
void list_keyblock( KBNODE keyblock, int secret, int fpr, void *opaque ); void list_keyblock( KBNODE keyblock, int secret, int fpr, void *opaque );
void print_fingerprint (PKT_public_key *pk, int mode); void print_fingerprint (estream_t fp, PKT_public_key *pk, int mode);
void print_revokers(PKT_public_key *pk); void print_revokers (estream_t fp, PKT_public_key *pk);
void show_policy_url(PKT_signature *sig,int indent,int mode); void show_policy_url(PKT_signature *sig,int indent,int mode);
void show_keyserver_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); void show_notation(PKT_signature *sig,int indent,int mode,int which);

View file

@ -953,7 +953,7 @@ list_node( CTX c, KBNODE node )
if( node->next && node->next->pkt->pkttype == PKT_RING_TRUST) { if( node->next && node->next->pkt->pkttype == PKT_RING_TRUST) {
putchar('\n'); any=1; putchar('\n'); any=1;
if( opt.fingerprint ) if( opt.fingerprint )
print_fingerprint (pk, 0); print_fingerprint (NULL, pk, 0);
printf("rtv:1:%u:\n", printf("rtv:1:%u:\n",
node->next->pkt->pkt.ring_trust->trustval ); node->next->pkt->pkt.ring_trust->trustval );
} }
@ -991,7 +991,7 @@ list_node( CTX c, KBNODE node )
putchar(':'); putchar(':');
putchar('\n'); putchar('\n');
if( opt.fingerprint && !any ) if( opt.fingerprint && !any )
print_fingerprint ( pk, 0 ); print_fingerprint (NULL, pk, 0 );
if( opt.with_colons if( opt.with_colons
&& node->next && node->next
&& node->next->pkt->pkttype == PKT_RING_TRUST ) { && node->next->pkt->pkttype == PKT_RING_TRUST ) {
@ -1030,7 +1030,7 @@ list_node( CTX c, KBNODE node )
if( !any ) if( !any )
putchar('\n'); putchar('\n');
if( !mainkey && opt.fingerprint > 1 ) if( !mainkey && opt.fingerprint > 1 )
print_fingerprint( pk, 0 ); print_fingerprint (NULL, pk, 0);
} }
else if( (mainkey = (node->pkt->pkttype == PKT_SECRET_KEY) ) else if( (mainkey = (node->pkt->pkttype == PKT_SECRET_KEY) )
|| node->pkt->pkttype == PKT_SECRET_SUBKEY ) { || node->pkt->pkttype == PKT_SECRET_SUBKEY ) {

View file

@ -258,7 +258,7 @@ do_edit_ownertrust (PKT_public_key *pk, int mode,
tty_printf(_(" aka \"%s\"\n"),p); tty_printf(_(" aka \"%s\"\n"),p);
} }
print_fingerprint (pk, 2); print_fingerprint (NULL, pk, 2);
tty_printf("\n"); tty_printf("\n");
release_kbnode (keyblock); release_kbnode (keyblock);
} }
@ -470,7 +470,7 @@ do_we_trust_pre( PKT_public_key *pk, unsigned int trustlevel )
if( !opt.batch && !rc ) if( !opt.batch && !rc )
{ {
print_pubkey_info(NULL,pk); print_pubkey_info(NULL,pk);
print_fingerprint (pk, 2); print_fingerprint (NULL, pk, 2);
tty_printf("\n"); tty_printf("\n");
tty_printf( tty_printf(
@ -529,7 +529,7 @@ check_signatures_trust( PKT_signature *sig )
if( !opt.quiet ) if( !opt.quiet )
log_info(_("WARNING: Using untrusted key!\n")); log_info(_("WARNING: Using untrusted key!\n"));
if (opt.with_fingerprint) if (opt.with_fingerprint)
print_fingerprint (pk, 1); print_fingerprint (NULL, pk, 1);
goto leave; goto leave;
} }
@ -617,7 +617,7 @@ check_signatures_trust( PKT_signature *sig )
{ {
case TRUST_EXPIRED: case TRUST_EXPIRED:
log_info(_("Note: This key has expired!\n")); log_info(_("Note: This key has expired!\n"));
print_fingerprint (pk, 1); print_fingerprint (NULL, pk, 1);
break; break;
default: default:
@ -631,7 +631,7 @@ check_signatures_trust( PKT_signature *sig )
" a trusted signature!\n")); " a trusted signature!\n"));
log_info(_(" There is no indication that the " log_info(_(" There is no indication that the "
"signature belongs to the owner.\n" )); "signature belongs to the owner.\n" ));
print_fingerprint (pk, 1); print_fingerprint (NULL, pk, 1);
break; break;
case TRUST_NEVER: 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(_("WARNING: We do NOT trust this key!\n"));
log_info(_(" The signature is probably a FORGERY.\n")); log_info(_(" The signature is probably a FORGERY.\n"));
if (opt.with_fingerprint) if (opt.with_fingerprint)
print_fingerprint (pk, 1); print_fingerprint (NULL, pk, 1);
rc = gpg_error (GPG_ERR_BAD_SIGNATURE); rc = gpg_error (GPG_ERR_BAD_SIGNATURE);
break; break;
@ -650,19 +650,19 @@ check_signatures_trust( PKT_signature *sig )
" sufficiently trusted signatures!\n")); " sufficiently trusted signatures!\n"));
log_info(_(" It is not certain that the" log_info(_(" It is not certain that the"
" signature belongs to the owner.\n" )); " signature belongs to the owner.\n" ));
print_fingerprint (pk, 1); print_fingerprint (NULL, pk, 1);
break; break;
case TRUST_FULLY: case TRUST_FULLY:
write_status( STATUS_TRUST_FULLY ); write_status( STATUS_TRUST_FULLY );
if (opt.with_fingerprint) if (opt.with_fingerprint)
print_fingerprint (pk, 1); print_fingerprint (NULL, pk, 1);
break; break;
case TRUST_ULTIMATE: case TRUST_ULTIMATE:
write_status( STATUS_TRUST_ULTIMATE ); write_status( STATUS_TRUST_ULTIMATE );
if (opt.with_fingerprint) if (opt.with_fingerprint)
print_fingerprint (pk, 1); print_fingerprint (NULL, pk, 1);
break; break;
} }