From fa25ce7f2f31af03d86c3c6a049785d88c2e746d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 3 Sep 2015 17:50:24 +0200 Subject: [PATCH] lib/ldap: Set server side sorting after calling ldap_control_paged_result() ldap_control_paged_result() seems to override already set server controls. refs #9364 --- .../Icinga/Protocol/Ldap/LdapConnection.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/library/Icinga/Protocol/Ldap/LdapConnection.php b/library/Icinga/Protocol/Ldap/LdapConnection.php index 32f8b1cea..5f1a7b728 100644 --- a/library/Icinga/Protocol/Ldap/LdapConnection.php +++ b/library/Icinga/Protocol/Ldap/LdapConnection.php @@ -742,14 +742,7 @@ class LdapConnection implements Selectable, Inspectable $ds = $this->getConnection(); $serverSorting = $this->capabilities->hasOid(LdapCapabilities::LDAP_SERVER_SORT_OID); - if ($serverSorting && $query->hasOrder()) { - ldap_set_option($ds, LDAP_OPT_SERVER_CONTROLS, array( - array( - 'oid' => LdapCapabilities::LDAP_SERVER_SORT_OID, - 'value' => $this->encodeSortRules($query->getOrder()) - ) - )); - } elseif ($query->hasOrder()) { + if (! $serverSorting && $query->hasOrder()) { foreach ($query->getOrder() as $rule) { if (! in_array($rule[0], $fields)) { $fields[] = $rule[0]; @@ -765,6 +758,15 @@ class LdapConnection implements Selectable, Inspectable // server to return results even if the paged search request cannot be satisfied ldap_control_paged_result($ds, $pageSize, false, $cookie); + if ($serverSorting) { + ldap_set_option($ds, LDAP_OPT_SERVER_CONTROLS, array( + array( + 'oid' => LdapCapabilities::LDAP_SERVER_SORT_OID, + 'value' => $this->encodeSortRules($query->getOrder()) + ) + )); + } + $results = @ldap_search( $ds, $base,