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,