* tdbio.h, tdbio.c (tdbio_read_record, tdbio_write_record): Store trust
authorDavid Shaw <dshaw@jabberwocky.com>
Wed, 4 Dec 2002 00:05:11 +0000 (00:05 +0000)
committerDavid Shaw <dshaw@jabberwocky.com>
Wed, 4 Dec 2002 00:05:11 +0000 (00:05 +0000)
model in the trustdb version record. (tdbio_update_version_record): New
function to update version record values during a trustdb check or update.
(tdbio_dump_record): Show trust model in dump.

* trustdb.c (validate_keys): Call tdbio_update_version_record on success
so that the correct options are stored in the trustdb.

* options.h: rearrange trust models so that CLASSIC is 0 and OPENPGP is 1.

g10/ChangeLog
g10/options.h
g10/tdbio.c
g10/tdbio.h
g10/trustdb.c

index ae9bdcb..d30496e 100644 (file)
@@ -1,5 +1,17 @@
 2002-12-03  David Shaw  <dshaw@jabberwocky.com>
 
+       * tdbio.h, tdbio.c (tdbio_read_record, tdbio_write_record): Store
+       trust model in the trustdb version record.
+       (tdbio_update_version_record): New function to update version
+       record values during a trustdb check or update.
+       (tdbio_dump_record): Show trust model in dump.
+
+       * trustdb.c (validate_keys): Call tdbio_update_version_record on
+       success so that the correct options are stored in the trustdb.
+
+       * options.h: rearrange trust models so that CLASSIC is 0 and
+       OPENPGP is 1.
+
        * options.h, g10.c (main), encode.c (write_pubkey_enc_from_list),
        pkclist.c (algo_available), revoke.c (gen_revoke): Add --pgp8
        mode.  This is basically identical to --pgp7 in all ways except
index 9917a4a..d8857be 100644 (file)
@@ -88,7 +88,7 @@ struct {
     int skip_verify;
     int compress_keys;
     int compress_sigs;
-    enum {TM_OPENPGP, TM_CLASSIC, TM_ALWAYS} trust_model;
+    enum {TM_CLASSIC=0, TM_OPENPGP=1, TM_ALWAYS} trust_model;
     unsigned int force_ownertrust;
     int pgp2;
     int pgp6;
index c928b76..45fae04 100644 (file)
@@ -418,6 +418,29 @@ cleanup(void)
     }
 }
 
+/* Caller must sync */
+int
+tdbio_update_version_record (void)
+{
+  TRUSTREC rec;
+  int rc;
+
+  memset( &rec, 0, sizeof rec );
+
+  rc=tdbio_read_record( 0, &rec, RECTYPE_VER);
+  if(rc==0)
+    {
+      rec.r.ver.created     = make_timestamp();
+      rec.r.ver.marginals   = opt.marginals_needed;
+      rec.r.ver.completes   = opt.completes_needed;
+      rec.r.ver.cert_depth  = opt.max_cert_depth;
+      rec.r.ver.trust_model = opt.trust_model;
+      rc=tdbio_write_record(&rec);
+    }
+
+  return rc;
+}
+
 static int
 create_version_record (void)
 {
@@ -425,11 +448,12 @@ create_version_record (void)
   int rc;
   
   memset( &rec, 0, sizeof rec );
-  rec.r.ver.version = 3;
-  rec.r.ver.created = make_timestamp();
-  rec.r.ver.marginals =  opt.marginals_needed;
-  rec.r.ver.completes =  opt.completes_needed;
-  rec.r.ver.cert_depth = opt.max_cert_depth;
+  rec.r.ver.version     = 3;
+  rec.r.ver.created     = make_timestamp();
+  rec.r.ver.marginals   = opt.marginals_needed;
+  rec.r.ver.completes   = opt.completes_needed;
+  rec.r.ver.cert_depth  = opt.max_cert_depth;
+  rec.r.ver.trust_model = opt.trust_model;
   rec.rectype = RECTYPE_VER;
   rec.recnum = 0;
   rc = tdbio_write_record( &rec );
@@ -1060,12 +1084,13 @@ tdbio_dump_record( TRUSTREC *rec, FILE *fp  )
       case 0: fprintf(fp, "blank\n");
        break;
       case RECTYPE_VER: fprintf(fp,
-           "version, td=%lu, f=%lu, m/c/d=%d/%d/%d nc=%lu (%s)\n",
+           "version, td=%lu, f=%lu, m/c/d=%d/%d/%d tm=%d nc=%lu (%s)\n",
                                    rec->r.ver.trusthashtbl,
                                   rec->r.ver.firstfree,
                                   rec->r.ver.marginals,
                                   rec->r.ver.completes,
                                   rec->r.ver.cert_depth,
+                                  rec->r.ver.trust_model,
                                    rec->r.ver.nextcheck,
                                   strtimestamp(rec->r.ver.nextcheck)
                                  );
@@ -1158,7 +1183,8 @@ tdbio_read_record( ulong recnum, TRUSTREC *rec, int expected )
        rec->r.ver.marginals = *p++;
        rec->r.ver.completes = *p++;
        rec->r.ver.cert_depth = *p++;
-       p += 4; /* lock flags */
+       rec->r.ver.trust_model = *p++;
+       p += 3;
        rec->r.ver.created  = buftoulong(p); p += 4;
        rec->r.ver.nextcheck = buftoulong(p); p += 4;
        p += 4;
@@ -1242,7 +1268,8 @@ tdbio_write_record( TRUSTREC *rec )
        *p++ = rec->r.ver.marginals;
        *p++ = rec->r.ver.completes;
        *p++ = rec->r.ver.cert_depth;
-       p += 4; /* skip lock flags */
+       *p++ = rec->r.ver.trust_model;
+       p += 3;
        ulongtobuf(p, rec->r.ver.created); p += 4;
        ulongtobuf(p, rec->r.ver.nextcheck); p += 4;
        p += 4;
index 6a28edc..91a73ef 100644 (file)
@@ -54,6 +54,7 @@ struct trust_record {
            byte  marginals;
            byte  completes;
            byte  cert_depth;
+           byte  trust_model;
            ulong created;   /* timestamp of trustdb creation  */
            ulong nextcheck; /* timestamp of next scheduled check */
            ulong reserved;  
@@ -89,6 +90,7 @@ struct trust_record {
 typedef struct trust_record TRUSTREC;
 
 /*-- tdbio.c --*/
+int tdbio_update_version_record(void);
 int tdbio_set_dbname( const char *new_dbname, int create );
 const char *tdbio_get_dbname(void);
 void tdbio_dump_record( TRUSTREC *rec, FILE *fp );
index ffdce2c..8c732bb 100644 (file)
@@ -1912,6 +1912,7 @@ validate_keys (int interactive)
           log_info (_("next trustdb check due at %s\n"),
                     strtimestamp (next_expire));
         }
+      tdbio_update_version_record();
       do_sync ();
       pending_check_trustdb = 0;
     }