]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/backglue.c
Additional fix for ITS#4522. The "dn=" ist not optional.
[openldap] / servers / slapd / backglue.c
index 69b63f66949c4f737e56aee28c84dd6b3b8511b4..202c63cd9d882ec212ec6b39bd2c1b56a4f50c79 100644 (file)
@@ -78,11 +78,13 @@ glue_back_select (
 
 
 typedef struct glue_state {
+       char *matched;
+       BerVarray refs;
+       LDAPControl **ctrls;
        int err;
        int matchlen;
-       char *matched;
        int nrefs;
-       BerVarray refs;
+       int nctrls;
 } glue_state;
 
 static int
@@ -139,6 +141,30 @@ glue_op_response ( Operation *op, SlapReply *rs )
                        gs->nrefs = j;
                        gs->refs = new;
                }
+               if (rs->sr_ctrls) {
+                       int i, j, k;
+                       LDAPControl **newctrls;
+
+                       for (i=0; rs->sr_ctrls[i]; i++);
+
+                       j = gs->nctrls;
+                       if (!j) {
+                               newctrls = ch_malloc((i+1)*sizeof(LDAPControl *));
+                       } else {
+                               newctrls = ch_realloc(gs->ctrls,
+                                       (j+i+1)*sizeof(LDAPControl *));
+                       }
+                       for (k=0; k<i; j++,k++) {
+                               newctrls[j] = ch_malloc(sizeof(LDAPControl));
+                               *newctrls[j] = *rs->sr_ctrls[k];
+                               if ( !BER_BVISNULL( &rs->sr_ctrls[k]->ldctl_value ))
+                                       ber_dupbv( &newctrls[j]->ldctl_value,
+                                               &rs->sr_ctrls[k]->ldctl_value );
+                       }
+                       newctrls[j] = NULL;
+                       gs->nctrls = j;
+                       gs->ctrls = newctrls;
+               }
        }
        return 0;
 }
@@ -243,12 +269,14 @@ glue_sub_search( Operation *op, SlapReply *rs, BackendDB *b0,
        /* Process any overlays on the master backend */
        if ( op->o_bd == b0 && on->on_next ) {
                BackendInfo *bi = op->o_bd->bd_info;
-               int rc;
+               int rc = SLAP_CB_CONTINUE;
                for ( on=on->on_next; on; on=on->on_next ) {
                        op->o_bd->bd_info = (BackendInfo *)on;
-                       rc = on->on_bi.bi_op_search( op, rs );
-                       if ( rc != SLAP_CB_CONTINUE )
-                               break;
+                       if ( on->on_bi.bi_op_search ) {
+                               rc = on->on_bi.bi_op_search( op, rs );
+                               if ( rc != SLAP_CB_CONTINUE )
+                                       break;
+                       }
                }
                op->o_bd->bd_info = bi;
                if ( rc != SLAP_CB_CONTINUE )
@@ -266,8 +294,8 @@ glue_op_search ( Operation *op, SlapReply *rs )
        BackendDB *b1 = NULL, *btmp;
        BackendInfo *bi0 = op->o_bd->bd_info;
        int i;
-       long stoptime = 0;
-       glue_state gs = {0, 0, NULL, 0, NULL};
+       long stoptime = 0, starttime;
+       glue_state gs = {NULL, NULL, NULL, 0, 0, 0, 0};
        slap_callback cb = { NULL, glue_op_response, NULL, NULL };
        int scope0, tlimit0;
        struct berval dn, ndn, *pdn;
@@ -276,6 +304,7 @@ glue_op_search ( Operation *op, SlapReply *rs )
 
        cb.sc_next = op->o_callback;
 
+       starttime = op->o_time;
        stoptime = slap_get_time () + op->ors_tlimit;
 
        op->o_bd = glue_back_select (b0, &op->o_req_ndn);
@@ -319,7 +348,8 @@ glue_op_search ( Operation *op, SlapReply *rs )
                        if (!dnIsSuffix(&btmp->be_nsuffix[0], &b1->be_nsuffix[0]))
                                continue;
                        if (tlimit0 != SLAP_NO_LIMIT) {
-                               op->ors_tlimit = stoptime - slap_get_time ();
+                               op->o_time = slap_get_time();
+                               op->ors_tlimit = stoptime - op->o_time;
                                if (op->ors_tlimit <= 0) {
                                        rs->sr_err = gs.err = LDAP_TIMELIMIT_EXCEEDED;
                                        break;
@@ -391,6 +421,7 @@ glue_op_search ( Operation *op, SlapReply *rs )
 end_of_loop:;
                op->ors_scope = scope0;
                op->ors_tlimit = tlimit0;
+               op->o_time = starttime;
                op->o_req_dn = dn;
                op->o_req_ndn = ndn;
 
@@ -403,6 +434,7 @@ end_of_loop:;
                rs->sr_err = gs.err;
                rs->sr_matched = gs.matched;
                rs->sr_ref = gs.refs;
+               rs->sr_ctrls = gs.ctrls;
 
                send_ldap_result( op, rs );
        }
@@ -413,6 +445,14 @@ end_of_loop:;
                free (gs.matched);
        if (gs.refs)
                ber_bvarray_free(gs.refs);
+       if (gs.ctrls) {
+               for (i = gs.nctrls; --i >= 0; ) {
+                       if (!BER_BVISNULL( &gs.ctrls[i]->ldctl_value ))
+                               free(gs.ctrls[i]->ldctl_value.bv_val);
+                       free(gs.ctrls[i]);
+               }
+               free(gs.ctrls);
+       }
        return rs->sr_err;
 }