From 624f5050b7256ed3b42007120a64bb65c184aa82 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 11:33:21 +0200 Subject: [PATCH] LdapConnection: Count properly in case the result may get unfolded refs #9772 --- .../Icinga/Protocol/Ldap/LdapConnection.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Protocol/Ldap/LdapConnection.php b/library/Icinga/Protocol/Ldap/LdapConnection.php index 089d9d765..712a74eb9 100644 --- a/library/Icinga/Protocol/Ldap/LdapConnection.php +++ b/library/Icinga/Protocol/Ldap/LdapConnection.php @@ -358,9 +358,25 @@ class LdapConnection implements Selectable, Inspectable */ public function count(LdapQuery $query) { - $ds = $this->getConnection(); $this->bind(); + if (($unfoldAttribute = $query->getUnfoldAttribute()) !== null) { + $desiredColumns = $query->getColumns(); + if (isset($desiredColumns[$unfoldAttribute])) { + $fields = array($unfoldAttribute => $desiredColumns[$unfoldAttribute]); + } elseif (in_array($unfoldAttribute, $desiredColumns, true)) { + $fields = array($unfoldAttribute); + } else { + throw new ProgrammingError( + 'The attribute used to unfold a query\'s result must be selected' + ); + } + + $res = $this->runQuery($query, $fields); + return count($res); + } + + $ds = $this->getConnection(); $results = @ldap_search( $ds, $query->getBase() ?: $this->getDn(),