s4-python: Move load_partition_usn to dsdb module.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 8 Apr 2010 20:07:42 +0000 (22:07 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 8 Apr 2010 21:20:36 +0000 (23:20 +0200)
source4/dsdb/config.mk
source4/dsdb/pydsdb.c
source4/dsdb/wscript_build
source4/lib/ldb/tests/python/urgent_replication.py
source4/scripting/python/pyglue.c
source4/scripting/python/samba/samdb.py

index 69b7227d627273b85b9ac52b62df338a0b194580..2bd19e987de4597525b4b754b516483409baa71b 100644 (file)
@@ -109,6 +109,6 @@ DNS_UPDATE_SRV_OBJ_FILES = $(addprefix $(dsdbsrcdir)/dns/, \
 
 [PYTHON::python_dsdb]
 LIBRARY_REALNAME = samba/dsdb.$(SHLIBEXT)
-PRIVATE_DEPENDENCIES = SAMDB
+PRIVATE_DEPENDENCIES = SAMDB pyldb
 
 python_dsdb_OBJ_FILES = $(dsdbsrcdir)/pydsdb.o
index cc75472a456925953726d90b2a264358512dcd4e..1d71c6b7dedee1ed026119ec07ccf978f4514878 100644 (file)
@@ -251,6 +251,52 @@ static PyObject *py_dsdb_set_global_schema(PyObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
+static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
+{
+       PyObject *py_dn, *py_ldb, *result;
+       struct ldb_dn *dn;
+       uint64_t highest_uSN, urgent_uSN;
+       struct ldb_context *ldb;
+       TALLOC_CTX *mem_ctx;
+       int ret;
+
+       mem_ctx = talloc_new(NULL);
+       if (mem_ctx == NULL) {
+          PyErr_NoMemory();
+          return NULL;
+       }
+
+       if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
+          talloc_free(mem_ctx);
+          return NULL;
+       }
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       if (!PyObject_AsDn(mem_ctx, py_dn, ldb, &dn)) {
+          talloc_free(mem_ctx);
+          return NULL;
+       }
+
+       ret = dsdb_load_partition_usn(ldb, dn, &highest_uSN, &urgent_uSN);
+       if (ret != LDB_SUCCESS) {
+          char *errstr = talloc_asprintf(mem_ctx, "Failed to load partition uSN - %s", ldb_errstring(ldb));
+          PyErr_SetString(PyExc_RuntimeError, errstr);
+          talloc_free(mem_ctx);
+          return NULL;
+       }
+
+       talloc_free(mem_ctx);
+
+       result = PyDict_New();
+
+       PyDict_SetItemString(result, "uSNHighest", PyInt_FromLong((uint64_t)highest_uSN));
+       PyDict_SetItemString(result, "uSNUrgent", PyInt_FromLong((uint64_t)urgent_uSN));
+
+
+       return result;
+}
+
 static PyMethodDef py_dsdb_methods[] = {
        { "samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
                METH_VARARGS, "Get the server site name as a string"},
@@ -275,6 +321,9 @@ static PyMethodDef py_dsdb_methods[] = {
                METH_VARARGS, "get the NTDS objectGUID as a string"},
        { "dsdb_set_global_schema", (PyCFunction)py_dsdb_set_global_schema,
                METH_VARARGS, NULL },
+       { "dsdb_load_partition_usn", (PyCFunction)py_dsdb_load_partition_usn,
+               METH_VARARGS,
+               "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
        { NULL }
 };
 
index 581c8ef4d023e4f17e39cd976ef1195566dd06d3..59672e03df2e29a9a1ddbd4a204b103e18a6a6e7 100644 (file)
@@ -51,6 +51,6 @@ bld.SAMBA_MODULE('DNS_UPDATE_SRV',
 
 bld.SAMBA_PYTHON('python_dsdb',
                  source='pydsdb.c',
-                 deps='SAMDB',
+                 deps='SAMDB pyldb',
                  realname='samba/dsdb.so'
                  )
index 97b06fbb9a9846dbe863b360f6e3d1de0319ffec..0a8fd7d53964e3ed83ab54336cfda25b3d6a0aaa 100755 (executable)
@@ -14,8 +14,7 @@ import samba.getopt as options
 from samba.auth import system_session
 from ldb import (SCOPE_BASE, LdbError, ERR_NO_SUCH_OBJECT, Message,
     MessageElement, Dn, FLAG_MOD_REPLACE)
-from samba import Ldb
-from samba import _glue
+from samba.samdb import SamDB
 
 from subunit.run import SubunitTestRunner
 import unittest
@@ -68,7 +67,7 @@ class UrgentReplicationTests(unittest.TestCase):
             "description":"nonurgenttest description"});
 
         # urgent replication should not be enabled when creating 
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertNotEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should not be enabled when modifying
@@ -77,12 +76,12 @@ class UrgentReplicationTests(unittest.TestCase):
         m["description"] = MessageElement("new description", FLAG_MOD_REPLACE,
           "description")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertNotEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should not be enabled when deleting
         self.delete_force(self.ldb, "cn=nonurgenttest,cn=users," + self.base_dn)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertNotEquals(res["uSNHighest"], res["uSNUrgent"]);
 
 
@@ -105,7 +104,7 @@ instanceType: 4
 systemFlags: 33554432""", ["relax:0"]);
 
         # urgent replication should be enabled when creation
-        res = _glue.dsdb_load_partition_usn(self.ldb, "cn=Configuration," + self.base_dn)
+        res = self.ldb.load_partition_usn("cn=Configuration," + self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should NOT be enabled when modifying
@@ -114,12 +113,12 @@ systemFlags: 33554432""", ["relax:0"]);
         m["options"] = MessageElement("0", FLAG_MOD_REPLACE,
           "options")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, "cn=Configuration," + self.base_dn)
