s4: Create helpers functions related to provision
authorMatthieu Patou <mat@matws.net>
Wed, 26 Aug 2009 16:30:15 +0000 (20:30 +0400)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 28 Aug 2009 12:41:49 +0000 (22:41 +1000)
One for getting attributes with DN syntax, one for getting forward
linked attributes and one for getting the list of partition

source4/scripting/python/samba/provision.py

index 0a3a44f0cdd0afabec6c01f8666dd3bb83959a79..bb95f3834ee5192c5e69574a0bf6bdae7193b310 100644 (file)
@@ -167,6 +167,32 @@ class Schema(object):
         prefixmap_ldif = "dn: cn=schema\nprefixMap:: %s\n\n" % prefixmap
         self.ldb.set_schema_from_ldif(prefixmap_ldif, self.schema_data)
 
+
+# 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 = {}
+    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, 
+                                     expression=expression, 
+                                     attribute="lDAPDisplayName", 
+                                     scope=SCOPE_SUBTREE)
+        if target is not None:
+            attributes[str(res[i]["lDAPDisplayName"])]=str(target)
+            
+    return attributes
+
+def get_dnsyntax_attributes(schemadn,schemaldb):
+    attrs = ["linkID", "lDAPDisplayName"]
+    res = schemaldb.search(expression="(&(!(linkID=*))(objectclass=attributeSchema)(attributeSyntax=2.5.5.1))", base=schemadn, scope=SCOPE_ONELEVEL, attrs=attrs)
+    attributes = []
+    for i in range (0, len(res)):
+        attributes.append(str(res[i]["lDAPDisplayName"]))
+        
+    return attributes
+    
     
 def check_install(lp, session_info, credentials):
     """Check whether the current install seems ok.
@@ -1431,28 +1457,21 @@ 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})
     
+    attrs = ["linkID", "lDAPDisplayName"]
     res = schema.ldb.search(expression="(&(objectclass=attributeSchema)(searchFlags:1.2.840.113556.1.4.803:=1))", base=names.schemadn, scope=SCOPE_ONELEVEL, attrs=attrs)
     index_config = ""
     for i in range (0, len(res)):
@@ -1838,5 +1857,3 @@ def create_krb5_conf(path, setup_path, dnsdomain, hostname, realm):
 
 
 
-