Fix 11/12 of ./setup/openchange_provision.
authorJulien Kerihuel <j.kerihuel@openchange.org>
Wed, 22 Feb 2012 17:37:44 +0000 (17:37 +0000)
committerJulien Kerihuel <j.kerihuel@openchange.org>
Wed, 22 Feb 2012 17:37:44 +0000 (17:37 +0000)
There is a remaining error when processing modify_ldif with
AD/oc_provision_schema_modify.ldif

python/openchange/provision.py
setup/AD/prefixMap.txt

index d3fa5d7eefb1ff43279ff03d3b834b070847d7b5..01bd795724867fa20f9616e5bb9904fb4084f7ef 100644 (file)
 #
 
 from base64 import b64encode
-import os
+import os,sys
 import struct
 import samba
 from openchange import mailbox
-from samba import Ldb
+from samba import param, Ldb, dsdb, substitute_var, read_and_sub_file
 from samba.samdb import SamDB
-from samba.auth import system_session
-from samba.provision import setup_add_ldif, setup_modify_ldif
+import ldb
+from ldb import (SCOPE_SUBTREE, SCOPE_BASE, FLAG_MOD_REPLACE, FLAG_MOD_ADD, FLAG_MOD_DELETE)
+from samba.auth import system_session, admin_session
+from samba.provision import (setup_add_ldif, setup_modify_ldif, setup_ldb,find_provision_key_parameters)
+from samba.upgradehelpers import (get_paths, get_ldbs)
 from openchange.urlutils import openchangedb_url
 
 __docformat__ = 'restructuredText'
@@ -147,15 +150,13 @@ def provision_schema(setup_path, names, lp, creds, reporter, ldif, msg):
     """
 
     session_info = system_session()
+    samdb = Ldb(url=lp.samdb_url(), session_info = session_info,
+                lp=lp, options=["modules:"])
 
-    db = SamDB(url=lp.samdb_url(), session_info=session_info, 
-               credentials=creds, lp=lp)
-
-    db.transaction_start()
-
+    reporter.reportNextStep(msg)
+    samdb.transaction_start()
     try:
-        reporter.reportNextStep(msg)
-        setup_add_ldif(db, setup_path(ldif), { 
+        setup_ldb(samdb, setup_path(ldif), {
                 "FIRSTORG": names.firstorg,
                 "FIRSTORGDN": names.firstorgdn,
                 "CONFIGDN": names.configdn,
@@ -165,12 +166,12 @@ def provision_schema(setup_path, names, lp, creds, reporter, ldif, msg):
                 "DNSDOMAIN": names.dnsdomain,
                 "NETBIOSNAME": names.netbiosname,
                 "HOSTNAME": names.hostname
-                })
-    except:
-        db.transaction_cancel()
+                })                            
+    except Exception:
+        samdb.transaction_cancel()
         raise
-
-    db.transaction_commit()
+    else:
+        samdb.transaction_commit()
 
 def modify_schema(setup_path, names, lp, creds, reporter, ldif, msg):
     """Modify schema using LDIF specified file
@@ -185,23 +186,21 @@ def modify_schema(setup_path, names, lp, creds, reporter, ldif, msg):
     """
 
     session_info = system_session()
+    samdb = Ldb(url=lp.samdb_url(), session_info=session_info, 
+                lp=lp, options=["modules:"])
 
-    db = SamDB(url=lp.samdb_url(), session_info=session_info, 
-               credentials=creds, lp=lp)
-
-    db.transaction_start()
-
+    reporter.reportNextStep(msg)
+    samdb.transaction_start()
     try:
-        reporter.reportNextStep(msg)
-        setup_modify_ldif(db, setup_path(ldif), { 
-                "SCHEMADN": names.schemadn,
-                "CONFIGDN": names.configdn
-                })
+        setup_modify_ldif(samdb, setup_path(ldif), 
+                          { 'SCHEMADN': names.schemadn,
+                            'CONFIGDN': names.configdn
+                            })
     except:
-        db.transaction_cancel()
+        samdb.transaction_cancel()
         raise
-
-    db.transaction_commit()
+    else:
+        samdb.transaction_commit()
 
 def install_schemas(setup_path, names, lp, creds, reporter):
     """Install the OpenChange-specific schemas in the SAM LDAP database. 
