Skip to content
Snippets Groups Projects
Commit c69fb372 authored by Sven Mäder's avatar Sven Mäder :speech_balloon:
Browse files

Use fast ldap search

parent 53f1ddf9
No related branches found
No related tags found
No related merge requests found
......@@ -66,28 +66,32 @@ class Home(object):
def search_ldap():
ldap = dphysldap.Ldap()
ldap_users = dphysldap.Users(ldap, ['uid', 'uidNumber', 'gidNumber', 'homeDirectory', 'blocked'])
entries = dphysldap.Entries(ldap, ['cn', 'nisMapEntry'])
people = 'ou=people,dc=phys,dc=ethz,dc=ch'
auto_home = 'nisMapName=auto.home,ou=automount,dc=phys,dc=ethz,dc=ch'
ldap_users.search('*')
ldap.search('(objectClass=posixAccount)', search_base=people, attributes=['uid', 'blocked', 'homeDirectory'])
ldap_users = ldap.response
for user in ldap_users:
user_attrs = {}
user_attrs['homeDirectory'] = user['homeDirectory'][0]
if user['blocked']:
user_attrs['blocked'] = user['blocked'][0]
user_attrs['homeDirectory'] = user['attributes']['homeDirectory']
if user['attributes']['blocked']:
user_attrs['blocked'] = user['attributes']['blocked']
else:
no_blocked.append(user['uid'][0])
no_blocked.append(user['attributes']['uid'][0])
user_attrs['blocked'] = 'no'
users[user['uid'][0]] = user_attrs
users[user['attributes']['uid'][0]] = user_attrs
entries.search('cn: *, nisMapEntry: phd-home*', ['nisObject'], base=auto_home)
ldap.search('(&(objectClass=nisObject)(cn=*)(nisMapEntry=phd-home*))',
search_base=auto_home, attributes=['cn', 'nisMapEntry'])
entries = ldap.response
for entry in entries:
nis_homes[entry['cn'][0]] = entry['nisMapEntry'][0]
nis_homes[entry['attributes']['cn'][0]] = entry['attributes']['nisMapEntry']
entries.search('cn: *, nisMapEntry: != phd-home*', ['nisObject'], base=auto_home)
ldap.search('(&(objectClass=nisObject)(cn=*)(!(nisMapEntry=phd-home*)))',
search_base=auto_home, attributes=['cn', 'nisMapEntry'])
entries = ldap.response
for entry in entries:
nis_shares[entry['cn'][0]] = entry['nisMapEntry'][0]
nis_shares[entry['attributes']['cn'][0]] = entry['attributes']['nisMapEntry']
def check_homes(top):
......
......@@ -241,6 +241,25 @@ class Ldap(object):
entries = self.get_entries(obj=self.obj_group, query=query, attributes=attributes)
return [Group(e) for e in entries]
def search(self, search_filter, search_base=None, search_scope=ldap3.SUBTREE,
attributes=[ldap3.ALL_ATTRIBUTES, ldap3.ALL_OPERATIONAL_ATTRIBUTES]):
"""
LDAP search operation
"""
if not search_base:
search_base = self.base
response = self.connection.search(search_base, search_filter,
search_scope=search_scope,
attributes=attributes)
return response
@property
def response(self):
"""
Get search operation response
"""
return self.connection.response
class Entries(list):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment