po: auto update
[gnupg.git] / g10 / tdbdump.c
index bf9f387..2c6f5c2 100644 (file)
@@ -14,7 +14,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
 
 #include <config.h>
 #include <string.h>
 #include <errno.h>
 #include <ctype.h>
-#include <assert.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
 
 #include "gpg.h"
-#include "status.h"
-#include "iobuf.h"
+#include "../common/status.h"
+#include "../common/iobuf.h"
 #include "keydb.h"
-#include "util.h"
+#include "../common/util.h"
 #include "trustdb.h"
 #include "options.h"
 #include "packet.h"
 #include "main.h"
-#include "i18n.h"
+#include "../common/i18n.h"
 #include "tdbio.h"
 
 
                      (x) >= 'A' && (x) <= 'F' ? ((x)-'A'+10) : ((x)-'a'+10))
 
 
-/****************
- * Wirte a record but die on error
+/*
+ * Write a record; die on error.
  */
 static void
-write_record( TRUSTREC *rec )
+write_record (ctrl_t ctrl, TRUSTREC *rec)
 {
-    int rc = tdbio_write_record( rec );
+    int rc = tdbio_write_record (ctrl, rec);
     if( !rc )
        return;
     log_error(_("trust record %lu, type %d: write failed: %s\n"),
@@ -61,29 +60,29 @@ 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 (ctrl_t ctrl, estream_t fp, const char *username)
 {
   TRUSTREC rec;
 
   (void)username;
 
-  init_trustdb();
+  init_trustdb (ctrl, 0);
   /* For now we ignore the user ID. */
   if (1)
     {
       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);
     }
 }
 
@@ -95,14 +94,14 @@ list_trustdb( const char *username )
  * Print a list of all defined owner trust value.
  */
 void
-export_ownertrust()
+export_ownertrust (ctrl_t ctrl)
 {
   TRUSTREC rec;
   ulong recnum;
   int i;
   byte *p;
 
-  init_trustdb();
+  init_trustdb (ctrl, 0);
   es_printf (_("# List of assigned trustvalues, created %s\n"
                "# (Use \"gpg --import-ownertrust\" to restore them)\n"),
              asctimestamp( make_timestamp() ) );
@@ -122,7 +121,7 @@ export_ownertrust()
 
 
 void
-import_ownertrust( const char *fname )
+import_ownertrust (ctrl_t ctrl, const char *fname )
 {
     estream_t fp;
     int is_stdin=0;
@@ -134,7 +133,7 @@ import_ownertrust( const char *fname )
     int any = 0;
     int rc;
 
-    init_trustdb();
+    init_trustdb (ctrl, 0);
     if( iobuf_is_pipe_filename (fname) ) {
        fp = es_stdin;
        fname = "[stdin]";
@@ -190,28 +189,32 @@ import_ownertrust( const char *fname )
        while (fprlen < 20)
            fpr[fprlen++] = 0;
 
-       rc = tdbio_search_trust_byfpr (fpr, &rec);
+       rc = tdbio_search_trust_byfpr (ctrl, fpr, &rec);
        if( !rc ) { /* found: update */
            if (rec.r.trust.ownertrust != otrust)
               {
-                if( rec.r.trust.ownertrust )
-                  log_info("changing ownertrust from %u to %u\n",
-                           rec.r.trust.ownertrust, otrust );
-                else
-                  log_info("setting ownertrust to %u\n", otrust );
+                if (!opt.quiet)
+                  {
+                    if( rec.r.trust.ownertrust )
+                      log_info("changing ownertrust from %u to %u\n",
+                               rec.r.trust.ownertrust, otrust );
+                    else
+                      log_info("setting ownertrust to %u\n", otrust );
+                  }
                 rec.r.trust.ownertrust = otrust;
-                write_record (&rec );
+                write_record (ctrl, &rec);
                 any = 1;
               }
        }
-       else if( rc == -1 ) { /* not found: insert */
-            log_info("inserting ownertrust of %u\n", otrust );
+       else if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND) { /* insert */
+            if (!opt.quiet)
+              log_info("inserting ownertrust of %u\n", otrust );
             memset (&rec, 0, sizeof rec);
-            rec.recnum = tdbio_new_recnum ();
+            rec.recnum = tdbio_new_recnum (ctrl);
             rec.rectype = RECTYPE_TRUST;
             memcpy (rec.r.trust.fingerprint, fpr, 20);
             rec.r.trust.ownertrust = otrust;
-            write_record (&rec );
+            write_record (ctrl, &rec);
             any = 1;
        }
        else /* error */
@@ -225,7 +228,7 @@ import_ownertrust( const char *fname )
 
     if (any)
       {
-        revalidation_mark ();
+        revalidation_mark (ctrl);
         rc = tdbio_sync ();
         if (rc)
           log_error (_("trustdb: sync failed: %s\n"), gpg_strerror (rc) );