我正嘗試使用PHP(5.3.2)/ Apache(2.0.59)/ Windows(2003)對Active Directory進行身份驗證。當我使用PHP連接到Active Directory時,是否需要ldap.conf?
不過,我發現了以下錯誤:
ldap_start_tls()[function.ldap啓動-TLS]:無法啓動TLS:在E連接錯誤:\ my_page.php第15行
這裏是我當前的腳本:
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.";
我已經看了this question for help,但是,我總是看到到ldap.conf的引用。
這是否用於OpenLDAP中,您連接的LDAP服務器?如果是這樣,我可以忽略它由於使用現有的企業Active Directory?
或者這是爲連接到LDAP服務器(即ldap_connect())的PHP庫嗎?
編輯#1
Wireshark的截圖...
我在那裏看到的,未知的CA ...我將如何去解決這個(在線看ATM)。
編輯#2
更新,我現在得到一個不同的錯誤。我創建了基於C的ldap.conf:\和C:\ OpenLDAP的\的sysconf
內容的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;
}
發佈更多信息,例如,如果您的LDAP客戶端嘗試促進與TLS的連接,可以獲取更多信息(例如,來自A/D的日誌)。 –
@TerryGardner查看我的編輯。我已經包含了Wireshark的屏幕截圖。似乎我有一個未知的CA? – TekiusFanatikus