summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorMatthieu Patou <mat@matws.net>2010-06-15 12:50:29 +0400
committerJelmer Vernooij <jelmer@samba.org>2010-06-20 00:43:08 +0200
commit75389cecdde884356e222e3f846e7358f82c20c0 (patch)
tree8f59d4d354557738a3412fb72575c423f879b12b /source4/scripting
parentf3e7d0ae8f63c57fc0ec7680b2863c6f50e167fe (diff)
downloadsamba-75389cecdde884356e222e3f846e7358f82c20c0.tar.gz
samba-75389cecdde884356e222e3f846e7358f82c20c0.tar.bz2
samba-75389cecdde884356e222e3f846e7358f82c20c0.zip
s4 upgradeprovision: Add function for searching stored constructed attributes
Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
Diffstat (limited to 'source4/scripting')
-rwxr-xr-xsource4/scripting/python/samba/upgradehelpers.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/source4/scripting/python/samba/upgradehelpers.py b/source4/scripting/python/samba/upgradehelpers.py
index 7cc176d7fd..1d02094d0d 100755
--- a/source4/scripting/python/samba/upgradehelpers.py
+++ b/source4/scripting/python/samba/upgradehelpers.py
@@ -684,3 +684,54 @@ def delta_update_basesamdb(refsam, sam, creds, session, lp, message):
if len(delta.items()) > 1:
delta.dn = refentry.dn
sam.modify(delta)
+
+
+def construct_existor_expr(attrs):
+ """Construct a exists or LDAP search expression.
+ ie (|(foo=*)(bar=*)
+
+ :param attrs: List of attribute on which we want to create the search
+ expression.
+ :return: A string representing the expression, if attrs is empty an
+ empty string is returned"""
+ expr = ""
+ if len(attrs) > 0:
+ expr = "(|"
+ for att in attrs:
+ expr = "%s(%s=*)"%(expr,att)
+ expr = "%s)"%expr
+ return expr
+
+def search_constructed_attrs_stored(samdb, rootdn, attrs):
+ """Search a given sam DB for calculated attributes that are
+ still stored in the db.
+
+ :param samdb: An LDB object pointing to the sam
+ :param rootdn: The base DN where the search should start
+ :param attrs: A list of attributes to be searched
+ :return: A hash with attributes as key and an array of
+ array. Each array contains the dn and the associated
+ values for this attribute as they are stored in the
+ sam."""
+
+ hashAtt = {}
+ expr = construct_existor_expr(attrs)
+ if expr == "":
+ return hashAtt
+ entry = samdb.search(expression=expr, base=ldb.Dn(samdb,str(rootdn)),
+ scope=SCOPE_SUBTREE, attrs=attrs,
+ controls=["search_options:1:2","bypassoperational:0"])
+ if len(entry) == 0:
+ # Nothing anymore
+ return hashAtt
+
+ for ent in entry:
+ for att in attrs:
+ if ent.get(att):
+ if hashAtt.has_key(att):
+ hashAtt[att][str(ent.dn).lower()] = str(ent[att])
+ else:
+ hashAtt[att] = {}
+ hashAtt[att][str(ent.dn).lower()] = str(ent[att])
+
+ return hashAtt