* options.h, gpg.c (main), mainproc.c (check_sig_and_print), keyserver.c
[gnupg.git] / g10 / tdbio.c
index 62ff267..fbd569d 100644 (file)
@@ -15,7 +15,8 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
  */
 
 #include <config.h>
  */
 
 #include <config.h>
 #include "trustdb.h"
 #include "tdbio.h"
 
 #include "trustdb.h"
 #include "tdbio.h"
 
-#if defined(HAVE_DOSISH_SYSTEM) && !defined(__CYGWIN32__)
+#if defined(HAVE_DOSISH_SYSTEM)
 #define ftruncate chsize
 #endif
 
 #define ftruncate chsize
 #endif
 
-#ifdef HAVE_DOSISH_SYSTEM
+#if defined(HAVE_DOSISH_SYSTEM) || defined(__CYGWIN__)
 #define MY_O_BINARY  O_BINARY
 #else
 #define MY_O_BINARY  0
 #define MY_O_BINARY  O_BINARY
 #else
 #define MY_O_BINARY  0
@@ -187,7 +188,7 @@ put_record_into_cache( ulong recno, const char *data )
     }
     /* see whether we reached the limit */
     if( cache_entries < MAX_CACHE_ENTRIES_SOFT ) { /* no */
     }
     /* see whether we reached the limit */
     if( cache_entries < MAX_CACHE_ENTRIES_SOFT ) { /* no */
-       r = m_alloc( sizeof *r );
+       r = xmalloc( sizeof *r );
        r->flags.used = 1;
        r->recno = recno;
        memcpy( r->data, data, TRUST_RECORD_LEN );
        r->flags.used = 1;
        r->recno = recno;
        memcpy( r->data, data, TRUST_RECORD_LEN );
@@ -230,7 +231,7 @@ put_record_into_cache( ulong recno, const char *data )
        if( cache_entries < MAX_CACHE_ENTRIES_HARD ) { /* no */
            if( opt.debug && !(cache_entries % 100) )
                log_debug("increasing tdbio cache size\n");
        if( cache_entries < MAX_CACHE_ENTRIES_HARD ) { /* no */
            if( opt.debug && !(cache_entries % 100) )
                log_debug("increasing tdbio cache size\n");
-           r = m_alloc( sizeof *r );
+           r = xmalloc( sizeof *r );
            r->flags.used = 1;
            r->recno = recno;
            memcpy( r->data, data, TRUST_RECORD_LEN );
            r->flags.used = 1;
            r->recno = recno;
            memcpy( r->data, data, TRUST_RECORD_LEN );
@@ -332,7 +333,9 @@ tdbio_sync()
     return 0;
 }
 
     return 0;
 }
 
-
+#if 0
+/* The transaction code is disabled in the 1.2.x branch, as it is not
+   yet used.  It will be enabled in 1.3.x. */
 
 /****************
  * Simple transactions system:
 
 /****************
  * Simple transactions system:
@@ -402,7 +405,7 @@ tdbio_cancel_transaction()
     in_transaction = 0;
     return 0;
 }
     in_transaction = 0;
     return 0;
 }
-
+#endif
 
 \f
 /********************************************************
 
 \f
 /********************************************************
@@ -418,6 +421,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)
 {
 static int
 create_version_record (void)
 {
@@ -425,11 +451,15 @@ create_version_record (void)
   int rc;
   
   memset( &rec, 0, sizeof rec );
   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;
+  if(opt.trust_model==TM_PGP || opt.trust_model==TM_CLASSIC)
+    rec.r.ver.trust_model = opt.trust_model;
+  else
+    rec.r.ver.trust_model = TM_PGP;
   rec.rectype = RECTYPE_VER;
   rec.recnum = 0;
   rc = tdbio_write_record( &rec );
   rec.rectype = RECTYPE_VER;
   rec.recnum = 0;
   rc = tdbio_write_record( &rec );
@@ -450,14 +480,23 @@ tdbio_set_dbname( const char *new_dbname, int create )
        atexit( cleanup );
        initialized = 1;
     }
        atexit( cleanup );
        initialized = 1;
     }
-    fname = new_dbname? m_strdup( new_dbname )
-                     : make_filename(opt.homedir,
-                                     "trustdb" EXTSEP_S "gpg", NULL );
+
+    if(new_dbname==NULL)
+      fname=make_filename(opt.homedir,"trustdb" EXTSEP_S "gpg", NULL);
+    else if (*new_dbname != DIRSEP_C )
+      {
+       if (strchr(new_dbname, DIRSEP_C) )
+         fname = make_filename (new_dbname, NULL);
+       else
+         fname = make_filename (opt.homedir, new_dbname, NULL);
+      }
+    else
+      fname = xstrdup (new_dbname);
 
     if( access( fname, R_OK ) ) {
        if( errno != ENOENT ) {
 
     if( access( fname, R_OK ) ) {
        if( errno != ENOENT ) {
-           log_error( _("%s: can't access: %s\n"), fname, strerror(errno) );
-           m_free(fname);
+           log_error( _("can't access `%s': %s\n"), fname, strerror(errno) );
+           xfree(fname);
            return G10ERR_TRUSTDB;
        }
        if( create ) {
            return G10ERR_TRUSTDB;
        }
        if( create ) {
@@ -475,31 +514,36 @@ tdbio_set_dbname( const char *new_dbname, int create )
            }
            *p = DIRSEP_C;
 
            }
            *p = DIRSEP_C;
 
-           m_free(db_name);
+           xfree(db_name);
            db_name = fname;
 #ifdef __riscos__
            if( !lockhandle )
                lockhandle = create_dotlock( db_name );
            if( !lockhandle )
            db_name = fname;
 #ifdef __riscos__
            if( !lockhandle )
                lockhandle = create_dotlock( db_name );
            if( !lockhandle )
-               log_fatal( _("%s: can't create lock\n"), db_name );
+               log_fatal( _("can't create lock for `%s'\n"), db_name );
             if( make_dotlock( lockhandle, -1 ) )
             if( make_dotlock( lockhandle, -1 ) )
-                log_fatal( _("%s: can't make lock\n"), db_name );
+                log_fatal( _("can't lock `%s'\n"), db_name );
 #endif /* __riscos__ */
            oldmask=umask(077);
 #endif /* __riscos__ */
            oldmask=umask(077);
-           fp =fopen( fname, "wb" );
+            if (is_secured_filename (fname)) {
+                fp = NULL;
+                errno = EPERM;
+            }
+            else
+                fp =fopen( fname, "wb" );
            umask(oldmask);
            if( !fp )
            umask(oldmask);
            if( !fp )
-               log_fatal( _("%s: can't create: %s\n"), fname, strerror(errno) );
+               log_fatal( _("can't create `%s': %s\n"), fname, strerror(errno) );
            fclose(fp);
            db_fd = open( db_name, O_RDWR | MY_O_BINARY );
            if( db_fd == -1 )
            fclose(fp);
            db_fd = open( db_name, O_RDWR | MY_O_BINARY );
            if( db_fd == -1 )
-               log_fatal( _("%s: can't open: %s\n"), db_name, strerror(errno) );
+               log_fatal( _("can't open `%s': %s\n"), db_name, strerror(errno) );
 
 #ifndef __riscos__
            if( !lockhandle )
                lockhandle = create_dotlock( db_name );
            if( !lockhandle )
 
 #ifndef __riscos__
            if( !lockhandle )
                lockhandle = create_dotlock( db_name );
            if( !lockhandle )
-               log_fatal( _("%s: can't create lock\n"), db_name );
+               log_fatal( _("can't create lock for `%s'\n"), db_name );
 #endif /* !__riscos__ */
 
             rc = create_version_record ();
 #endif /* !__riscos__ */
 
             rc = create_version_record ();
@@ -516,7 +560,7 @@ tdbio_set_dbname( const char *new_dbname, int create )
            return 0;
        }
     }
            return 0;
        }
     }
