• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6491
  • Last Modified:

LDAP search filter for multi value attribute

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.
0
shrikrishnasamant
Asked:
shrikrishnasamant
1 Solution
 
shrikrishnasamantAuthor Commented:
This is kind of very urgent
0
 
NopiusCommented:
> 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

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now