in src/terraform/providers/terraform-provider-avere/static/generate-rid-avereflatfiles.py [0:0]
def getUsers(conn, basedn, ridInteger):
logging.info('get users for "{}"'.format(basedn))
users = {}
usernamesWithGidKey = {}
# paging technique from here: https://stackoverflow.com/questions/3378142/ldap-ldap-sizelimit-exceeded
searchFilter = "(&(objectclass=user))"
attributeList = ["sAMAccountName","objectSid","distinguishedName","primaryGroupID"]
pageSize = 500
resultsControl = ldap.controls.SimplePagedResultsControl(criticality=True, size=pageSize, cookie='')
msgid = conn.search_ext(base=basedn, scope=ldap.SCOPE_SUBTREE, filterstr=searchFilter, attrlist=attributeList, serverctrls=[resultsControl])
pages = 0
while True: # loop over all of the pages using the same cookie, otherwise the search will fail
pages += 1
rtype, rdata, rmsgid, serverctrls = conn.result3(msgid)
for dn, entry in rdata:
user = initializeUserFromEntry(dn, entry, ridInteger)
if user == None:
continue
users[user.distinguishedName] = user
if user.gid not in usernamesWithGidKey:
usernamesWithGidKey[user.gid]=[]
usernamesWithGidKey[user.gid].append(user.accountName)
# get the next page or exit loop
pctrls = [c for c in serverctrls if c.controlType == ldap.controls.SimplePagedResultsControl.controlType]
if pctrls:
if pctrls[0].cookie: # Copy cookie from response control to request control
resultsControl.cookie = pctrls[0].cookie
msgid = conn.search_ext(base=basedn, scope=ldap.SCOPE_SUBTREE, filterstr=searchFilter, attrlist=attributeList, serverctrls=[resultsControl])
else:
break
else:
break
logging.info("found {} user(s) in {} page(s)".format(len(users), pages))
return users, usernamesWithGidKey