-    m_free(db_name);
+    xfree(db_name);
     db_name = fname;
     return 0;
 }
     db_name = fname;
     return 0;
 }
@@ -542,19 +586,24 @@ open_db()
   if (!lockhandle )
     lockhandle = create_dotlock( db_name );
   if (!lockhandle )
   if (!lockhandle )
     lockhandle = create_dotlock( db_name );
   if (!lockhandle )
-    log_fatal( _("%s: can't create lock\n"), db_name );
+    log_fatal( _("can't create lock for `%s'\n"), db_name );
 #ifdef __riscos__
   if (make_dotlock( lockhandle, -1 ) )
 #ifdef __riscos__
   if (make_dotlock( lockhandle, -1 ) )
-    log_fatal( _("%s: can't make lock\n"), db_name );
+    log_fatal( _("can't lock `%s'\n"), db_name );
 #endif /* __riscos__ */
   db_fd = open (db_name, O_RDWR | MY_O_BINARY );
 #endif /* __riscos__ */
   db_fd = open (db_name, O_RDWR | MY_O_BINARY );
-  if (db_fd == -1 && errno == EACCES) {
+  if (db_fd == -1 && (errno == EACCES
+#ifdef EROFS
+                      || errno == EROFS)
+#endif
+      ) {
       db_fd = open (db_name, O_RDONLY | MY_O_BINARY );
       if (db_fd != -1)
           log_info (_("NOTE: trustdb not writable\n"));
   }
   if ( db_fd == -1 )
       db_fd = open (db_name, O_RDONLY | MY_O_BINARY );
       if (db_fd != -1)
           log_info (_("NOTE: trustdb not writable\n"));
   }
   if ( db_fd == -1 )
-    log_fatal( _("%s: can't open: %s\n"), db_name, strerror(errno) );
+    log_fatal( _("can't open `%s': %s\n"), db_name, strerror(errno) );
+  register_secured_file (db_name);
 
   /* check whether we need to do a version migration */
   do
 
   /* check whether we need to do a version migration */
   do
@@ -615,38 +664,39 @@ create_hashtable( TRUSTREC *vr, int type )
 int
 tdbio_db_matches_options()
 {
 int
 tdbio_db_matches_options()
 {
-    static int yes_no = -1;
+  static int yes_no = -1;
 
 
-    if( yes_no == -1 ) {
-       TRUSTREC vr;
-       int rc;
-
-       rc = tdbio_read_record( 0, &vr, RECTYPE_VER );
-       if( rc )
-           log_fatal( _("%s: error reading version record: %s\n"),
-                                                   db_name, g10_errstr(rc) );
+  if( yes_no == -1 )
+    {
+      TRUSTREC vr;
+      int rc;
 
 
-       if( !vr.r.ver.marginals && !vr.r.ver.completes
-                               && !vr.r.ver.cert_depth )
-       {   /* special hack for trustdbs created by old versions of GnuPG */
-           vr.r.ver.marginals =  opt.marginals_needed;
-           vr.r.ver.completes =  opt.completes_needed;
-           vr.r.ver.cert_depth = opt.max_cert_depth;
-           rc = tdbio_write_record( &vr );
-           if( !rc && !in_transaction )
-               rc = tdbio_sync();
-           if( rc )
-               log_error( _("%s: error writing version record: %s\n"),
-                                               db_name, g10_errstr(rc) );
-       }
+      rc = tdbio_read_record( 0, &vr, RECTYPE_VER );
+      if( rc )
+       log_fatal( _("%s: error reading version record: %s\n"),
+                  db_name, g10_errstr(rc) );
 
 
-       yes_no = vr.r.ver.marginals == opt.marginals_needed
-                && vr.r.ver.completes == opt.completes_needed
-                && vr.r.ver.cert_depth == opt.max_cert_depth;
+      yes_no = vr.r.ver.marginals == opt.marginals_needed
+       && vr.r.ver.completes == opt.completes_needed
+       && vr.r.ver.cert_depth == opt.max_cert_depth
+       && vr.r.ver.trust_model == opt.trust_model;
     }
     }
-    return yes_no;
+
+  return yes_no;
 }
 
 }
 
