summaryrefslogtreecommitdiff
path: root/source3/tdb/tdb.c
diff options
context:
space:
mode:
authorDavid O'Neill <dmo@samba.org>2001-01-29 21:34:08 +0000
committerDavid O'Neill <dmo@samba.org>2001-01-29 21:34:08 +0000
commit2506c61ab3bd667d54c5e004cc80ce5e40643b5d (patch)
treeb31d685b78a8ba71f3599aa481ce281d5fea290b /source3/tdb/tdb.c
parent9ec19336e519ef3543eb9d3eafb24585657a2e8d (diff)
downloadsamba-2506c61ab3bd667d54c5e004cc80ce5e40643b5d.tar.gz
samba-2506c61ab3bd667d54c5e004cc80ce5e40643b5d.tar.bz2
samba-2506c61ab3bd667d54c5e004cc80ce5e40643b5d.zip
Changes from APPLIANCE_HEAD:
source/include/proto.h - make proto source/printing/nt_printing.c source/rpc_server/srv_spoolss_nt.c - Fix for the overwriting of printerdata entries when WinNT and Win2k are modifying printer parameters on PCL printers. Turns out that Win2k creates a printer with a NULL devmode entry and then expects to set it on *OPEN* (yes this is insane). So we cannot return a "default" devmode for a printer - and we must allow an open to set it. source/tdb/tdb.c - Show freelist in an easier format. Show total free. - When storing a new record, allocate memory for the key + data before the tdb_allocate() as if the malloc fails a (sparse) hole is left in the tdb. source/tdb/tdbtool.c - Show freelist in an easier format. Show total free. source/tdb/Makefile - cleaned up Makefile dependancies source/smbd/lanman.c - Fix for Win9x corrupting it's own parameter string. source/printing/printfsp.c source/printing/printing.c source/rpc_server/srv_spoolss_nt.c source/smbd/close.c - Added normal close parameter into print_fsp_end() which treats an abnormal close as error condition and deletes the spool file. (This used to be commit 025f7a092ad258ff774e3f5e53737f8210cc8af6)
Diffstat (limited to 'source3/tdb/tdb.c')
-rw-r--r--source3/tdb/tdb.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c
index 944a734ddc..39d061b0a8 100644
--- a/source3/tdb/tdb.c
+++ b/source3/tdb/tdb.c
@@ -84,10 +84,10 @@ static void *tdb_mmap(tdb_len size, int readonly, int fd)
void *ret = NULL;
#ifdef HAVE_MMAP
ret = mmap(NULL, size, PROT_READ | (readonly ? 0 : PROT_WRITE), MAP_SHARED|MAP_FILE, fd, 0);
-#endif
- if (ret == (void *)-1)
- ret = NULL;
+ if (ret == (void *)-1)
+ ret = NULL;
+#endif
return ret;
}
@@ -302,7 +302,8 @@ static int update_tailer(TDB_CONTEXT *tdb, tdb_off offset,
#ifdef TDB_DEBUG
void tdb_printfreelist(TDB_CONTEXT *tdb)
{
- tdb_off offset, rec_ptr, last_ptr;
+ long total_free = 0;
+ tdb_off offset, rec_ptr, last_ptr;
struct list_struct rec, lastrec, newrec;
tdb_lock(tdb, -1, F_WRLCK);
@@ -326,11 +327,13 @@ void tdb_printfreelist(TDB_CONTEXT *tdb)
return;
}
- printf("entry offset=[0x%08x], rec.rec_len = [0x%08x]\n", rec.next, rec.rec_len );
+ printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%d)]\n", rec.next, rec.rec_len, rec.rec_len );
+ total_free += rec.rec_len;
/* move to the next record */
rec_ptr = rec.next;
}
+ printf("total rec_len = [0x%08x (%d)]\n", total_free, total_free );
tdb_unlock(tdb, -1, F_WRLCK);
}
@@ -1013,6 +1016,17 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
coalescing with `allocated' block before it's updated. */
if (flag != TDB_INSERT) tdb_delete(tdb, key);
+ /* Copy key+value *before* allocating free space in case malloc
+ fails and we are left with a dead spot in the tdb. */
+
+ if (!(p = (char *)malloc(key.dsize + dbuf.dsize))) {
+ tdb->ecode = TDB_ERR_OOM;
+ goto fail;
+ }
+
+ memcpy(p, key.dptr, key.dsize);
+ memcpy(p+key.dsize, dbuf.dptr, dbuf.dsize);
+
/* now we're into insert / modify / replace of a record which
* we know could not be optimised by an in-place store (for
* various reasons). */
@@ -1027,18 +1041,12 @@ int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
rec.full_hash = hash;
rec.magic = TDB_MAGIC;
- if (!(p = (char *)malloc(key.dsize + dbuf.dsize))) {
- tdb->ecode = TDB_ERR_OOM;
- goto fail;
- }
-
- memcpy(p, key.dptr, key.dsize);
- memcpy(p+key.dsize, dbuf.dptr, dbuf.dsize);
/* write out and point the top of the hash chain at it */
if (rec_write(tdb, rec_ptr, &rec) == -1
|| tdb_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+dbuf.dsize)==-1
|| ofs_write(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) {
fail:
+ /* Need to tdb_unallocate() here */
ret = -1;
}
out: