[turba] partial ldap driver fix

Cory Merritt cmerritt at merricomp.com
Wed Jan 14 19:37:32 PST 2004


I was having a little trouble with the ldap global address book using an
openldap backend.  Users that were being added with a cn of "lastname, first"
generate an Invalid DN message.  I decided to write some code to strip out the
comma and change it to "firstname last".  The changes also set the sn in the
LDAP Driver as it is required for my ldap server.  There is probably a better
way to do this, but it works for me. :)

*** ldap.php.old        2004-01-14 19:55:08.000000000 -0700
--- ldap.php    2004-01-14 20:06:50.000000000 -0700
***************
*** 274,279 ****
--- 274,301 ----
          $dn = $attributes['dn'];
          unset($attributes['dn']);

+          //The next line was added to check for
+          //commas in the Contacts Common Name.
+          if (ereg("\,",$attributes['cn'])) {
+
+             //Remove any commas and spaces from the cn, and then use it to
build
+             //a dn for the object.  This code assumes that if there is a
comma
+             //in the cn, the cn is formatted as lastname, first.  The new cn
+             //that will be generated will be firstname [space] lastname.
+             $newcn = split("\,",$attributes['cn']);
+             $name = $newcn[1] . " " . $newcn[0];
+
+             //Next Lines set the cn value in the attributes array, and then
+           //create a dn for the object.
+             $attributes['cn'] = $name;
+
+             //Build the new dn using the cn without the comma's.
+             $dn = "cn=" . trim($name) . "," . $this->_params['root'];
+          }
+
+          //Add the sn to the attributes array.
+          $attributes['sn'] = "LDAP User";
+
          // Put the Objectclass into the attributes array
          if (!is_array($this->_params['objectclass'])) {
              $attributes['objectclass'] = $this->_params['objectclass'];


-------------- next part --------------
*** ldap.php.old        2004-01-14 19:55:08.000000000 -0700
--- ldap.php    2004-01-14 20:06:50.000000000 -0700
***************
*** 274,279 ****
--- 274,301 ----
          $dn = $attributes['dn'];
          unset($attributes['dn']);

+          //The next line was added to check for
+          //commas in the Contacts Common Name.
+          if (ereg("\,",$attributes['cn'])) {
+
+             //Remove any commas and spaces from the cn, and then use it to build
+             //a dn for the object.  This code assumes that if there is a comma
+             //in the cn, the cn is formatted as lastname, first.  The new cn
+             //that will be generated will be firstname [space] lastname.
+             $newcn = split("\,",$attributes['cn']);
+             $name = $newcn[1] . " " . $newcn[0];
+
+             //Next Lines set the cn value in the attributes array, and then
+           //create a dn for the object.
+             $attributes['cn'] = $name;
+
+             //Build the new dn using the cn without the comma's.
+             $dn = "cn=" . trim($name) . "," . $this->_params['root'];
+          }
+
+          //Add the sn to the attributes array.
+          $attributes['sn'] = "LDAP User";
+
          // Put the Objectclass into the attributes array
          if (!is_array($this->_params['objectclass'])) {
              $attributes['objectclass'] = $this->_params['objectclass'];


More information about the turba mailing list