summaryrefslogtreecommitdiff
path: root/source3/tdb
diff options
context:
space:
mode:
Diffstat (limited to 'source3/tdb')
-rw-r--r--source3/tdb/Makefile32
-rw-r--r--source3/tdb/Makefile.in54
-rw-r--r--source3/tdb/aclocal.m412
-rwxr-xr-xsource3/tdb/autogen.sh8
-rw-r--r--source3/tdb/common/dump.c (renamed from source3/tdb/dump.c)0
-rw-r--r--source3/tdb/common/error.c (renamed from source3/tdb/error.c)0
-rw-r--r--source3/tdb/common/freelist.c (renamed from source3/tdb/freelist.c)0
-rw-r--r--source3/tdb/common/io.c (renamed from source3/tdb/io.c)0
-rw-r--r--source3/tdb/common/lock.c (renamed from source3/tdb/lock.c)0
-rw-r--r--source3/tdb/common/open.c (renamed from source3/tdb/open.c)0
-rw-r--r--source3/tdb/common/tdb.c (renamed from source3/tdb/tdb.c)0
-rw-r--r--source3/tdb/common/tdb_private.h (renamed from source3/tdb/tdb_private.h)0
-rw-r--r--source3/tdb/common/tdbback.c (renamed from source3/tdb/tdbback.c)0
-rw-r--r--source3/tdb/common/tdbutil.c (renamed from source3/tdb/tdbutil.c)0
-rw-r--r--source3/tdb/common/transaction.c (renamed from source3/tdb/transaction.c)0
-rw-r--r--source3/tdb/common/traverse.c (renamed from source3/tdb/traverse.c)0
-rw-r--r--source3/tdb/config.m437
-rw-r--r--source3/tdb/config.mk71
-rw-r--r--source3/tdb/configure.in13
-rw-r--r--source3/tdb/docs/README (renamed from source3/tdb/README)72
-rw-r--r--source3/tdb/docs/tdb.magic (renamed from source3/tdb/tdb.magic)0
-rw-r--r--source3/tdb/include/tdb.h (renamed from source3/tdb/tdb.h)0
-rw-r--r--source3/tdb/include/tdbback.h (renamed from source3/tdb/tdbback.h)0
-rw-r--r--source3/tdb/include/tdbconfig.h.in58
-rw-r--r--source3/tdb/include/tdbutil.h (renamed from source3/tdb/tdbutil.h)0
-rw-r--r--source3/tdb/swig/Tdb.py116
-rw-r--r--source3/tdb/swig/tdb.i168
-rw-r--r--source3/tdb/tdb.pc.in10
-rw-r--r--source3/tdb/tools/tdbbackup.c (renamed from source3/tdb/tdbbackup.c)0
-rw-r--r--source3/tdb/tools/tdbdump.c (renamed from source3/tdb/tdbdump.c)0
-rw-r--r--source3/tdb/tools/tdbtest.c (renamed from source3/tdb/tdbtest.c)0
-rw-r--r--source3/tdb/tools/tdbtool.c (renamed from source3/tdb/tdbtool.c)0
-rw-r--r--source3/tdb/tools/tdbtorture.c (renamed from source3/tdb/tdbtorture.c)0
33 files changed, 617 insertions, 34 deletions
diff --git a/source3/tdb/Makefile b/source3/tdb/Makefile
deleted file mode 100644
index e824a7cfe8..0000000000
--- a/source3/tdb/Makefile
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Makefile for tdb directory
-#
-
-CFLAGS = -DSTANDALONE -DTDB_DEBUG -g -DHAVE_MMAP=1
-CC = gcc
-
-ADMINPROGS = tdbdump tdbbackup
-PROGS = tdbtest tdbtool tdbtorture
-TDB_OBJ = tdb.o tdbback.o dump.o error.o freelist.o io.o lock.o open.o traverse.o transaction.o
-
-default: $(PROGS)
-
-admintools: $(ADMINPROGS)
-
-tdbtest: tdbtest.o $(TDB_OBJ)
- $(CC) $(CFLAGS) -o tdbtest tdbtest.o $(TDB_OBJ) -lgdbm
-
-tdbtool: tdbtool.o $(TDB_OBJ)
- $(CC) $(CFLAGS) -o tdbtool tdbtool.o $(TDB_OBJ)
-
-tdbtorture: tdbtorture.o $(TDB_OBJ)
- $(CC) $(CFLAGS) -o tdbtorture tdbtorture.o $(TDB_OBJ)
-
-tdbdump: tdbdump.o $(TDB_OBJ)
- $(CC) $(CFLAGS) -o tdbdump tdbdump.o $(TDB_OBJ)
-
-tdbbackup: tdbbackup.o $(TDB_OBJ)
- $(CC) $(CFLAGS) -o tdbbackup tdbbackup.o $(TDB_OBJ)
-
-clean:
- rm -f $(PROGS) *.o *~ *% core test.db test.tdb test.gdbm
diff --git a/source3/tdb/Makefile.in b/source3/tdb/Makefile.in
new file mode 100644
index 0000000000..1c23aaeea7
--- /dev/null
+++ b/source3/tdb/Makefile.in
@@ -0,0 +1,54 @@
+#
+# Makefile for tdb directory
+#
+
+CFLAGS = -Iinclude @CFLAGS@
+CC = @CC@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+bindir = @bindir@
+includedir = @includedir@
+libdir = @libdir@
+
+PROGS = bin/tdbtool bin/tdbtorture
+TDB_OBJ = common/tdb.o common/dump.o common/io.o common/lock.o \
+ common/open.o common/traverse.o common/freelist.o common/error.o \
+ common/transaction.o
+
+all: $(PROGS)
+
+.c.o:
+ @echo Compiling $*.c
+ @$(CC) $(CFLAGS) -c $< -o $@
+
+install: all
+ mkdir -p $(bindir)
+ mkdir -p $(includedir)
+ mkdir -p $(libdir)
+ mkdir -p $(libdir)/pkgconfig
+ cp $(PROGS) $(bindir)
+ cp include/tdb.h $(includedir)
+ cp tdb.pc $(libdir)/pkgconfig
+
+bin/tdbtest: tools/tdbtest.o $(TDB_OBJ)
+ $(CC) $(CFLAGS) -o bin/tdbtest tools/tdbtest.o $(TDB_OBJ) -lgdbm
+
+bin/tdbtool: tools/tdbtool.o $(TDB_OBJ)
+ $(CC) $(CFLAGS) -o bin/tdbtool tools/tdbtool.o $(TDB_OBJ)
+
+bin/tdbtorture: tools/tdbtorture.o $(TDB_OBJ)
+ $(CC) $(CFLAGS) -o bin/tdbtorture tools/tdbtorture.o $(TDB_OBJ)
+
+bin/tdbdump: tools/tdbdump.o $(TDB_OBJ)
+ $(CC) $(CFLAGS) -o bin/tdbdump tools/tdbdump.o $(TDB_OBJ)
+
+bin/tdbbackup: tools/tdbbackup.o $(TDB_OBJ)
+ $(CC) $(CFLAGS) -o bin/tdbbackup tools/tdbbackup.o $(TDB_OBJ)
+
+clean:
+ rm -f $(PROGS) common/*.o tools/*.o *~ *.bak */*~ */*.bak *% core test.db test.tdb test.gdbm
+
+installcheck: install
+ $(bindir)/tdbtorture
+
+test: installcheck
diff --git a/source3/tdb/aclocal.m4 b/source3/tdb/aclocal.m4
new file mode 100644
index 0000000000..cdc2a2fa52
--- /dev/null
+++ b/source3/tdb/aclocal.m4
@@ -0,0 +1,12 @@
+dnl see if a declaration exists for a function or variable
+dnl defines HAVE_function_DECL if it exists
+dnl AC_HAVE_DECL(var, includes)
+AC_DEFUN(AC_HAVE_DECL,
+[
+ AC_CACHE_CHECK([for $1 declaration],ac_cv_have_$1_decl,[
+ AC_TRY_COMPILE([$2],[int i = (int)$1],
+ ac_cv_have_$1_decl=yes,ac_cv_have_$1_decl=no)])
+ if test x"$ac_cv_have_$1_decl" = x"yes"; then
+ AC_DEFINE([HAVE_]translit([$1], [a-z], [A-Z])[_DECL],1,[Whether $1() is available])
+ fi
+])
diff --git a/source3/tdb/autogen.sh b/source3/tdb/autogen.sh
new file mode 100755
index 0000000000..89053ad9f8
--- /dev/null
+++ b/source3/tdb/autogen.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+autoheader || exit 1
+autoconf || exit 1
+
+echo "Now run ./configure and then make."
+exit 0
+
diff --git a/source3/tdb/dump.c b/source3/tdb/common/dump.c
index 577f23aac6..577f23aac6 100644
--- a/source3/tdb/dump.c
+++ b/source3/tdb/common/dump.c
diff --git a/source3/tdb/error.c b/source3/tdb/common/error.c
index 4cf33a29ab..4cf33a29ab 100644
--- a/source3/tdb/error.c
+++ b/source3/tdb/common/error.c
diff --git a/source3/tdb/freelist.c b/source3/tdb/common/freelist.c
index 3483751164..3483751164 100644
--- a/source3/tdb/freelist.c
+++ b/source3/tdb/common/freelist.c
diff --git a/source3/tdb/io.c b/source3/tdb/common/io.c
index 5d7edfefff..5d7edfefff 100644
--- a/source3/tdb/io.c
+++ b/source3/tdb/common/io.c
diff --git a/source3/tdb/lock.c b/source3/tdb/common/lock.c
index a96d77a229..a96d77a229 100644
--- a/source3/tdb/lock.c
+++ b/source3/tdb/common/lock.c
diff --git a/source3/tdb/open.c b/source3/tdb/common/open.c
index b53b4c9f5c..b53b4c9f5c 100644
--- a/source3/tdb/open.c
+++ b/source3/tdb/common/open.c
diff --git a/source3/tdb/tdb.c b/source3/tdb/common/tdb.c
index 524d404a50..524d404a50 100644
--- a/source3/tdb/tdb.c
+++ b/source3/tdb/common/tdb.c
diff --git a/source3/tdb/tdb_private.h b/source3/tdb/common/tdb_private.h
index d4f94048a4..d4f94048a4 100644
--- a/source3/tdb/tdb_private.h
+++ b/source3/tdb/common/tdb_private.h
diff --git a/source3/tdb/tdbback.c b/source3/tdb/common/tdbback.c
index 4698e6016b..4698e6016b 100644
--- a/source3/tdb/tdbback.c
+++ b/source3/tdb/common/tdbback.c
diff --git a/source3/tdb/tdbutil.c b/source3/tdb/common/tdbutil.c
index b946f856aa..b946f856aa 100644
--- a/source3/tdb/tdbutil.c
+++ b/source3/tdb/common/tdbutil.c
diff --git a/source3/tdb/transaction.c b/source3/tdb/common/transaction.c
index b71728db5c..b71728db5c 100644
--- a/source3/tdb/transaction.c
+++ b/source3/tdb/common/transaction.c
diff --git a/source3/tdb/traverse.c b/source3/tdb/common/traverse.c
index 712504a764..712504a764 100644
--- a/source3/tdb/traverse.c
+++ b/source3/tdb/common/traverse.c
diff --git a/source3/tdb/config.m4 b/source3/tdb/config.m4
new file mode 100644
index 0000000000..cb0801795c
--- /dev/null
+++ b/source3/tdb/config.m4
@@ -0,0 +1,37 @@
+AC_CHECK_FUNCS(mmap pread pwrite getpagesize utime)
+AC_CHECK_HEADERS(getopt.h sys/select.h sys/time.h)
+
+AC_HAVE_DECL(pread, [#include <unistd.h>])
+AC_HAVE_DECL(pwrite, [#include <unistd.h>])
+
+AC_MSG_CHECKING([for Python])
+
+PYTHON=
+
+AC_ARG_WITH(python,
+[ --with-python=PYTHONNAME build Python libraries],
+[ case "${withval-python}" in
+ yes)
+ PYTHON=python
+ ;;
+ no)
+ PYTHON=
+ ;;
+ *)
+ PYTHON=${withval-python}
+ ;;
+ esac ])
+
+if test x"$PYTHON" != "x"; then
+ incdir=`python -c 'import sys; print "%s/include/python%d.%d" % (sys.prefix, sys.version_info[[0]], sys.version_info[[1]])'`
+ CPPFLAGS="$CPPFLAGS -I $incdir"
+fi
+
+if test x"$PYTHON" != "x"; then
+ AC_MSG_RESULT([${withval-python}])
+else
+ SMB_ENABLE(swig_tdb, NO)
+ AC_MSG_RESULT(no)
+fi
+
+AC_SUBST(PYTHON)
diff --git a/source3/tdb/config.mk b/source3/tdb/config.mk
new file mode 100644
index 0000000000..b1e6e82d74
--- /dev/null
+++ b/source3/tdb/config.mk
@@ -0,0 +1,71 @@
+################################################
+# Start SUBSYSTEM LIBTDB
+[LIBRARY::LIBTDB]
+VERSION = 0.0.1
+SO_VERSION = 0
+DESCRIPTION = Trivial Database Library
+OBJ_FILES = \
+ common/tdb.o common/dump.o common/io.o common/lock.o \
+ common/open.o common/traverse.o common/freelist.o \
+ common/error.o common/transaction.o common/tdbutil.o
+PUBLIC_DEPENDENCIES = \
+ LIBREPLACE
+PUBLIC_HEADERS = include/tdb.h
+#
+# End SUBSYSTEM ldb
+################################################
+
+################################################
+# Start BINARY tdbtool
+[BINARY::tdbtool]
+INSTALLDIR = BINDIR
+ENABLE = NO
+OBJ_FILES= \
+ tools/tdbtool.o
+PRIVATE_DEPENDENCIES = \
+ LIBTDB
+# End BINARY tdbtool
+################################################
+
+################################################
+# Start BINARY tdbtorture
+[BINARY::tdbtorture]
+INSTALLDIR = BINDIR
+OBJ_FILES= \
+ tools/tdbtorture.o
+PRIVATE_DEPENDENCIES = \
+ LIBTDB
+# End BINARY tdbtorture
+################################################
+
+################################################
+# Start BINARY tdbdump
+[BINARY::tdbdump]
+INSTALLDIR = BINDIR
+OBJ_FILES= \
+ tools/tdbdump.o
+PRIVATE_DEPENDENCIES = \
+ LIBTDB
+# End BINARY tdbdump
+################################################
+
+################################################
+# Start BINARY tdbbackup
+[BINARY::tdbbackup]
+INSTALLDIR = BINDIR
+ENABLE = NO
+OBJ_FILES= \
+ tools/tdbbackup.o
+PRIVATE_DEPENDENCIES = \
+ LIBTDB
+# End BINARY tdbbackup
+################################################
+
+#######################
+# Start LIBRARY swig_tdb
+[LIBRARY::swig_tdb]
+LIBRARY_REALNAME = swig/_tdb.$(SHLIBEXT)
+OBJ_FILES = swig/tdb_wrap.o
+PUBLIC_DEPENDENCIES = LIBTDB DYNCONFIG
+# End LIBRARY swig_tdb
+#######################
diff --git a/source3/tdb/configure.in b/source3/tdb/configure.in
new file mode 100644
index 0000000000..0a72af20d9
--- /dev/null
+++ b/source3/tdb/configure.in
@@ -0,0 +1,13 @@
+AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""])
+AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""])
+AC_DEFUN([SMB_ENABLE], [echo -n ""])
+AC_INIT(include/tdb.h)
+AC_CONFIG_HEADER(include/config.h)
+AC_PROG_CC
+AC_SYS_LARGEFILE
+AC_CHECK_SIZEOF(off_t,cross)
+AC_CHECK_SIZEOF(size_t,cross)
+AC_CHECK_SIZEOF(ssize_t,cross)
+AC_FUNC_MMAP
+sinclude(config.m4)
+AC_OUTPUT(Makefile tdb.pc)
diff --git a/source3/tdb/README b/source3/tdb/docs/README
index fac3eacb4d..b31ce36ab1 100644
--- a/source3/tdb/README
+++ b/source3/tdb/docs/README
@@ -15,7 +15,6 @@ Compilation
-----------
add HAVE_MMAP=1 to use mmap instead of read/write
-add TDB_DEBUG=1 for verbose debug info
add NOLOCK=1 to disable locking code
Testing
@@ -41,6 +40,7 @@ The interface is very similar to gdbm except for the following:
- no tdbm_reorganise() function
- no tdbm_sync() function. No operations are cached in the library anyway
- added a tdb_traverse() function for traversing the whole database
+- added transactions support
A general rule for using tdb is that the caller frees any returned
TDB_DATA structures. Just call free(p.dptr) to free a TDB_DATA
@@ -68,6 +68,19 @@ TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags,
memory. The filename is ignored in this case.
TDB_NOLOCK - don't do any locking
TDB_NOMMAP - don't use mmap
+ TDB_NOSYNC - don't synchronise transactions to disk
+
+----------------------------------------------------------------------
+TDB_CONTEXT *tdb_open_ex(char *name, int hash_size, int tdb_flags,
+ int open_flags, mode_t mode,
+ tdb_log_func log_fn,
+ tdb_hash_func hash_fn)
+
+This is like tdb_open(), but allows you to pass an initial logging and
+hash function. Be careful when passing a hash function - all users of
+the database must use the same hash function or you will get data
+corruption.
+
----------------------------------------------------------------------
char *tdb_error(TDB_CONTEXT *tdb);
@@ -114,7 +127,25 @@ int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb,
if fn is NULL then it is not called
- a non-zero return value from fn() indicates that the traversal should stop
+ a non-zero return value from fn() indicates that the traversal
+ should stop. Traversal callbacks may not start transactions.
+
+----------------------------------------------------------------------
+int tdb_traverse_read(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb,
+ TDB_DATA key, TDB_DATA dbuf, void *state), void *state);
+
+ traverse the entire database - calling fn(tdb, key, data, state) on
+ each element, but marking the database read only during the
+ traversal, so any write operations will fail. This allows tdb to
+ use read locks, which increases the parallelism possible during the
+ traversal.
+
+ return -1 on error or the record count traversed
+
+ if fn is NULL then it is not called
+
+ a non-zero return value from fn() indicates that the traversal
+ should stop. Traversal callbacks may not start transactions.
----------------------------------------------------------------------
TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
@@ -165,3 +196,40 @@ int tdb_lockchain(TDB_CONTEXT *tdb, TDB_DATA key);
int tdb_unlockchain(TDB_CONTEXT *tdb, TDB_DATA key);
unlock one hash chain
+
+----------------------------------------------------------------------
+int tdb_transaction_start(TDB_CONTEXT *tdb)
+
+ start a transaction. All operations after the transaction start can
+ either be committed with tdb_transaction_commit() or cancelled with
+ tdb_transaction_cancel().
+
+ If you call tdb_transaction_start() again on the same tdb context
+ while a transaction is in progress, then the same transaction
+ buffer is re-used. The number of tdb_transaction_{commit,cancel}
+ operations must match the number of successful
+ tdb_transaction_start() calls.
+
+ Note that transactions are by default disk synchronous, and use a
+ recover area in the database to automatically recover the database
+ on the next open if the system crashes during a transaction. You
+ can disable the synchronous transaction recovery setup using the
+ TDB_NOSYNC flag, which will greatly speed up operations at the risk
+ of corrupting your database if the system crashes.
+
+ Operations made within a transaction are not visible to other users
+ of the database until a successful commit.
+
+----------------------------------------------------------------------
+int tdb_transaction_cancel(TDB_CONTEXT *tdb)
+
+ cancel a current transaction, discarding all write and lock
+ operations that have been made since the transaction started.
+
+
+----------------------------------------------------------------------
+int tdb_transaction_commit(TDB_CONTEXT *tdb)
+
+ commit a current transaction, updating the database and releasing
+ the transaction locks.
+
diff --git a/source3/tdb/tdb.magic b/source3/tdb/docs/tdb.magic
index f5619e7327..f5619e7327 100644
--- a/source3/tdb/tdb.magic
+++ b/source3/tdb/docs/tdb.magic
diff --git a/source3/tdb/tdb.h b/source3/tdb/include/tdb.h
index 82f8828c89..82f8828c89 100644
--- a/source3/tdb/tdb.h
+++ b/source3/tdb/include/tdb.h
diff --git a/source3/tdb/tdbback.h b/source3/tdb/include/tdbback.h
index 7ebeaa494d..7ebeaa494d 100644
--- a/source3/tdb/tdbback.h
+++ b/source3/tdb/include/tdbback.h
diff --git a/source3/tdb/include/tdbconfig.h.in b/source3/tdb/include/tdbconfig.h.in
new file mode 100644
index 0000000000..d6d2c09b3c
--- /dev/null
+++ b/source3/tdb/include/tdbconfig.h.in
@@ -0,0 +1,58 @@
+/* include/tdbconfig.h.in. Generated from configure.in by autoheader. */
+
+/* Define to 1 if you have the `getpagesize' function. */
+#undef HAVE_GETPAGESIZE
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `mmap' function. */
+#undef HAVE_MMAP
+
+/* Define to 1 if you have the `pread' function. */
+#undef HAVE_PREAD
+
+/* Define to 1 if you have the `pwrite' function. */
+#undef HAVE_PWRITE
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
diff --git a/source3/tdb/tdbutil.h b/source3/tdb/include/tdbutil.h
index 44351619f4..44351619f4 100644
--- a/source3/tdb/tdbutil.h
+++ b/source3/tdb/include/tdbutil.h
diff --git a/source3/tdb/swig/Tdb.py b/source3/tdb/swig/Tdb.py
new file mode 100644
index 0000000000..aac7a90354
--- /dev/null
+++ b/source3/tdb/swig/Tdb.py
@@ -0,0 +1,116 @@
+"""Provide a more Pythonic and object-oriented interface to tdb."""
+
+#
+# Swig interface to Samba
+#
+# Copyright (C) Tim Potter 2006
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# 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, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+import os
+from tdb import *
+
+# Open flags
+
+DEFAULT = TDB_DEFAULT
+CLEAR_IF_FIRST = TDB_CLEAR_IF_FIRST
+INTERNAL = TDB_INTERNAL
+NOLOCK = TDB_NOLOCK
+NOMMAP = TDB_NOMMAP
+
+# Class representing a TDB file
+
+class Tdb:
+
+ # Create and destroy Tdb objects
+
+ def __init__(self, name, hash_size = 0, flags = TDB_DEFAULT,
+ open_flags = os.O_RDWR | os.O_CREAT, mode = 0600):
+ self.tdb = tdb_open(name, hash_size, flags, open_flags, mode)
+ if self.tdb is None:
+ raise IOError, tdb_errorstr(self.tdb)
+
+ def __del__(self):
+ self.close()
+
+ def close(self):
+ if hasattr(self, 'tdb') and self.tdb is not None:
+ if tdb_close(self.tdb) == -1:
+ raise IOError, tdb_errorstr(self.tdb)
+ self.tdb = None
+
+ # Random access to keys, values
+
+ def __getitem__(self, key):
+ result = tdb_fetch(self.tdb, key)
+ if result is None:
+ raise KeyError, '%s: %s' % (key, tdb_errorstr(self.tdb))
+ return result
+
+ def __setitem__(self, key, item):
+ if tdb_store(self.tdb, key, item) == -1:
+ raise IOError, tdb_errorstr(self.tdb)
+
+ def __delitem__(self, key):
+ if not tdb_exists(self.tdb, key):
+ raise KeyError, '%s: %s' % (key, tdb_errorstr(self.tdb))
+ tdb_delete(self.tdb, key)
+
+ def has_key(self, key):
+ return tdb_exists(self.tdb, key)
+
+ # Tdb iterator
+
+ class TdbIterator:
+ def __init__(self, tdb):
+ self.tdb = tdb
+ self.key = None
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if self.key is None:
+ self.key = tdb_firstkey(self.tdb)
+ if self.key is None:
+ raise StopIteration
+ return self.key
+ else:
+ self.key = tdb_nextkey(self.tdb, self.key)
+ if self.key is None:
+ raise StopIteration
+ return self.key
+
+ def __iter__(self):
+ return Tdb.TdbIterator(self.tdb)
+
+ # Implement other dict functions using TdbIterator
+
+ def keys(self):
+ return [k for k in iter(self)]
+
+ def values(self):
+ return [self[k] for k in iter(self)]
+
+ def items(self):
+ return [(k, self[k]) for k in iter(self)]
+
+ def __len__(self):
+ return len(self.keys())
+
+ def clear(self):
+ for k in iter(self):
+ del(self[k])
diff --git a/source3/tdb/swig/tdb.i b/source3/tdb/swig/tdb.i
new file mode 100644
index 0000000000..98bf6441ce
--- /dev/null
+++ b/source3/tdb/swig/tdb.i
@@ -0,0 +1,168 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Swig interface to tdb.
+
+ Copyright (C) 2004,2005 Tim Potter <tpot@samba.org>
+
+ ** NOTE! The following LGPL license applies to the tdb
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+%module tdb
+
+%{
+
+/* This symbol is used in both includes.h and Python.h which causes an
+ annoying compiler warning. */
+
+#ifdef HAVE_FSTAT
+#undef HAVE_FSTAT
+#endif
+
+#if (__GNUC__ >= 3)
+/** Use gcc attribute to check printf fns. a1 is the 1-based index of
+ * the parameter containing the format, and a2 the index of the first
+ * argument. Note that some gcc 2.x versions don't handle this
+ * properly **/
+#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
+#else
+#define PRINTF_ATTRIBUTE(a1, a2)
+#endif
+
+/* Include tdb headers */
+
+#include "lib/tdb/include/tdb.h"
+
+%}
+
+/* The tdb functions will crash if a NULL tdb context is passed */
+
+%include exception.i
+
+%typemap(check) TDB_CONTEXT* {
+ if ($1 == NULL)
+ SWIG_exception(SWIG_ValueError,
+ "tdb context must be non-NULL");
+}
+
+/* In and out typemaps for the TDB_DATA structure. This is converted to
+ and from the Python string type which can contain arbitrary binary
+ data.. */
+
+%typemap(in) TDB_DATA {
+ if (!PyString_Check($input)) {
+ PyErr_SetString(PyExc_TypeError, "string arg expected");
+ return NULL;
+ }
+ $1.dsize = PyString_Size($input);
+ $1.dptr = PyString_AsString($input);
+}
+
+%typemap(out) TDB_DATA {
+ if ($1.dptr == NULL && $1.dsize == 0) {
+ $result = Py_None;
+ } else {
+ $result = PyString_FromStringAndSize($1.dptr, $1.dsize);
+ free($1.dptr);
+ }
+}
+
+/* Treat a mode_t as an unsigned integer */
+
+typedef int mode_t;
+
+/* flags to tdb_store() */
+
+#define TDB_REPLACE 1
+#define TDB_INSERT 2
+#define TDB_MODIFY 3
+
+/* flags for tdb_open() */
+
+#define TDB_DEFAULT 0 /* just a readability place holder */
+#define TDB_CLEAR_IF_FIRST 1
+#define TDB_INTERNAL 2 /* don't store on disk */
+#define TDB_NOLOCK 4 /* don't do any locking */
+#define TDB_NOMMAP 8 /* don't use mmap */
+#define TDB_CONVERT 16 /* convert endian (internal use) */
+#define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
+
+/* Throw an IOError exception if tdb_open() or tdb_open_ex() returns NULL */
+
+%exception {
+ $action
+ if (result == NULL) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ SWIG_fail;
+ }
+}
+
+TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags,
+ int open_flags, mode_t mode);
+
+TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
+ int open_flags, mode_t mode,
+ tdb_log_func log_fn,
+ tdb_hash_func hash_fn);
+
+%exception;
+
+int tdb_reopen(TDB_CONTEXT *tdb);
+
+int tdb_reopen_all(int parent_longlived);
+
+void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func);
+
+enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb);
+
+const char *tdb_errorstr(TDB_CONTEXT *tdb);
+
+TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
+
+int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
+
+int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag = TDB_REPLACE);
+
+int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf);
+
+int tdb_close(TDB_CONTEXT *tdb);
+
+TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
+
+TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
+
+int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *state);
+
+int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
+
+int tdb_lockall(TDB_CONTEXT *tdb);
+
+void tdb_unlockall(TDB_CONTEXT *tdb);
+
+/* Low level locking functions: use with care */
+
+int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key);
+
+int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key);
+
+/* Debug functions. Not used in production. */
+
+void tdb_dump_all(TDB_CONTEXT *tdb);
+
+int tdb_printfreelist(TDB_CONTEXT *tdb);
diff --git a/source3/tdb/tdb.pc.in b/source3/tdb/tdb.pc.in
new file mode 100644
index 0000000000..0d54afe242
--- /dev/null
+++ b/source3/tdb/tdb.pc.in
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: tdb
+Description: A trivial database
+Version: 4.0
+#Libs: @LIBS@ -L${libdir} -ltdb
+Cflags: -I${includedir} @CFLAGS@
diff --git a/source3/tdb/tdbbackup.c b/source3/tdb/tools/tdbbackup.c
index f49cd339c7..f49cd339c7 100644
--- a/source3/tdb/tdbbackup.c
+++ b/source3/tdb/tools/tdbbackup.c
diff --git a/source3/tdb/tdbdump.c b/source3/tdb/tools/tdbdump.c
index b702fb0735..b702fb0735 100644
--- a/source3/tdb/tdbdump.c
+++ b/source3/tdb/tools/tdbdump.c
diff --git a/source3/tdb/tdbtest.c b/source3/tdb/tools/tdbtest.c
index 89295a3291..89295a3291 100644
--- a/source3/tdb/tdbtest.c
+++ b/source3/tdb/tools/tdbtest.c
diff --git a/source3/tdb/tdbtool.c b/source3/tdb/tools/tdbtool.c
index bcfb96adc0..bcfb96adc0 100644
--- a/source3/tdb/tdbtool.c
+++ b/source3/tdb/tools/tdbtool.c
diff --git a/source3/tdb/tdbtorture.c b/source3/tdb/tools/tdbtorture.c
index 2d367b91e1..2d367b91e1 100644
--- a/source3/tdb/tdbtorture.c
+++ b/source3/tdb/tools/tdbtorture.c