Changes to make use of code taken from libassuan. This replaces the
[gnupg.git] / g10 / tdbio.c
index bc609ad..5b34bc8 100644 (file)
@@ -332,7 +332,9 @@ tdbio_sync()
     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:
@@ -402,7 +404,7 @@ tdbio_cancel_transaction()
     in_transaction = 0;
     return 0;
 }
-
+#endif
 
 \f
 /********************************************************
@@ -492,7 +494,7 @@ tdbio_set_dbname( const char *new_dbname, int create )
 
     if( access( fname, R_OK ) ) {
        if( errno != ENOENT ) {
-           log_error( _("%s: can't access: %s\n"), fname, strerror(errno) );
+           log_error( _("can't access `%s': %s\n"), fname, strerror(errno) );
            m_free(fname);
            return G10ERR_TRUSTDB;
        }
@@ -517,25 +519,30 @@ tdbio_set_dbname( const char *new_dbname, int create )
            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 ) )
-                log_fatal( _("%s: can't make lock\n"), db_name );
+                log_fatal( _("can't lock `%s'\n"), db_name );
 #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 )
-               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 )
-               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 )
-               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 ();
@@ -578,10 +585,10 @@ open_db()
   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 ) )
-    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 );
   if (db_fd == -1 && errno == EACCES) {
@@ -590,7 +597,8 @@ open_db()
           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
@@ -772,8 +780,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 ) {
-       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;
     }
 
@@ -782,7 +789,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 ) {
-           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;
        }
@@ -921,7 +928,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 ) {
-       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;
     }
@@ -934,7 +941,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 )
-           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;
     }
@@ -963,7 +970,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 )
-                       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;
                }
@@ -1010,7 +1017,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 ) {
-       log_error( db_name, "lookup_hashtable failed: %s\n", g10_errstr(rc) );
+       log_error("lookup_hashtable failed: %s\n", g10_errstr(rc) );
        return rc;
     }
 
@@ -1020,14 +1027,14 @@ lookup_hashtable( ulong table, const byte *key, size_t keylen,
 
     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 ) {
-           log_error( db_name, "hashtable has invalid indirections\n");
+           log_error("hashtable has invalid indirections\n");
            return G10ERR_TRUSTDB;
        }
        goto next_level;
@@ -1619,6 +1626,3 @@ migrate_from_v2 ()
   log_info ("migrated %d version 2 ownertrusts\n", count);
   m_free (ottable);
 }
-
-
-