我正在尝试使用 PHP (5.3.2)/Apache (2.0.59)/Windows (2003) 对 Active Directory 进行身份验证。
但是,我收到以下错误:
ldap_start_tls() [function.ldap-start-tls]:无法启动 TLS:第 15 行 E:\my_page.php 中的连接错误
这是我当前的脚本:
putenv('LDAPTLS_REQCERT=never');
$resource = ldap_connect("xxx")
or die("Failed to connect to LDAP server.");
echo "Connected to LDAP server.<br />";
//these options may not be necessary in all environments
ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($resource, LDAP_OPT_REFERRALS, 0);
$result = ldap_start_tls($resource) or die("Failed to start TLS.<br />");
echo "Started TLS.<br />";
$result = ldap_sasl_bind($resource, NULL, '', 'GSSAPI', 'xxx', '', '')
or die("Failed to GSSAPI bind.<br />");
echo "GSSAPI bound.";
我已经查看了这个问题以寻求帮助,但是,我一直看到对 ldap.conf 的引用。
这是您连接到的 LDAP 服务器中的 OpenLDAP 吗?如果是,由于使用现有的企业 Active Directory,我可以忽略它吗?
或者这适用于连接到 LDAP 服务器的 PHP 库(即 ldap_connect())?
编辑#1
Wireshark的截图...
我在那里看到,未知的 CA ......我将如何解决这个问题(寻找在线 ATM)。
编辑#2
更新,我现在得到一个不同的错误。我在 c:\ 和 c:\openldap\sysconf 上创建了 ldap.conf
ldap.conf 的内容:
#
# LDAP Defaults
#
TLS_REQCERT never
现在,它卡在了正常的 ldap_sasl_bind 方法 - 它没有安装。
编辑#3
完成品:
function isAuthenticated($user, $pass){
//init
$ldap_server = "";
$ldap_user = "";
$ldap_pass = "";
$ldap_dn = "";
$ldap_filter_fields = array("dn","cn","samaccountname");
//establish connection
$ldap_conn = ldap_connect($ldap_server)
or die("Failed to connect to LDAP server.");
//these options may not be necessary in all environments
ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($resource, LDAP_OPT_REFERRALS, 0);
//Magic happens here, encrypted tunnel starts!
$result = ldap_start_tls($ldap_conn) or die("Failed to start TLS.<br />");
$out = 0;
//connect using our known user
if($bind = ldap_bind($ldap_conn, $ldap_user, $ldap_pass)){
//search for the user
$ldap_search_results = ldap_search($ldap_conn, $ldap_dn, "samaccountname=".$user, $ldap_filter_fields) or die ("Failed to search LDAP");
//get entry
$ldap_record = ldap_get_entries($ldap_conn, $ldap_search_results);
debug($ldap_record);
if($ldap_record["count"] > 0){
//try to authenticate user here
if($bind2 = @ldap_bind($ldap_conn, $ldap_record[0]["dn"], $pass))
$out = 1;
else
//wrong password
$out = 0;
}
else
//user wasn't found
$out = 3;
}
else
//something happened when connecting with our ldap_user
$out = 2;
return $out;
}