0

I am trying to use Python ldap3 to retrieve users from a ldap. This is my setup

from ldap3 import Server, Connection, ObjectDef, AttrDef, Reader, Writer, ALL
server = Server('ldap://ldapserver:389', get_info=ALL)
conn = Connection(server, 'eTGlobalUserName=user,eTGlobalUserContainerName=Global Users,eTNamespaceName=CommonObjects,dc=iam,dc=eta', 'pass123', auto_bind=True)

When i search using the connection object, i can retrieve all users:

conn.search('eTGlobalUserContainerName=Global Users,eTNamespaceName=CommonObjects,dc=iam,dc=eta', '(objectclass=eTGlobalUser)')

But when i try to get all users with the Reader i only get one item and it does not even contain an user, this is what i did:

obj_person = ObjectDef('eTGlobalUser',conn)
r = Reader(conn,obj_person,'eTGlobalUserContainerName=Global Users,eTNamespaceName=CommonObjects,dc=iam,dc=eta')
r.search()

Is there anything i am missing?

Edit 1 This is the output of print(r):

This is the output of print(r):
CURSOR : Reader
CONN   : ldap://ldapserver:389 - cleartext - user: eTGlobalUserName=user,eTGlobalUserContainerName=Global Users,eTNamespaceName=CommonObjects,dc=asusisv-iam,dc=eta - not 
lazy - bound - open - <local: 10.150.8.169:54196 - remote: 10.145.10.123:389> - tls not started - listening - SyncStrategy - internal decoder
DEFS   : eTGlobalUser
ATTRS  : ['eTAccessControlList', ... , 'eTGlobalUserName', ... , 'objectClass']
BASE   : 'eTGlobalUserContainerName=Global Users,eTNamespaceName=CommonObjects,dc=iam,dc=eta' [SUB]
FILTER : '(objectClass=eTGlobalUser)'
José Cousiño
  • 399
  • 1
  • 6
  • 15

1 Answers1

0

You can access results with r.entries

Once a Reader cursor is populated with entries, you can get a specific entry with the standard index feature of List object.

The Cursor object also has a shortcut : use r[0], r[1] and so on to perform the same operation. For example :

for entry in r.entries:
    print(entry.entry_dn) 
    print(entry.<attribute_name>)

# or
for entry in r:
    ...

If you get 0 entries, you can just print(r) to see how is built the reader cursor and check if CONN, BASE and FILTER (that are used to build r.search() queries) are correctly converted from the parameters you give in ObjectDef() and Reader().

EricLavault
  • 12,130
  • 3
  • 23
  • 45
  • @JoséCousiño It seems correct to me compared to `conn.search()` parameters, except maybe for the case (?) so after calling `r.search()` you should have `r.entries` populated. I don't know why this is not happening.. Nothing in the logs ? – EricLavault Oct 22 '19 at 16:25