From d720180348380aa5cf31088feeb0328081530356 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 11:41:21 +0200 Subject: [PATCH] LdapConnection: Properly apply limit and offset for unfolded queries refs #9772 --- .../Icinga/Protocol/Ldap/LdapConnection.php | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/library/Icinga/Protocol/Ldap/LdapConnection.php b/library/Icinga/Protocol/Ldap/LdapConnection.php index 5e05c960b..05d8b1032 100644 --- a/library/Icinga/Protocol/Ldap/LdapConnection.php +++ b/library/Icinga/Protocol/Ldap/LdapConnection.php @@ -727,23 +727,21 @@ class LdapConnection implements Selectable, Inspectable $count = 0; $entries = array(); $entry = ldap_first_entry($ds, $results); + $unfoldAttribute = $query->getUnfoldAttribute(); do { - $count += 1; - if (! $serverSorting || $offset === 0 || $offset < $count) { - $row = $this->cleanupAttributes( + if ($unfoldAttribute) { + $rows = $this->cleanupAttributes( ldap_get_attributes($ds, $entry), array_flip($fields), - $query->getUnfoldAttribute() + $unfoldAttribute ); - if (is_array($row)) { + if (is_array($rows)) { // TODO: Register the DN the same way as a section name in the ArrayDatasource! - - $count -= 1; - foreach ($row as $additionalRow) { + foreach ($rows as $row) { $count += 1; if (! $serverSorting || $offset === 0 || $offset < $count) { - $entries[] = $additionalRow; + $entries[] = $row; } if ($serverSorting && $limit > 0 && $limit === count($entries)) { @@ -751,7 +749,18 @@ class LdapConnection implements Selectable, Inspectable } } } else { - $entries[ldap_get_dn($ds, $entry)] = $row; + $count += 1; + if (! $serverSorting || $offset === 0 || $offset < $count) { + $entries[ldap_get_dn($ds, $entry)] = $rows; + } + } + } else { + $count += 1; + if (! $serverSorting || $offset === 0 || $offset < $count) { + $entries[ldap_get_dn($ds, $entry)] = $this->cleanupAttributes( + ldap_get_attributes($ds, $entry), + array_flip($fields) + ); } } } while ((! $serverSorting || $limit === 0 || $limit !== count($entries)) @@ -811,6 +820,7 @@ class LdapConnection implements Selectable, Inspectable $count = 0; $cookie = ''; $entries = array(); + $unfoldAttribute = $query->getUnfoldAttribute(); do { // Do not request the pagination control as a critical extension, as we want the // server to return results even if the paged search request cannot be satisfied @@ -861,22 +871,19 @@ class LdapConnection implements Selectable, Inspectable $entry = ldap_first_entry($ds, $results); do { - $count += 1; - if (! $serverSorting || $offset === 0 || $offset < $count) { - $row = $this->cleanupAttributes( + if ($unfoldAttribute) { + $rows = $this->cleanupAttributes( ldap_get_attributes($ds, $entry), array_flip($fields), - $query->getUnfoldAttribute() + $unfoldAttribute ); - if (is_array($row)) { + if (is_array($rows)) { // TODO: Register the DN the same way as a section name in the ArrayDatasource! - - $count -= 1; - foreach ($row as $additionalRow) { + foreach ($rows as $row) { $count += 1; if (! $serverSorting || $offset === 0 || $offset < $count) { - $entries[] = $additionalRow; + $entries[] = $row; } if ($serverSorting && $limit > 0 && $limit === count($entries)) { @@ -884,7 +891,18 @@ class LdapConnection implements Selectable, Inspectable } } } else { - $entries[ldap_get_dn($ds, $entry)] = $row; + $count += 1; + if (! $serverSorting || $offset === 0 || $offset < $count) { + $entries[ldap_get_dn($ds, $entry)] = $rows; + } + } + } else { + $count += 1; + if (! $serverSorting || $offset === 0 || $offset < $count) { + $entries[ldap_get_dn($ds, $entry)] = $this->cleanupAttributes( + ldap_get_attributes($ds, $entry), + array_flip($fields) + ); } } } while (