views:

9

answers:

1

Hi,

I have a large Openldap directory. In the directory the display name property for every is filled but i need to modify these entry and make it like "givenName + + sn". Is there are way i can do it directly in the directory just like sql queries (update query). I have read about the ldapmodify but could not find the way to use it like this.

Any help in this regard will be appreciated.

A: 

There is no way to do this with a single LDAP API call. You'll always have to use one LDAP search operation to get givenname and sn attributes, and one LDAP modify operation to modify the displayName attribute.

If you use the command line ldaptools "ldapsearch" and "ldapmodify", you can do this easily with some shell scripting, but you'll have to be careful: sometimes ldapsearch(1) can return LDIF data in base64 format, with UTF-8 strings that contain characters beyond ascii. For instance: 'sn:: Base64data' (note the double ':')

So, if I were you I would use a simple script in my language of choice, that has an LDAP API, instead of using shell commands. This would save me the troubles of base64 decoding that the ldaptools sometimes impose.

For instance, with php-cli, your script would be roughly like this (perhaps some more error checking would be appropriate):

<?php
$ldap = ldap_connect('host');
ldap_bind($ldap, ...);
$sr = ldap_search($ldap, 'ou=people,...', 'objectclass=*');
$entries= ldap_get_entries($ldap, $sr);
for($i=0; $i<$entries['count']; $i++) {
    $modify = array('displayname' => $entries[$i]['givenname'] . ' ' . $entries[$i]['sn']);
    ldap_modify($ldap, $entries[$i]['dn'], $modify);
}

Addendum: if you want to keep this data up to date without any intervention, you will probably need to use a specialized OpenLDAP module that keeps "virtual" attributes, or even a virtual directory, such as Penrose or Oracle Virtual Directory, on top of OpenLDAP. However this might be overkill for a simple concatenation of attributes.

Avel
Thnx for the contribution, but ldap_search has limitation of 1000 records per call, and I have more than 100K records. How to resolve this issue.
Shahzad Fateh Ali
ldap_search per se has no such limitation. Your server has, with its specific configuration. You can change the server configuration accordingly.
Avel