1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-02-01 16:33:02 +01:00

gpg: Simplify default key listing.

* g10/mainproc.c (list_node): Rework.
--

GnuPG-bug-id: 1640
This commit is contained in:
Werner Koch 2014-06-02 19:50:18 +02:00
parent d9cde7ba7d
commit f3249b1c4d

View File

@ -921,204 +921,135 @@ print_userid( PACKET *pkt )
static void static void
list_node( CTX c, KBNODE node ) list_node( CTX c, KBNODE node )
{ {
int any=0;
int mainkey; int mainkey;
char pkstrbuf[PUBKEY_STRING_SIZE]; char pkstrbuf[PUBKEY_STRING_SIZE];
if( !node ) if (!node)
; ;
else if( (mainkey = (node->pkt->pkttype == PKT_PUBLIC_KEY) ) else if ((mainkey = (node->pkt->pkttype == PKT_PUBLIC_KEY))
|| node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) { || node->pkt->pkttype == PKT_PUBLIC_SUBKEY )
{
PKT_public_key *pk = node->pkt->pkt.public_key; PKT_public_key *pk = node->pkt->pkt.public_key;
if( opt.with_colons ) if (opt.with_colons)
{ {
u32 keyid[2]; u32 keyid[2];
keyid_from_pk( pk, keyid ); keyid_from_pk( pk, keyid );
if( mainkey ) if (mainkey)
c->trustletter = opt.fast_list_mode? c->trustletter = (opt.fast_list_mode?
0 : get_validity_info( pk, NULL ); 0 : get_validity_info( pk, NULL));
printf("%s:", mainkey? "pub":"sub" ); es_printf ("%s:", mainkey? "pub":"sub" );
if( c->trustletter ) if (c->trustletter)
putchar( c->trustletter ); es_putc (c->trustletter, es_stdout);
printf(":%u:%d:%08lX%08lX:%s:%s::", es_printf (":%u:%d:%08lX%08lX:%s:%s::",
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],
colon_datestr_from_pk( pk ), colon_datestr_from_pk( pk ),
colon_strtime (pk->expiredate) ); colon_strtime (pk->expiredate) );
if( mainkey && !opt.fast_list_mode ) if (mainkey && !opt.fast_list_mode)
putchar( get_ownertrust_info (pk) ); es_putc (get_ownertrust_info (pk), es_stdout);
putchar(':'); es_putc (':', es_stdout);
if( node->next && node->next->pkt->pkttype == PKT_RING_TRUST) {
putchar('\n'); any=1;
if( opt.fingerprint )
print_fingerprint (NULL, pk, 0);
printf("rtv:1:%u:\n",
node->next->pkt->pkt.ring_trust->trustval );
}
} }
else else
printf("%s %s/%s %s%s", es_printf ("%s %s/%s %s",
mainkey? "pub":"sub", mainkey? "pub":"sub",
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf), pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
keystr_from_pk( pk ), keystr_from_pk (pk),
datestr_from_pk( pk ), mainkey?" ":""); datestr_from_pk (pk));
if( mainkey ) { if (pk->flags.revoked)
/* and now list all userids with their signatures */ {
for( node = node->next; node; node = node->next ) { es_printf (" [");
if( node->pkt->pkttype == PKT_SIGNATURE ) { es_printf (_("revoked: %s"), revokestr_from_pk (pk));
if( !any ) { es_printf ("]\n");
if( node->pkt->pkt.signature->sig_class == 0x20 ) }
puts("[revoked]"); else if( pk->expiredate && !opt.with_colons)
{
es_printf (" [");
es_printf (_("expires: %s"), expirestr_from_pk (pk));
es_printf ("]\n");
}
else else
putchar('\n'); es_putc ('\n', es_stdout);
any = 1;
if ((mainkey && opt.fingerprint) || opt.fingerprint > 1)
print_fingerprint (NULL, pk, 0);
if (opt.with_colons)
{
if (node->next && node->next->pkt->pkttype == PKT_RING_TRUST)
es_printf ("rtv:1:%u:\n",
node->next->pkt->pkt.ring_trust->trustval);
} }
list_node(c, node );
if (mainkey)
{
/* Now list all userids with their signatures. */
for (node = node->next; node; node = node->next)
{
if (node->pkt->pkttype == PKT_SIGNATURE)
{
list_node (c, node );
} }
else if( node->pkt->pkttype == PKT_USER_ID ) { else if (node->pkt->pkttype == PKT_USER_ID)
if( any ) { {
if( opt.with_colons ) if (opt.with_colons)
printf("%s:::::::::", es_printf ("%s:::::::::",
node->pkt->pkt.user_id->attrib_data?"uat":"uid"); node->pkt->pkt.user_id->attrib_data?"uat":"uid");
else else
printf( "uid%*s", 28, "" ); es_printf ("uid%*s", 28, "" );
} print_userid (node->pkt);
print_userid( node->pkt ); if (opt.with_colons)
if( opt.with_colons ) es_putc (':', es_stdout);
putchar(':'); es_putc ('\n', es_stdout);
putchar('\n'); if (opt.with_colons
if( opt.fingerprint && !any )
print_fingerprint (NULL, pk, 0 );
if( opt.with_colons
&& node->next && node->next
&& node->next->pkt->pkttype == PKT_RING_TRUST ) { && node->next->pkt->pkttype == PKT_RING_TRUST)
printf("rtv:2:%u:\n", {
es_printf ("rtv:2:%u:\n",
node->next->pkt->pkt.ring_trust? node->next->pkt->pkt.ring_trust?
node->next->pkt->pkt.ring_trust->trustval : 0); node->next->pkt->pkt.ring_trust->trustval : 0);
} }
any=1;
}
else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
if( !any ) {
putchar('\n');
any = 1;
} }
else if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY)
{
list_node(c, node ); list_node(c, node );
} }
} }
} }
else }
else if ((mainkey = (node->pkt->pkttype == PKT_SECRET_KEY) )
|| node->pkt->pkttype == PKT_SECRET_SUBKEY)
{ {
/* of subkey */
if( pk->flags.revoked )
{
printf(" [");
printf(_("revoked: %s"),revokestr_from_pk(pk));
printf("]");
}
else if( pk->expiredate )
{
printf(" [");
printf(_("expires: %s"),expirestr_from_pk(pk));
printf("]");
}
}
if( !any )
putchar('\n');
if( !mainkey && opt.fingerprint > 1 )
print_fingerprint (NULL, pk, 0);
}
else if( (mainkey = (node->pkt->pkttype == PKT_SECRET_KEY) )
|| node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
log_debug ("FIXME: No way to print secret key packets here\n"); log_debug ("FIXME: No way to print secret key packets here\n");
/* fixme: We may use a fucntion to trun a secret key packet into /* fixme: We may use a fucntion to turn a secret key packet into
a public key one and use that here. */ a public key one and use that here. */
/* PKT_secret_key *sk = node->pkt->pkt.secret_key; */
/* if( opt.with_colons ) */
/* { */
/* u32 keyid[2]; */
/* keyid_from_sk( sk, keyid ); */
/* printf("%s::%u:%d:%08lX%08lX:%s:%s:::", */
/* mainkey? "sec":"ssb", */
/* nbits_from_sk( sk ), */
/* sk->pubkey_algo, */
/* (ulong)keyid[0],(ulong)keyid[1], */
/* colon_datestr_from_sk( sk ), */
/* colon_strtime (sk->expiredate) */
/* /\* fixme: add LID *\/ ); */
/* } */
/* else */
/* printf("%s %4u%c/%s %s ", mainkey? "sec":"ssb", */
/* nbits_from_sk( sk ), pubkey_letter( sk->pubkey_algo ), */
/* keystr_from_sk( sk ), datestr_from_sk( sk )); */
/* if( mainkey ) { */
/* /\* and now list all userids with their signatures *\/ */
/* for( node = node->next; node; node = node->next ) { */
/* if( node->pkt->pkttype == PKT_SIGNATURE ) { */
/* if( !any ) { */
/* if( node->pkt->pkt.signature->sig_class == 0x20 ) */
/* puts("[revoked]"); */
/* else */
/* putchar('\n'); */
/* any = 1; */
/* } */
/* list_node(c, node ); */
/* } */
/* else if( node->pkt->pkttype == PKT_USER_ID ) { */
/* if( any ) { */
/* if( opt.with_colons ) */
/* printf("%s:::::::::", */
/* node->pkt->pkt.user_id->attrib_data?"uat":"uid"); */
/* else */
/* printf( "uid%*s", 28, "" ); */
/* } */
/* print_userid( node->pkt ); */
/* if( opt.with_colons ) */
/* putchar(':'); */
/* putchar('\n'); */
/* if( opt.fingerprint && !any ) */
/* print_fingerprint( NULL, sk, 0 ); */
/* any=1; */
/* } */
/* else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) { */
/* if( !any ) { */
/* putchar('\n'); */
/* any = 1; */
/* } */
/* list_node(c, node ); */
/* } */
/* } */
/* } */
/* if( !any ) */
/* putchar('\n'); */
/* if( !mainkey && opt.fingerprint > 1 ) */
/* print_fingerprint( NULL, sk, 0 ); */
} }
else if( node->pkt->pkttype == PKT_SIGNATURE ) { else if (node->pkt->pkttype == PKT_SIGNATURE)
{
PKT_signature *sig = node->pkt->pkt.signature; PKT_signature *sig = node->pkt->pkt.signature;
int is_selfsig = 0; int is_selfsig = 0;
int rc2=0; int rc2 = 0;
size_t n; size_t n;
char *p; char *p;
int sigrc = ' '; int sigrc = ' ';
if( !opt.verbose ) if (!opt.verbose)
return; return;
if( sig->sig_class == 0x20 || sig->sig_class == 0x30 ) if (sig->sig_class == 0x20 || sig->sig_class == 0x30)
fputs("rev", stdout); es_fputs ("rev", es_stdout);
else else
fputs("sig", stdout); es_fputs ("sig", es_stdout);
if( opt.check_sigs ) { if (opt.check_sigs)
fflush(stdout); {
rc2=do_check_sig( c, node, &is_selfsig, NULL, NULL ); fflush (stdout);
switch (gpg_err_code (rc2)) { rc2 = do_check_sig (c, node, &is_selfsig, NULL, NULL);
switch (gpg_err_code (rc2))
{
case 0: sigrc = '!'; break; case 0: sigrc = '!'; break;
case GPG_ERR_BAD_SIGNATURE: sigrc = '-'; break; case GPG_ERR_BAD_SIGNATURE: sigrc = '-'; break;
case GPG_ERR_NO_PUBKEY: case GPG_ERR_NO_PUBKEY:
@ -1126,62 +1057,67 @@ list_node( CTX c, KBNODE node )
default: sigrc = '%'; break; default: sigrc = '%'; break;
} }
} }
else { /* check whether this is a self signature */ else /* Check whether this is a self signature. */
{
u32 keyid[2]; u32 keyid[2];
if( c->list->pkt->pkttype == PKT_PUBLIC_KEY if (c->list->pkt->pkttype == PKT_PUBLIC_KEY
|| c->list->pkt->pkttype == PKT_SECRET_KEY ) || c->list->pkt->pkttype == PKT_SECRET_KEY )
{ {
keyid_from_pk (c->list->pkt->pkt.public_key, keyid); keyid_from_pk (c->list->pkt->pkt.public_key, keyid);
if( keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] ) if (keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1])
is_selfsig = 1; is_selfsig = 1;
} }
} }
if( opt.with_colons ) {
putchar(':'); if (opt.with_colons)
if( sigrc != ' ' ) {
putchar(sigrc); es_putc (':', es_stdout);
printf("::%d:%08lX%08lX:%s:%s:", sig->pubkey_algo, if (sigrc != ' ')
es_putc (sigrc, es_stdout);
es_printf ("::%d:%08lX%08lX:%s:%s:", sig->pubkey_algo,
(ulong)sig->keyid[0], (ulong)sig->keyid[1], (ulong)sig->keyid[0], (ulong)sig->keyid[1],
colon_datestr_from_sig(sig), colon_datestr_from_sig (sig),
colon_expirestr_from_sig(sig)); colon_expirestr_from_sig (sig));
if(sig->trust_depth || sig->trust_value) if (sig->trust_depth || sig->trust_value)
printf("%d %d",sig->trust_depth,sig->trust_value); es_printf ("%d %d",sig->trust_depth,sig->trust_value);
printf(":"); es_putc (':', es_stdout);
if(sig->trust_regexp) if (sig->trust_regexp)
es_write_sanitized (es_stdout,sig->trust_regexp, es_write_sanitized (es_stdout, sig->trust_regexp,
strlen(sig->trust_regexp), ":", NULL); strlen (sig->trust_regexp), ":", NULL);
printf(":"); es_putc (':', es_stdout);
} }
else else
printf("%c %s %s ", es_printf ("%c %s %s ",
sigrc, keystr(sig->keyid), datestr_from_sig(sig)); sigrc, keystr (sig->keyid), datestr_from_sig(sig));
if( sigrc == '%' ) if (sigrc == '%')
printf("[%s] ", g10_errstr(rc2) ); es_printf ("[%s] ", g10_errstr(rc2) );
else if( sigrc == '?' ) else if (sigrc == '?')
; ;
else if( is_selfsig ) { else if (is_selfsig)
if( opt.with_colons ) {
putchar(':'); if (opt.with_colons)
fputs( sig->sig_class == 0x18? "[keybind]":"[selfsig]", stdout); es_putc (':', es_stdout);
if( opt.with_colons ) es_fputs (sig->sig_class == 0x18? "[keybind]":"[selfsig]", es_stdout);
putchar(':'); if (opt.with_colons)
es_putc (':', es_stdout);
} }
else if( !opt.fast_list_mode ) { else if (!opt.fast_list_mode)
p = get_user_id( sig->keyid, &n ); {
p = get_user_id (sig->keyid, &n);
es_write_sanitized (es_stdout, p, n, es_write_sanitized (es_stdout, p, n,
opt.with_colons?":":NULL, NULL ); opt.with_colons?":":NULL, NULL );
xfree(p); xfree (p);
} }
if( opt.with_colons ) if (opt.with_colons)
printf(":%02x%c:", sig->sig_class, sig->flags.exportable?'x':'l'); es_printf (":%02x%c:", sig->sig_class, sig->flags.exportable?'x':'l');
putchar('\n'); es_putc ('\n', es_stdout);
} }
else else
log_error("invalid node with packet of type %d\n", node->pkt->pkttype); log_error ("invalid node with packet of type %d\n", node->pkt->pkttype);
} }