[PHP-DEV] PHP 4.0 Bug #7228: Problems when using the ldap_add() function From: christoffer.leitet <email protected>
Date: 10/15/00

From: christoffer.leitet <email protected>
Operating system: Linux 2.2.16 (slackware)
PHP version: 4.0.2
PHP Bug Type: LDAP related
Bug description: Problems when using the ldap_add() function

This script is copypasted (and modifyed for my system) from the manual, and reproduces the error on my system..

<?php
$ds=ldap_connect("iplanet.server.com"); // assuming the LDAP server is on this host

if ($ds) {
    // bind with appropriate dn to give update access
    $r=ldap_bind($ds,"cn=Directory Manager", "secret");

    // prepare data
    $info["cn"]="John Jones";
    $info["sn"]="Jones";
    $info["mail"]="jonj <email protected>";
    $info["objectclass"]="person";

    // add data to directory
    $r=ldap_add($ds, "cn=John Jones, o=whitebird", $info);

    ldap_close($ds);
} else {
    echo "Unable to connect to LDAP server";
}
?>

This script generates the error somewhat like: Warning: LDAP: add operation could not be completed. in /home/leitet/public_html/Beta1/functions/func.inc.php on line 17

When I use a ldap_modify() call, it works, and the designated attribute I want to change is changed. But when I first use the function for updating the directory using ldap_modify() and then use the ldap_add() function, both fails giving: LDAP: modify operation could not be completed and LDAP: add operation could not be completed.

I have a "out of the box" php.ini. Have compiled LDAP support into php by using openldap, and connects to a Netscape Directory Server in order to try to update it..

The mentioned fuctions follows:

// Update number of entries
function update_number_of_entries($ds,$ldap_default_path)
{
  $data1 = "nsnumdomains";
  $aa="(objectClass=*)";
  $sr=ldap_read($ds, $ldap_default_path, $aa);
  $entry = ldap_first_entry($ds, $sr);
  $value = ldap_get_values($ds, $entry, $data1);
  $value[0]++;
  $data[nsnumdomains] = $value[0];
  ldap_modify($ds,$ldap_default_path,$data);
}

function insert_domain($ds,$domain,$ldap_default_path,$nrusers,$nrgroups)
{
  // making the domain
  $ldap_path = "o=$domain, $ldap_default_path";
  $data["objectclass"][0] = "top";
  $data["objectclass"][1] = "organization";
  $data["objectclass"][2] = "nsmanageddomain";
  $data["nsnumusers"] = "0";
  $data["nsnumdepts"] = "0";
  $data["owner"] = "cn=Domain Administrators, o=$domain, $ldap_default_path";
  $data["aci"][0] = "(targetattr=\"*\")(targetfilter=(objectclass=nsManagedDept))(version 3.0; acl \"Dept domain administration\"; allow (all) groupdn = \"ldap:///cn=Domain Administrators, o=$domain, $ldap_default_path\";)";
  $data["aci"][1] = "(targetattr=\"*\")(targetfilter=(objectclass=nsManagedDomain))(version 3.0; acl \"Domain help desk access\"; allow (read,search) groupdn = \"ldap:///cn=Help Desk Administrators, o=$domain, $ldap_default_path\";)";
  $data["aci"][2] = "(targetattr=\"*\")(targetfilter=(objectclass=nsManagedDomain))(version 3.0; acl \"Domain access by Dept. Administrator\"; allow (read,search) groupdn = \"ldap:///cn=Dept Administrators, o=$domain, $ldap_default_path\";)";
  $data["aci"][3] = "(targetattr=\"nsNumUsers\")(targetfilter=(objectclass=nsManagedDomain))(version 3.0; acl \"write nsNumUsers by Dept. Administrator\"; allow (write) group dn = \"ldap:///cn=Dept Administrators, o=$domain, $ldap_default_path\";)";
  $data["nsmaxdepts"] = "$nrgroups";
  $data["o"] = "$domain";
  $data["nsmaxusers"] = "$nrusers";
  $data["nsdefaultmaxdeptsize"] = "10";
  ldap_add($ds,$ldap_path,$data);
  echo "Making the domain on $ldap_path";
}

-- 
Edit Bug report at: http://bugs.php.net/?id=7228&edit=1

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>