在某些情况下,ldap_get_entries 返回元素计数为零的数组,所以我有一个像 array('count'=>0) 这样的数组,没有任何进一步的条目。
发生这种情况的条件是什么?
PS:
- 如果我正在搜索的 OU 为空,我会收到另一个错误(无效的基本 DN)
- 如果用户没有对 OU 的权限,我会收到与上述相同的错误
编辑:
- PHP 代码无关紧要,因为我可以用它进行各种搜索,而上述问题仅发生在一些奇怪的 Active Directory 配置中
- 如果你还坚持...
$entries = ldap_get_entries($this->ldap_connection, $search_result);
- ldap_get_entries 在大多数情况下返回我期望它返回的正确错误
因此,为了重申我的问题,ldap_get_entries 返回 count=0 且没有任何错误的数组的条件是什么。我的意思是:
- Active Directory 权利和权限
- 用户权限
- OU 权限(又名安全选项卡)
- 有关何时发生这种情况的任何 PHP 相关信息
谢谢
EDIT2 - 根据要求,这是其余的代码:
public function connect() {
// connect to the server
$this->ldap_connection = ldap_connect($this->ldap_server);
if (!$this->ldap_connection){
$error_message= "LDAP-Connect-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
// set protocol version
if (!ldap_set_option($this->ldap_connection, LDAP_OPT_PROTOCOL_VERSION, $this->ldap_protocol_version)){
$error_message= "LDAP-SetProtocolVersion-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
// set with/without referrals (limit/do not limit search on current server)
if (!ldap_set_option($this->ldap_connection, LDAP_OPT_REFERRALS, $this->ldap_protocol_referrals)){
$error_message= "LDAP-SetReferrals-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
// binding to ldap server
if (!@ldap_bind($this->ldap_connection, $this->ldap_auth_rdn, $this->ldap_auth_pass)){
$error_message= "LDAP-Bind-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
}
public function search($filter,$fields){
if (!$this->ldap_connection) {
$this->connect();
}
// search the ldap
$search_result = @ldap_search($this->ldap_connection, $this->ldap_base_distinguished_name, $filter,$fields);
if ($search_result===false){
$error_message= "LDAP-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
//Create result set
$entries = ldap_get_entries($this->ldap_connection, $search_result);
if ($entries === false ){
$error_message= "LDAP-Error: " . ldap_error($this->ldap_connection) . ".";
throw new RuntimeErrorException($error_message);
}
return (is_null($entries) ? array() : $entries); // http://bugs.php.net/48469
}