summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2015-06-04 17:34:33 +0200
committerWerner Koch <wk@gnupg.org>2015-06-04 17:34:55 +0200
commitbf06d04f53296f4b4b73b9360cf1571559bb2295 (patch)
tree1cf683828bb43715bc1b9896886a4ceb14a62bdd
parentgpg: Re-indent and improve documentation of g10/tdbio.c (diff)
downloadgnupg2-bf06d04f53296f4b4b73b9360cf1571559bb2295.tar.xz
gnupg2-bf06d04f53296f4b4b73b9360cf1571559bb2295.zip
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>
-rw-r--r--g10/gpg.c4
-rw-r--r--g10/tdbdump.c18
-rw-r--r--g10/tdbio.c3
-rw-r--r--g10/trustdb.h2
4 files changed, 14 insertions, 13 deletions
diff --git a/g10/gpg.c b/g10/gpg.c
index 5a8a6621f..1801c878d 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -4167,10 +4167,10 @@ main (int argc, char **argv)
#ifndef NO_TRUST_MODELS
case aListTrustDB:
if( !argc )
- list_trustdb(NULL);
+ list_trustdb (es_stdout, NULL);
else {
for( ; argc; argc--, argv++ )
- list_trustdb( *argv );
+ list_trustdb (es_stdout, *argv );
}
break;
diff --git a/g10/tdbdump.c b/g10/tdbdump.c
index f9a047351..ff90b46ed 100644
--- a/g10/tdbdump.c
+++ b/g10/tdbdump.c
@@ -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
-list_trustdb (const char *username)
+list_trustdb (estream_t fp, const char *username)
{
TRUSTREC rec;
@@ -78,12 +78,12 @@ list_trustdb (const char *username)
ulong recnum;
int i;
- es_printf ("TrustDB: %s\n", tdbio_get_dbname() );
- for(i=9+strlen(tdbio_get_dbname()); i > 0; i-- )
- es_putc ('-', es_stdout);
- es_putc ('\n', es_stdout);
- for(recnum=0; !tdbio_read_record( recnum, &rec, 0); recnum++ )
- tdbio_dump_record (&rec, es_stdout);
+ es_fprintf (fp, "TrustDB: %s\n", tdbio_get_dbname ());
+ for (i = 9 + strlen (tdbio_get_dbname()); i > 0; i-- )
+ es_fputc ('-', fp);
+ es_putc ('\n', fp);
+ for (recnum=0; !tdbio_read_record (recnum, &rec, 0); recnum++)
+ tdbio_dump_record (&rec, fp);
}
}
diff --git a/g10/tdbio.c b/g10/tdbio.c
index 4d65e61e8..b6b5938e2 100644
--- a/g10/tdbio.c
+++ b/g10/tdbio.c
@@ -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",
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;
}
}
diff --git a/g10/trustdb.h b/g10/trustdb.h
index f190f72c1..771a821fd 100644
--- a/g10/trustdb.h
+++ b/g10/trustdb.h
@@ -141,7 +141,7 @@ void tdb_update_ownertrust (PKT_public_key *pk, unsigned int new_trust);
int tdb_clear_ownertrusts (PKT_public_key *pk);
/*-- tdbdump.c --*/
-void list_trustdb(const char *username);
+void list_trustdb (estream_t fp, const char *username);
void export_ownertrust(void);
void import_ownertrust(const char *fname);