首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检索ldap3中所有属性的列表(python3-ldap)

检索ldap3中所有属性的列表(python3-ldap)
EN

Stack Overflow用户
提问于 2016-12-02 04:11:14
回答 1查看 8K关注 0票数 3

服务器没有为python-ldap和ldap3库返回相同数量的属性。

缺少的属性是我必须执行某些操作的属性。

这是我在ldap3中使用的搜索查询示例:

代码语言:javascript
复制
from ldap3 import Server,Connection,ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES,ALL,SEARCH_SCOPE_WHOLE_SUBTREE,SUBTREE

host = something1
user = something2
password = something3
baseDn = something4
search_filter = "(uid=something5)"

server = Server(host, get_info=ALL)
conn = Connection(server,user, password,auto_bind=True,check_names=True)
conn.search(baseDn,search_filter, search_scope=SEARCH_SCOPE_WHOLE_SUBTREE, attributes=['*'])

entry = conn.entries
print(json.loads(entry[0].entry_to_json()))

与python-ldap一起使用的搜索查询:

代码语言:javascript
复制
searchScope = ldap.SCOPE_SUBTREE
## retrieve all attributes 
retrieveAttributes = None
ldap_result_id = l.search(baseDn, searchScope, searchFilter,   retrieveAttributes)
result_set = []
while 1:
    result_type, result_data = l.result(ldap_result_id, 0)
    if (result_data == []):
        break
    else:
        ## you could do whatever you want with the individual entry
        ## The appending to list is just for illustration.
        if result_type == ldap.RES_SEARCH_ENTRY:
            result_set.append(result_data)

print json.loads(result_set)

如果有人可以发布,有没有办法检索ldap3中给定查询的所有可用属性。

EN

回答 1

Stack Overflow用户

发布于 2017-02-14 23:41:25

如果使用Reader类,则可以找到allowedAttributes和allowedAttributesEffective:

代码语言:javascript
复制
from ldap3 import Server,Connection,Reader,ObjectDef

host = something1
user = something2
password = something3
baseDn = something4
search_filter = "(uid=something5)"

server = Server(host, get_info=ALL)
conn = Connection(server,user, password,auto_bind=True,check_names=True)
inetorgperson = ObjectDef(['person','user'], conn)
reader = Reader(conn,inetorgperson,baseDn,search_filter)

reader.search()

>>> len(reader[0].allowedAttributes)
741
>>> len(reader[0].allowedAttributesEffective)
620
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40919531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档