Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why not always use (objectClass=*) in the LDAP search filter?

I created the following filter for search users in Active Directory:

(&(objectClass=*)(|(sAMAccountName=u)(userPrincipalName=u)) 

It is possible to create more qualified filter:

(&(objectClass=person)(|(sAMAccountName=u)(userPrincipalName=u)) 

The question is why?

What benefits of using specified class person?

Is it possible that the same directory contain object where objectClass is not person but the following is true (|(sAMAccountName=u)(userPrincipalName=u))?

Why not always use (objectClass=*) in the LDAP search filter?

like image 869
Michael Avatar asked Oct 12 '25 19:10

Michael


2 Answers

(objectClass=*) is a present filter used to filter out objects that have no populated objectClass ... which is none, since all LDAP objects have at least one structural objectClass, hence the filter component in the first filter is unnecessary and may even slow down the search, depending on the server configuration.

The first filter in your question might cause the server to make comparisons using matching rules that are unnecessary. The second filter is a better filter from a performance perspective, assuming that an index for objectClass equality has been created on the server.

like image 95
Terry Gardner Avatar answered Oct 16 '25 03:10

Terry Gardner


It is probably a holdover from generic LDAP services, where in priniciple any object could share the same attribute with the same value, but be of different object classes.

However, Active Directory has a limitation that sAMAccountName must be unique within the domain, across all object classes. And only 4 object classes should have the attribute? (Users, groups, printers, and workstations I think).

So you could most likely just query for (|(sAMAccountName=u)(userPrincipalName=u))

without the objectclass filter at all.

like image 30
geoffc Avatar answered Oct 16 '25 03:10

geoffc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!