4

当我尝试通过 PHP 向 OpenDS 添加属性时,出现以下错误:

ldap_add():添加:对象类违规

请帮忙。

这是我的代码

<?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>");

}
?>

如果我$ldaprecord['mmmm'] = "77878";从代码中删除它工作正常。如何添加这样的新属性?

4

1 回答 1

7

嗯,看起来你只是想设置objectclassinetOrgPerson,但你还必须设置其他inetorgPerson正在扩展的上层类——那可能topperson……

所以:

$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";
于 2011-04-20T10:21:25.790 回答