【发布时间】:2013-04-09 09:31:10
【问题描述】:
我在对服务器执行经过身份验证的绑定时遇到问题。这些问题似乎不在代码中,但可能是服务器问题。
你知道的;
- 在 Apache/PHP 中启用了 LDAP
- 我以 user@domain.com 的身份连接
- 域控制器正在运行 LDAP,并且在防火墙中有一个条目 (Windows Server 2008 R2)
- 我可以执行匿名绑定
我可以使用这个脚本匿名绑定;
$ldapconn = ldap_connect("machinename.domain.com")
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding anonymously
$ldapbind = ldap_bind($ldapconn);
if ($ldapbind) {
echo "LDAP bind anonymous successful...";
} else {
echo "LDAP bind anonymous failed...";
}
}
但是,当我尝试使用此脚本进行经过身份验证的绑定时,它失败了。
// Authenticated Bind
$ldaprdn = 'username@domain.com'; // ldap rdn or dn
$ldappass = 'password'; // associated password
// connect to ldap server
$ldapconn = ldap_connect("machinename.domain.com")
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
echo "LDAP bind successful...";
} else {
echo "LDAP bind failed...";
}
}
我哪里错了?
【问题讨论】:
-
使用已知的好工具,例如
ldapsearch,在编写任何代码之前验证 bindDN 和 bindPassword。