summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-06-20 18:40:33 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-06-20 11:18:36 +0200
commit5eecc854236f0b943aaa89e0c3a46f9fbd208ca9 (patch)
tree89ae34b70f5a32f22b301ec9e4db363e046737cd
parent957801fcb0c81317c84d448f1e04d069216f07ac (diff)
downloadsamba-5eecc854236f0b943aaa89e0c3a46f9fbd208ca9.tar.gz
samba-5eecc854236f0b943aaa89e0c3a46f9fbd208ca9.tar.bz2
samba-5eecc854236f0b943aaa89e0c3a46f9fbd208ca9.zip
tdb2: create tdb2 versions of various testing TDBs.
Soon, TDB2 will handle tdb1 files, but until then, we substitute. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--lib/tdb/python/tests/simple.py63
-rw-r--r--lib/tdb2/pytdb.c14
-rw-r--r--selftest/target/Samba3.pm6
-rw-r--r--selftest/wscript3
-rw-r--r--source3/selftest/ktest-secrets.tdb2bin0 -> 14592 bytes
-rw-r--r--source4/scripting/python/samba/samba3.py7
-rw-r--r--testdata/samba3/account_policy.tdb2bin0 -> 12192 bytes
-rw-r--r--testdata/samba3/group_mapping.tdb2bin0 -> 14592 bytes
-rw-r--r--testdata/samba3/passdb.tdb2bin0 -> 11392 bytes
-rw-r--r--testdata/samba3/registry.tdb2bin0 -> 15392 bytes
-rw-r--r--testdata/samba3/secrets.tdb2bin0 -> 17792 bytes
-rw-r--r--testdata/samba3/share_info.tdb2bin0 -> 11392 bytes
-rw-r--r--testdata/samba3/winbindd_idmap.tdb2bin0 -> 15392 bytes
13 files changed, 68 insertions, 25 deletions
diff --git a/lib/tdb/python/tests/simple.py b/lib/tdb/python/tests/simple.py
index 99f31d2fcd..2877092fe3 100644
--- a/lib/tdb/python/tests/simple.py
+++ b/lib/tdb/python/tests/simple.py
@@ -20,8 +20,13 @@ class OpenTdbTests(TestCase):
class CloseTdbTests(TestCase):
def test_double_close(self):
- self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT,
- os.O_CREAT|os.O_RDWR)
+ # No hash size in tdb2.
+ if tdb.__version__.startswith("2"):
+ self.tdb = tdb.Tdb(tempfile.mkstemp()[1], tdb.DEFAULT,
+ os.O_CREAT|os.O_RDWR)
+ else:
+ self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT,
+ os.O_CREAT|os.O_RDWR)
self.assertNotEqual(None, self.tdb)
# ensure that double close does not crash python
@@ -42,8 +47,12 @@ class SimpleTdbTests(TestCase):
def setUp(self):
super(SimpleTdbTests, self).setUp()
- self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT,
- os.O_CREAT|os.O_RDWR)
+ if tdb.__version__.startswith("2"):
+ self.tdb = tdb.Tdb(tempfile.mkstemp()[1], tdb.DEFAULT,
+ os.O_CREAT|os.O_RDWR)
+ else:
+ self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT,
+ os.O_CREAT|os.O_RDWR)
self.assertNotEqual(None, self.tdb)
def tearDown(self):
@@ -56,7 +65,8 @@ class SimpleTdbTests(TestCase):
self.tdb.lock_all()
def test_max_dead(self):
- self.tdb.max_dead = 20
+ if not tdb.__version__.startswith("2"):
+ self.tdb.max_dead = 20
def test_unlockall(self):
self.tdb.lock_all()
@@ -67,7 +77,8 @@ class SimpleTdbTests(TestCase):
self.tdb.read_unlock_all()
def test_reopen(self):
- self.tdb.reopen()
+ if not tdb.__version__.startswith("2"):
+ self.tdb.reopen()
def test_store(self):
self.tdb.store("bar", "bla")
@@ -75,7 +86,8 @@ class SimpleTdbTests(TestCase):
def test_getitem(self):
self.tdb["bar"] = "foo"
- self.tdb.reopen()
+ if not tdb.__version__.startswith("2"):
+ self.tdb.reopen()
self.assertEquals("foo", self.tdb["bar"])
def test_delete(self):
@@ -91,13 +103,16 @@ class SimpleTdbTests(TestCase):
self.assertRaises(KeyError, lambda: self.tdb["bla"])
def test_hash_size(self):
- self.tdb.hash_size
+ if not tdb.__version__.startswith("2"):
+ self.tdb.hash_size
def test_map_size(self):
- self.tdb.map_size
+ if not tdb.__version__.startswith("2"):
+ self.tdb.map_size
def test_freelist_size(self):
- self.tdb.freelist_size
+ if not tdb.__version__.startswith("2"):
+ self.tdb.freelist_size
def test_name(self):
self.tdb.filename
@@ -145,17 +160,19 @@ class SimpleTdbTests(TestCase):
self.assertEquals(0, len(list(self.tdb)))
def test_repack(self):
- self.tdb["foo"] = "abc"
- self.tdb["bar"] = "def"
- del self.tdb["foo"]
- self.tdb.repack()
+ if not tdb.__version__.startswith("2"):
+ self.tdb["foo"] = "abc"
+ self.tdb["bar"] = "def"
+ del self.tdb["foo"]
+ self.tdb.repack()
def test_seqnum(self):
- self.tdb.enable_seqnum()
- seq1 = self.tdb.seqnum
- self.tdb.increment_seqnum_nonblock()
- seq2 = self.tdb.seqnum
- self.assertEquals(seq2-seq1, 1)
+ if not tdb.__version__.startswith("2"):
+ self.tdb.enable_seqnum()
+ seq1 = self.tdb.seqnum
+ self.tdb.increment_seqnum_nonblock()
+ seq2 = self.tdb.seqnum
+ self.assertEquals(seq2-seq1, 1)
def test_len(self):
self.assertEquals(0, len(list(self.tdb)))
@@ -163,8 +180,12 @@ class SimpleTdbTests(TestCase):
self.assertEquals(1, len(list(self.tdb)))
def test_add_flags(self):
- self.tdb.add_flags(tdb.NOMMAP)
- self.tdb.remove_flags(tdb.NOMMAP)
+ if tdb.__version__.startswith("2"):
+ self.tdb.add_flag(tdb.NOMMAP)
+ self.tdb.remove_flag(tdb.NOMMAP)
+ else:
+ self.tdb.add_flags(tdb.NOMMAP)
+ self.tdb.remove_flags(tdb.NOMMAP)
class VersionTests(TestCase):
diff --git a/lib/tdb2/pytdb.c b/lib/tdb2/pytdb.c
index 86f604874b..c760045508 100644
--- a/lib/tdb2/pytdb.c
+++ b/lib/tdb2/pytdb.c
@@ -72,12 +72,21 @@ static PyObject *PyString_FromTDB_DATA(TDB_DATA data)
return NULL; \
}
+static void stderr_log(struct tdb_context *tdb,
+ enum tdb_log_level level,
+ const char *message,
+ void *data)
+{
+ fprintf(stderr, "%s:%s\n", tdb_name(tdb), message);
+}
+
static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
char *name = NULL;
int tdb_flags = TDB_DEFAULT, flags = O_RDWR, mode = 0600;
struct tdb_context *ctx;
PyTdbObject *ret;
+ union tdb_attribute logattr;
const char *kwnames[] = { "name", "tdb_flags", "flags", "mode", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siii", (char **)kwnames, &name, &tdb_flags, &flags, &mode))
@@ -87,7 +96,10 @@ static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwarg
tdb_flags |= TDB_INTERNAL;
}
- ctx = tdb_open(name, tdb_flags, flags, mode, NULL);
+ logattr.log.base.attr = TDB_ATTRIBUTE_LOG;
+ logattr.log.base.next = NULL;
+ logattr.log.fn = stderr_log;
+ ctx = tdb_open(name, tdb_flags, flags, mode, &logattr);
if (ctx == NULL) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 595780aa14..505130f596 100644
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -424,7 +424,11 @@ $ret->{USERNAME} = KTEST\\Administrator
#Samba4 DC with the same parameters as are being used here. The
#domain SID is S-1-5-21-1071277805-689288055-3486227160
- system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
+ if (defined($ENV{BUILD_TDB2})) {
+ system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb2 $prefix/private/secrets.tdb");
+ } else {
+ system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
+ }
chmod 0600, "$prefix/private/secrets.tdb";
#This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
diff --git a/selftest/wscript b/selftest/wscript
index ab9f269b79..558cb2abd2 100644
--- a/selftest/wscript
+++ b/selftest/wscript
@@ -174,6 +174,9 @@ def cmd_testonly(opt):
if env.USING_SYSTEM_LDB:
os.environ['LDB_MODULES_PATH'] = 'bin/modules/ldb'
+ if env.BUILD_TDB2:
+ os.environ['BUILD_TDB2'] = '1'
+
# tell build system where to find config.h
os.environ['VFSLIBDIR'] = os.path.abspath('bin/modules/vfs')
os.environ['CONFIG_H'] = 'bin/default/include/config.h'
diff --git a/source3/selftest/ktest-secrets.tdb2 b/source3/selftest/ktest-secrets.tdb2
new file mode 100644
index 0000000000..2af58b140f
--- /dev/null
+++ b/source3/selftest/ktest-secrets.tdb2
Binary files differ
diff --git a/source4/scripting/python/samba/samba3.py b/source4/scripting/python/samba/samba3.py
index 2c323bd0b4..ae5b20edd2 100644
--- a/source4/scripting/python/samba/samba3.py
+++ b/source4/scripting/python/samba/samba3.py
@@ -50,9 +50,12 @@ class TdbDatabase(object):
def __init__(self, file):
"""Open a file.
- :param file: Path of the file to open.
+ :param file: Path of the file to open (appending "2" if TDB2 enabled).
"""
- self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
+ if tdb.__version__.startswith("2"):
+ self.tdb = tdb.Tdb(file + "2", flags=os.O_RDONLY)
+ else:
+ self.tdb = tdb.Tdb(file, flags=os.O_RDONLY)
self._check_version()
def _check_version(self):
diff --git a/testdata/samba3/account_policy.tdb2 b/testdata/samba3/account_policy.tdb2
new file mode 100644
index 0000000000..434787e070
--- /dev/null
+++ b/testdata/samba3/account_policy.tdb2
Binary files differ
diff --git a/testdata/samba3/group_mapping.tdb2 b/testdata/samba3/group_mapping.tdb2
new file mode 100644
index 0000000000..1a6466ea04
--- /dev/null
+++ b/testdata/samba3/group_mapping.tdb2
Binary files differ
diff --git a/testdata/samba3/passdb.tdb2 b/testdata/samba3/passdb.tdb2
new file mode 100644
index 0000000000..4ef87ed001
--- /dev/null
+++ b/testdata/samba3/passdb.tdb2
Binary files differ
diff --git a/testdata/samba3/registry.tdb2 b/testdata/samba3/registry.tdb2
new file mode 100644
index 0000000000..d747c3d055
--- /dev/null
+++ b/testdata/samba3/registry.tdb2
Binary files differ
diff --git a/testdata/samba3/secrets.tdb2 b/testdata/samba3/secrets.tdb2
new file mode 100644
index 0000000000..5f88d6ac80
--- /dev/null
+++ b/testdata/samba3/secrets.tdb2
Binary files differ
diff --git a/testdata/samba3/share_info.tdb2 b/testdata/samba3/share_info.tdb2
new file mode 100644
index 0000000000..96e4c7aaf8
--- /dev/null
+++ b/testdata/samba3/share_info.tdb2
Binary files differ
diff --git a/testdata/samba3/winbindd_idmap.tdb2 b/testdata/samba3/winbindd_idmap.tdb2
new file mode 100644
index 0000000000..a63d875055
--- /dev/null
+++ b/testdata/samba3/winbindd_idmap.tdb2
Binary files differ