4

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'] = "lkl@fh.com";
  $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?

shadyyx
  • 15,825
  • 6
  • 60
  • 95
Roshan Wijesena
  • 3,106
  • 8
  • 38
  • 57
  • 1
    Please, provide some code. This error could raise when You try to set some properties to the object that is not a member of class with the properties being set... In LDAP your object has to be memberOf the class that has this properties implemented. – shadyyx Apr 20 '11 at 10:06
  • Thanks for your reply i modified the my post please see it – Roshan Wijesena Apr 20 '11 at 10:15

1 Answers1

7

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'] = "lkl@fh.com";
$ldaprecord['mmmm'] = "77878";
shadyyx
  • 15,825
  • 6
  • 60
  • 95
  • its not a problem problem is when i add $ldaprecord['mmmm'] = "77878"; this code line error is coming how could i add additional attribute like that – Roshan Wijesena Apr 20 '11 at 10:25
  • 1
    OK, so this could be because this property is not implemented in any class in LDAP... Try to use some existing property of inetOrgPerson... try to look here: http://oav.net/mirrors/LDAP-ObjectClasses.html – shadyyx Apr 20 '11 at 10:38
  • thank for the reply is there any posibity to create my own attribute the inetOrgPerson class – Roshan Wijesena Apr 20 '11 at 10:45
  • 1
    Maybe after reading this: https://www.opends.org/wiki/page/HowToExtendTheLDAPSchema#section-HowToExtendTheLDAPSchema-ManagingObjectClasses You should be able to create Your own objectclass (e.g. extending from inetOrgPerson) that will have custom properties... – shadyyx Apr 20 '11 at 10:52
  • again have problem with opends now i would like to save unicode in the opends directory its can saved but when i fetch the results unicode characters are not displaying as it is – Roshan Wijesena Apr 20 '11 at 12:34