[PATCH] s4: Make code reuse for get_linked_attributes

Matthieu Patou mat at matws.net
Wed Aug 26 10:57:15 MDT 2009


---
 source4/scripting/bin/rebuildextendeddn     |    2 +-
 source4/scripting/python/samba/provision.py |   28 +++++++++-----------------
 2 files changed, 11 insertions(+), 19 deletions(-)
 mode change 100644 => 100755 source4/scripting/bin/rebuildextendeddn

diff --git a/source4/scripting/bin/rebuildextendeddn b/source4/scripting/bin/rebuildextendeddn
old mode 100644
new mode 100755
index 1a6da70..078332f
--- a/source4/scripting/bin/rebuildextendeddn
+++ b/source4/scripting/bin/rebuildextendeddn
@@ -141,7 +141,7 @@ def rebuild_en_dn(credentials,session_info,paths):
 
 	sam_ldb = Ldb(paths.samdb, session_info=session_info, credentials=credentials,lp=lp)
 	sam_ldb.transaction_start()
-	attrs.extend(get_linked_attributes(partitions[2],sam_ldb))
+	attrs.extend(get_linked_attributes(partitions[2],sam_ldb).keys())
 	attrs.extend(get_dnsyntax_attributes(partitions[2],sam_ldb))
 
 	for partition in partitions:
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index 2ae8510..4b35680 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -1431,24 +1431,16 @@ def provision_openldap_backend(result, paths=None, setup_path=None, names=None,
     if nosync:
         nosync_config = "dbnosync"
         
-        
-    attrs = ["linkID", "lDAPDisplayName"]
-    res = schema.ldb.search(expression="(&(linkID=*)(!(linkID:1.2.840.113556.1.4.803:=1))(objectclass=attributeSchema)(attributeSyntax=2.5.5.1))", base=names.schemadn, scope=SCOPE_ONELEVEL, attrs=attrs)
-
-    memberof_config = "# Generated from Samba4 schema\n"
+    lnkattr = get_linked_attributes(names.schemadn,schema.ldb)
     refint_attributes = ""
-    for i in range (0, len(res)):
-        expression = "(&(objectclass=attributeSchema)(linkID=%d)(attributeSyntax=2.5.5.1))" % (int(res[i]["linkID"][0])+1)
-        target = schema.ldb.searchone(basedn=names.schemadn, 
-                                      expression=expression, 
-                                      attribute="lDAPDisplayName", 
-                                      scope=SCOPE_SUBTREE)
-        if target is not None:
-            refint_attributes = refint_attributes + " " + res[i]["lDAPDisplayName"][0]
+    memberof_config = "# Generated from Samba4 schema\n"
+    for att in  lnkattr.keys():
+        if lnkattr[att] is not None:
+            refint_attributes = refint_attributes + " " + att 
             
             memberof_config += read_and_sub_file(setup_path("memberof.conf"),
-                                                 { "MEMBER_ATTR" : str(res[i]["lDAPDisplayName"][0]),
-                                                   "MEMBEROF_ATTR" : str(target) })
+                                                 { "MEMBER_ATTR" : att ,
+                                                   "MEMBEROF_ATTR" : lnkattr[att] })
             
     refint_config = read_and_sub_file(setup_path("refint.conf"),
                                       { "LINK_ATTRS" : refint_attributes})
@@ -1838,11 +1830,11 @@ def create_krb5_conf(path, setup_path, dnsdomain, hostname, realm):
 
 
 
- 
+# 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"]
 		res = schemaldb.search(expression="(&(linkID=*)(!(linkID:1.2.840.113556.1.4.803:=1))(objectclass=attributeSchema)(attributeSyntax=2.5.5.1))", base=schemadn, scope=SCOPE_ONELEVEL, attrs=attrs)
-		attributes = []
+		attributes = {}
 		for i in range (0, len(res)):
 			expression = "(&(objectclass=attributeSchema)(linkID=%d)(attributeSyntax=2.5.5.1))" % (int(res[i]["linkID"][0])+1)
 			target = schemaldb.searchone(basedn=schemadn, 
@@ -1850,7 +1842,7 @@ def get_linked_attributes(schemadn,schemaldb):
                                     attribute="lDAPDisplayName", 
                                     scope=SCOPE_SUBTREE)
 			if target is not None:
-				attributes.append(str(res[i]["lDAPDisplayName"]))
+				attributes[str(res[i]["lDAPDisplayName"])]=str(target)
 
 		return attributes
 
-- 
1.6.0.4


--------------090203020906080509050208--


More information about the samba-technical mailing list