]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/backglue.c
ITS#5186 check for multiple suffixes at config time, not open time
[openldap] / servers / slapd / backglue.c
index 56b2f08ae67f25a56df5c850abc66896e096e4e7..f91f1959101e4d608971b63d8cbeec49eca26477 100644 (file)
@@ -35,6 +35,7 @@
 
 #define SLAPD_TOOLS
 #include "slap.h"
+#include "config.h"
 
 typedef struct gluenode {
        BackendDB *gn_be;
@@ -160,6 +161,31 @@ glue_op_response ( Operation *op, SlapReply *rs )
                        if (!j) {
                                newctrls = ch_malloc((i+1)*sizeof(LDAPControl *));
                        } else {
+                               /* Forget old pagedResults response if we're sending
+                                * a new one now
+                                */
+                               if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
+                                       int newpage = 0;
+                                       for ( k=0; k<i; k++ ) {
+                                               if ( !strcmp(rs->sr_ctrls[k]->ldctl_oid,
+                                                       LDAP_CONTROL_PAGEDRESULTS )) {
+                                                       newpage = 1;
+                                                       break;
+                                               }
+                                       }
+                                       if ( newpage ) {
+                                               for ( k=0; k<j; k++ ) {
+                                                       if ( !strcmp(gs->ctrls[k]->ldctl_oid,
+                                                               LDAP_CONTROL_PAGEDRESULTS )) {
+                                                                       gs->ctrls[k]->ldctl_oid = NULL;
+                                                                       ldap_control_free( gs->ctrls[k] );
+                                                                       gs->ctrls[k] = gs->ctrls[--j];
+                                                                       gs->ctrls[j] = NULL;
+                                                                       break;
+                                                       }
+                                               }
+                                       }
+                               }
                                newctrls = ch_realloc(gs->ctrls,
                                        (j+i+1)*sizeof(LDAPControl *));
                        }
@@ -320,7 +346,7 @@ glue_op_search ( Operation *op, SlapReply *rs )
        slap_overinst   *on = (slap_overinst *)op->o_bd->bd_info;
        glueinfo                *gi = (glueinfo *)on->on_bi.bi_private;
        BackendDB *b0 = op->o_bd;
-       BackendDB *b1 = NULL, *btmp;
+       BackendDB *btmp;
        BackendInfo *bi0 = op->o_bd->bd_info;
        int i;
        long stoptime = 0, starttime;
@@ -359,7 +385,6 @@ glue_op_search ( Operation *op, SlapReply *rs )
                tlimit0 = op->ors_tlimit;
                dn = op->o_req_dn;
                ndn = op->o_req_ndn;
-               b1 = op->o_bd;
 
                /*
                 * Execute in reverse order, most specific first 
@@ -374,9 +399,16 @@ glue_op_search ( Operation *op, SlapReply *rs )
                        }
                        if (!btmp || !btmp->be_search)
                                continue;
-                       if (!dnIsSuffix(&btmp->be_nsuffix[0], &b1->be_nsuffix[0]))
+                       if (!dnIsSuffix(&btmp->be_nsuffix[0], &b0->be_nsuffix[0]))
+                               continue;
+                       if (get_no_subordinate_glue(op) && btmp != b0)
                                continue;
-                       if (get_no_subordinate_glue(op) && btmp != b1)
+                       /* If we remembered which backend we were on before,
+                        * skip down to it now
+                        */
+                       if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED &&
+                               op->o_conn->c_pagedresults_state.ps_be &&
+                               op->o_conn->c_pagedresults_state.ps_be != btmp )
                                continue;
 
                        if (tlimit0 != SLAP_NO_LIMIT) {
@@ -448,7 +480,41 @@ glue_op_search ( Operation *op, SlapReply *rs )
                        case LDAP_X_CANNOT_CHAIN:
 #endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
                                goto end_of_loop;
-                       
+
+                       case LDAP_SUCCESS:
+                               if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
+                                       PagedResultsState *ps = op->o_pagedresults_state;
+
+                                       /* Assume this backend can be forgotten now */
+                                       op->o_conn->c_pagedresults_state.ps_be = NULL;
+
+                                       /* If we have a full page, exit the loop. We may
+                                        * need to remember this backend so we can continue
+                                        * from here on a subsequent request.
+                                        */
+                                       if ( rs->sr_nentries >= ps->ps_size ) {
+                                               /* Don't bother to remember the first backend.
+                                                * Only remember the last one if there's more state left.
+                                                */
+                                               if ( op->o_bd != b0 &&
+                                                       ( op->o_conn->c_pagedresults_state.ps_cookie ||
+                                                       op->o_bd != gi->gi_n[0].gn_be ))
+                                                       op->o_conn->c_pagedresults_state.ps_be = op->o_bd;
+                                               goto end_of_loop;
+                                       }
+
+                                       /* This backend has run out of entries, but more responses
+                                        * can fit in the page. Fake a reset of the state so the
+                                        * next backend will start up properly. Only back-[bh]db
+                                        * and back-sql look at this state info.
+                                        */
+                                       if ( ps->ps_cookieval.bv_len == sizeof( PagedResultsCookie )) {
+                                               ps->ps_cookie = 0;
+                                               memset( ps->ps_cookieval.bv_val, 0,
+                                                       sizeof( PagedResultsCookie ));
+                                       }
+                               }
+                               
                        default:
                                break;
                        }
@@ -583,7 +649,7 @@ glue_open (
                                        gi->gi_n[i].gn_be->bd_info );
                        /* Let backend.c take care of the rest of startup */
                        if ( !rc )
-                               rc = backend_startup_one( gi->gi_n[i].gn_be );
+                               rc = backend_startup_one( gi->gi_n[i].gn_be, NULL );
                        if ( rc ) break;
                }
                if ( !rc && !bsame && on->on_info->oi_orig->bi_open )
@@ -621,9 +687,9 @@ glue_entry_get_rw (
        int     rw,
        Entry   **e )
 {
+       int rc;
        BackendDB *b0 = op->o_bd;
        op->o_bd = glue_back_select( b0, dn );
-       int rc;
 
        if ( op->o_bd->be_fetch ) {
                rc = op->o_bd->be_fetch( op, dn, oc, ad, rw, e );
@@ -816,7 +882,8 @@ glue_tool_sync (
 
 static int
 glue_db_init(
-       BackendDB *be
+       BackendDB *be,
+       ConfigReply *cr
 )
 {
        slap_overinst   *on = (slap_overinst *)be->bd_info;
@@ -861,7 +928,6 @@ glue_db_init(
 
        /*FIXME : need to add support */
        oi->oi_bi.bi_tool_dn2id_get = 0;
-       oi->oi_bi.bi_tool_id2entry_get = 0;
        oi->oi_bi.bi_tool_entry_modify = 0;
 
        SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_GLUE_INSTANCE;
@@ -871,7 +937,8 @@ glue_db_init(
 
 static int
 glue_db_destroy (
-       BackendDB *be
+       BackendDB *be,
+       ConfigReply *cr
 )
 {
        slap_overinst   *on = (slap_overinst *)be->bd_info;
@@ -883,7 +950,8 @@ glue_db_destroy (
 
 static int
 glue_db_close( 
-       BackendDB *be
+       BackendDB *be,
+       ConfigReply *cr
 )
 {
        slap_overinst   *on = (slap_overinst *)be->bd_info;