+byte
+tdbio_read_model(void)
+{
+  TRUSTREC vr;
+  int rc;
+  rc = tdbio_read_record( 0, &vr, RECTYPE_VER );
+  if( rc )
+    log_fatal( _("%s: error reading version record: %s\n"),
+              db_name, g10_errstr(rc) );
+  return vr.r.ver.trust_model;
+}
 
 /****************
  * Return the nextstamp value.
 
 /****************
  * Return the nextstamp value.
@@ -735,8 +785,7 @@ upd_hashtable( ulong table, byte *key, int keylen, ulong newrecnum )
     hashrec += msb / ITEMS_PER_HTBL_RECORD;
     rc = tdbio_read_record( hashrec, &rec, RECTYPE_HTBL );
     if( rc ) {
     hashrec += msb / ITEMS_PER_HTBL_RECORD;
     rc = tdbio_read_record( hashrec, &rec, RECTYPE_HTBL );
     if( rc ) {
-       log_error( db_name, "upd_hashtable: read failed: %s\n",
-                                                       g10_errstr(rc) );
+       log_error("upd_hashtable: read failed: %s\n",   g10_errstr(rc) );
        return rc;
     }
 
        return rc;
     }
 
@@ -745,7 +794,7 @@ upd_hashtable( ulong table, byte *key, int keylen, ulong newrecnum )
        rec.r.htbl.item[msb % ITEMS_PER_HTBL_RECORD] = newrecnum;
        rc = tdbio_write_record( &rec );
        if( rc ) {
        rec.r.htbl.item[msb % ITEMS_PER_HTBL_RECORD] = newrecnum;
        rc = tdbio_write_record( &rec );
        if( rc ) {
-           log_error( db_name, "upd_hashtable: write htbl failed: %s\n",
+           log_error("upd_hashtable: write htbl failed: %s\n",
                                                            g10_errstr(rc) );
            return rc;
        }
                                                            g10_errstr(rc) );
            return rc;
        }
@@ -884,7 +933,7 @@ drop_from_hashtable( ulong table, byte *key, int keylen, ulong recnum )
     hashrec += msb / ITEMS_PER_HTBL_RECORD;
     rc = tdbio_read_record( hashrec, &rec, RECTYPE_HTBL );
     if( rc ) {
     hashrec += msb / ITEMS_PER_HTBL_RECORD;
     rc = tdbio_read_record( hashrec, &rec, RECTYPE_HTBL );
     if( rc ) {
-       log_error( db_name, "drop_from_hashtable: read failed: %s\n",
+       log_error("drop_from_hashtable: read failed: %s\n",
                                                        g10_errstr(rc) );
        return rc;
     }
                                                        g10_errstr(rc) );
        return rc;
     }
@@ -897,7 +946,7 @@ drop_from_hashtable( ulong table, byte *key, int keylen, ulong recnum )
        rec.r.htbl.item[msb % ITEMS_PER_HTBL_RECORD] = 0;
        rc = tdbio_write_record( &rec );
        if( rc )
        rec.r.htbl.item[msb % ITEMS_PER_HTBL_RECORD] = 0;
        rc = tdbio_write_record( &rec );
        if( rc )
-           log_error( db_name, "drop_from_hashtable: write htbl failed: %s\n",
+           log_error("drop_from_hashtable: write htbl failed: %s\n",
                                                            g10_errstr(rc) );
        return rc;
     }
                                                            g10_errstr(rc) );
        return rc;
     }
@@ -926,7 +975,7 @@ drop_from_hashtable( ulong table, byte *key, int keylen, ulong recnum )
                    rec.r.hlst.rnum[i] = 0; /* drop */
                    rc = tdbio_write_record( &rec );
                    if( rc )
                    rec.r.hlst.rnum[i] = 0; /* drop */
                    rc = tdbio_write_record( &rec );
                    if( rc )
