Search code examples
ldapldap-query

Can't find members of group using its cn in LDAP


I am totally new to LDAP, and have just started. I have seen a couple of examples, which to my understanding have used the query as I have done, but in my case it seems to be not working.

I have a hierarchy like this (I am using Apache Directory Studio):

enter image description here

If I double click on the object with ou=scientists then its info will pop up as followed: enter image description here

So this group with ou=scientists has a cn=Scientists (I have checked and there are no following spaces after Scientists.

I want to simply find stuff inside the group with ou=scientists. There is 1 way to do it like this: ou=scientists,dc=example,dc=com which gives the expected result. enter image description here

But I want to be able to find the content inside the group with ou=scientists not by its ou value, but by its cn value. So I thought to myself, ok I can use this: cn=Scientists,dc=example,dc=com

But this yields 0 results. I think I am missing a key point here. What should I actually do?


Solution

  • There are multiple things to consider when you query a LDAP directory.

    In your case you want to lookup from a branch (call search base dn in LDAP) and apply a filter in all the childrens of this branch to select those you want :

    ldapsearch ... -b <search base dn> -s sub "<FILTER>"

    So for your DIT :

    ldapsearch ... -b dc=example,dc=com -s sub "(&(objectClass=groupOfUniqueNames)(cn=scientists))"

    Consider learning how the search request works in LDAP if you want to work more deeply with ldap : https://ldapwiki.com/wiki/SearchRequest