+        res = self.ldb.load_partition_usn("cn=Configuration," + self.base_dn)
         self.assertNotEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should be enabled when deleting
         self.delete_force(self.ldb, "cn=NTDS Settings test,cn=test server,cn=Servers,cn=Default-First-Site-Name,cn=Sites,cn=Configuration," + self.base_dn)
-        res = _glue.dsdb_load_partition_usn(self.ldb, "cn=Configuration," + self.base_dn)
+        res = self.ldb.load_partition_usn("cn=Configuration," + self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         self.delete_force(self.ldb, "cn=test server,cn=Servers,cn=Default-First-Site-Name,cn=Sites,cn=Configuration," + self.base_dn)
@@ -139,7 +138,7 @@ systemFlags: 33554432""", ["relax:0"]);
                       "systemFlags": "1"});
 
         # urgent replication should be enabled when creating
-        res = _glue.dsdb_load_partition_usn(self.ldb, "cn=Configuration," + self.base_dn)
+        res = self.ldb.load_partition_usn("cn=Configuration," + self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should NOT be enabled when modifying
@@ -148,13 +147,13 @@ systemFlags: 33554432""", ["relax:0"]);
         m["systemFlags"] = MessageElement("0", FLAG_MOD_REPLACE,
           "systemFlags")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, "cn=Configuration," + self.base_dn)
+        res = self.ldb.load_partition_usn("cn=Configuration," + self.base_dn)
         self.assertNotEquals(res["uSNHighest"], res["uSNUrgent"]);
 
 
         # urgent replication should be enabled when deleting
         self.delete_force(self.ldb, "cn=test crossRef,CN=Partitions,CN=Configuration," + self.base_dn)
