我想在OpenLDAP中添加新用户,并编写以下方法来创建新用户。调用此方法时,我必须传递以下变量:
$ldapconn
:由ldap_connect返回。$username
:我要创建的用户名。$password
:登录帐户的密码。public static function createNewUser($ldapconn, $username, $password) {
if (!$ldapconn) { return false; }
require_once("LDAPConfigurator.php");
$r = ldap_bind($ldapconn, "cn=admin,dc=test,dc=com", "12345X");
// Prepare data
$info["cn"]="John Jones";
$info["sn"]="Jones";
$info["mail"]="[email protected]";
$info["objectclass"]="person";
// Add data to directory
$r = ldap_add($ldapconn, "cn=John Jones,dc=test,dc=com", $info);
return true;
}
LDAP连接$ldapconn
将在此方法之外关闭。
准备的数据从本文档复制而来。
我希望它可以在phpLDAPadmin中的“ dc = test,dc = com”下显示给我一个新孩子。但是最终结果什么也没出现,向我展示了:
Warning: ldap_add(): Add: Object class violation in /var/www/html/test.php on line 23
我想问一下如何解决问题(Object class violation
)?
“ inetOrgPerson”是inetorgperson.schema定义的OpenLDAP中人员条目的默认对象类。所以你需要做
$info["objectclass"]="inetOrgPerson";
如果要使用“ person”之类的自定义对象类,则需要在架构中扩展inetOrgPerson。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句