4

Server is not returning same number of attributes for python-ldap and ldap3 Libraries.

The missing attributes are the one that I have to perform some operations.

This is the sample of the search query I used for 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()))

Search query used with 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)

If someone can post, is there any way to retrieve all the attributes that are available for given query in ldap3.

1
  • 1
    It might be an issue with the server's implementation of LDAP, but for me, attributes = ['*'] worked in getting all the attributes back using ldap3. This is used against under Active Directory. Commented Feb 28, 2017 at 22:36

1 Answer 1

5

If you use the Reader class, you can find allowedAttributes and 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.