The branch, master has been updated via 1f07f53... ldb: Remove last import of dsdb. via 94e06fe... Some more formatting fixes, move schema related functions from Ldb to Schema. via d3d7ff6... Move convert_to_openldap onto Schema class. from afad634... Formatting cleanups; use True/False for booleans, unnecessary backslashes, spacing.
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 1f07f53827908d48e50b018c50e97de4740b740b Author: Jelmer Vernooij <jel...@samba.org> Date: Sun Jun 20 02:44:39 2010 +0200 ldb: Remove last import of dsdb. commit 94e06fe2032b0143939abd85044b5c3ccddefe70 Author: Jelmer Vernooij <jel...@samba.org> Date: Sun Jun 20 02:32:23 2010 +0200 Some more formatting fixes, move schema related functions from Ldb to Schema. commit d3d7ff66d4a7952a50e7d9175528985358cb3522 Author: Jelmer Vernooij <jel...@samba.org> Date: Sun Jun 20 01:43:51 2010 +0200 Move convert_to_openldap onto Schema class. ----------------------------------------------------------------------- Summary of changes: source4/scripting/bin/upgradeprovision | 9 ++-- source4/scripting/python/samba/__init__.py | 44 ++++---------------- source4/scripting/python/samba/provision.py | 2 +- source4/scripting/python/samba/provisionbackend.py | 4 +- source4/scripting/python/samba/samdb.py | 26 +++++++----- source4/scripting/python/samba/schema.py | 10 ++++- source4/scripting/python/samba/upgradehelpers.py | 4 +- 7 files changed, 43 insertions(+), 56 deletions(-) Changeset truncated at 500 lines: diff --git a/source4/scripting/bin/upgradeprovision b/source4/scripting/bin/upgradeprovision index 1c33132..47e50ec 100755 --- a/source4/scripting/bin/upgradeprovision +++ b/source4/scripting/bin/upgradeprovision @@ -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) diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index 25b8ff9..a6532b7 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -42,7 +42,6 @@ else: import ldb -import dsdb import _glue from samba._ldb import Ldb as _Ldb @@ -110,11 +109,6 @@ class Ldb(_Ldb): if url is not None: self.connect(url, flags, options) - def set_create_perms(self, perms=0600): - # we usually want Samba databases to be private. If we later find we - # need one public, we will have to change this here - super(Ldb, self).set_create_perms(perms) - def searchone(self, attribute, basedn=None, expression=None, scope=ldb.SCOPE_BASE): """Search for one attribute as a string. @@ -133,7 +127,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 +165,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=*))(!(distinguishedna...@baseinfo)))", - [], controls=["show_deleted:0"]): + "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedna...@baseinfo)))", + [], controls=["show_deleted:0"]): try: self.delete(msg.dn, ["relax:0"]) except ldb.LdbError, (errno, _): @@ -192,7 +190,6 @@ class Ldb(_Ldb): def erase(self): """Erase this ldb, removing all records.""" - self.erase_except_schema_controlled() # delete the specials @@ -259,36 +256,11 @@ 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 convert_schema_to_openldap(self, target, mapping): - return dsdb.dsdb_convert_schema_to_openldap(self, target, mapping) - def substitute_var(text, values): """Substitute strings of the form ${NAME} in str, replacing diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 873be67..ca62b60 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -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) diff --git a/source4/scripting/python/samba/provisionbackend.py b/source4/scripting/python/samba/provisionbackend.py index a40a4b3..ccb793f 100644 --- a/source4/scripting/python/samba/provisionbackend.py +++ b/source4/scripting/python/samba/provisionbackend.py @@ -484,7 +484,7 @@ class OpenLDAPBackend(LDAPBackend): backend_schema = "backend-schema.schema" f = open(self.setup_path(mapping), 'r') - backend_schema_data = self.schema.ldb.convert_schema_to_openldap( + backend_schema_data = self.schema.convert_to_openldap( "openldap", f.read()) assert backend_schema_data is not None f = open(os.path.join(self.ldapdir, backend_schema), 'w') @@ -686,7 +686,7 @@ class FDSBackend(LDAPBackend): backend_schema = "99_ad.ldif" # Build a schema file in Fedora DS format - backend_schema_data = self.schema.ldb.convert_schema_to_openldap("fedora-ds", open(self.setup_path(mapping), 'r').read()) + backend_schema_data = self.schema.convert_to_openldap("fedora-ds", open(self.setup_path(mapping), 'r').read()) assert backend_schema_data is not None f = open(os.path.join(self.ldapdir, backend_schema), 'w') try: diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py index a47db96..0a3ca41 100644 --- a/source4/scripting/python/samba/samdb.py +++ b/source4/scripting/python/samba/samdb.py @@ -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) diff --git a/source4/scripting/python/samba/schema.py b/source4/scripting/python/samba/schema.py index bffb0e5..9e8db65 100644 --- a/source4/scripting/python/samba/schema.py +++ b/source4/scripting/python/samba/schema.py @@ -28,6 +28,7 @@ from samba.dcerpc import security from samba.ms_schema import read_ms_schema from samba.ndr import ndr_pack from samba.samdb import SamDB +from samba import dsdb from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL import os @@ -105,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) @@ -135,6 +139,10 @@ dn: @INDEXLIST def dnsyntax_attributes(self): return get_dnsyntax_attributes(self.schemadn, self.ldb) + def convert_to_openldap(self, target, mapping): + return dsdb.dsdb_convert_schema_to_openldap(self.ldb, target, mapping) + + # Return a hash with the forward attribute as a key and the back as the value def get_linked_attributes(schemadn,schemaldb): attrs = ["linkID", "lDAPDisplayName"] diff --git a/source4/scripting/python/samba/upgradehelpers.py b/source4/scripting/python/samba/upgradehelpers.py index 5a37dab..428d434 100755 --- a/source4/scripting/python/samba/upgradehelpers.py +++ b/source4/scripting/python/samba/upgradehelpers.py @@ -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) -- Samba Shared Repository