summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-12-21 07:34:27 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-12-21 07:34:27 +0100
commit6efb7ff98191c5f62f66be33591f674b682986ac (patch)
treeedd2a761bf370b3e2cdb2ebd3015e4e5814439e8
parentf36ff0bac29a0e26db8ac0994d046611e3704dd0 (diff)
downloadsamba-6efb7ff98191c5f62f66be33591f674b682986ac.tar.gz
samba-6efb7ff98191c5f62f66be33591f674b682986ac.tar.bz2
samba-6efb7ff98191c5f62f66be33591f674b682986ac.zip
Fix various Python-related bugs.
-rw-r--r--lib/tevent/pytevent.c1
-rw-r--r--source4/auth/tests/bindings.py2
-rw-r--r--source4/dsdb/samdb/ldb_modules/tests/samba3sam.py340
-rw-r--r--source4/lib/ldb/pyldb.c21
-rw-r--r--source4/lib/ldb/pyldb.h4
-rwxr-xr-xsource4/lib/ldb/tests/python/ldap.py114
-rw-r--r--source4/param/param_wrap.c19
-rw-r--r--source4/param/pyparam.c495
-rw-r--r--source4/scripting/python/samba/tests/upgrade.py2
-rwxr-xr-xsource4/setup/provision3
10 files changed, 754 insertions, 247 deletions
diff --git a/lib/tevent/pytevent.c b/lib/tevent/pytevent.c
index 02e0db3f84..4f18c87a90 100644
--- a/lib/tevent/pytevent.c
+++ b/lib/tevent/pytevent.c
@@ -96,6 +96,7 @@ PyTypeObject PyEventContext = {
.tp_methods = py_event_ctx_methods,
.tp_basicsize = sizeof(py_talloc_Object),
.tp_dealloc = py_talloc_dealloc,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = py_event_ctx_new,
};
diff --git a/source4/auth/tests/bindings.py b/source4/auth/tests/bindings.py
index b7a5994675..15368a4bf7 100644
--- a/source4/auth/tests/bindings.py
+++ b/source4/auth/tests/bindings.py
@@ -31,4 +31,4 @@ class AuthTests(unittest.TestCase):
auth.system_session()
def test_system_session_anon(self):
- auth.system_session_anon()
+ auth.system_session_anonymous()
diff --git a/source4/dsdb/samdb/ldb_modules/tests/samba3sam.py b/source4/dsdb/samdb/ldb_modules/tests/samba3sam.py
index d1a8e71842..be192f8e74 100644
--- a/source4/dsdb/samdb/ldb_modules/tests/samba3sam.py
+++ b/source4/dsdb/samdb/ldb_modules/tests/samba3sam.py
@@ -151,7 +151,7 @@ class Samba3SamTestCase(MapBaseTestCase):
"""Looking up by mapped attribute"""
msg = self.ldb.search(expression="(name=Backup Operators)")
self.assertEquals(len(msg), 1)
- self.assertEquals(msg[0]["name"], "Backup Operators")
+ self.assertEquals(str(msg[0]["name"]), "Backup Operators")
def test_old_name_of_renamed(self):
"""Looking up by old name of renamed attribute"""
@@ -197,9 +197,9 @@ class Samba3SamTestCase(MapBaseTestCase):
scope=SCOPE_BASE,
attrs=['foo','blah','cn','showInAdvancedViewOnly'])
self.assertEquals(len(msg), 1)
- self.assertEquals(msg[0]["showInAdvancedViewOnly"], "TRUE")
- self.assertEquals(msg[0]["foo"], "bar")
- self.assertEquals(msg[0]["blah"], "Blie")
+ self.assertEquals(str(msg[0]["showInAdvancedViewOnly"]), "TRUE")
+ self.assertEquals(str(msg[0]["foo"]), "bar")
+ self.assertEquals(str(msg[0]["blah"]), "Blie")
# Adding record that will be mapped
self.ldb.add({"dn": "cn=Niemand,cn=Users,dc=vernstok,dc=nl",
@@ -212,32 +212,32 @@ class Samba3SamTestCase(MapBaseTestCase):
msg = self.ldb.search(expression="(unixName=bin)",
attrs=['unixName','cn','dn', 'sambaUnicodePwd'])
self.assertEquals(len(msg), 1)
- self.assertEquals(msg[0]["cn"], "Niemand")
- self.assertEquals(msg[0]["sambaUnicodePwd"], "geheim")
+ self.assertEquals(str(msg[0]["cn"]), "Niemand")
+ self.assertEquals(str(msg[0]["sambaUnicodePwd"]), "geheim")
# Checking for existence of record (local && remote)
msg = self.ldb.search(expression="(&(unixName=bin)(sambaUnicodePwd=geheim))",
attrs=['unixName','cn','dn', 'sambaUnicodePwd'])
self.assertEquals(len(msg), 1) # TODO: should check with more records
- self.assertEquals(msg[0]["cn"], "Niemand")
- self.assertEquals(msg[0]["unixName"], "bin")
- self.assertEquals(msg[0]["sambaUnicodePwd"], "geheim")
+ self.assertEquals(str(msg[0]["cn"]), "Niemand")
+ self.assertEquals(str(msg[0]["unixName"]), "bin")
+ self.assertEquals(str(msg[0]["sambaUnicodePwd"]), "geheim")
# Checking for existence of record (local || remote)
msg = self.ldb.search(expression="(|(unixName=bin)(sambaUnicodePwd=geheim))",
attrs=['unixName','cn','dn', 'sambaUnicodePwd'])
#print "got %d replies" % len(msg)
self.assertEquals(len(msg), 1) # TODO: should check with more records
- self.assertEquals(msg[0]["cn"], "Niemand")
- self.assertEquals(msg[0]["unixName"], "bin")
- self.assertEquals(msg[0]["sambaUnicodePwd"], "geheim")
+ self.assertEquals(str(msg[0]["cn"]), "Niemand")
+ self.assertEquals(str(msg[0]["unixName"]), "bin")
+ self.assertEquals(str(msg[0]["sambaUnicodePwd"]), "geheim")
# Checking for data in destination database
msg = self.samba3.db.search(expression="(cn=Niemand)")
self.assertTrue(len(msg) >= 1)
- self.assertEquals(msg[0]["sambaSID"],
+ self.assertEquals(str(msg[0]["sambaSID"]),
"S-1-5-21-4231626423-2410014848-2360679739-2001")
- self.assertEquals(msg[0]["displayName"], "Niemand")
+ self.assertEquals(str(msg[0]["displayName"]), "Niemand")
# Adding attribute...
self.ldb.modify_ldif("""
@@ -250,8 +250,8 @@ description: Blah
# Checking whether changes are still there...
msg = self.ldb.search(expression="(cn=Niemand)")
self.assertTrue(len(msg) >= 1)
- self.assertEquals(msg[0]["cn"], "Niemand")
- self.assertEquals(msg[0]["description"], "Blah")
+ self.assertEquals(str(msg[0]["cn"]), "Niemand")
+ self.assertEquals(str(msg[0]["description"]), "Blah")
# Modifying attribute...
self.ldb.modify_ldif("""
@@ -264,7 +264,7 @@ description: Blie
# Checking whether changes are still there...
msg = self.ldb.search(expression="(cn=Niemand)")
self.assertTrue(len(msg) >= 1)
- self.assertEquals(msg[0]["description"], "Blie")
+ self.assertEquals(str(msg[0]["description"]), "Blie")
# Deleting attribute...
self.ldb.modify_ldif("""
@@ -396,7 +396,7 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
self.assertTrue(not "dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "x")
+ self.assertEquals(str(res[0]["lastLogon"]), "x")
# Search remote record by remote DN
dn = self.samba3.dn("cn=A")
@@ -406,7 +406,7 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(str(res[0].dn), dn)
self.assertTrue(not "dnsHostName" in res[0])
self.assertTrue(not "lastLogon" in res[0])
- self.assertEquals(res[0]["sambaLogonTime"], "x")
+ self.assertEquals(str(res[0]["sambaLogonTime"]), "x")
# Search split record by local DN
dn = self.samba4.dn("cn=X")
@@ -414,8 +414,8 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
- self.assertEquals(res[0]["dnsHostName"], "x")
- self.assertEquals(res[0]["lastLogon"], "x")
+ self.assertEquals(str(res[0]["dnsHostName"]), "x")
+ self.assertEquals(str(res[0]["lastLogon"]), "x")
# Search split record by remote DN
dn = self.samba3.dn("cn=X")
@@ -425,7 +425,7 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(str(res[0].dn), dn)
self.assertTrue(not "dnsHostName" in res[0])
self.assertTrue(not "lastLogon" in res[0])
- self.assertEquals(res[0]["sambaLogonTime"], "x")
+ self.assertEquals(str(res[0]["sambaLogonTime"]), "x")
# Testing search by attribute
@@ -434,22 +434,22 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 2)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=Y"))
- self.assertEquals(res[0]["dnsHostName"], "y")
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["dnsHostName"]), "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[1]["dnsHostName"], "x")
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["dnsHostName"]), "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
# Search by kept attribute
res = self.ldb.search(expression="(description=y)",
scope=SCOPE_DEFAULT, attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 2)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=Z"))
- self.assertEquals(res[0]["dnsHostName"], "z")
- self.assertEquals(res[0]["lastLogon"], "z")
+ self.assertEquals(str(res[0]["dnsHostName"]), "z")
+ self.assertEquals(str(res[0]["lastLogon"]), "z")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=C"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "z")
+ self.assertEquals(str(res[1]["lastLogon"]), "z")
# Search by renamed attribute
res = self.ldb.search(expression="(badPwdCount=x)", scope=SCOPE_DEFAULT,
@@ -457,10 +457,10 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(len(res), 2)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=B"))
self.assertTrue(not "dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
# Search by converted attribute
# TODO:
@@ -470,14 +470,14 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
res = self.ldb.search(expression="(objectSid=*)", base=None, scope=SCOPE_DEFAULT, attrs=["dnsHostName", "lastLogon", "objectSid"])
self.assertEquals(len(res), 3)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[0]["dnsHostName"], "x")
- self.assertEquals(res[0]["lastLogon"], "x")
+ self.assertEquals(str(res[0]["dnsHostName"]), "x")
+ self.assertEquals(str(res[0]["lastLogon"]), "x")
self.assertSidEquals("S-1-5-21-4231626423-2410014848-2360679739-552",
res[0]["objectSid"])
self.assertTrue("objectSid" in res[0])
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
self.assertSidEquals("S-1-5-21-4231626423-2410014848-2360679739-552",
res[1]["objectSid"])
self.assertTrue("objectSid" in res[1])
@@ -490,8 +490,8 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "x")
- self.assertEquals(res[0]["primaryGroupID"], "512")
+ self.assertEquals(str(res[0]["lastLogon"]), "x")
+ self.assertEquals(str(res[0]["primaryGroupID"]), "512")
# TODO: There should actually be two results, A and X. The
# primaryGroupID of X seems to get corrupted somewhere, and the
@@ -517,13 +517,13 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
res = self.ldb.search(expression="(objectClass=user)", attrs=attrs)
self.assertEquals(len(res), 2)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[0]["dnsHostName"], "x")
- self.assertEquals(res[0]["lastLogon"], "x")
- self.assertEquals(res[0]["objectClass"][0], "user")
+ self.assertEquals(str(res[0]["dnsHostName"]), "x")
+ self.assertEquals(str(res[0]["lastLogon"]), "x")
+ self.assertEquals(str(res[0]["objectClass"][0]), "user")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "x")
- self.assertEquals(res[1]["objectClass"][0], "user")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
+ self.assertEquals(str(res[1]["objectClass"][0]), "user")
# Prove that the objectClass is actually used for the search
res = self.ldb.search(expression="(|(objectClass=user)(badPwdCount=x))",
@@ -531,15 +531,15 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(len(res), 3)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=B"))
self.assertTrue(not "dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(set(res[0]["objectClass"]), set(["top"]))
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[1]["dnsHostName"], "x")
- self.assertEquals(res[1]["lastLogon"], "x")
- self.assertEquals(res[1]["objectClass"][0], "user")
+ self.assertEquals(str(res[1]["dnsHostName"]), "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
+ self.assertEquals(str(res[1]["objectClass"][0]), "user")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[2])
- self.assertEquals(res[2]["lastLogon"], "x")
+ self.assertEquals(str(res[2]["lastLogon"]), "x")
self.assertEquals(res[2]["objectClass"][0], "user")
# Testing search by parse tree
@@ -549,33 +549,33 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 2)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=Y"))
- self.assertEquals(res[0]["dnsHostName"], "y")
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["dnsHostName"]), "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[1]["dnsHostName"], "x")
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["dnsHostName"]), "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
# Search by conjunction of remote attributes
res = self.ldb.search(expression="(&(lastLogon=x)(description=x))",
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 2)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[0]["dnsHostName"], "x")
- self.assertEquals(res[0]["lastLogon"], "x")
+ self.assertEquals(str(res[0]["dnsHostName"]), "x")
+ self.assertEquals(str(res[0]["lastLogon"]), "x")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
# Search by conjunction of local and remote attribute
res = self.ldb.search(expression="(&(codePage=x)(description=x))",
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 2)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=Y"))
- self.assertEquals(res[0]["dnsHostName"], "y")
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["dnsHostName"]), "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[1]["dnsHostName"], "x")
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["dnsHostName"]), "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
# Search by conjunction of local and remote attribute w/o match
attrs = ["dnsHostName", "lastLogon"]
@@ -591,11 +591,11 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 2)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=Y"))
- self.assertEquals(res[0]["dnsHostName"], "y")
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["dnsHostName"]), "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[1]["dnsHostName"], "x")
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["dnsHostName"]), "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
# Search by disjunction of remote attributes
res = self.ldb.search(expression="(|(badPwdCount=x)(lastLogon=x))",
@@ -603,27 +603,27 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(len(res), 3)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=B"))
self.assertFalse("dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[1]["dnsHostName"], "x")
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["dnsHostName"]), "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=A"))
self.assertFalse("dnsHostName" in res[2])
- self.assertEquals(res[2]["lastLogon"], "x")
+ self.assertEquals(str(res[2]["lastLogon"]), "x")
# Search by disjunction of local and remote attribute
res = self.ldb.search(expression="(|(revision=x)(lastLogon=y))",
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 3)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=Y"))
- self.assertEquals(res[0]["dnsHostName"], "y")
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["dnsHostName"]), "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=B"))
self.assertFalse("dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "y")
+ self.assertEquals(str(res[1]["lastLogon"]), "y")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[2]["dnsHostName"], "x")
- self.assertEquals(res[2]["lastLogon"], "x")
+ self.assertEquals(str(res[2]["dnsHostName"]), "x")
+ self.assertEquals(str(res[2]["lastLogon"]), "x")
# Search by disjunction of local and remote attribute w/o match
res = self.ldb.search(expression="(|(codePage=y)(nextRid=z))",
@@ -636,27 +636,27 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(len(res), 5)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=B"))
self.assertTrue(not "dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=Z"))
- self.assertEquals(res[2]["dnsHostName"], "z")
- self.assertEquals(res[2]["lastLogon"], "z")
+ self.assertEquals(str(res[2]["dnsHostName"]), "z")
+ self.assertEquals(str(res[2]["lastLogon"]), "z")
self.assertEquals(str(res[3].dn), self.samba4.dn("cn=C"))
self.assertTrue(not "dnsHostName" in res[3])
- self.assertEquals(res[3]["lastLogon"], "z")
+ self.assertEquals(str(res[3]["lastLogon"]), "z")
# Search by negated remote attribute
res = self.ldb.search(expression="(!(description=x))",
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 3)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=Z"))
- self.assertEquals(res[0]["dnsHostName"], "z")
- self.assertEquals(res[0]["lastLogon"], "z")
+ self.assertEquals(str(res[0]["dnsHostName"]), "z")
+ self.assertEquals(str(res[0]["lastLogon"]), "z")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=C"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "z")
+ self.assertEquals(str(res[1]["lastLogon"]), "z")
# Search by negated conjunction of local attributes
res = self.ldb.search(expression="(!(&(codePage=x)(revision=x)))",
@@ -664,33 +664,33 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(len(res), 5)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=B"))
self.assertTrue(not "dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=Z"))
- self.assertEquals(res[2]["dnsHostName"], "z")
- self.assertEquals(res[2]["lastLogon"], "z")
+ self.assertEquals(str(res[2]["dnsHostName"]), "z")
+ self.assertEquals(str(res[2]["lastLogon"]), "z")
self.assertEquals(str(res[3].dn), self.samba4.dn("cn=C"))
self.assertTrue(not "dnsHostName" in res[3])
- self.assertEquals(res[3]["lastLogon"], "z")
+ self.assertEquals(str(res[3]["lastLogon"]), "z")
# Search by negated conjunction of remote attributes
res = self.ldb.search(expression="(!(&(lastLogon=x)(description=x)))",
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 5)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=Y"))
- self.assertEquals(res[0]["dnsHostName"], "y")
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["dnsHostName"]), "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=B"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "y")
+ self.assertEquals(str(res[1]["lastLogon"]), "y")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=Z"))
- self.assertEquals(res[2]["dnsHostName"], "z")
- self.assertEquals(res[2]["lastLogon"], "z")
+ self.assertEquals(str(res[2]["dnsHostName"]), "z")
+ self.assertEquals(str(res[2]["lastLogon"]), "z")
self.assertEquals(str(res[3].dn), self.samba4.dn("cn=C"))
self.assertTrue(not "dnsHostName" in res[3])
- self.assertEquals(res[3]["lastLogon"], "z")
+ self.assertEquals(str(res[3]["lastLogon"]), "z")
# Search by negated conjunction of local and remote attribute
res = self.ldb.search(expression="(!(&(codePage=x)(description=x)))",
@@ -698,46 +698,46 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(len(res), 5)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=B"))
self.assertTrue(not "dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=Z"))
- self.assertEquals(res[2]["dnsHostName"], "z")
- self.assertEquals(res[2]["lastLogon"], "z")
+ self.assertEquals(str(res[2]["dnsHostName"]), "z")
+ self.assertEquals(str(res[2]["lastLogon"]), "z")
self.assertEquals(str(res[3].dn), self.samba4.dn("cn=C"))
self.assertTrue(not "dnsHostName" in res[3])
- self.assertEquals(res[3]["lastLogon"], "z")
+ self.assertEquals(str(res[3]["lastLogon"]), "z")
# Search by negated disjunction of local attributes
res = self.ldb.search(expression="(!(|(revision=x)(dnsHostName=x)))",
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=B"))
self.assertTrue(not "dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[1])
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=Z"))
- self.assertEquals(res[2]["dnsHostName"], "z")
- self.assertEquals(res[2]["lastLogon"], "z")
+ self.assertEquals(str(res[2]["dnsHostName"]), "z")
+ self.assertEquals(str(res[2]["lastLogon"]), "z")
self.assertEquals(str(res[3].dn), self.samba4.dn("cn=C"))
self.assertTrue(not "dnsHostName" in res[3])
- self.assertEquals(res[3]["lastLogon"], "z")
+ self.assertEquals(str(res[3]["lastLogon"]), "z")
# Search by negated disjunction of remote attributes
res = self.ldb.search(expression="(!(|(badPwdCount=x)(lastLogon=x)))",
attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 4)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=Y"))
- self.assertEquals(res[0]["dnsHostName"], "y")
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["dnsHostName"]), "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=Z"))
- self.assertEquals(res[1]["dnsHostName"], "z")
- self.assertEquals(res[1]["lastLogon"], "z")
+ self.assertEquals(str(res[1]["dnsHostName"]), "z")
+ self.assertEquals(str(res[1]["lastLogon"]), "z")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=C"))
self.assertTrue(not "dnsHostName" in res[2])
- self.assertEquals(res[2]["lastLogon"], "z")
+ self.assertEquals(str(res[2]["lastLogon"]), "z")
# Search by negated disjunction of local and remote attribute
res = self.ldb.search(expression="(!(|(revision=x)(lastLogon=y)))",
@@ -745,32 +745,32 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
self.assertEquals(len(res), 4)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "x")
+ self.assertEquals(str(res[0]["lastLogon"]), "x")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=Z"))
- self.assertEquals(res[1]["dnsHostName"], "z")
- self.assertEquals(res[1]["lastLogon"], "z")
+ self.assertEquals(str(res[1]["dnsHostName"]), "z")
+ self.assertEquals(str(res[1]["lastLogon"]), "z")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=C"))
self.assertTrue(not "dnsHostName" in res[2])
- self.assertEquals(res[2]["lastLogon"], "z")
+ self.assertEquals(str(res[2]["lastLogon"]), "z")
# Search by complex parse tree
res = self.ldb.search(expression="(|(&(revision=x)(dnsHostName=x))(!(&(description=x)(nextRid=y)))(badPwdCount=y))", attrs=["dnsHostName", "lastLogon"])
self.assertEquals(len(res), 6)
self.assertEquals(str(res[0].dn), self.samba4.dn("cn=B"))
self.assertTrue(not "dnsHostName" in res[0])
- self.assertEquals(res[0]["lastLogon"], "y")
+ self.assertEquals(str(res[0]["lastLogon"]), "y")
self.assertEquals(str(res[1].dn), self.samba4.dn("cn=X"))
- self.assertEquals(res[1]["dnsHostName"], "x")
- self.assertEquals(res[1]["lastLogon"], "x")
+ self.assertEquals(str(res[1]["dnsHostName"]), "x")
+ self.assertEquals(str(res[1]["lastLogon"]), "x")
self.assertEquals(str(res[2].dn), self.samba4.dn("cn=A"))
self.assertTrue(not "dnsHostName" in res[2])
- self.assertEquals(res[2]["lastLogon"], "x")
+ self.assertEquals(str(res[2]["lastLogon"]), "x")
self.assertEquals(str(res[3].dn), self.samba4.dn("cn=Z"))
- self.assertEquals(res[3]["dnsHostName"], "z")
- self.assertEquals(res[3]["lastLogon"], "z")
+ self.assertEquals(str(res[3]["dnsHostName"]), "z")
+ self.assertEquals(str(res[3]["lastLogon"]), "z")
self.assertEquals(str(res[4].dn), self.samba4.dn("cn=C"))
self.assertTrue(not "dnsHostName" in res[4])
- self.assertEquals(res[4]["lastLogon"], "z")
+ self.assertEquals(str(res[4]["lastLogon"]), "z")
# Clean up
dns = [self.samba4.dn("cn=%s" % n) for n in ["A","B","C","X","Y","Z"]]
@@ -791,9 +791,9 @@ primaryGroupID: 1-5-21-4231626423-2410014848-2360679739-512
res = self.ldb.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
- self.assertEquals(res[0]["foo"], "bar")
- self.assertEquals(res[0]["revision"], "1")
- self.assertEquals(res[0]["description"], "test")
+ self.assertEquals(str(res[0]["foo"]), "bar")
+ self.assertEquals(str(res[0]["revision"]), "1")
+ self.assertEquals(str(res[0]["description"]), "test")
# Check it's not in the local db
res = self.samba4.db.search(expression="(cn=test)",
scope=SCOPE_DEFAULT, attrs=attrs)
@@ -816,9 +816,9 @@ description: foo
res = self.ldb.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
- self.assertEquals(res[0]["foo"], "baz")
- self.assertEquals(res[0]["revision"], "1")
- self.assertEquals(res[0]["description"], "foo")
+ self.assertEquals(str(res[0]["foo"]), "baz")
+ self.assertEquals(str(res[0]["revision"]), "1")
+ self.assertEquals(str(res[0]["description"]), "foo")
# Rename local record
dn2 = "cn=toast,dc=idealx,dc=org"
@@ -827,9 +827,9 @@ description: foo
res = self.ldb.search(dn2, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn2)
- self.assertEquals(res[0]["foo"], "baz")
- self.assertEquals(res[0]["revision"], "1")
- self.assertEquals(res[0]["description"], "foo")
+ self.assertEquals(str(res[0]["foo"]), "baz")
+ self.assertEquals(str(res[0]["revision"]), "1")
+ self.assertEquals(str(res[0]["description"]), "foo")
# Delete local record
self.ldb.delete(dn2)
@@ -852,17 +852,17 @@ description: foo
attrs=["description", "sambaBadPasswordCount", "sambaNextRid"])
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn2)
- self.assertEquals(res[0]["description"], "foo")
- self.assertEquals(res[0]["sambaBadPasswordCount"], "3")
- self.assertEquals(res[0]["sambaNextRid"], "1001")
+ self.assertEquals(str(res[0]["description"]), "foo")
+ self.assertEquals(str(res[0]["sambaBadPasswordCount"]), "3")
+ self.assertEquals(str(res[0]["sambaNextRid"]), "1001")
# Check in mapped db
attrs = ["description", "badPwdCount", "nextRid"]
res = self.ldb.search(dn, scope=SCOPE_BASE, attrs=attrs, expression="")
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
- self.assertEquals(res[0]["description"], "foo")
- self.assertEquals(res[0]["badPwdCount"], "3")
- self.assertEquals(res[0]["nextRid"], "1001")
+ self.assertEquals(str(res[0]["description"]), "foo")
+ self.assertEquals(str(res[0]["badPwdCount"]), "3")
+ self.assertEquals(str(res[0]["nextRid"]), "1001")
# Check in local db
res = self.samba4.db.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 0)
@@ -881,17 +881,17 @@ badPwdCount: 4
attrs=["description", "badPwdCount", "nextRid"])
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
- self.assertEquals(res[0]["description"], "test")
- self.assertEquals(res[0]["badPwdCount"], "4")
- self.assertEquals(res[0]["nextRid"], "1001")
+ self.assertEquals(str(res[0]["description"]), "test")
+ self.assertEquals(str(res[0]["badPwdCount"]), "4")
+ self.assertEquals(str(res[0]["nextRid"]), "1001")
# Check in remote db
res = self.samba3.db.search(dn2, scope=SCOPE_BASE,
attrs=["description", "sambaBadPasswordCount", "sambaNextRid"])
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn2)
- self.assertEquals(res[0]["description"], "test")
- self.assertEquals(res[0]["sambaBadPasswordCount"], "4")
- self.assertEquals(res[0]["sambaNextRid"], "1001")
+ self.assertEquals(str(res[0]["description"]), "test")
+ self.assertEquals(str(res[0]["sambaBadPasswordCount"]), "4")
+ self.assertEquals(str(res[0]["sambaNextRid"]), "1001")
# Rename remote record
dn2 = self.samba4.dn("cn=toast")
@@ -902,18 +902,18 @@ badPwdCount: 4
attrs=["description", "badPwdCount", "nextRid"])
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
- self.assertEquals(res[0]["description"], "test")
- self.assertEquals(res[0]["badPwdCount"], "4")
- self.assertEquals(res[0]["nextRid"], "1001")
+ self.assertEquals(str(res[0]["description"]), "test")
+ self.assertEquals(str(res[0]["badPwdCount"]), "4")
+ self.assertEquals(str(res[0]["nextRid"]), "1001")
# Check in remote db
dn2 = self.samba3.dn("cn=toast")
res = self.samba3.db.search(dn2, scope=SCOPE_BASE,
attrs=["description", "sambaBadPasswordCount", "sambaNextRid"])
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn2)
- self.assertEquals(res[0]["description"], "test")
- self.assertEquals(res[0]["sambaBadPasswordCount"], "4")
- self.assertEquals(res[0]["sambaNextRid"], "1001")
+ self.assertEquals(str(res[0]["description"]), "test")
+ self.assertEquals(str(res[0]["sambaBadPasswordCount"]), "4")
+ self.assertEquals(str(res[0]["sambaNextRid"]), "1001")
# Delete remote record
self.ldb.delete(dn)
@@ -950,20 +950,20 @@ description: test
res = self.ldb.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
- self.assertEquals(res[0]["description"], "test")
- self.assertEquals(res[0]["revision"], "1")
+ self.assertEquals(str(res[0]["description"]), "test")
+ self.assertEquals(str(res[0]["revision"]), "1")
# Check in remote db
res = self.samba3.db.search(dn2, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn2)
- self.assertEquals(res[0]["description"], "test")
+ self.assertEquals(str(res[0]["description"]), "test")
self.assertTrue(not "revision" in res[0])
# Check in local db
res = self.samba4.db.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
self.assertTrue(not "description" in res[0])
- self.assertEquals(res[0]["revision"], "1")
+ self.assertEquals(str(res[0]["revision"]), "1")
# Delete (newly) split record
self.ldb.delete(dn)
@@ -985,10 +985,10 @@ description: test
res = self.ldb.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
- self.assertEquals(res[0]["description"], "foo")
- self.assertEquals(res[0]["badPwdCount"], "3")
- self.assertEquals(res[0]["nextRid"], "1001")
- self.assertEquals(res[0]["revision"], "1")
+ self.assertEquals(str(res[0]["description"]), "foo")
+ self.assertEquals(str(res[0]["badPwdCount"]), "3")
+ self.assertEquals(str(res[0]["nextRid"]), "1001")
+ self.assertEquals(str(res[0]["revision"]), "1")
# Check in local db
res = self.samba4.db.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
@@ -996,16 +996,16 @@ description: test
self.assertTrue(not "description" in res[0])
self.assertTrue(not "badPwdCount" in res[0])
self.assertTrue(not "nextRid" in res[0])
- self.assertEquals(res[0]["revision"], "1")
+ self.assertEquals(str(res[0]["revision"]), "1")
# Check in remote db
attrs = ["description", "sambaBadPasswordCount", "sambaNextRid",
"revision"]
res = self.samba3.db.search(dn2, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn2)
- self.assertEquals(res[0]["description"], "foo")
- self.assertEquals(res[0]["sambaBadPasswordCount"], "3")
- self.assertEquals(res[0]["sambaNextRid"], "1001")
+ self.assertEquals(str(res[0]["description"]), "foo")
+ self.assertEquals(str(res[0]["sambaBadPasswordCount"]), "3")
+ self.assertEquals(str(res[0]["sambaNextRid"]), "1001")
self.assertTrue(not "revision" in res[0])
# Modify of split record
@@ -1024,10 +1024,10 @@ revision: 2
res = self.ldb.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
- self.assertEquals(res[0]["description"], "test")
- self.assertEquals(res[0]["badPwdCount"], "4")
- self.assertEquals(res[0]["nextRid"], "1001")
- self.assertEquals(res[0]["revision"], "2")
+ self.assertEquals(str(res[0]["description"]), "test")
+ self.assertEquals(str(res[0]["badPwdCount"]), "4")
+ self.assertEquals(str(res[0]["nextRid"]), "1001")
+ self.assertEquals(str(res[0]["revision"]), "2")
# Check in local db
res = self.samba4.db.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
@@ -1035,16 +1035,16 @@ revision: 2
self.assertTrue(not "description" in res[0])
self.assertTrue(not "badPwdCount" in res[0])
self.assertTrue(not "nextRid" in res[0])
- self.assertEquals(res[0]["revision"], "2")
+ self.assertEquals(str(res[0]["revision"]), "2")
# Check in remote db
attrs = ["description", "sambaBadPasswordCount", "sambaNextRid",
"revision"]
res = self.samba3.db.search(dn2, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn2)
- self.assertEquals(res[0]["description"], "test")
- self.assertEquals(res[0]["sambaBadPasswordCount"], "4")
- self.assertEquals(res[0]["sambaNextRid"], "1001")
+ self.assertEquals(str(res[0]["description"]), "test")
+ self.assertEquals(str(res[0]["sambaBadPasswordCount"]), "4")
+ self.assertEquals(str(res[0]["sambaNextRid"]), "1001")
self.assertTrue(not "revision" in res[0])
# Rename split record
@@ -1056,10 +1056,10 @@ revision: 2
res = self.ldb.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn)
- self.assertEquals(res[0]["description"], "test")
- self.assertEquals(res[0]["badPwdCount"], "4")
- self.assertEquals(res[0]["nextRid"], "1001")
- self.assertEquals(res[0]["revision"], "2")
+ self.assertEquals(str(res[0]["description"]), "test")
+ self.assertEquals(str(res[0]["badPwdCount"]), "4")
+ self.assertEquals(str(res[0]["nextRid"]), "1001")
+ self.assertEquals(str(res[0]["revision"]), "2")
# Check in local db
res = self.samba4.db.search(dn, scope=SCOPE_BASE, attrs=attrs)
self.assertEquals(len(res), 1)
@@ -1067,7 +1067,7 @@ revision: 2
self.assertTrue(not "description" in res[0])
self.assertTrue(not "badPwdCount" in res[0])
self.assertTrue(not "nextRid" in res[0])
- self.assertEquals(res[0]["revision"], "2")
+ self.assertEquals(str(res[0]["revision"]), "2")
# Check in remote db
dn2 = self.samba3.dn("cn=toast")
res = self.samba3.db.search(dn2, scope=SCOPE_BASE,
@@ -1075,9 +1075,9 @@ revision: 2
"revision"])
self.assertEquals(len(res), 1)
self.assertEquals(str(res[0].dn), dn2)
- self.assertEquals(res[0]["description"], "test")
- self.assertEquals(res[0]["sambaBadPasswordCount"], "4")
- self.assertEquals(res[0]["sambaNextRid"], "1001")
+ self.assertEquals(str(res[0]["description"]), "test")
+ self.assertEquals(str(res[0]["sambaBadPasswordCount"]), "4")
+ self.assertEquals(str(res[0]["sambaNextRid"]), "1001")
self.assertTrue(not "revision" in res[0])
# Delete split record
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index c30953859a..dfabed54e3 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -1275,9 +1275,9 @@ static PyObject *py_ldb_msg_element_iter(PyLdbMessageElementObject *self)
return PyObject_GetIter(ldb_msg_element_to_set(NULL, PyLdbMessageElement_AsMessageElement(self)));
}
-PyObject *PyLdbMessageElement_FromMessageElement(struct ldb_message_element *el)
+PyObject *PyLdbMessageElement_FromMessageElement(struct ldb_message_element *el, TALLOC_CTX *mem_ctx)
{
- return py_talloc_import(&PyLdbMessageElement, el);
+ return py_talloc_import_ex(&PyLdbMessageElement, mem_ctx, el);
}
static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
@@ -1338,11 +1338,22 @@ static PyObject *py_ldb_msg_element_repr(PyLdbMessageElementObject *self)
return ret;
}
+static PyObject *py_ldb_msg_element_str(PyLdbMessageElementObject *self)
+{
+ struct ldb_message_element *el = PyLdbMessageElement_AsMessageElement(self);
+
+ if (el->num_values == 1)
+ return PyString_FromStringAndSize((char *)el->values[0].data, el->values[0].length);
+ else
+ return Py_None;
+}
+
PyTypeObject PyLdbMessageElement = {
.tp_name = "MessageElement",
.tp_basicsize = sizeof(PyLdbMessageElementObject),
.tp_dealloc = py_talloc_dealloc,
.tp_repr = (reprfunc)py_ldb_msg_element_repr,
+ .tp_str = (reprfunc)py_ldb_msg_element_str,
.tp_methods = py_ldb_msg_element_methods,
.tp_compare = (cmpfunc)py_ldb_msg_element_cmp,
.tp_iter = (getiterfunc)py_ldb_msg_element_iter,
@@ -1388,7 +1399,7 @@ static PyObject *py_ldb_msg_getitem_helper(PyLdbMessageObject *self, PyObject *p
if (el == NULL) {
return NULL;
}
- return (PyObject *)PyLdbMessageElement_FromMessageElement(el);
+ return (PyObject *)PyLdbMessageElement_FromMessageElement(el, self->talloc_ctx);
}
static PyObject *py_ldb_msg_getitem(PyLdbMessageObject *self, PyObject *py_name)
@@ -1424,7 +1435,7 @@ static PyObject *py_ldb_msg_items(PyLdbMessageObject *self)
j++;
}
for (i = 0; i < msg->num_elements; i++, j++) {
- PyList_SetItem(l, j, Py_BuildValue("(sO)", msg->elements[i].name, PyLdbMessageElement_FromMessageElement(&msg->elements[i])));
+ PyList_SetItem(l, j, Py_BuildValue("(sO)", msg->elements[i].name, PyLdbMessageElement_FromMessageElement(&msg->elements[i], self->talloc_ctx)));
}
return l;
}
@@ -1956,7 +1967,7 @@ void initldb(void)
PyModule_AddObject(m, "ERR_OBJECT_CLASS_VIOLATION", PyInt_FromLong(LDB_ERR_OBJECT_CLASS_VIOLATION));
PyModule_AddObject(m, "ERR_NOT_ALLOWED_ON_NON_LEAF", PyInt_FromLong(LDB_ERR_NOT_ALLOWED_ON_NON_LEAF));
PyModule_AddObject(m, "ERR_NOT_ALLOWED_ON_RDN", PyInt_FromLong(LDB_ERR_NOT_ALLOWED_ON_RDN));
- PyModule_AddObject(m, "ERR_ENTYR_ALREADY_EXISTS", PyInt_FromLong(LDB_ERR_ENTRY_ALREADY_EXISTS));
+ PyModule_AddObject(m, "ERR_ENTRY_ALREADY_EXISTS", PyInt_FromLong(LDB_ERR_ENTRY_ALREADY_EXISTS));
PyModule_AddObject(m, "ERR_OBJECT_CLASS_MODS_PROHIBITED", PyInt_FromLong(LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED));
PyModule_AddObject(m, "ERR_AFFECTS_MULTIPLE_DSAS", PyInt_FromLong(LDB_ERR_AFFECTS_MULTIPLE_DSAS));
diff --git a/source4/lib/ldb/pyldb.h b/source4/lib/ldb/pyldb.h
index 4ffc21325a..b55bb68401 100644
--- a/source4/lib/ldb/pyldb.h
+++ b/source4/lib/ldb/pyldb.h
@@ -61,8 +61,8 @@ PyObject *PyLdbModule_FromModule(struct ldb_module *mod);
typedef py_talloc_Object PyLdbMessageElementObject;
PyAPI_DATA(PyTypeObject) PyLdbMessageElement;
struct ldb_message_element *PyObject_AsMessageElement(TALLOC_CTX *mem_ctx, PyObject *obj, int flags, const char *name);
-PyObject *PyLdbMessageElement_FromMessageElement(struct ldb_message_element *);
-#define PyLdbMessageElement_AsMessageElement(pyobj) py_talloc_get_type(pyobj, struct ldb_message_element)
+PyObject *PyLdbMessageElement_FromMessageElement(struct ldb_message_element *, TALLOC_CTX *mem_ctx);
+#define PyLdbMessageElement_AsMessageElement(pyobj) ((struct ldb_message_element *)py_talloc_get_ptr(pyobj))
#define PyLdbMessageElement_Check(ob) PyObject_TypeCheck(ob, &PyLdbMessageElement)
typedef py_talloc_Object PyLdbTreeObject;
diff --git a/source4/lib/ldb/tests/python/ldap.py b/source4/lib/ldb/tests/python/ldap.py
index 821bd04b5c..f9006dbd63 100755
--- a/source4/lib/ldb/tests/python/ldap.py
+++ b/source4/lib/ldb/tests/python/ldap.py
@@ -14,9 +14,9 @@ import samba.getopt as options
from samba.auth import system_session
from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError
-from ldb import LDB_ERR_NO_SUCH_OBJECT, LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS
-from ldb import LDB_ERR_ENTRY_ALREADY_EXISTS, LDB_ERR_UNWILLING_TO_PERFORM
-from ldb import LDB_ERR_NOT_ALLOWED_ON_NON_LEAF, LDB_ERR_OTHER, LDB_ERR_INVALID_DN_SYNTAX
+from ldb import ERR_NO_SUCH_OBJECT, ERR_ATTRIBUTE_OR_VALUE_EXISTS
+from ldb import ERR_ENTRY_ALREADY_EXISTS, ERR_UNWILLING_TO_PERFORM
+from ldb import ERR_NOT_ALLOWED_ON_NON_LEAF, ERR_OTHER, ERR_INVALID_DN_SYNTAX
from samba import Ldb
from subunit import SubunitTestRunner
from samba import param
@@ -45,7 +45,7 @@ class BasicTests(unittest.TestCase):
try:
ldb.delete(dn)
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT)
+ self.assertEquals(num, ERR_NO_SUCH_OBJECT)
def find_basedn(self, ldb):
res = ldb.search(base="", expression="", scope=SCOPE_BASE,
@@ -88,7 +88,7 @@ class BasicTests(unittest.TestCase):
"member": "cn=ldaptestuser,cn=useRs," + self.base_dn})
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT)
+ self.assertEquals(num, ERR_NO_SUCH_OBJECT)
def test_all(self):
"""Basic tests"""
@@ -129,7 +129,7 @@ class BasicTests(unittest.TestCase):
})
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_INVALID_DN_SYNTAX)
+ self.assertEquals(num, ERR_INVALID_DN_SYNTAX)
self.delete_force(self.ldb, "cn=ldaptestcomputer3,cn=computers," + self.base_dn)
try:
@@ -140,7 +140,7 @@ class BasicTests(unittest.TestCase):
})
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_UNWILLING_TO_PERFORM)
+ self.assertEquals(num, ERR_UNWILLING_TO_PERFORM)
self.delete_force(self.ldb, "cn=ldaptestcomputer3,cn=computers," + self.base_dn)
try:
@@ -151,7 +151,7 @@ class BasicTests(unittest.TestCase):
})
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_UNWILLING_TO_PERFORM)
+ self.assertEquals(num, ERR_UNWILLING_TO_PERFORM)
self.delete_force(self.ldb, "cn=ldaptestuser7,cn=users," + self.base_dn)
try:
@@ -162,7 +162,7 @@ class BasicTests(unittest.TestCase):
})
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_UNWILLING_TO_PERFORM)
+ self.assertEquals(num, ERR_UNWILLING_TO_PERFORM)
self.delete_force(self.ldb, "cn=ldaptestuser7,cn=users," + self.base_dn)
@@ -213,7 +213,7 @@ servicePrincipalName: cifs/ldaptest2computer
""")
self.fail()
except LdbError, (num, msg):
- self.assertEquals(num, LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS)
+ self.assertEquals(num, ERR_ATTRIBUTE_OR_VALUE_EXISTS)
ldb.modify_ldif("""
dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """
@@ -231,7 +231,7 @@ servicePrincipalName: host/ldaptest2computer
""")
self.fail()
except LdbError, (num, msg):
- self.assertEquals(num, LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS)
+ self.assertEquals(num, ERR_ATTRIBUTE_OR_VALUE_EXISTS)
print "Testing ranged results"
ldb.modify_ldif("""
@@ -352,7 +352,7 @@ servicePrincipalName: host/ldaptest2computer29
self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn))
self.assertEquals(res[0]["cn"][0], "ldaptestuser")
- self.assertEquals(res[0]["name"], "ldaptestuser")
+ self.assertEquals(str(res[0]["name"]), "ldaptestuser")
# Testing ldb.search for (&(anr=testy)(objectClass=user))
res = ldb.search(expression="(&(anr=testy)(objectClass=user))")
@@ -384,24 +384,24 @@ servicePrincipalName: host/ldaptest2computer29
self.assertEquals(len(res), 1, "Could not find (&(anr=testy ldap user)(objectClass=user))")
self.assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestuser2")
- self.assertEquals(res[0]["name"], "ldaptestuser2")
+ self.assertEquals(str(res[0]["cn"]), "ldaptestuser2")
+ self.assertEquals(str(res[0]["name"]), "ldaptestuser2")
# Testing ldb.search for (&(anr==testy ldap user2)(objectClass=user))
# res = ldb.search(expression="(&(anr==testy ldap user2)(objectClass=user))")
# self.assertEquals(len(res), 1, "Could not find (&(anr==testy ldap user2)(objectClass=user))")
self.assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestuser2")
- self.assertEquals(res[0]["name"], "ldaptestuser2")
+ self.assertEquals(str(res[0]["cn"]), "ldaptestuser2")
+ self.assertEquals(str(res[0]["name"]), "ldaptestuser2")
# Testing ldb.search for (&(anr==ldap user2)(objectClass=user))
# res = ldb.search(expression="(&(anr==ldap user2)(objectClass=user))")
# self.assertEquals(len(res), 1, "Could not find (&(anr==ldap user2)(objectClass=user))")
self.assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestuser2")
- self.assertEquals(res[0]["name"], "ldaptestuser2")
+ self.assertEquals(str(res[0]["cn"]), "ldaptestuser2")
+ self.assertEquals(str(res[0]["name"]), "ldaptestuser2")
# Testing ldb.search for (&(anr==not ldap user2)(objectClass=user))
# res = ldb.search(expression="(&(anr==not ldap user2)(objectClass=user))")
@@ -436,7 +436,7 @@ member: cn=ldaptestuser3,cn=users,""" + self.base_dn + """
""")
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT)
+ self.assertEquals(num, ERR_NO_SUCH_OBJECT)
print "Testing Renames"
@@ -457,24 +457,24 @@ member: cn=ldaptestuser3,cn=users,""" + self.base_dn + """
self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser3)(objectClass=user))")
self.assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestUSER3")
- self.assertEquals(res[0]["name"], "ldaptestUSER3")
+ self.assertEquals(str(res[0]["cn"]), "ldaptestUSER3")
+ self.assertEquals(str(res[0]["name"]), "ldaptestUSER3")
#"Testing ldb.search for (&(&(cn=ldaptestuser3)(userAccountControl=*))(objectClass=user))"
res = ldb.search(expression="(&(&(cn=ldaptestuser3)(userAccountControl=*))(objectClass=user))")
self.assertEquals(len(res), 1, "(&(&(cn=ldaptestuser3)(userAccountControl=*))(objectClass=user))")
self.assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestUSER3")
- self.assertEquals(res[0]["name"], "ldaptestUSER3")
+ self.assertEquals(str(res[0]["cn"]), "ldaptestUSER3")
+ self.assertEquals(str(res[0]["name"]), "ldaptestUSER3")
#"Testing ldb.search for (&(&(cn=ldaptestuser3)(userAccountControl=546))(objectClass=user))"
res = ldb.search(expression="(&(&(cn=ldaptestuser3)(userAccountControl=546))(objectClass=user))")
self.assertEquals(len(res), 1, "(&(&(cn=ldaptestuser3)(userAccountControl=546))(objectClass=user))")
self.assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestUSER3")
- self.assertEquals(res[0]["name"], "ldaptestUSER3")
+ self.assertEquals(str(res[0]["cn"]), "ldaptestUSER3")
+ self.assertEquals(str(res[0]["name"]), "ldaptestUSER3")
#"Testing ldb.search for (&(&(cn=ldaptestuser3)(userAccountControl=547))(objectClass=user))"
res = ldb.search(expression="(&(&(cn=ldaptestuser3)(userAccountControl=547))(objectClass=user))")
@@ -495,8 +495,8 @@ member: cn=ldaptestuser3,cn=users,""" + self.base_dn + """
res = ldb.search(expression="(distinguishedName=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")")
self.assertEquals(len(res), 1, "Could not find (dn=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")")
self.assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestUSER3")
- self.assertEquals(res[0]["name"], "ldaptestUSER3")
+ self.assertEquals(str(res[0]["cn"]), "ldaptestUSER3")
+ self.assertEquals(str(res[0]["name"]), "ldaptestUSER3")
# ensure we cannot add it again
try:
@@ -505,7 +505,7 @@ member: cn=ldaptestuser3,cn=users,""" + self.base_dn + """
"cn": "LDAPtestUSER3"})
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_ENTRY_ALREADY_EXISTS)
+ self.assertEquals(num, ERR_ENTRY_ALREADY_EXISTS)
# rename back
ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestuser2,cn=users," + self.base_dn)
@@ -516,7 +516,7 @@ member: cn=ldaptestuser3,cn=users,""" + self.base_dn + """
"cn=ldaptestuser2,cn=users," + self.base_dn)
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT)
+ self.assertEquals(num, ERR_NO_SUCH_OBJECT)
# ensure can now use that name
ldb.add({"dn": "cn=ldaptestuser3,cn=users," + self.base_dn,
@@ -528,7 +528,7 @@ member: cn=ldaptestuser3,cn=users,""" + self.base_dn + """
ldb.rename("cn=ldaptestuser2,cn=users," + self.base_dn, "cn=ldaptestuser3,cn=users," + self.base_dn)
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_ENTRY_ALREADY_EXISTS)
+ self.assertEquals(num, ERR_ENTRY_ALREADY_EXISTS)
try:
ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestuser3,cn=configuration," + self.base_dn)
self.fail()
@@ -569,12 +569,12 @@ member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """
print "Testing subtree ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + self.base_dn
try:
- ldb.search("cn=ldaptestcontainer," + self.base_dn,
+ res = ldb.search("cn=ldaptestcontainer," + self.base_dn,
expression="(&(cn=ldaptestuser4)(objectClass=user))",
scope=SCOPE_SUBTREE)
- self.fail()
+ self.fail(res)
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT)
+ self.assertEquals(num, ERR_NO_SUCH_OBJECT)
print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + self.base_dn
try:
@@ -582,7 +582,7 @@ member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """
expression="(&(cn=ldaptestuser4)(objectClass=user))", scope=SCOPE_ONELEVEL)
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT)
+ self.assertEquals(num, ERR_NO_SUCH_OBJECT)
print "Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in renamed container"
res = ldb.search("cn=ldaptestcontainer2," + self.base_dn, expression="(&(cn=ldaptestuser4)(objectClass=user))", scope=SCOPE_SUBTREE)
@@ -602,21 +602,21 @@ member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """
ldb.rename("cn=ldaptestcontainer2," + self.base_dn, "cn=ldaptestcontainer,cn=ldaptestcontainer2," + self.base_dn)
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_UNWILLING_TO_PERFORM)
+ self.assertEquals(num, ERR_UNWILLING_TO_PERFORM)
print "Testing ldb.rename (into non-existent container) of cn=ldaptestcontainer2," + self.base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer3," + self.base_dn
try:
ldb.rename("cn=ldaptestcontainer2," + self.base_dn, "cn=ldaptestcontainer,cn=ldaptestcontainer3," + self.base_dn)
self.fail()
except LdbError, (num, _):
- self.assertTrue(num in (LDB_ERR_UNWILLING_TO_PERFORM, LDB_ERR_OTHER))
+ self.assertTrue(num in (ERR_UNWILLING_TO_PERFORM, ERR_OTHER))
print "Testing delete (should fail, not a leaf node) of renamed cn=ldaptestcontainer2," + self.base_dn
try:
ldb.delete("cn=ldaptestcontainer2," + self.base_dn)
self.fail()
except LdbError, (num, _):
- self.assertEquals(num, LDB_ERR_NOT_ALLOWED_ON_NON_LEAF)
+ self.assertEquals(num, NOT_ALLOWED_ON_NON_LEAF)
print "Testing base ldb.search for CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn
res = ldb.search(expression="(objectclass=*)", base=("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn), scope=SCOPE_BASE)
@@ -648,12 +648,12 @@ member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """
self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))")
self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestuser")
- self.assertEquals(res[0]["name"], "ldaptestuser")
- self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"])
+ self.assertEquals(str(res[0]["cn"]), "ldaptestuser")
+ self.assertEquals(str(res[0]["name"]), "ldaptestuser")
+ self.assertEquals(str(res[0]["objectClass"]), ["top", "person", "organizationalPerson", "user"])
self.assertTrue("objectGUID" in res[0])
self.assertTrue("whenCreated" in res[0])
- self.assertEquals(res[0]["objectCategory"], ("CN=Person,CN=Schema,CN=Configuration," + self.base_dn))
+ self.assertEquals(str(res[0]["objectCategory"]), ("CN=Person,CN=Schema,CN=Configuration," + self.base_dn))
self.assertEquals(int(res[0]["sAMAccountType"][0]), 805306368)
self.assertEquals(int(res[0]["userAccountControl"][0]), 546)
self.assertEquals(res[0]["memberOf"][0].upper(), ("CN=ldaptestgroup2,CN=Users," + self.base_dn).upper())
@@ -692,9 +692,9 @@ member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """
self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))")
self.assertEquals(str(res[0].dn), ("CN=ldaptestcomputer,CN=Computers," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestcomputer")
- self.assertEquals(res[0]["name"], "ldaptestcomputer")
- self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user", "computer"])
+ self.assertEquals(str(res[0]["cn"]), "ldaptestcomputer")
+ self.assertEquals(str(res[0]["name"]), "ldaptestcomputer")
+ self.assertEquals(str(res[0]["objectClass"]), ["top", "person", "organizationalPerson", "user", "computer"])
self.assertTrue("objectGUID" in res[0])
self.assertTrue("whenCreated" in res[0])
self.assertEquals(res[0]["objectCategory"], ("CN=Computer,CN=Schema,CN=Configuration," + self.base_dn))
@@ -755,9 +755,9 @@ member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """
self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptest2computer)(objectClass=user))")
self.assertEquals(res[0].dn, ("CN=ldaptest2computer,CN=Computers," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptest2computer")
- self.assertEquals(res[0]["name"], "ldaptest2computer")
- self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user", "computer"])
+ self.assertEquals(str(res[0]["cn"]), "ldaptest2computer")
+ self.assertEquals(str(res[0]["name"]), "ldaptest2computer")
+ self.assertEquals(list(res[0]["objectClass"]), ["top", "person", "organizationalPerson", "user", "computer"])
self.assertTrue("objectGUID" in res[0])
self.assertTrue("whenCreated" in res[0])
self.assertEquals(res[0]["objectCategory"][0], "CN=Computer,CN=Schema,CN=Configuration," + self.base_dn)
@@ -772,9 +772,9 @@ member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """
self.assertEquals(len(res_user), 1, "Could not find (&(cn=ldaptestUSer2)(objectClass=user))")
self.assertEquals(res_user[0].dn, ("CN=ldaptestuser2,CN=Users," + self.base_dn))
- self.assertEquals(res_user[0]["cn"], "ldaptestuser2")
- self.assertEquals(res_user[0]["name"], "ldaptestuser2")
- self.assertEquals(res_user[0]["objectClass"], ["top", "person", "organizationalPerson", "user"])
+ self.assertEquals(str(res_user[0]["cn"]), "ldaptestuser2")
+ self.assertEquals(str(res_user[0]["name"]), "ldaptestuser2")
+ self.assertEquals(list(res_user[0]["objectClass"]), ["top", "person", "organizationalPerson", "user"])
self.assertTrue("objectSid" in res_user[0])
self.assertTrue("objectGUID" in res_user[0])
self.assertTrue("whenCreated" in res_user[0])
@@ -792,9 +792,9 @@ member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """
self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))")
self.assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestgroup2")
- self.assertEquals(res[0]["name"], "ldaptestgroup2")
- self.assertEquals(res[0]["objectClass"], ["top", "group"])
+ self.assertEquals(str(res[0]["cn"]), "ldaptestgroup2")
+ self.assertEquals(str(res[0]["name"]), "ldaptestgroup2")
+ self.assertEquals(list(res[0]["objectClass"]), ["top", "group"])
self.assertTrue("objectGUID" in res[0])
self.assertTrue("objectSid" in res[0])
self.assertTrue("whenCreated" in res[0])
@@ -892,9 +892,9 @@ member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self.base_dn + """
self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))")
self.assertEquals(res[0].dn, ("CN=ldaptestutf8user èùéìòà,CN=Users," + self.base_dn))
- self.assertEquals(res[0]["cn"], "ldaptestutf8user èùéìòà")
- self.assertEquals(res[0]["name"], "ldaptestutf8user èùéìòà")
- self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"])
+ self.assertEquals(str(res[0]["cn"]), "ldaptestutf8user èùéìòà")
+ self.assertEquals(str(res[0]["name"]), "ldaptestutf8user èùéìòà")
+ self.assertEquals(list(res[0]["objectClass"]), ["top", "person", "organizationalPerson", "user"])
self.assertTrue("objectGUID" in res[0])
self.assertTrue("whenCreated" in res[0])
@@ -957,7 +957,7 @@ member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self.base_dn + """
scope=SCOPE_BASE, attrs=["objectClass"])
self.assertEquals(len(res), 1)
- self.assertEquals(res[0]["objectClass"], ["top", "domain", "domainDNS"])
+ self.assertEquals(list(res[0]["objectClass"]), ["top", "domain", "domainDNS"])
# check enumeration
diff --git a/source4/param/param_wrap.c b/source4/param/param_wrap.c
index 6ce17957c1..596c21038e 100644
--- a/source4/param/param_wrap.c
+++ b/source4/param/param_wrap.c
@@ -2793,27 +2793,26 @@ SWIGINTERN struct param_opt *param_section_next_parameter(param_section *self,st
struct loadparm_context *lp_from_py_object(PyObject *py_obj)
{
- struct loadparm_context *lp_ctx;
+ struct loadparm_context *lp_ctx = NULL;
if (PyString_Check(py_obj)) {
lp_ctx = loadparm_init(NULL);
if (!lp_load(lp_ctx, PyString_AsString(py_obj))) {
talloc_free(lp_ctx);
+ PyErr_SetString(PyExc_RuntimeError, "Unable to load file");
return NULL;
}
return lp_ctx;
}
- if (py_obj == Py_None) {
- lp_ctx = loadparm_init(NULL);
- if (!lp_load_default(lp_ctx)) {
- talloc_free(lp_ctx);
- return NULL;
- }
+ SWIG_ConvertPtr(py_obj, (void *)&lp_ctx, SWIGTYPE_p_loadparm_context, 0 | 0 );
+ if (lp_ctx != NULL)
return lp_ctx;
+ lp_ctx = loadparm_init(NULL);
+ if (!lp_load_default(lp_ctx)) {
+ talloc_free(lp_ctx);
+ PyErr_SetString(PyExc_RuntimeError, "Unable to load default file");
+ return NULL;
}
-
- if (SWIG_ConvertPtr(py_obj, (void *)&lp_ctx, SWIGTYPE_p_loadparm_context, 0 | 0 ) < 0)
- return NULL;
return lp_ctx;
}
diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c
new file mode 100644
index 0000000000..b432398065
--- /dev/null
+++ b/source4/param/pyparam.c
@@ -0,0 +1,495 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
+
+ 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "includes.h"
+#include "param/param.h"
+#include "param/loadparm.h"
+#include "pytalloc.h"
+
+#define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_ptr(obj)
+#define PyLoadparmContext_Check(obj) PyObject_TypeCheck(obj, &PyLoadparmContext)
+
+PyAPI_DATA(PyTypeObject) PyLoadparmContext;
+PyAPI_DATA(PyTypeObject) PyLoadparmService;
+
+PyObject *PyLoadparmService_FromService(struct loadparm_service *service)
+{
+ return py_talloc_import(&PyLoadparmService, service);
+}
+
+static PyObject *py_lp_ctx_get_helper(struct loadparm_context *lp_ctx, const char *service_name, const char *param_name)
+{
+ struct parm_struct *parm = NULL;
+ void *parm_ptr = NULL;
+ int i;
+
+ if (service_name != NULL) {
+ struct loadparm_service *service;
+ /* its a share parameter */
+ service = lp_service(lp_ctx, service_name);
+ if (service == NULL) {
+ return NULL;
+ }
+ if (strchr(param_name, ':')) {
+ /* its a parametric option on a share */
+ const char *type = talloc_strndup(lp_ctx,
+ param_name,
+ strcspn(param_name, ":"));
+ const char *option = strchr(param_name, ':') + 1;
+ const char *value;
+ if (type == NULL || option == NULL) {
+ return NULL;
+ }
+ value = lp_get_parametric(lp_ctx, service, type, option);
+ if (value == NULL) {
+ return NULL;
+ }
+ return PyString_FromString(value);
+ }
+
+ parm = lp_parm_struct(param_name);
+ if (parm == NULL || parm->class == P_GLOBAL) {
+ return NULL;
+ }
+ parm_ptr = lp_parm_ptr(lp_ctx, service, parm);
+ } else if (strchr(param_name, ':')) {
+ /* its a global parametric option */
+ const char *type = talloc_strndup(lp_ctx,
+ param_name, strcspn(param_name, ":"));
+ const char *option = strchr(param_name, ':') + 1;
+ const char *value;
+ if (type == NULL || option == NULL) {
+ return NULL;
+ }
+ value = lp_get_parametric(lp_ctx, NULL, type, option);
+ if (value == NULL)
+ return NULL;
+ return PyString_FromString(value);
+ } else {
+ /* its a global parameter */
+ parm = lp_parm_struct(param_name);
+ if (parm == NULL) {
+ return NULL;
+ }
+ parm_ptr = lp_parm_ptr(lp_ctx, NULL, parm);
+ }
+
+ if (parm == NULL || parm_ptr == NULL) {
+ return NULL;
+ }
+
+ /* construct and return the right type of python object */
+ switch (parm->type) {
+ case P_STRING:
+ case P_USTRING:
+ return PyString_FromString(*(char **)parm_ptr);
+ case P_BOOL:
+ return PyBool_FromLong(*(bool *)parm_ptr);
+ case P_INTEGER:
+ case P_OCTAL:
+ case P_BYTES:
+ return PyLong_FromLong(*(int *)parm_ptr);
+ case P_ENUM:
+ for (i=0; parm->enum_list[i].name; i++) {
+ if (*(int *)parm_ptr == parm->enum_list[i].value) {
+ return PyString_FromString(parm->enum_list[i].name);
+ }
+ }
+ return NULL;
+ case P_LIST:
+ {
+ int j;
+ const char **strlist = *(const char ***)parm_ptr;
+ PyObject *pylist = PyList_New(str_list_length(strlist));
+ for (j = 0; strlist[j]; j++)
+ PyList_SetItem(pylist, j,
+ PyString_FromString(strlist[j]));
+ return pylist;
+ }
+
+ break;
+ }
+ return NULL;
+
+}
+
+static PyObject *py_lp_ctx_load(py_talloc_Object *self, PyObject *args)
+{
+ char *filename;
+ bool ret;
+ if (!PyArg_ParseTuple(args, "s", &filename))
+ return NULL;
+
+ ret = lp_load((struct loadparm_context *)self->ptr, filename);
+
+ if (!ret) {
+ PyErr_SetString(PyExc_RuntimeError, "Unable to load file");
+ return NULL;
+ }
+ return Py_None;
+}
+
+static PyObject *py_lp_ctx_load_default(py_talloc_Object *self)
+{
+ bool ret;
+ ret = lp_load_default(self->ptr);
+
+ if (!ret) {
+ PyErr_SetString(PyExc_RuntimeError, "Unable to load file");
+ return NULL;
+ }
+ return Py_None;
+}
+
+static PyObject *py_lp_ctx_get(py_talloc_Object *self, PyObject *args)
+{
+ char *param_name;
+ char *section_name = NULL;
+ PyObject *ret;
+ if (!PyArg_ParseTuple(args, "s|s", &param_name, &section_name))
+ return NULL;
+
+ ret = py_lp_ctx_get_helper(self->ptr, section_name, param_name);
+ if (ret == NULL)
+ return Py_None;
+ return ret;
+}
+
+static PyObject *py_lp_ctx_is_myname(py_talloc_Object *self, PyObject *args)
+{
+ char *name;
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+
+ return PyBool_FromLong(lp_is_myname(self->ptr, name));
+}
+
+static PyObject *py_lp_ctx_set(py_talloc_Object *self, PyObject *args)
+{
+ char *name, *value;
+ bool ret;
+ if (!PyArg_ParseTuple(args, "ss", &name, &value))
+ return NULL;
+
+ ret = lp_set_cmdline(self->ptr, name, value);
+ if (!ret) {
+ PyErr_SetString(PyExc_RuntimeError, "Unable to set parameter");
+ return NULL;
+ }
+
+ return Py_None;
+}
+
+static PyObject *py_lp_ctx_private_path(py_talloc_Object *self, PyObject *args)
+{
+ char *name, *path;
+ PyObject *ret;
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+
+ path = private_path(NULL, self->ptr, name);
+ ret = PyString_FromString(path);
+ talloc_free(path);
+
+ return ret;
+}
+
+static PyMethodDef py_lp_ctx_methods[] = {
+ { "load", (PyCFunction)py_lp_ctx_load, METH_VARARGS,
+ "S.load(filename) -> None\n"
+ "Load specified file." },
+ { "load_default", (PyCFunction)py_lp_ctx_load_default, METH_NOARGS,
+ "S.load_default() -> None\n"
+ "Load default smb.conf file." },
+ { "is_myname", (PyCFunction)py_lp_ctx_is_myname, METH_VARARGS,
+ "S.is_myname(name) -> bool\n"
+ "Check whether the specified name matches one of our netbios names." },
+ { "get", (PyCFunction)py_lp_ctx_get, METH_VARARGS,
+ "S.get(name, service_name) -> value\n"
+ "Find specified parameter." },
+ { "set", (PyCFunction)py_lp_ctx_set, METH_VARARGS,
+ "S.set(name, value) -> bool\n"
+ "Change a parameter." },
+ { "private_path", (PyCFunction)py_lp_ctx_private_path, METH_VARARGS,
+ "S.private_path(name) -> path\n" },
+ { NULL }
+};
+
+static PyObject *py_lp_ctx_default_service(py_talloc_Object *self, void *closure)
+{
+ return PyLoadparmService_FromService(lp_default_service((struct loadparm_context *)self->ptr));
+}
+
+static PyObject *py_lp_ctx_config_file(py_talloc_Object *self, void *closure)
+{
+ return PyString_FromString(lp_configfile(self->ptr));
+}
+
+static PyGetSetDef py_lp_ctx_getset[] = {
+ { (char *)"default_service", (getter)py_lp_ctx_default_service, NULL, NULL },
+ { (char *)"config_file", (getter)py_lp_ctx_config_file, NULL,
+ (char *)"Name of last config file that was loaded." },
+ { NULL }
+};
+
+static PyObject *py_lp_ctx_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ return py_talloc_import(type, loadparm_init(NULL));
+}
+
+static Py_ssize_t py_lp_ctx_len(py_talloc_Object *self)
+{
+ return lp_numservices(self->ptr);
+}
+
+static PyObject *py_lp_ctx_getitem(py_talloc_Object *self, PyObject *name)
+{
+ struct loadparm_service *service;
+ if (!PyString_Check(name)) {
+ PyErr_SetString(PyExc_TypeError, "Only string subscripts are supported");
+ return NULL;
+ }
+ service = lp_service(self->ptr, PyString_AsString(name));
+ if (service == NULL) {
+ PyErr_SetString(PyExc_KeyError, "No such section");
+ return NULL;
+ }
+ return PyLoadparmService_FromService(service);
+}
+
+static PyMappingMethods py_lp_ctx_mapping = {
+ .mp_length = (lenfunc)py_lp_ctx_len,
+ .mp_subscript = (binaryfunc)py_lp_ctx_getitem,
+};
+
+PyTypeObject PyLoadparmContext = {
+ .tp_name = "LoadparmContext",
+ .tp_basicsize = sizeof(py_talloc_Object),
+ .tp_dealloc = py_talloc_dealloc,
+ .tp_getset = py_lp_ctx_getset,
+ .tp_methods = py_lp_ctx_methods,
+ .tp_new = py_lp_ctx_new,
+ .tp_as_mapping = &py_lp_ctx_mapping,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+};
+
+PyTypeObject PyLoadparmService = {
+ .tp_name = "LoadparmService",
+ .tp_dealloc = py_talloc_dealloc,
+ .tp_basicsize = sizeof(py_talloc_Object),
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+};
+
+struct loadparm_context *lp_from_py_object(PyObject *py_obj)
+{
+ struct loadparm_context *lp_ctx;
+ if (PyString_Check(py_obj)) {
+ lp_ctx = loadparm_init(NULL);
+ if (!lp_load(lp_ctx, PyString_AsString(py_obj))) {
+ talloc_free(lp_ctx);
+ return NULL;
+ }
+ return lp_ctx;
+ }
+
+ if (py_obj == Py_None) {
+ lp_ctx = loadparm_init(NULL);
+ if (!lp_load_default(lp_ctx)) {
+ talloc_free(lp_ctx);
+ return NULL;
+ }
+ return lp_ctx;
+ }
+
+ if (PyLoadparmContext_Check(py_obj))
+ return PyLoadparmContext_AsLoadparmContext(py_obj);
+
+ return NULL;
+}
+
+struct loadparm_context *py_default_loadparm_context(TALLOC_CTX *mem_ctx)
+{
+ struct loadparm_context *ret;
+ ret = loadparm_init(mem_ctx);
+ if (!lp_load_default(ret))
+ return NULL;
+ return ret;
+}
+
+void initparam(void)
+{
+ PyObject *m;
+
+ if (PyType_Ready(&PyLoadparmContext) < 0)
+ return;
+
+ m = Py_InitModule3("param", NULL, "Parsing and writing Samba configuration files.");
+ if (m == NULL)
+ return;
+
+ Py_INCREF(&PyLoadparmContext);
+ PyModule_AddObject(m, "LoadparmContext", (PyObject *)&PyLoadparmContext);
+}
+
+/*
+typedef struct loadparm_context {
+ %extend {
+ int use(struct param_context *param_ctx) { return param_use($self, param_ctx); }
+ }
+} loadparm_context;
+
+typedef struct loadparm_service {
+ %extend {
+ const char *volume_label(struct loadparm_service *sDefault) { return volume_label($self, sDefault); }
+ const char *printername(struct loadparm_service *sDefault) { return lp_printername($self, sDefault); }
+ int maxprintjobs(struct loadparm_service *sDefault) { return lp_maxprintjobs($self, sDefault); }
+ }
+} loadparm_service;
+
+%rename(ParamFile) param_context;
+
+%talloctype(param_context);
+typedef struct param_context {
+ %extend {
+ param(TALLOC_CTX *mem_ctx) { return param_init(mem_ctx); }
+ %feature("docstring") add_section "S.get_section(name) -> section\n"
+ "Get an existing section.";
+ struct param_section *get_section(const char *name);
+ %feature("docstring") add_section "S.add_section(name) -> section\n"
+ "Add a new section.";
+ struct param_section *add_section(const char *name);
+ struct param_opt *get(const char *name, const char *section_name="global");
+ const char *get_string(const char *name, const char *section_name="global");
+ int set_string(const char *param, const char *value, const char *section="global");
+#ifdef SWIGPYTHON
+ int set(const char *parameter, PyObject *ob, const char *section_name="global")
+ {
+ struct param_opt *opt = param_get_add($self, parameter, section_name);
+
+ talloc_free(opt->value);
+ opt->value = talloc_strdup(opt, PyString_AsString(PyObject_Str(ob)));
+
+ return 0;
+ }
+
+#endif
+
+ %feature("docstring") first_section "S.first_section() -> section\n"
+ "Find first section";
+ struct param_section *first_section() { return $self->sections; }
+ %feature("docstring") next_section "S.next_section(prev) -> section\n"
+ "Find next section";
+ struct param_section *next_section(struct param_section *s) { return s->next; }
+
+ %feature("docstring") read "S.read(filename) -> bool\n"
+ "Read a filename.";
+ int read(const char *fn);
+ %feature("docstring") read "S.write(filename) -> bool\n"
+ "Write this object to a file.";
+ int write(const char *fn);
+ }
+ %pythoncode {
+ def __getitem__(self, name):
+ ret = self.get_section(name)
+ if ret is None:
+ raise KeyError("No such section %s" % name)
+ return ret
+
+ class SectionIterator:
+ def __init__(self, param):
+ self.param = param
+ self.key = None
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if self.key is None:
+ self.key = self.param.first_section()
+ if self.key is None:
+ raise StopIteration
+ return self.key
+ else:
+ self.key = self.param.next_section(self.key)
+ if self.key is None:
+ raise StopIteration
+ return self.key
+
+ def __iter__(self):
+ return self.SectionIterator(self)
+ }
+} param;
+
+%talloctype(param_opt);
+
+typedef struct param_opt {
+ %immutable key;
+ %immutable value;
+ const char *key, *value;
+ %extend {
+#ifdef SWIGPYTHON
+ const char *__str__() { return $self->value; }
+#endif
+ }
+} param_opt;
+
+%talloctype(param);
+typedef struct param_section {
+ %immutable name;
+ const char *name;
+ %extend {
+ struct param_opt *get(const char *name);
+ struct param_opt *first_parameter() { return $self->parameters; }
+ struct param_opt *next_parameter(struct param_opt *s) { return s->next; }
+ }
+ %pythoncode {
+ def __getitem__(self, name):
+ ret = self.get(name)
+ if ret is None:
+ raise KeyError("No such option %s" % name)
+ return ret
+
+ class ParamIterator:
+ def __init__(self, section):
+ self.section = section
+ self.key = None
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if self.key is None:
+ self.key = self.section.first_parameter()
+ if self.key is None:
+ raise StopIteration
+ return self.key
+ else:
+ self.key = self.section.next_parameter(self.key)
+ if self.key is None:
+ raise StopIteration
+ return self.key
+
+ def __iter__(self):
+ return self.ParamIterator(self)
+ }
+} param_section;
+*/
diff --git a/source4/scripting/python/samba/tests/upgrade.py b/source4/scripting/python/samba/tests/upgrade.py
index 4dc86ace8a..17ebfa7bf5 100644
--- a/source4/scripting/python/samba/tests/upgrade.py
+++ b/source4/scripting/python/samba/tests/upgrade.py
@@ -34,4 +34,4 @@ class WinsUpgradeTests(LdbTestCase):
def test_version(self):
import_wins(self.ldb, {})
self.assertEquals("VERSION",
- self.ldb.search(expression="(objectClass=winsMaxVersion)")[0]["cn"])
+ str(self.ldb.search(expression="(objectClass=winsMaxVersion)")[0]["cn"]))
diff --git a/source4/setup/provision b/source4/setup/provision
index 4b48bab676..68f5d4fac7 100755
--- a/source4/setup/provision
+++ b/source4/setup/provision
@@ -166,8 +166,9 @@ if opts.blank:
elif opts.partitions_only:
samdb_fill = FILL_DRS
+session = system_session()
provision(setup_dir, message,
- system_session(), creds, smbconf=smbconf, targetdir=opts.targetdir,
+ session, creds, smbconf=smbconf, targetdir=opts.targetdir,
samdb_fill=samdb_fill, realm=opts.realm, domain=opts.domain,
domainguid=opts.domain_guid, domainsid=opts.domain_sid,
policyguid=opts.policy_guid, hostname=opts.host_name,