-        res = _glue.dsdb_load_partition_usn(self.ldb, "cn=Configuration," + self.base_dn)
+        res = self.ldb.load_partition_usn("cn=Configuration," + self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
 
@@ -183,7 +182,7 @@ name: test attributeSchema
 systemFlags: 0""", ["relax:0"]);
 
             # urgent replication should be enabled when creating
-            res = _glue.dsdb_load_partition_usn(self.ldb, "cn=Schema,cn=Configuration," + self.base_dn)
+            res = self.ldb.load_partition_usn("cn=Schema,cn=Configuration," + self.base_dn)
             self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         except LdbError:
@@ -195,7 +194,7 @@ systemFlags: 0""", ["relax:0"]);
         m["lDAPDisplayName"] = MessageElement("updated test attributeSchema", FLAG_MOD_REPLACE,
           "lDAPDisplayName")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, "cn=Schema,cn=Configuration," + self.base_dn)
+        res = self.ldb.load_partition_usn("cn=Schema,cn=Configuration," + self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
 
@@ -226,7 +225,7 @@ systemFlags: 16
 defaultHidingValue: TRUE""", ["relax:0"]);
 
             # urgent replication should be enabled when creating
-            res = _glue.dsdb_load_partition_usn(self.ldb, "cn=Schema,cn=Configuration," + self.base_dn)
+            res = self.ldb.load_partition_usn("cn=Schema,cn=Configuration," + self.base_dn)
             self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         except LdbError:
@@ -238,7 +237,7 @@ defaultHidingValue: TRUE""", ["relax:0"]);
         m["lDAPDisplayName"] = MessageElement("updated test classSchema", FLAG_MOD_REPLACE,
           "lDAPDisplayName")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, "cn=Schema,cn=Configuration," + self.base_dn)
+        res = self.ldb.load_partition_usn("cn=Schema,cn=Configuration," + self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
 
@@ -255,7 +254,7 @@ defaultHidingValue: TRUE""", ["relax:0"]);
 
 
         # urgent replication should be enabled when creating
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should be enabled when modifying
@@ -264,12 +263,12 @@ defaultHidingValue: TRUE""", ["relax:0"]);
         m["currentValue"] = MessageElement("yyyyyyyy", FLAG_MOD_REPLACE,
           "currentValue")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should NOT be enabled when deleting 
         self.delete_force(self.ldb, "cn=test secret,cn=System," + self.base_dn)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertNotEquals(res["uSNHighest"], res["uSNUrgent"]);
 
 
@@ -288,7 +287,7 @@ isCriticalSystemObject: TRUE
 rIDAvailablePool: 133001-1073741823""", ["relax:0"])
 
         # urgent replication should be enabled when creating
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should be enabled when modifying
@@ -297,12 +296,12 @@ rIDAvailablePool: 133001-1073741823""", ["relax:0"])
         m["systemFlags"] = MessageElement("0", FLAG_MOD_REPLACE,
           "systemFlags")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should NOT be enabled when deleting 
         self.delete_force(self.ldb, "CN=RID Manager test,CN=System," + self.base_dn)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertNotEquals(res["uSNHighest"], res["uSNUrgent"]);
 
 
@@ -320,7 +319,7 @@ rIDAvailablePool: 133001-1073741823""", ["relax:0"])
             "description":"urgent attributes test description"});
 
         # urgent replication should NOT be enabled when creating
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertNotEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should be enabled when modifying userAccountControl 
@@ -329,7 +328,7 @@ rIDAvailablePool: 133001-1073741823""", ["relax:0"])
         m["userAccountControl"] = MessageElement("0", FLAG_MOD_REPLACE,
           "userAccountControl")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should be enabled when modifying lockoutTime
@@ -338,7 +337,7 @@ rIDAvailablePool: 133001-1073741823""", ["relax:0"])
         m["lockoutTime"] = MessageElement("1", FLAG_MOD_REPLACE,
           "lockoutTime")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should be enabled when modifying pwdLastSet
@@ -347,7 +346,7 @@ rIDAvailablePool: 133001-1073741823""", ["relax:0"])
         m["pwdLastSet"] = MessageElement("1", FLAG_MOD_REPLACE,
           "pwdLastSet")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should NOT be enabled when modifying a not-urgent
