Some more formatting fixes, move schema related functions from Ldb to Schema.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 20 Jun 2010 00:32:23 +0000 (02:32 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 20 Jun 2010 00:46:57 +0000 (02:46 +0200)
source4/scripting/bin/upgradeprovision
source4/scripting/python/samba/__init__.py
source4/scripting/python/samba/provision.py
source4/scripting/python/samba/samdb.py
source4/scripting/python/samba/schema.py
source4/scripting/python/samba/upgradehelpers.py

index 1c331327694e43b2b089de72892c44c7847b0bc5..47e50ece575d79eb33673f498b4d4e6cef8d67e6 100755 (executable)
@@ -107,7 +107,7 @@ hashOverwrittenAtt = {  "prefixMap": replace, "systemMayContain": replace,
 
 
 backlinked = []
-forwardlinked = {}
+forwardlinked = set()
 dn_syntax_att = []
 def define_what_to_log(opts):
     what = 0
@@ -223,7 +223,8 @@ def populate_links(samdb, schemadn):
     linkedAttHash = get_linked_attributes(Dn(samdb, str(schemadn)), samdb)
     backlinked.extend(linkedAttHash.values())
     for t in linkedAttHash.keys():
-        forwardlinked[t] = 1
+        forwardlinked.add(t)
+
 
 def populate_dnsyntax(samdb, schemadn):
     """Populate an array with all the attributes that have DN synthax
@@ -777,7 +778,7 @@ def update_present(ref_samdb, samdb, basedn, listPresent, usns, invocationid):
             if usns is not None:
                 # We have updated by provision usn information so let's exploit
                 # replMetadataProperties
-                if forwardlinked.has_key(att):
+                if att in forwardlinked:
                     handle_links(samdb, att, basedn, current[0]["dn"],
                                     current[0][att], reference[0][att], delta)
 
@@ -952,7 +953,7 @@ def update_partition(ref_samdb, samdb, basedn, names, schema, provisionUSNs):
     # a complete schema is needed as the insertion of attributes
     # and class is done against it
     # and the schema is self validated
-    samdb.set_schema_from_ldb(schema.ldb)
+    samdb.set_schema(schema)
     try:
         message(SIMPLE, "There are %d missing objects" % (len(listMissing)))
         add_deletedobj_containers(ref_samdb, samdb, names)
index ca433127ba254adf0c6a0f22025df6fb1798238f..3eefaa7ffc94ab787283e4823b3c6b8851e21238 100644 (file)
@@ -133,7 +133,11 @@ class Ldb(_Ldb):
         return self.schema_format_value(attribute, values.pop())
 
     def erase_users_computers(self, dn):
-        """Erases user and computer objects from our AD. This is needed since the 'samldb' module denies the deletion of primary groups. Therefore all groups shouldn't be primary somewhere anymore."""
+        """Erases user and computer objects from our AD.
+        
+        This is needed since the 'samldb' module denies the deletion of primary
+        groups. Therefore all groups shouldn't be primary somewhere anymore.
+        """
 
         try:
             res = self.search(base=dn, scope=ldb.SCOPE_SUBTREE, attrs=[],
@@ -167,8 +171,8 @@ class Ldb(_Ldb):
 
         # Delete the 'visible' records, and the invisble 'deleted' records (if this DB supports it)
         for msg in self.search(basedn, ldb.SCOPE_SUBTREE,
-                               "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))",
-                               [], controls=["show_deleted:0"]):
+                       "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))",
+                       [], controls=["show_deleted:0"]):
             try:
                 self.delete(msg.dn, ["relax:0"])
             except ldb.LdbError, (errno, _):
@@ -192,7 +196,6 @@ class Ldb(_Ldb):
 
     def erase(self):
         """Erase this ldb, removing all records."""
-
         self.erase_except_schema_controlled()
 
         # delete the specials
@@ -259,33 +262,17 @@ class Ldb(_Ldb):
         :param ldif: LDIF text.
         """
         for changetype, msg in self.parse_ldif(ldif):
-            if (changetype == ldb.CHANGETYPE_ADD):
+            if changetype == ldb.CHANGETYPE_ADD:
                 self.add(msg, controls)
             else:
                 self.modify(msg, controls)
 
-    def set_domain_sid(self, sid):
-        """Change the domain SID used by this LDB.
-
-        :param sid: The new domain sid to use.
-        """
-        dsdb.samdb_set_domain_sid(self, sid)
-
     def domain_sid(self):
         """Read the domain SID used by this LDB.
 
         """
         dsdb.samdb_get_domain_sid(self)
 
-    def set_schema_from_ldif(self, pf, df):
-        dsdb.dsdb_set_schema_from_ldif(self, pf, df)
-
-    def set_schema_from_ldb(self, ldb):
-        dsdb.dsdb_set_schema_from_ldb(self, ldb)
-
-    def write_prefixes_from_schema(self):
-        dsdb.dsdb_write_prefixes_from_schema_to_ldb(self)
-
 
 def substitute_var(text, values):
     """Substitute strings of the form ${NAME} in str, replacing
index 873be6730db62cc45e9bf715cc025458aafd7534..ca62b6062f29c4231138531ff7fe1dc518cb55b7 100644 (file)
@@ -976,7 +976,7 @@ def setup_samdb(path, setup_path, session_info, provision_backend, lp, names,
     logger.info("Pre-loading the Samba 4 and AD schema")
 
     # Load the schema from the one we computed earlier
-    samdb.set_schema_from_ldb(schema.ldb)
+    samdb.set_schema(schema)
 
     # And now we can connect to the DB - the schema won't be loaded from the DB
     samdb.connect(path)
index a47db9680ad02c3ad5cb312880d97d555af29ca1..0a3ca41604a555e5ddfa7f339c0368fc792f2dd3 100644 (file)
@@ -150,7 +150,7 @@ pwdLastSet: 0
         else:
             self.transaction_commit()
 
-    def deletegroup (self, groupname):
+    def deletegroup(self, groupname):
         """Deletes a group
 
         :param groupname: Name of the target group
@@ -162,19 +162,16 @@ pwdLastSet: 0
             targetgroup = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
                                expression=groupfilter, attrs=[])
             if len(targetgroup) == 0:
-                print('Unable to find group "%s"' % (groupname or expression))
-                raise
+                raise Exception('Unable to find group "%s"' % groupname)
             assert(len(targetgroup) == 1)
-
-            self.delete (targetgroup[0].dn);
-
+            self.delete(targetgroup[0].dn);
         except:
             self.transaction_cancel()
             raise
         else:
             self.transaction_commit()
 
-    def add_remove_group_members (self, groupname, listofmembers,
+    def add_remove_group_members(self, groupname, listofmembers,
                                   add_members_operation=True):
         """Adds or removes group members
 
@@ -191,8 +188,7 @@ pwdLastSet: 0
             targetgroup = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
                                expression=groupfilter, attrs=['member'])
             if len(targetgroup) == 0:
-                print('Unable to find group "%s"' % (groupname or expression))
-                raise
+                raise Exception('Unable to find group "%s"' % groupname)
             assert(len(targetgroup) == 1)
 
             modified = False
@@ -364,8 +360,7 @@ member: %s
             res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
                               expression=filter, attrs=[])
             if len(res) == 0:
-                print('Unable to find user "%s"' % (username or filter))
-                raise
+                raise Exception('Unable to find user "%s"' % (username or filter))
             assert(len(res) == 1)
             user_dn = res[0].dn
 
@@ -480,3 +475,12 @@ accountExpires: %u
 
     def load_partition_usn(self, base_dn):
         return dsdb.dsdb_load_partition_usn(self, base_dn)
+
+    def set_schema(self, schema):
+        self.set_schema_from_ldb(schema.ldb)
+
+    def set_schema_from_ldb(self, ldb):
+        dsdb.dsdb_set_schema_from_ldb(self, ldb)
+
+    def write_prefixes_from_schema(self):
+        dsdb.dsdb_write_prefixes_from_schema_to_ldb(self)
index 2495cf2e0c9bec7f7c0e293d02b318fcd74b9392..9e8db65d6e75cd303ed66668ee6020a1a634dc9c 100644 (file)
@@ -106,7 +106,10 @@ class Schema(object):
 
         # We don't actually add this ldif, just parse it
         prefixmap_ldif = "dn: cn=schema\nprefixMap:: %s\n\n" % self.prefixmap_data
-        self.ldb.set_schema_from_ldif(prefixmap_ldif, self.schema_data)
+        self.set_from_ldif(prefixmap_ldif, self.schema_data)
+
+    def set_from_ldif(self, pf, df):
+        dsdb.dsdb_set_schema_from_ldif(self.ldb, pf, df)
 
     def write_to_tmp_ldb(self, schemadb_path):
         self.ldb.connect(url=schemadb_path)
index 5a37dab1088ec2608722d3489f30f08106b43ffb..428d43450f9f9b8dd0a759c7feb08630d59b7130 100755 (executable)
@@ -38,6 +38,7 @@ from samba.provision import (ProvisionNames, provision_paths_from_lp,
                             setsysvolacl)
 from samba.dcerpc import misc, security, xattr
 from samba.ndr import ndr_unpack
+from samba.samdb import SamDB
 
 # All the ldb related to registry are commented because the path for them is relative
 # in the provisionPath object
@@ -66,6 +67,7 @@ hashAttrNotCopied = {   "dn": 1, "whenCreated": 1, "whenChanged": 1,
                         "sAMAccountType":1 }
 
 class ProvisionLDB(object):
+
     def __init__(self):
         self.sam = None
         self.secrets = None
@@ -155,7 +157,7 @@ def get_ldbs(paths, creds, session, lp):
 
     ldbs = ProvisionLDB()
 
-    ldbs.sam = Ldb(paths.samdb, session_info=session, credentials=creds, lp=lp, options=["modules:samba_dsdb"])
+    ldbs.sam = SamDB(paths.samdb, session_info=session, credentials=creds, lp=lp, options=["modules:samba_dsdb"])
     ldbs.secrets = Ldb(paths.secrets, session_info=session, credentials=creds, lp=lp)
     ldbs.idmap = Ldb(paths.idmapdb, session_info=session, credentials=creds, lp=lp)
     ldbs.privilege = Ldb(paths.privilege, session_info=session, credentials=creds, lp=lp)