2016-12-01 57 views
1

服務器沒有爲python-ldap和ldap3庫返回相同數量的屬性。檢索ldap3中所有屬性的列表(python3-ldap)

缺少的屬性是我必須執行一些操作。

這是我用來LDAP3搜索查詢的示例:

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用於搜索查詢:

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中給定查詢的屬性。

+1

這可能是與服務器的實現LDAP的問題,但對我來說,'屬性= [「*」]'工作使用ldap3獲取所有屬性。 這在Active Directory下使用。 –

回答

0

如果使用Reader類,你可以找到allowedAttributes和allowedAttributesEffective:

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 
相關問題