@@ -357,12 +356,12 @@ rIDAvailablePool: 133001-1073741823""", ["relax:0"])
         m["description"] = MessageElement("updated urgent attributes test description",
                                           FLAG_MOD_REPLACE, "description")
         ldb.modify(m)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertNotEquals(res["uSNHighest"], res["uSNUrgent"]);
 
         # urgent replication should NOT be enabled when deleting
         self.delete_force(self.ldb, "cn=user UrgAttr test,cn=users," + self.base_dn)
-        res = _glue.dsdb_load_partition_usn(self.ldb, self.base_dn)
+        res = self.ldb.load_partition_usn(self.base_dn)
         self.assertNotEquals(res["uSNHighest"], res["uSNUrgent"]);
 
 
@@ -373,7 +372,8 @@ if not "://" in host:
         host = "ldap://%s" % host
 
 
-ldb = Ldb(host, credentials=creds, session_info=system_session(), lp=lp)
+ldb = SamDB(host, credentials=creds, session_info=system_session(), lp=lp,
+            global_schema=False)
 
 runner = SubunitTestRunner()
 rc = 0
index 530c33e7d40fbe0d680970cbebe23339658fb948..629c9b11e22a11a735d92a70db8eab4457a11e40 100644 (file)
@@ -186,52 +186,6 @@ static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
-static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
-{
-       PyObject *py_dn, *py_ldb, *result;
-       struct ldb_dn *dn;
-       uint64_t highest_uSN, urgent_uSN;
-       struct ldb_context *ldb;
-       TALLOC_CTX *mem_ctx;
-       int ret;
-
-       mem_ctx = talloc_new(NULL);
-       if (mem_ctx == NULL) {
-          PyErr_NoMemory();
-          return NULL;
-       }
-
-       if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
-          talloc_free(mem_ctx);
-          return NULL;
-       }
-
-       PyErr_LDB_OR_RAISE(py_ldb, ldb);
-
-       if (!PyObject_AsDn(mem_ctx, py_dn, ldb, &dn)) {
-          talloc_free(mem_ctx);
-          return NULL;
-       }
-
-       ret = dsdb_load_partition_usn(ldb, dn, &highest_uSN, &urgent_uSN);
-       if (ret != LDB_SUCCESS) {
-          char *errstr = talloc_asprintf(mem_ctx, "Failed to load partition uSN - %s", ldb_errstring(ldb));
-          PyErr_SetString(PyExc_RuntimeError, errstr);
-          talloc_free(mem_ctx);
-          return NULL;
-       }
-
-       talloc_free(mem_ctx);
-
-       result = PyDict_New();
-
-       PyDict_SetItemString(result, "uSNHighest", PyInt_FromLong((uint64_t)highest_uSN));
-       PyDict_SetItemString(result, "uSNUrgent", PyInt_FromLong((uint64_t)urgent_uSN));
-
-
-       return result;
-}
-
 /*
   return the list of interface IPs we have configured
   takes an loadparm context, returns a list of IPs in string form
@@ -302,8 +256,6 @@ static PyMethodDef py_misc_methods[] = {
                NULL },
        { "set_debug_level", (PyCFunction)py_set_debug_level, METH_VARARGS,
                "set debug level" },
-       { "dsdb_load_partition_usn", (PyCFunction)py_dsdb_load_partition_usn, METH_VARARGS,
-               "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
        { "interface_ips", (PyCFunction)py_interface_ips, METH_VARARGS,
                "get interface IP address list"},
        { NULL }
index 2f33c31c632f0061b070ba1147e299b86542552a..790cb2badc01a9e0838a08ef0b886bbfbf0d5a31 100644 (file)
@@ -267,3 +267,6 @@ accountExpires: %u
     def server_site_name(self):
         "Get the server site name"
         return dsdb.samdb_server_site_name(self)
+
+    def load_partition_usn(self, base_dn):
+        return dsdb.dsdb_load_partition_usn(self, base_dn)