1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-03-27 22:39:59 +01:00

Reverted recent changes to --output. This is the stable branch and it

might break applications.
This commit is contained in:
Werner Koch 2003-04-14 07:52:18 +00:00
parent b79275a66f
commit 7b63a8ed5c
5 changed files with 62 additions and 113 deletions

@ -1,18 +1,3 @@
2003-04-13 Timo Schulz <twoaday@freakmail.de>
* mainproc.c (mainproc_open_output): New. Support for
--output when GPG is in the list mode.
(mainproc_get_output): New.
* keylist.c (print_fingerprint): If the mode is zero and
we are in the colon mode, we try to get the file handle
via mainproc_get_output().
* g10.c (main): Use the new code to support --output in
the list mode.
* main.h: Add prototypes.
2003-04-10 Werner Koch <wk@gnupg.org> 2003-04-10 Werner Koch <wk@gnupg.org>
* passphrase.c (read_passphrase_from_fd): Do a dummy read if the * passphrase.c (read_passphrase_from_fd): Do a dummy read if the

@ -2545,13 +2545,10 @@ main( int argc, char **argv )
set_packet_list_mode(1); set_packet_list_mode(1);
opt.list_packets=1; opt.list_packets=1;
} }
if( opt.outfile )
mainproc_open_output( opt.outfile );
rc = proc_packets(NULL, a ); rc = proc_packets(NULL, a );
if( rc ) if( rc )
log_error("processing message failed: %s\n", g10_errstr(rc) ); log_error("processing message failed: %s\n", g10_errstr(rc) );
iobuf_close(a); iobuf_close(a);
mainproc_open_output( NULL );
} }
break; break;
} }