@@ -215,29 +214,26 @@ def install_schemas(setup_path, names, lp, creds, reporter):
     session_info = system_session()
 
     # Step 1. Extending the prefixmap attribute of the schema DN record
-    db = SamDB(url=lp.samdb_url(), session_info=session_info,
+    samdb = SamDB(url=lp.samdb_url(), session_info=session_info,
                   credentials=creds, lp=lp)
 
-    prefixmap = open(setup_path("AD/prefixMap.txt"), 'r').read()
+    schemadn = str(names.schemadn)
+    current = samdb.search(expression="objectClass=*", base=schemadn, 
+                           scope=SCOPE_SUBTREE)
+    
 
-    db.transaction_start()
+    schema_ldif = ""
+    prefixmap_data = ""
+    for ent in current:
+        schema_ldif += samdb.write_ldif(ent, ldb.CHANGETYPE_NONE)
 
-    try:
-        reporter.reportNextStep("Register Exchange OIDs")
-        setup_modify_ldif(db,
-                          setup_path("AD/provision_schema_basedn_modify.ldif"), {
-                "SCHEMADN": names.schemadn,
-                "NETBIOSNAME": names.netbiosname,
-                "DEFAULTSITE": names.sitename,
-                "CONFIGDN": names.configdn,
-                "SERVERDN": names.serverdn,
-                "PREFIXMAP_B64": b64encode(prefixmap)
-                })
-    except:
-        db.transaction_cancel()
-        raise
+    prefixmap_data = open(setup_path("AD/prefixMap.txt"), 'r').read()
+    prefixmap_data = b64encode(prefixmap_data)
 
-    db.transaction_commit()
+    # We don't actually add this ldif, just parse it
+    prefixmap_ldif = "dn: %s\nprefixMap:: %s\n\n" % (schemadn, prefixmap_data)
+    reporter.reportNextStep("Register Exchange OIDs")
+    dsdb._dsdb_set_schema_from_ldif(samdb, prefixmap_ldif, schema_ldif, schemadn)
 
     provision_schema(setup_path, names, lp, creds, reporter, "AD/oc_provision_schema_attributes.ldif", "Add Exchange attributes to Samba schema")
     provision_schema(setup_path, names, lp, creds, reporter, "AD/oc_provision_schema_auxiliary_class.ldif", "Add Exchange auxiliary classes to Samba schema")
index 23efcec85d69b820250235af5f1bb96a82c63dcf..64214547fc0c253b81a1bb2498324ba5068e0dcf 100644 (file)
 29:1.3.6.1.4.1.250.1
 30:1.2.840.113549.1.9
 31:0.9.2342.19200300.100.4
-32:1.3.6.1.4.1.7165.4.1
-33:1.3.6.1.4.1.7165.4.2
-34:1.2.840.113556.1.5.7000.62
-35:1.2.840.113556.1.4.7000.102
-36:1.2.840.113556.1.6.20.1
-37:1.2.840.113556.1.6.20.2
+32:1.2.840.113556.1.6.23
+33:1.2.840.113556.1.6.18.1
+34:1.2.840.113556.1.6.18.2
+35:1.2.840.113556.1.6.13.3
+36:1.2.840.113556.1.6.13.4
+37:1.3.6.1.1.1.1
+38:1.3.6.1.1.1.2
+39:1.3.6.1.4.1.7165.4.1
+40:1.3.6.1.4.1.7165.4.2
+41:1.2.840.113556.1.5.7000.62
+42:1.2.840.113556.1.4.7000.102
+43:1.2.840.113556.1.6.20.1
+44:1.2.840.113556.1.6.20.2