1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-05-31 22:18:03 +02:00

gpg: Fix output in case of a corrupted trustdb.

* g10/tdbdump.c (list_trustdb): Add arg FP and change callers to pass
es_stdout.
* g10/tdbio.c (upd_hashtable): On a corrupted trustdb call
list_trustdb only in verbose > 1 mode and let it dump to stderr.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2015-06-04 17:34:33 +02:00
parent 840f807a90
commit bf06d04f53
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
4 changed files with 14 additions and 13 deletions

View File

@ -4167,10 +4167,10 @@ main (int argc, char **argv)
#ifndef NO_TRUST_MODELS #ifndef NO_TRUST_MODELS
case aListTrustDB: case aListTrustDB:
if( !argc ) if( !argc )
list_trustdb(NULL); list_trustdb (es_stdout, NULL);
else { else {
for( ; argc; argc--, argv++ ) for( ; argc; argc--, argv++ )
list_trustdb( *argv ); list_trustdb (es_stdout, *argv );
} }
break; break;

View File

@ -61,11 +61,11 @@ write_record( TRUSTREC *rec )
} }
/**************** /*
* Dump the entire trustdb or only the entries of one key. * Dump the entire trustdb to FP or only the entries of one key.
*/ */
void void
list_trustdb (const char *username) list_trustdb (estream_t fp, const char *username)
{ {
TRUSTREC rec; TRUSTREC rec;
@ -78,12 +78,12 @@ list_trustdb (const char *username)
ulong recnum; ulong recnum;
int i; int i;
es_printf ("TrustDB: %s\n", tdbio_get_dbname() ); es_fprintf (fp, "TrustDB: %s\n", tdbio_get_dbname ());
for(i=9+strlen(tdbio_get_dbname()); i > 0; i-- ) for (i = 9 + strlen (tdbio_get_dbname()); i > 0; i-- )
es_putc ('-', es_stdout); es_fputc ('-', fp);
es_putc ('\n', es_stdout); es_putc ('\n', fp);
for(recnum=0; !tdbio_read_record( recnum, &rec, 0); recnum++ ) for (recnum=0; !tdbio_read_record (recnum, &rec, 0); recnum++)
tdbio_dump_record (&rec, es_stdout); tdbio_dump_record (&rec, fp);
} }
} }

View File

@ -1132,7 +1132,8 @@ upd_hashtable (ulong table, byte *key, int keylen, ulong newrecnum)
{ {
log_error ("hashtbl %lu: %lu/%d points to an invalid record %lu\n", log_error ("hashtbl %lu: %lu/%d points to an invalid record %lu\n",
table, hashrec, (msb % ITEMS_PER_HTBL_RECORD), item); table, hashrec, (msb % ITEMS_PER_HTBL_RECORD), item);
list_trustdb (NULL); /*FIXME: Bad - prints to stdout!!! */ if (opt.verbose > 1)
list_trustdb (es_stderr, NULL);
return GPG_ERR_TRUSTDB; return GPG_ERR_TRUSTDB;
} }
} }

View File

@ -141,7 +141,7 @@ void tdb_update_ownertrust (PKT_public_key *pk, unsigned int new_trust);
int tdb_clear_ownertrusts (PKT_public_key *pk); int tdb_clear_ownertrusts (PKT_public_key *pk);
/*-- tdbdump.c --*/ /*-- tdbdump.c --*/
void list_trustdb(const char *username); void list_trustdb (estream_t fp, const char *username);
void export_ownertrust(void); void export_ownertrust(void);
void import_ownertrust(const char *fname); void import_ownertrust(const char *fname);