ldap - Modify entry in OpenLDAP directory -
i have large openldap directory. in directory display name property every filled need modify these entry , make "givenname + + sn". there way can directly in directory sql queries (update query). have read ldapmodify not find way use this.
any in regard appreciated.
there no way single ldap api call. you'll have use 1 ldap search operation givenname , sn attributes, , 1 ldap modify operation modify displayname attribute.
if use command line ldaptools "ldapsearch" , "ldapmodify", can shell scripting, you'll have careful: ldapsearch(1) can return ldif data in base64 format, utf-8 strings contain characters beyond ascii. instance: 'sn:: base64data' (note double ':')
so, if use simple script in language of choice, has ldap api, instead of using shell commands. save me troubles of base64 decoding ldaptools impose.
for instance, php-cli, script roughly (perhaps more error checking 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 want keep data date without intervention, need use specialized openldap module keeps "virtual" attributes, or virtual directory, such penrose or oracle virtual directory, on top of openldap. might overkill simple concatenation of attributes.
Comments
Post a Comment