Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

php - ldap_add(): Add: Object class violation error

When I try to add attribute to the OpenDS via PHP I get the following error:

ldap_add(): Add: Object class violation

Please help.

Here is my code

<?php
$ldapconfig['host'] = 'PC100';
$ldapconfig['port'] = 1389;
$ldapconfig['basedn'] = 'dc=company,dc=com';

$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);

$password=1;
$username="cn=Directory Manager";

if ($bind=ldap_bind($ds, $username, $password)) {
  echo("Login correct");
  ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); // IMPORTANT
  $dn = "cn=roshan1,dc=example,dc=com"; 
  //$newuser["objectclass"] = "inetOrgPerson"; 
  //$newuser["cn"] = "new1"; 
  //$newuser["sn"] = "user"; 

  $ldaprecord['cn'] = "roshan1";
  $ldaprecord['givenName'] = "mkljl";
  $ldaprecord['sn'] = "roshan";
  $ldaprecord['objectclass'] = "inetOrgPerson";    
  $ldaprecord['mail'] = "[email protected]";
  $ldaprecord['mmmm'] = "77878";

  // add data to directory
  $r = ldap_add($ds, $dn, $ldaprecord);

} else {

  echo("Unable to bind to server.</br>");

}
?>

If I remove $ldaprecord['mmmm'] = "77878"; from the code it works fine. How can I add a new attribute like this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Hmm, it looks like You are trying only to set objectclass to inetOrgPerson, but You have to set also other upper classes from which inetorgPerson is extending - that would be top and person maybe...

So:

$ldaprecord['cn'] = "roshan1";
$ldaprecord['givenName'] = "mkljl";
$ldaprecord['sn'] = "roshan";
$ldaprecord['objectclass'][0] = "top";
$ldaprecord['objectclass'][1] = "person";
$ldaprecord['objectclass'][2] = "inetOrgPerson";
$ldaprecord['mail'] = "[email protected]";
$ldaprecord['mmmm'] = "77878";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...