我尝试通过php ldap Active-Directory为Microsoft Server 2008 R2数据中心添加用户,但我不能。我总是得到这个错误:
An error occurred. Error number 64: Naming violation
代码是:
<?php
$ldaprdn = 'administrador@correo.mx';
$ldappass = 'dir378prob@';
$ds = 'correo.mx';
$dn = 'ou=usuarios,dc=correo,dc=mx';
$puertoldap = 389;
$ldapconn = ldap_connect($ds,$puertoldap)or die("ERROR: I Don'n connect to LDAP.");
if ($ldapconn)
{
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);
$con = ldap_bind($ldapconn, $ldaprdn, $ldappass);
if ($con)
{
$info["cn"] = $_POST['cn'];
$info["sn"] = $_POST['sn'];
$info["mail"] = $_POST['mail'];
$info["objectclass"] = "inetorgperson";
// prepare DN for new entry
$dn_aux = "mail=" . $_POST['mail'] . ",ou=usuarios,dc=correo,dc=mx";
$result = ldap_add($ldapconn, $dn_aux, $info);
if($result)
{
echo "New entry with DN " . $dn . " added to LDAP directory.";
}
// else display error
else
{
echo "An error occurred. Error number " . ldap_errno($conn) . ": " .
ldap_err2str(ldap_errno($conn));
}
}
else
{
echo "LDAP bind error...";
}
}
ldap_close($ldapconn);
?>
我正在迈出这个ldap的第一步,所以请你详细解释一下。
答案 0 :(得分:1)
不确定正确的PHP语法,但以下行:
$dn_aux = "mail=" . $_POST['mail'] . ",ou=usuarios,dc=correo,dc=mx";
关于Active-Directory不正确。解释是,在这样的目录中,您无法选择用于命名对象的属性。例如,'InetOrgPerson'对象必须使用CN属性来命名它。有关详细信息,请阅读Microsoft文档中object naming中的carefuly命名属性。
尝试:
dn_aux = "CN=" . $_POST['cn'] . ",ou=usuarios,dc=correo,dc=mx";