From 9b22b245619b804f3e3543029f09cea0dc5b716f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 4 Sep 2015 09:57:04 +0200 Subject: [PATCH] lib/ldap: Use ldap_count_entries for counting the result set --- .../Icinga/Protocol/Ldap/LdapConnection.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Protocol/Ldap/LdapConnection.php b/library/Icinga/Protocol/Ldap/LdapConnection.php index 5f1a7b728..3d30f9852 100644 --- a/library/Icinga/Protocol/Ldap/LdapConnection.php +++ b/library/Icinga/Protocol/Ldap/LdapConnection.php @@ -358,10 +358,30 @@ class LdapConnection implements Selectable, Inspectable */ public function count(LdapQuery $query) { + $ds = $this->getConnection(); $this->bind(); - $res = $this->runQuery($query, array()); - return count($res); + $results = @ldap_search( + $ds, + $query->getBase() ?: $this->getDn(), + (string) $query, + array('dn'), + 0, + 0 + ); + + if ($results === false) { + if (ldap_errno($ds) !== self::LDAP_NO_SUCH_OBJECT) { + throw new LdapException( + 'LDAP count query "%s" (base %s) failed: %s', + (string) $query, + $query->getBase() ?: $this->getDn(), + ldap_error($ds) + ); + } + } + + return ldap_count_entries($ds, $results); } /**