From ef82e8471b3bc171ae99ffd753937b55aa0e6e2f Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@redhat.com>
Date: Tue, 26 May 2015 10:41:03 -0700
Subject: [PATCH 68/72] Ticket #48146 - async simple paged results issue
Description: commit 5060d11f5039efa8534a8b65392ac6e10cbd2168 introduced
a regression. Handling backend "be" should be done after checking OID
MTN_CONTROL_USE_ONE_BACKEND_EXT_OID in the request control.
https://fedorahosted.org/389/ticket/48146
Reviewed by mreynolds@redhat.com (Thank you, Mark!!)
(cherry picked from commit bd2c0d0b6a499d7f91a36e8a9feb83e4fbd3dac5)
(cherry picked from commit 0c7b38abfb4c5c02286efd5e698616534a798993)
---
ldap/servers/slapd/opshared.c | 108 ++++++++++++++++++++++--------------------
1 file changed, 57 insertions(+), 51 deletions(-)
diff --git a/ldap/servers/slapd/opshared.c b/ldap/servers/slapd/opshared.c
index 430b0c6..ff67a9b 100644
--- a/ldap/servers/slapd/opshared.c
+++ b/ldap/servers/slapd/opshared.c
@@ -408,57 +408,12 @@ op_shared_search (Slapi_PBlock *pb, int send_result)
*/
operation_set_target_spec (pb->pb_op, basesdn);
- if (be_name == NULL)
- {
- /* no specific backend was requested, use the mapping tree
- */
- err_code = slapi_mapping_tree_select_all(pb, be_list, referral_list, errorbuf);
- if (((err_code != LDAP_SUCCESS) && (err_code != LDAP_OPERATIONS_ERROR) && (err_code != LDAP_REFERRAL))
- || ((err_code == LDAP_OPERATIONS_ERROR) && (be_list[0] == NULL)))
- {
- send_ldap_result(pb, err_code, NULL, errorbuf, 0, NULL);
- rc = -1;
- goto free_and_return;
- }
- if (be_list[0] != NULL)
- {
- index = 0;
- if (pr_be) { /* PAGED RESULT: be is found from the previous paging. */
- /* move the index in the be_list which matches pr_be */
- while (be_list[index] && be_list[index+1] && pr_be != be_list[index])
- index++;
- } else {
- while (be_list[index] && be_list[index+1])
- index++;
- }
- /* "be" is either pr_be or the last backend */
- be = be_list[index];
- }
- else
- be = pr_be?pr_be:NULL;
- }
- else
- {
- /* specific backend be_name was requested, use slapi_be_select_by_instance_name
- */
- if (pr_be) {
- be_single = be = pr_be;
- } else {
- be_single = be = slapi_be_select_by_instance_name(be_name);
- }
- if (be_single)
- slapi_be_Rlock(be_single);
- be_list[0] = NULL;
- referral_list[0] = NULL;
- referral = NULL;
- }
-
- /* this is time to check if mapping tree specific control
- * was used to specify that we want to parse only
- * one backend
+ /*
+ * this is time to check if mapping tree specific control was used to
+ * specify that we want to parse only one backend.
*/
slapi_pblock_get(pb, SLAPI_REQCONTROLS, &ctrlp);
- if (NULL != ctrlp)
+ if (ctrlp)
{
if (slapi_control_present(ctrlp, MTN_CONTROL_USE_ONE_BACKEND_EXT_OID,
&ctl_value, &iscritical))
@@ -513,7 +468,57 @@ op_shared_search (Slapi_PBlock *pb, int send_result)
}
}
}
+ }
+
+ if (be_name == NULL)
+ {
+ /* no specific backend was requested, use the mapping tree
+ */
+ err_code = slapi_mapping_tree_select_all(pb, be_list, referral_list, errorbuf);
+ if (((err_code != LDAP_SUCCESS) && (err_code != LDAP_OPERATIONS_ERROR) && (err_code != LDAP_REFERRAL))
+ || ((err_code == LDAP_OPERATIONS_ERROR) && (be_list[0] == NULL)))
+ {
+ send_ldap_result(pb, err_code, NULL, errorbuf, 0, NULL);
+ rc = -1;
+ goto free_and_return;
+ }
+ if (be_list[0] != NULL)
+ {
+ index = 0;
+ if (pr_be) { /* PAGED RESULT: be is found from the previous paging. */
+ /* move the index in the be_list which matches pr_be */
+ while (be_list[index] && be_list[index+1] && pr_be != be_list[index])
+ index++;
+ } else {
+ while (be_list[index] && be_list[index+1])
+ index++;
+ }
+ /* "be" is either pr_be or the last backend */
+ be = be_list[index];
+ }
+ else
+ be = pr_be?pr_be:NULL;
+ }
+ else
+ {
+ /* specific backend be_name was requested, use slapi_be_select_by_instance_name
+ */
+ if (pr_be) {
+ be_single = be = pr_be;
+ } else {
+ be_single = be = slapi_be_select_by_instance_name(be_name);
+ }
+ if (be_single) {
+ slapi_be_Rlock(be_single);
+ }
+ be_list[0] = NULL;
+ referral_list[0] = NULL;
+ referral = NULL;
+ }
+ /* Handle the rest of the controls. */
+ if (ctrlp)
+ {
if ( slapi_control_present (ctrlp, LDAP_CONTROL_GET_EFFECTIVE_RIGHTS,
&ctl_value, &iscritical) )
{
@@ -1024,10 +1029,11 @@ next_be:
}
free_and_return:
- if ((be_list[0] != NULL) || (referral_list[0] != NULL))
+ if ((be_list[0] != NULL) || (referral_list[0] != NULL)) {
slapi_mapping_tree_free_all(be_list, referral_list);
- else if (be_single)
+ } else if (be_single) {
slapi_be_Unlock(be_single);
+ }
free_and_return_nolock:
slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, &rc);
--
1.9.3