-                       log_error( db_name, "drop_from_hashtable: write htbl failed: %s\n",
+                       log_error("drop_from_hashtable: write htbl failed: %s\n",
                                                                        g10_errstr(rc) );
                    return rc;
                }
                                                                        g10_errstr(rc) );
                    return rc;
                }
@@ -973,7 +1022,7 @@ lookup_hashtable( ulong table, const byte *key, size_t keylen,
     hashrec += msb / ITEMS_PER_HTBL_RECORD;
     rc = tdbio_read_record( hashrec, rec, RECTYPE_HTBL );
     if( rc ) {
     hashrec += msb / ITEMS_PER_HTBL_RECORD;
     rc = tdbio_read_record( hashrec, rec, RECTYPE_HTBL );
     if( rc ) {
-       log_error( db_name, "lookup_hashtable failed: %s\n", g10_errstr(rc) );
+       log_error("lookup_hashtable failed: %s\n", g10_errstr(rc) );
        return rc;
     }
 
        return rc;
     }
 
@@ -983,14 +1032,14 @@ lookup_hashtable( ulong table, const byte *key, size_t keylen,
 
     rc = tdbio_read_record( item, rec, 0 );
     if( rc ) {
 
     rc = tdbio_read_record( item, rec, 0 );
     if( rc ) {
-       log_error( db_name, "hashtable read failed: %s\n", g10_errstr(rc) );
+       log_error( "hashtable read failed: %s\n", g10_errstr(rc) );
        return rc;
     }
     if( rec->rectype == RECTYPE_HTBL ) {
        hashrec = item;
        level++;
        if( level >= keylen ) {
        return rc;
     }
     if( rec->rectype == RECTYPE_HTBL ) {
        hashrec = item;
        level++;
        if( level >= keylen ) {
-           log_error( db_name, "hashtable has invalid indirections\n");
+           log_error("hashtable has invalid indirections\n");
            return G10ERR_TRUSTDB;
        }
        goto next_level;
            return G10ERR_TRUSTDB;
        }
        goto next_level;
@@ -1060,12 +1109,13 @@ tdbio_dump_record( TRUSTREC *rec, FILE *fp  )
       case 0: fprintf(fp, "blank\n");
        break;
       case RECTYPE_VER: fprintf(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.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)
                                  );
                                    rec->r.ver.nextcheck,
                                   strtimestamp(rec->r.ver.nextcheck)
                                  );
@@ -1158,7 +1208,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++;
        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;
        rec->r.ver.created  = buftoulong(p); p += 4;
        rec->r.ver.nextcheck = buftoulong(p); p += 4;
        p += 4;
@@ -1195,13 +1246,16 @@ tdbio_read_record( ulong recnum, TRUSTREC *rec, int expected )
        memcpy( rec->r.trust.fingerprint, p, 20); p+=20;
         rec->r.trust.ownertrust = *p++;
         rec->r.trust.depth = *p++;
        memcpy( rec->r.trust.fingerprint, p, 20); p+=20;
         rec->r.trust.ownertrust = *p++;
         rec->r.trust.depth = *p++;
-        p += 2;
-       rec->r.trust.validlist  = buftoulong(p); p += 4;
+        rec->r.trust.min_ownertrust = *p++;
+        p++;
+       rec->r.trust.validlist = buftoulong(p); p += 4;
        break;
       case RECTYPE_VALID:
        memcpy( rec->r.valid.namehash, p, 20); p+=20;
         rec->r.valid.validity = *p++;
        rec->r.valid.next = buftoulong(p); p += 4;
        break;
       case RECTYPE_VALID:
        memcpy( rec->r.valid.namehash, p, 20); p+=20;
         rec->r.valid.validity = *p++;
        rec->r.valid.next = buftoulong(p); p += 4;
+       rec->r.valid.full_count = *p++;
+       rec->r.valid.marginal_count = *p++;
        break;
       default:
        log_error( "%s: invalid record type %d at recnum %lu\n",
        break;
       default:
        log_error( "%s: invalid record type %d at recnum %lu\n",
@@ -1241,7 +1295,8 @@ tdbio_write_record( TRUSTREC *rec )
        *p++ = rec->r.ver.marginals;
        *p++ = rec->r.ver.completes;
        *p++ = rec->r.ver.cert_depth;
        *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;
        ulongtobuf(p, rec->r.ver.created); p += 4;
        ulongtobuf(p, rec->r.ver.nextcheck); p += 4;
        p += 4;
@@ -1273,7 +1328,8 @@ tdbio_write_record( TRUSTREC *rec )
        memcpy( p, rec->r.trust.fingerprint, 20); p += 20;
        *p++ = rec->r.trust.ownertrust;
        *p++ = rec->r.trust.depth;
        memcpy( p, rec->r.trust.fingerprint, 20); p += 20;
        *p++ = rec->r.trust.ownertrust;
        *p++ = rec->r.trust.depth;
-        p += 2;
+       *p++ = rec->r.trust.min_ownertrust;
+        p++;
        ulongtobuf( p, rec->r.trust.validlist); p += 4;
        break;
 
        ulongtobuf( p, rec->r.trust.validlist); p += 4;
        break;
 
@@ -1281,6 +1337,8 @@ tdbio_write_record( TRUSTREC *rec )
        memcpy( p, rec->r.valid.namehash, 20); p += 20;
        *p++ = rec->r.valid.validity;
        ulongtobuf( p, rec->r.valid.next); p += 4;
        memcpy( p, rec->r.valid.namehash, 20); p += 20;
        *p++ = rec->r.valid.validity;
        ulongtobuf( p, rec->r.valid.next); p += 4;
+       *p++ = rec->r.valid.full_count;
+       *p++ = rec->r.valid.marginal_count;
        break;
 
       default:
        break;
 
       default:
@@ -1470,7 +1528,7 @@ migrate_from_v2 ()
   int rc, count;
 
   ottable_size = 5;
   int rc, count;
 
   ottable_size = 5;
-  ottable = m_alloc (ottable_size * sizeof *ottable);
+  ottable = xmalloc (ottable_size * sizeof *ottable);
   ottable_used = 0;
 
   /* We have some restrictions here.  We can't use the version record
   ottable_used = 0;
 
   /* We have some restrictions here.  We can't use the version record
@@ -1500,7 +1558,7 @@ migrate_from_v2 ()
       if (ottable_used == ottable_size)
         {
           ottable_size += 1000;
       if (ottable_used == ottable_size)
         {
           ottable_size += 1000;
-          ottable = m_realloc (ottable, ottable_size * sizeof *ottable);
+          ottable = xrealloc (ottable, ottable_size * sizeof *ottable);
         }
       ottable[ottable_used].keyrecno = buftoulong (oldbuf+6);
       ottable[ottable_used].ot = oldbuf[18];
         }
       ottable[ottable_used].keyrecno = buftoulong (oldbuf+6);
       ottable[ottable_used].ot = oldbuf[18];
@@ -1571,8 +1629,5 @@ migrate_from_v2 ()
   if (rc)
     log_fatal ("failed to sync `%s'\n", db_name);
   log_info ("migrated %d version 2 ownertrusts\n", count);
   if (rc)
     log_fatal ("failed to sync `%s'\n", db_name);
   log_info ("migrated %d version 2 ownertrusts\n", count);
-  m_free (ottable);
+  xfree (ottable);
 }
 }
-
-
-