s4:provison Add prefixes to ldb using same code a later modify will use
authorAndrew Bartlett <abartlet@samba.org>
Wed, 26 Aug 2009 03:43:33 +0000 (13:43 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 26 Aug 2009 03:49:10 +0000 (13:49 +1000)
This allows us to test out the code that will do the modify of the
prefixMap, and to provide the bindings that may assist a future
upgrade script.

Andrew Bartlett

source4/scripting/python/pyglue.c
source4/scripting/python/samba/__init__.py
source4/scripting/python/samba/provision.py
source4/setup/provision_schema_basedn_modify.ldif

index f5694e162c1be814d907f69f31c128d15dbef1e1..55ba5c37fc70331cfe9a0c00761b326bfe76128c 100644 (file)
@@ -344,6 +344,30 @@ static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self, PyObject *ar
        return ret;
 }
 
+static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb;
+       struct ldb_context *ldb;
+       WERROR result;
+       struct dsdb_schema *schema;
+
+       if (!PyArg_ParseTuple(args, "O", &py_ldb))
+               return NULL;
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       schema = dsdb_get_schema(ldb);
+       if (!schema) {
+               PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on ldb!\n");
+               return NULL;
+       }
+
+       result = dsdb_write_prefixes_from_schema_to_ldb(NULL, ldb, schema);
+       PyErr_WERROR_IS_ERR_RAISE(result);
+
+       Py_RETURN_NONE;
+}
+
 static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
 {
        PyObject *py_ldb;
@@ -424,6 +448,8 @@ static PyMethodDef py_misc_methods[] = {
                NULL },
        { "dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
                NULL },
+       { "dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,
+               NULL },
        { "dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
                NULL },
        { "dsdb_convert_schema_to_openldap", (PyCFunction)py_dsdb_convert_schema_to_openldap, METH_VARARGS,
index 69a0320be78546a53688b5b5cba8fba257eaa960..4df3d6f55a26d6fd970f6928fdbb105de96b956d 100644 (file)
@@ -239,6 +239,9 @@ class Ldb(ldb.Ldb):
     def set_schema_from_ldb(self, ldb):
         glue.dsdb_set_schema_from_ldb(self, ldb)
 
+    def write_prefixes_from_schema(self):
+        glue.dsdb_write_prefixes_from_schema_to_ldb(self)
+
     def convert_schema_to_openldap(self, target, mapping):
         return glue.dsdb_convert_schema_to_openldap(self, target, mapping)
 
index aa6b6789ddef4a3ac099db5f2f56f359ddf0002b..a8cedaf23a6be4020aa2762a101edaecd07de0e0 100644 (file)
@@ -151,18 +151,21 @@ class Schema(object):
         self.schema_data += open(setup_path("schema_samba4.ldif"), 'r').read()
         self.schema_data = substitute_var(self.schema_data, {"SCHEMADN": schemadn})
         check_all_substituted(self.schema_data)
-        prefixmap = open(setup_path("prefixMap.txt"), 'r').read()
-        prefixmap = b64encode(prefixmap)
-        
+
         self.schema_dn_modify = read_and_sub_file(setup_path("provision_schema_basedn_modify.ldif"),
                                                   {"SCHEMADN": schemadn,
-                                                   "PREFIXMAP_B64": prefixmap,
                                                    "SERVERDN": serverdn,
                                                    })
         self.schema_dn_add = read_and_sub_file(setup_path("provision_schema_basedn.ldif"),
                                                {"SCHEMADN": schemadn
                                                 })
-        self.ldb.set_schema_from_ldif(self.schema_dn_modify, self.schema_data)
+
+        prefixmap = open(setup_path("prefixMap.txt"), 'r').read()
+        prefixmap = b64encode(prefixmap)
+
+        # We don't actually add this ldif, just parse it
+        prefixmap_ldif = "dn: cn=schema\nprefixMap:: %s\n\n" % prefixmap
+        self.ldb.set_schema_from_ldif(prefixmap_ldif, self.schema_data)
 
     
 def check_install(lp, session_info, credentials):
@@ -910,6 +913,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp,
         message("Setting up sam.ldb schema")
         samdb.add_ldif(schema.schema_dn_add)
         samdb.modify_ldif(schema.schema_dn_modify)
+        samdb.write_prefixes_from_schema()
         samdb.add_ldif(schema.schema_data)
         setup_add_ldif(samdb, setup_path("aggregate_schema.ldif"), 
                        {"SCHEMADN": names.schemadn})
index ef883fcf224c940192fb8c6755d44cf2a50cc146..5591f8bc3690dd0653447a2eeda67b149708e986 100644 (file)
@@ -6,7 +6,4 @@ changetype: modify
 -
 replace: objectVersion
 objectVersion: 30
--
-replace: prefixMap
-prefixMap:: ${PREFIXMAP_B64}