當前位置: 首頁>>代碼示例>>Python>>正文


Python ldap.controls方法代碼示例

本文整理匯總了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 
開發者ID:Tylous,項目名稱:Vibe,代碼行數:17,代碼來源:AD.py

示例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) 
開發者ID:quay,項目名稱:quay,代碼行數:36,代碼來源:externalldap.py


注:本文中的ldap.controls方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。