Search code examples
ldapldap-query

LDAP search for user with repeating attribute


I'm relatively new to LDAP and I am trying to figure out how I can search for a user who has multiple of the same attribute.

For example I have two users configured like this:

dn: uid=test1,ou=users,dc=domain,dc=com
mail: test1@domain.com
mail: test-manager@domain.com

dn: uid=test2,ou=users,dc=domain,dc=com
mail: test2@domain.com

Is there a way that I can identify that test1 has more than one mail attributes and return just that user? So essentially, what should the query be in the ldapsearch command below?

ldapsearch -x -H ldap://ldap.domain.com -L -b 'dc=domain,dc=com' '<query to identify users with more than one mail>'

By the way I did find this question ldap filter to search for multiple values for an attribute, but I don't think it was answered satisfactorily.


Solution

  • Appears that the link you supplied has the correct answer to the question "LDAP search for user with repeating attribute". A specific query for uid=test1,ou=users,dc=domain,dc=com would be like:

    (&(mail=test1@domain.com)(mail=test-manager@domain.com)(objectClass=inetOrgPerson))
    

    However, LDAP does not have any single query to determine if entries that have more than one value for the an attribute.

    You would need to write code or parse results to determine users with more than one value.