I read about how to look for LDAP servers using Python, but I got stuck for hours and I'm not sure why. This is my first experience using this API.
This is how I open the connection and try to search:
aims_server = '#####.com' base_dn = 'cn=EMPLOYEES,cn=portal,cn=Groups,dc=Company,dc=com' username = 'cn=admin,cn=users,dc=Company,dc=com' password='#####' directory=ldap.open(aims_server) directory.simple_bind_s(username, password) #retrieve the current members from group old = {'uniquemember':attr['uniquemember']}
Then I intentionally break the code, so I can use the debugger and search using this:
>>> searchFilter = "cn=*" >>> directory.search_s(base_dn,ldap.SCOPE_SUBTREE,searchFilter, retrieveAttributes)
Results:
[('cn=EMPLOYEES,cn=portal,cn=groups,dc=Company,dc=com', {'displayname': ['Employees'], 'description': ['Members of this group are employees. '], 'objectclass': ['top', 'groupOfUniqueNames', 'orclGroup'], 'orclisvisible': ['true'], 'owner': ['cn=portal_admin ,cn=users,dc=Company,dc=com', 'cn=portal,cn=users, dc=Company,dc=com'], 'uniquemember': ['cn=alan,cn=users,dc=Company,dc=com', 'cn=alan_r,cn=users,dc=Company,dc=com', ....
If I have the filter "cn=*" , it will return the dictionary above, but if I actually put something in searchFilter , it will not bring any results.
Does anyone have any ideas? I wonder if I'm not looking deep enough in directories?
EDIT
The best I can understand is to change the settings:
searchFilter = "cn=*" retrieveAttributes = ["uniquemember"]
Then:
(cn, attr) = searcher.pop()
Return:
{'uniquemember': ['cn=alan_t,cn=users,dc=company,dc=com','cn=alan_r,cn=users,dc=company....
It seems that he is trying to find a level too high, how would I go down to another level to look for unique members?
I just want to find their names!