We help IT Professionals succeed at work.

LDAP search filter for multi value attribute

shrikrishnasamant
on
Hi,
I have a ldap db and on of its attributes is multi-valued. When i do an ldapsearch on an user entry and ask for result of that attribute for example
ldapsearch -h -p -D <dn> -b -s "(cn=AJ)" myattribute
It returns for cn=AJ
myattribute=name,AJ
myattribute=place,USA
myattribute=city,baltimore
Is there any way that i can get only the one result that i require. For example if i want only city out of that multivalued attribute it should only return "myattribute=city,baltimore".
I have tried "ldapsearch -h -p -D <dn> -b -s "(&(cn=AJ)(myattriibute=city*))" myattribute"
but this doesn't seem to work and returns all results as above.
Comment
Watch Question

Author

Commented:
This is kind of very urgent
system administrator
Top Expert 2007
Commented:
> Is there any way that i can get only the one result that i require.

No way. ldapsearch will always return all attributes with the given name 'myattribute'.

You may perform a post processing of these results to extract any special value like:
dapsearch -h -p -D <dn> -b -s "(cn=AJ)" myattribute | grep 'myaddribute=city,'

But this is _not_ the right way of keeping data in LDAP. All attributes having the same name are considered having equal semantics. If you need such different values, you should use different attributes. You might need to redesign entire LDAP tree. There are many standard LDAP schemes that allows you to express all that fields.
 
For your example there is a standard cosine schema: http://www.faqs.org/rfcs/rfc1274.html

You may use 2 object-classes 'locality' and 'country' for your entry:

countryName=USA
localityName=Baltimore
stateOrProvinceName=AJ