Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DN in Search Filter

In my LDAP Client program sometimes I have to include the DN value within the search filter. But this DN is changing frequently and every I have to change this filter in my code.

When I googled it for that I got something like this

Suppose you want to pull all users of ObjectType = Person from the R&D and HR ous, but not any users from Marketing and PM. The filter would be:

(&(objectClass=person)(|(ou:dn:=ResearchAndDevelopment)(ou:dn:=HumanResources)))

Can anybody explain this more in detail?

like image 738
Dungeon Hunter Avatar asked Sep 19 '11 15:09

Dungeon Hunter


People also ask

What is DN in LDAP search?

The LDAP API references an LDAP object by its distinguished name (DN). A DN is a sequence of relative distinguished names (RDN) connected by commas. An RDN is an attribute with an associated value in the form attribute=value; normally expressed in a UTF-8 string format.

What is a search DN?

Base Distinguished NameThe base DN is often referred to as the search base. For example, if you specify a base DN of OU=people, O=siroe.com for a client, the LDAP search operation initiated by the client examines only the OU=people subtree in the O=siroe.com directory tree.

What is LDAP user search filter?

LDAP Authentication Search Filter is a basic LDAP Query for searching users based on mapping of username to a particular LDAP attribute. 2. The following are some commonly used Search Filters. You will need to use a search filter which uses the attributes specific to your LDAP environment.

How do I test LDAP search filters?

Test the external (LDAP) group name search filter. In the LDAP group name field, type the name of an existing external group, for example g1-10 , and click Test LDAP query. If the query is successful, a check mark displays beside the Test LDAP query button. If the query is not successful, an error message displays.


1 Answers

You should check RFC 2254 (The String Representation of LDAP Search Filters).

LDAP filters use polish notation for the boolean operators. So the operator is written before its operands:

(&(condition1)(condition2)(condition3)...)

The example above means that you want all LDAP entries which satisfy condition1 AND condition2 AND condition3 and so on.

Then there are condition themselves. They are very simple and can consist only of few types:

  • present condition - (attrName=*)
  • simple condition - (attrName>=value) / (attrName<=value) / (attrNamevalue=value) / (attrName~=value)
  • substring condition - (attrName=*value*) / (attrName=*value) / (attrName=value*)
  • extensible condition - (attrName:dn:=value) / (attrName:matchingRule:=value)

The extensible condition with the :dn: keyword means, that you want attributes from the entry DN to be considered as well. So for your case entry cn=John Doe,ou=HumanResources,ou=Users,dc=example,dc=com would match the filter (ou:dn:=HumanResource).


Translating your example filter to an English sentence would be:

Find me all LDAP entries which have objectClass equal to person and have either ResearchAndDevelopment or HumanResources in their ou attribute or somewhere on their DN.

like image 74
Pavel Horal Avatar answered Sep 20 '22 02:09

Pavel Horal