@ -1050,7 +1050,6 @@ print_fingerprint (PKT_public_key *pk, PKT_secret_key *sk, int mode )
fingerprint_from_pk (pk, array, &n); fingerprint_from_pk (pk, array, &n);
p = array; p = array;
if (opt.with_colons && !mode) { if (opt.with_colons && !mode) {
fp = mainproc_get_output( );
fprintf (fp, "fpr:::::::::"); fprintf (fp, "fpr:::::::::");
for (i=0; i < n ; i++, p++ ) for (i=0; i < n ; i++, p++ )
fprintf (fp, "%02X", *p ); fprintf (fp, "%02X", *p );

@ -79,38 +79,12 @@ struct mainproc_context {
}; };
static FILE *list_fp = NULL;
static int do_proc_packets( CTX c, IOBUF a ); static int do_proc_packets( CTX c, IOBUF a );
static void list_node( CTX c, KBNODE node ); static void list_node( CTX c, KBNODE node );
static void proc_tree( CTX c, KBNODE node ); static void proc_tree( CTX c, KBNODE node );
void
mainproc_open_output( const char * file )
{
if( !file ) {
if( list_fp && list_fp != stderr && list_fp != stdout ) {
fclose( list_fp );
list_fp = stdout;
}
return;
}
if( *file != '-' )
list_fp = fopen( file, "w" );
if( !list_fp )
list_fp = stdout;
}
FILE*
mainproc_get_output( void )
{
return list_fp? list_fp : stdout;
}
static void static void
release_list( CTX c ) release_list( CTX c )
{ {
@ -759,28 +733,27 @@ do_check_sig( CTX c, KBNODE node, int *is_selfsig, int *is_expkey )
static void static void
print_userid (PACKET *pkt) print_userid( PACKET *pkt )
{ {
if (!pkt) if( !pkt )
BUG(); BUG();
if (pkt->pkttype != PKT_USER_ID) if( pkt->pkttype != PKT_USER_ID ) {
{ printf("ERROR: unexpected packet type %d", pkt->pkttype );
printf("ERROR: unexpected packet type %d", pkt->pkttype ); return;
return;
} }
if (opt.with_colons) if( opt.with_colons )
{ {
if (pkt->pkt.user_id->attrib_data) if(pkt->pkt.user_id->attrib_data)
fprintf (list_fp, "%u %lu", printf("%u %lu",
pkt->pkt.user_id->numattribs, pkt->pkt.user_id->numattribs,
pkt->pkt.user_id->attrib_len); pkt->pkt.user_id->attrib_len);
else else
print_string (list_fp, pkt->pkt.user_id->name, print_string( stdout, pkt->pkt.user_id->name,
pkt->pkt.user_id->len, ':'); pkt->pkt.user_id->len, ':');
} }
else else
print_utf8_string (list_fp, pkt->pkt.user_id->name, print_utf8_string( stdout, pkt->pkt.user_id->name,
pkt->pkt.user_id->len); pkt->pkt.user_id->len );
} }
@ -854,31 +827,31 @@ list_node( CTX c, KBNODE node )
c->trustletter = opt.fast_list_mode? c->trustletter = opt.fast_list_mode?
0 : get_validity_info( pk, NULL ); 0 : get_validity_info( pk, NULL );
} }
fprintf( list_fp, "%s:", mainkey? "pub":"sub" ); printf("%s:", mainkey? "pub":"sub" );
if( c->trustletter ) if( c->trustletter )
fputc( c->trustletter, list_fp ); putchar( c->trustletter );
fprintf( list_fp, ":%u:%d:%08lX%08lX:%s:%s:", 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( c->local_id ) if( c->local_id )
fprintf( list_fp, "%lu", c->local_id ); printf("%lu", c->local_id );
fputc( ':', list_fp ); putchar(':');
if( mainkey && !opt.fast_list_mode ) if( mainkey && !opt.fast_list_mode )
fputc( get_ownertrust_info (pk), list_fp ); putchar( get_ownertrust_info (pk) );
fputc( ':', list_fp ); putchar(':');
if( node->next && node->next->pkt->pkttype == PKT_RING_TRUST) { if( node->next && node->next->pkt->pkttype == PKT_RING_TRUST) {
fputc('\n', list_fp ); any=1; putchar('\n'); any=1;
if( opt.fingerprint ) if( opt.fingerprint )
print_fingerprint( pk, NULL, 0 ); print_fingerprint( pk, NULL, 0 );
fprintf( list_fp, "rtv:1:%u:\n", printf("rtv:1:%u:\n",
node->next->pkt->pkt.ring_trust->trustval ); node->next->pkt->pkt.ring_trust->trustval );
} }
} }
else else
fprintf( list_fp, "%s %4u%c/%08lX %s ", printf("%s %4u%c/%08lX %s ",
mainkey? "pub":"sub", mainkey? "pub":"sub",
nbits_from_pk( pk ), nbits_from_pk( pk ),
pubkey_letter( pk->pubkey_algo ), pubkey_letter( pk->pubkey_algo ),
@ -891,9 +864,9 @@ list_node( CTX c, KBNODE node )
if( node->pkt->pkttype == PKT_SIGNATURE ) { if( node->pkt->pkttype == PKT_SIGNATURE ) {
if( !any ) { if( !any ) {
if( node->pkt->pkt.signature->sig_class == 0x20 ) if( node->pkt->pkt.signature->sig_class == 0x20 )
fputs("[revoked]", list_fp ); puts("[revoked]");
else else
fputc('\n', list_fp ); putchar('\n');
any = 1; any = 1;
} }
list_node(c, node ); list_node(c, node );
@ -901,27 +874,27 @@ list_node( CTX c, KBNODE node )
else if( node->pkt->pkttype == PKT_USER_ID ) { else if( node->pkt->pkttype == PKT_USER_ID ) {
if( any ) { if( any ) {
if( opt.with_colons ) if( opt.with_colons )
fprintf( list_fp, "%s:::::::::", printf("%s:::::::::",
node->pkt->pkt.user_id->attrib_data?"uat":"uid"); node->pkt->pkt.user_id->attrib_data?"uat":"uid");
else else
fprintf( list_fp, "uid%*s", 28, "" ); printf( "uid%*s", 28, "" );
} }
print_userid( node->pkt ); print_userid( node->pkt );
if( opt.with_colons ) if( opt.with_colons )
fputc( ':', list_fp ); putchar(':');
fputc( '\n', list_fp ); putchar('\n');
if( opt.fingerprint && !any ) if( opt.fingerprint && !any )
print_fingerprint( pk, NULL, 0 ); print_fingerprint( pk, NULL, 0 );
if( node->next if( node->next
&& node->next->pkt->pkttype == PKT_RING_TRUST ) { && node->next->pkt->pkttype == PKT_RING_TRUST ) {
fprintf( list_fp, "rtv:2:%u:\n", printf("rtv:2:%u:\n",
node->next->pkt->pkt.ring_trust->trustval ); node->next->pkt->pkt.ring_trust->trustval );
} }
any=1; any=1;
} }
else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) { else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
if( !any ) { if( !any ) {
fputc('\n', list_fp ); putchar('\n');
any = 1; any = 1;
} }
list_node(c, node ); list_node(c, node );
@ -929,11 +902,11 @@ list_node( CTX c, KBNODE node )
} }
} }
else if( pk->expiredate ) { /* of subkey */ else if( pk->expiredate ) { /* of subkey */
fprintf( list_fp, _(" [expires: %s]"), expirestr_from_pk( pk ) ); printf(_(" [expires: %s]"), expirestr_from_pk( pk ) );
} }
if( !any ) if( !any )
fputc('\n', list_fp ); putchar('\n');
if( !mainkey && opt.fingerprint > 1 ) if( !mainkey && opt.fingerprint > 1 )
print_fingerprint( pk, NULL, 0 ); print_fingerprint( pk, NULL, 0 );
} }
@ -944,7 +917,7 @@ list_node( CTX c, KBNODE node )
if( opt.with_colons ) { if( opt.with_colons ) {
u32 keyid[2]; u32 keyid[2];
keyid_from_sk( sk, keyid ); keyid_from_sk( sk, keyid );
fprintf( list_fp, "%s::%u:%d:%08lX%08lX:%s:%s:::", printf("%s::%u:%d:%08lX%08lX:%s:%s:::",
mainkey? "sec":"ssb", mainkey? "sec":"ssb",
nbits_from_sk( sk ), nbits_from_sk( sk ),
sk->pubkey_algo, sk->pubkey_algo,
@ -954,7 +927,7 @@ list_node( CTX c, KBNODE node )
/* fixme: add LID */ ); /* fixme: add LID */ );
} }
else else
fprintf( list_fp, "%s %4u%c/%08lX %s ", printf("%s %4u%c/%08lX %s ",
mainkey? "sec":"ssb", mainkey? "sec":"ssb",
nbits_from_sk( sk ), nbits_from_sk( sk ),
pubkey_letter( sk->pubkey_algo ), pubkey_letter( sk->pubkey_algo ),
@ -966,9 +939,9 @@ list_node( CTX c, KBNODE node )
if( node->pkt->pkttype == PKT_SIGNATURE ) { if( node->pkt->pkttype == PKT_SIGNATURE ) {
if( !any ) { if( !any ) {
if( node->pkt->pkt.signature->sig_class == 0x20 ) if( node->pkt->pkt.signature->sig_class == 0x20 )
fputs("[revoked]", list_fp); puts("[revoked]");
else else
fputc('\n', list_fp); putchar('\n');
any = 1; any = 1;
} }
list_node(c, node ); list_node(c, node );
@ -976,22 +949,22 @@ list_node( CTX c, KBNODE node )
else if( node->pkt->pkttype == PKT_USER_ID ) { else if( node->pkt->pkttype == PKT_USER_ID ) {
if( any ) { if( any ) {
if( opt.with_colons ) if( opt.with_colons )
fprintf( list_fp, "%s:::::::::", printf("%s:::::::::",
node->pkt->pkt.user_id->attrib_data?"uat":"uid"); node->pkt->pkt.user_id->attrib_data?"uat":"uid");
else else
fprintf( list_fp, "uid%*s", 28, "" ); printf( "uid%*s", 28, "" );
} }
print_userid( node->pkt ); print_userid( node->pkt );
if( opt.with_colons ) if( opt.with_colons )
fputc(':', list_fp); putchar(':');
fputc('\n', list_fp); putchar('\n');
if( opt.fingerprint && !any ) if( opt.fingerprint && !any )
print_fingerprint( NULL, sk, 0 ); print_fingerprint( NULL, sk, 0 );
any=1; any=1;
} }
else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) { else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
if( !any ) { if( !any ) {
fputc('\n', list_fp); putchar('\n');
any = 1; any = 1;
} }
list_node(c, node ); list_node(c, node );
@ -1015,11 +988,11 @@ list_node( CTX c, KBNODE node )
return; return;
if( sig->sig_class == 0x20 || sig->sig_class == 0x30 ) if( sig->sig_class == 0x20 || sig->sig_class == 0x30 )
fputs("rev", list_fp); fputs("rev", stdout);
else else
fputs("sig", list_fp); fputs("sig", stdout);
if( opt.check_sigs ) { if( opt.check_sigs ) {
fflush(list_fp); fflush(stdout);
switch( (rc2=do_check_sig( c, node, &is_selfsig, NULL )) ) { switch( (rc2=do_check_sig( c, node, &is_selfsig, NULL )) ) {
case 0: sigrc = '!'; break; case 0: sigrc = '!'; break;
case G10ERR_BAD_SIGN: sigrc = '-'; break; case G10ERR_BAD_SIGN: sigrc = '-'; break;
@ -1043,36 +1016,35 @@ list_node( CTX c, KBNODE node )
} }
} }
if( opt.with_colons ) { if( opt.with_colons ) {
fputc(':', list_fp); putchar(':');
if( sigrc != ' ' ) if( sigrc != ' ' )
fputc(sigrc, list_fp); putchar(sigrc);
fprintf( list_fp, "::%d:%08lX%08lX:%s::::", sig->pubkey_algo, printf("::%d:%08lX%08lX:%s::::", sig->pubkey_algo,
(ulong)sig->keyid[0], (ulong)sig->keyid[0],
(ulong)sig->keyid[1], colon_datestr_from_sig(sig)); (ulong)sig->keyid[1], colon_datestr_from_sig(sig));
} }
else else
fprintf( list_fp, "%c %08lX %s ", printf("%c %08lX %s ",
sigrc, (ulong)sig->keyid[1], datestr_from_sig(sig)); sigrc, (ulong)sig->keyid[1], datestr_from_sig(sig));
if( sigrc == '%' ) if( sigrc == '%' )
fprintf( list_fp, "[%s] ", g10_errstr(rc2) ); printf("[%s] ", g10_errstr(rc2) );
else if( sigrc == '?' ) else if( sigrc == '?' )
; ;
else if( is_selfsig ) { else if( is_selfsig ) {
if( opt.with_colons ) if( opt.with_colons )
fputc(':', list_fp); putchar(':');
fputs( sig->sig_class == 0x18? "[keybind]":"[selfsig]", list_fp ); fputs( sig->sig_class == 0x18? "[keybind]":"[selfsig]", stdout);
if( opt.with_colons ) if( opt.with_colons )
fputc(':', list_fp); putchar(':');
} }
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 );
print_string( list_fp, p, n, opt.with_colons ); print_string( stdout, p, n, opt.with_colons );
m_free(p); m_free(p);
} }
if( opt.with_colons ) if( opt.with_colons )
fprintf( list_fp, ":%02x%c:", sig->sig_class, printf(":%02x%c:", sig->sig_class, sig->flags.exportable?'x':'l');
sig->flags.exportable?'x':'l'); putchar('\n');
fputc('\n', list_fp);
} }
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);
@ -1132,8 +1104,6 @@ do_proc_packets( CTX c, IOBUF a )
int any_data=0; int any_data=0;
int newpkt; int newpkt;
if( !list_fp )
list_fp = stdout;
c->iobuf = a; c->iobuf = a;
init_packet(pkt); init_packet(pkt);
while( (rc=parse_packet(a, pkt)) != -1 ) { while( (rc=parse_packet(a, pkt)) != -1 ) {

@ -356,8 +356,6 @@ int proc_signature_packets( void *ctx, IOBUF a,
STRLIST signedfiles, const char *sigfile ); STRLIST signedfiles, const char *sigfile );
int proc_encryption_packets( void *ctx, IOBUF a ); int proc_encryption_packets( void *ctx, IOBUF a );
int list_packets( IOBUF a ); int list_packets( IOBUF a );
void mainproc_open_output( const char * file );
FILE* mainproc_get_output( void );
/*-- parse-packet.c --*/ /*-- parse-packet.c --*/
int set_packet_list_mode( int mode ); int set_packet_list_mode( int mode );