状況によっては、ldap_get_entries は要素 count=zero の配列を返すため、それ以上のエントリがない 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 がエラーなしでカウント = 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
}