upgradeprovision: treat provision without oem attribute as quite recent, it's provisi...
[ddiss/samba.git] / source4 / scripting / bin / upgradeprovision
index d2a645a637375b9bb6d862b5616aedead8f618a4..35e469693c4631ee2914d7740e6f50774e6a1a12 100755 (executable)
@@ -1101,7 +1101,8 @@ def reload_full_schema(samdb, names):
     :param names: List of key provision parameters
     """
 
-    current = samdb.search(expression="objectClass=*", base=str(names.schemadn),
+    schemadn = str(names.schemadn)
+    current = samdb.search(expression="objectClass=*", base=schemadn,
                                 scope=SCOPE_SUBTREE)
     schema_ldif = ""
     prefixmap_data = ""
@@ -1113,9 +1114,9 @@ def reload_full_schema(samdb, names):
     prefixmap_data = b64encode(prefixmap_data)
 
     # We don't actually add this ldif, just parse it
-    prefixmap_ldif = "dn: cn=schema\nprefixMap:: %s\n\n" % prefixmap_data
+    prefixmap_ldif = "dn: %s\nprefixMap:: %s\n\n" % (schemadn, prefixmap_data)
 
-    dsdb._dsdb_set_schema_from_ldif(samdb, prefixmap_ldif, schema_ldif)
+    dsdb._dsdb_set_schema_from_ldif(samdb, prefixmap_ldif, schema_ldif, schemadn)
 
 
 def update_partition(ref_samdb, samdb, basedn, names, schema, provisionUSNs, prereloadfunc):
@@ -1346,10 +1347,20 @@ def rebuild_sd(samdb, names):
             message(ERROR, "On %s bad stuff %s" % (str(delta.dn),badsd.as_sddl(names.domainsid)))
             return
 
+def hasATProvision(samdb):
+        entry = samdb.search(expression="dn=@PROVISION", base = "",
+                                scope=SCOPE_BASE,
+                                attrs=["dn"])
+
+        if entry != None and len(entry) == 1:
+            return True
+        else:
+            return False
+
 def removeProvisionUSN(samdb):
         attrs = [samba.provision.LAST_PROVISION_USN_ATTRIBUTE, "dn"]
         entry = samdb.search(expression="dn=@PROVISION", base = "",
-                                scope=SCOPE_SUBTREE,
+                                scope=SCOPE_BASE,
                                 attrs=attrs)
         empty = Message()
         empty.dn = entry[0].dn
@@ -1793,7 +1804,8 @@ if __name__ == '__main__':
             new_ldbs.groupedCommit()
             deltaattr = None
         # 11)
-            if re.match(".*alpha((9)|(\d\d+)).*", str(oem)):
+            message(GUESS, oem)
+            if oem is None or hasATProvision(ldbs.sam) or re.match(".*alpha((9)|(\d\d+)).*", str(oem)):
                 # 11) A
                 # Starting from alpha9 we can consider that the structure is quite ok
                 # and that we should do only dela