problem with ldap_mod_replace and cn entry

Alles, was PHP betrifft, kann hier besprochen werden.

problem with ldap_mod_replace and cn entry

Postby kschroeder » 03. May 2012 07:25

Hello,

I try to update novell edir informations via ldap.
Everything works fine except for the cn property.

With each update try I get an additional entry added to the list.

A var_dump of the read entries gives me: (snipped)
["cn"]=> array(8) { ["count"]=> int(7) [0]=> string(4) "Code" [1]=> string(1) "a" [2]=> string(2) "XX" [3]=> string(1) " " [4]=> string(3) "bbb" [5]=> string(7) "aasdasd" [6]=> string(4) "CCCC" } [14]=> string(2) "cn"

If I look in the ldap browser I get: aaa; XX; ; bbb; aasdasd; CCCC

How do I get rid of all the entries and always only replace the one?
I expected, a ldap_mod_replace would only replace values instead of adding some.

Here's the piece of code so far:
Code: Select all
   $ds = ldap_connect($LDAP_SERVER);
   ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
   if ($ds) {
      $r=ldap_bind($ds,$LDAP_USER,$LDAP_PASS);

      $ldap_info['sn']=$lastname;
      $ldap_info['givenname']=$givenname;
      $ldap_info['mail']=$email;
      $ldap_info['cn']=array($ldaploginname,$company);
      $ldap_info['street']=$street;
      $ldap_info['postalcode']=$postcode;
      $ldap_info['physicaldeliveryofficename']=$city;
      $ldap_info['preferredlanguage']=$prefsprache;

      if (@ldap_mod_replace($ds, $ldapdn, $ldap_info)) {
         ?>
         <table><tr><td class="border_message">Update</td></tr></table>
         <?
      } else {
         ?>
         <table><tr><td class="border_error">Error</td></tr></table>
         <?
      }
   }
   ldap_close($ds);
kschroeder
 
Posts: 254
Joined: 11. May 2007 13:33

Re: problem with ldap_mod_replace and cn entry

Postby kschroeder » 03. May 2012 13:03

I don't know if this is really the right way to solve it but it works:

I decided to remove the current entry first, before "updating":
Code: Select all
      $entry["cn"][]=$ldapoldcompany;
      ldap_mod_del($ds, $ldapdn, $entry);

Unfortunately it doesn't work with an undefined array like $entry["cn"]=array(), so I had to remember the old value to delete it.
kschroeder
 
Posts: 254
Joined: 11. May 2007 13:33


Return to PHP

Who is online

Users browsing this forum: No registered users and 39 guests