summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-06-20 02:32:23 +0200
committerJelmer Vernooij <jelmer@samba.org>2010-06-20 02:46:57 +0200
commit94e06fe2032b0143939abd85044b5c3ccddefe70 (patch)
tree887f6600128d3e32de674e60e75ee74bd0262766 /source4/scripting
parentd3d7ff66d4a7952a50e7d9175528985358cb3522 (diff)
downloadsamba-94e06fe2032b0143939abd85044b5c3ccddefe70.tar.gz
samba-94e06fe2032b0143939abd85044b5c3ccddefe70.tar.bz2
samba-94e06fe2032b0143939abd85044b5c3ccddefe70.zip
Some more formatting fixes, move schema related functions from Ldb to Schema.
Diffstat (limited to 'source4/scripting')
-rwxr-xr-xsource4/scripting/bin/upgradeprovision9
-rw-r--r--source4/scripting/python/samba/__init__.py29
-rw-r--r--source4/scripting/python/samba/provision.py2
-rw-r--r--source4/scripting/python/samba/samdb.py26
-rw-r--r--source4/scripting/python/samba/schema.py5
-rwxr-xr-xsource4/scripting/python/samba/upgradehelpers.py4
6 files changed, 36 insertions, 39 deletions
diff --git a/source4/scripting/bin/upgradeprovision b/source4/scripting/bin/upgradeprovision
index 1c33132769..47e50ece57 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 ca433127ba..3eefaa7ffc 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -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
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index 873be6730d..ca62b6062f 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/samdb.py b/source4/scripting/python/samba/samdb.py
index a47db9680a..0a3ca41604 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 2495cf2e0c..9e8db65d6e 100644
--- a/source4/scripting/python/samba/schema.py
+++ b/source4/scripting/python/samba/schema.py
@@ -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)
diff --git a/source4/scripting/python/samba/upgradehelpers.py b/source4/scripting/python/samba/upgradehelpers.py
index 5a37dab108..428d43450f 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)