本文整理汇总了Python中ldap.controls方法的典型用法代码示例。如果您正苦于以下问题:Python ldap.controls方法的具体用法?Python ldap.controls怎么用?Python ldap.controls使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ldap
的用法示例。
在下文中一共展示了ldap.controls方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ldap_query
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import controls [as 别名]
def ldap_query(self,l, base_dn, subtree, objectFilter, attrs):
ldap_control = ldap.controls.SimplePagedResultsControl (True, size=1000, cookie='' )
results = []
while True:
msgid = l.search_ext (base_dn, subtree, objectFilter, attrs, serverctrls=[ldap_control] )
rtype, rawResults, id, server_controls = l.result3 ( msgid )
results += rawResults
page_controls = [c for c in server_controls if c.controlType == ldap.controls.SimplePagedResultsControl.controlType]
if page_controls:
cookie = page_controls[0].cookie
if not cookie:
break
else:
ldap_control.cookie = cookie
return results
示例2: at_least_one_user_exists
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import controls [as 别名]
def at_least_one_user_exists(self):
logger.debug("Checking if any users exist in LDAP")
try:
with self._ldap.get_connection():
pass
except ldap.INVALID_CREDENTIALS:
return (None, "LDAP Admin dn or password is invalid")
has_pagination = not self._force_no_pagination
with self._ldap.get_connection() as conn:
for user_search_dn in self._user_dns:
search_flt = "(objectClass=*)"
search_flt = self._add_user_filter(search_flt)
lc = ldap.controls.libldap.SimplePagedResultsControl(
criticality=True, size=1, cookie=""
)
try:
if has_pagination:
msgid = conn.search_ext(
user_search_dn, ldap.SCOPE_SUBTREE, search_flt, serverctrls=[lc]
)
_, rdata, _, serverctrls = conn.result3(msgid)
else:
msgid = conn.search(user_search_dn, ldap.SCOPE_SUBTREE, search_flt)
_, rdata = conn.result(msgid)
for entry in rdata: # Handles both lists and iterators.
return (True, None)
except ldap.LDAPError as lde:
return (False, str(lde) or "Could not find DN %s" % user_search_dn)
return (False, None)