Beispiel #1
0
 def get_node_data(self, node_id):
     """
     @see UniDomain.Classes.db#get_node_data
     """
     node = Classes.AttributeCollection()
     ldap_result = self.udBase(node_id, '(objectClass=*)',
                               node.supported_attributes())
     if len(ldap_result) > 0:
         if len(ldap_result
                ) > 1:  #since we search for DNs this never should happen.
             logging.warning('multiple records found for %s, using %s.',
                             node_id, ldap_result[0][0])
         ats = ldap_result[0][1]
         for at in ats.keys():
             node.data[at] = [(val, norm_dn(node_id)) for val in ats[at]]
         #load policies for this node.
         ldap_result = self.conn.search_s(node_id, ldap.SCOPE_ONELEVEL,
                                          '(objectClass=udPolicy)')
         for policy in ldap_result:
             logging.debug('----policy is %s', policy)
             policyName = policy[0].split(',')[0].split('=')[1].strip()
             node.policies[policyName] = [(norm_dn(policy[0]), policy[1])]
             logging.debug('---- now is %s', node.policies[policyName])
     else:
         logging.error('no node data for dn %s.', node_id)
     return node
Beispiel #2
0
 def get_udGroup_data(self, group):
     """load data of a udGroup and its metagroups."""
     mydn = set(self.userID.split(
         ','))  # sets have the & operator to find interesctions.
     query = self.udSub('(&(objectClass=udGroup)(cn=%s))' % group)
     groups = [
         (
             dn,
             len(set(norm_dn(dn).split(','))
                 & mydn)  #match common path parts to user dn
         ) for dn, atts in self.conn.result(query)[1]
     ]
     if len(groups) == 0:
         logging.warning('no such udGroup %s', group)
         return Classes.AttributeCollection()
     groups.sort(key=lambda x: x[1],
                 reverse=True)  # longest matching path wins
     logging.debug('using %s for group name %s', groups[0][0], group)
     node = self.get_node_data(groups[0][0])
     return node