]> git.sur5r.net Git - openldap/commitdiff
ITS#6056 pagedresults stacked control is not overlay-friendly, add
authorHoward Chu <hyc@openldap.org>
Wed, 15 Apr 2009 10:34:24 +0000 (10:34 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 15 Apr 2009 10:34:24 +0000 (10:34 +0000)
slap_add_ctrls() function

servers/slapd/back-bdb/search.c
servers/slapd/controls.c
servers/slapd/overlays/deref.c
servers/slapd/proto-slap.h

index 1f28e9fda2a161c31d8a2cf6d9420dc6094c91cf..def485ec9ee3fd080cef8f53213aa8a36dc1c006 100644 (file)
@@ -1274,7 +1274,7 @@ send_paged_response(
        ID              *lastid,
        int             tentries )
 {
-       LDAPControl     ctrl, *ctrls[2];
+       LDAPControl     *ctrls[2];
        BerElementBuffer berbuf;
        BerElement      *ber = (BerElement *)&berbuf;
        PagedResultsCookie respcookie;
@@ -1284,8 +1284,6 @@ send_paged_response(
                "send_paged_response: lastid=0x%08lx nentries=%d\n", 
                lastid ? *lastid : 0, rs->sr_nentries, NULL );
 
-       BER_BVZERO( &ctrl.ldctl_value );
-       ctrls[0] = &ctrl;
        ctrls[1] = NULL;
 
        ber_init2( ber, NULL, LBER_USE_DER );
@@ -1308,6 +1306,7 @@ send_paged_response(
        /* return size of 0 -- no estimate */
        ber_printf( ber, "{iO}", 0, &cookie ); 
 
+       ctrls[0] = op->o_tmpalloc( sizeof(LDAPControl), op->o_tmpmemctx );
        if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
                goto done;
        }
@@ -1315,10 +1314,9 @@ send_paged_response(
        ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
        ctrls[0]->ldctl_iscritical = 0;
 
-       rs->sr_ctrls = ctrls;
+       slap_add_ctrls( op, rs, ctrls );
        rs->sr_err = LDAP_SUCCESS;
        send_ldap_result( op, rs );
-       rs->sr_ctrls = NULL;
 
 done:
        (void) ber_free_buf( ber );
index d5dd764f83f64615cf7999d81d35e74364160d7c..93476070d1a8b3a86e03933ef59d78cedca8d0ca 100644 (file)
@@ -539,6 +539,37 @@ void slap_free_ctrls(
        op->o_tmpfree( ctrls, op->o_tmpmemctx );
 }
 
+int slap_add_ctrls(
+       Operation *op,
+       SlapReply *rs,
+       LDAPControl **ctrls )
+{
+       int i = 0, j;
+       LDAPControl **ctrlsp;
+
+       if ( rs->sr_ctrls ) {
+               for ( ; rs->sr_ctrls[ i ]; i++ ) ;
+       }
+
+       for ( j=0; ctrls[j]; j++ ) ;
+
+       ctrlsp = op->o_tmpalloc(( i+j+1 )*sizeof(LDAPControl *), op->o_tmpmemctx );
+       i = 0;
+       if ( rs->sr_ctrls ) {
+               for ( ; rs->sr_ctrls[i]; i++ )
+                       ctrlsp[i] = rs->sr_ctrls[i];
+       }
+       for ( j=0; ctrls[j]; j++)
+               ctrlsp[i++] = ctrls[j];
+       ctrlsp[i] = NULL;
+
+       if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED )
+               op->o_tmpfree( rs->sr_ctrls, op->o_tmpmemctx );
+       rs->sr_ctrls = ctrlsp;
+       rs->sr_flags |= REP_CTRLS_MUSTBEFREED;
+       return i;
+}
+
 int slap_parse_ctrl(
        Operation *op,
        SlapReply *rs,
index a25dc37296157b4633761b689237044f89914b11..d397c02385ac47b9950f6afc20b9f47714c55409 100644 (file)
@@ -290,7 +290,7 @@ deref_response( Operation *op, SlapReply *rs )
                struct berval bv = BER_BVNULL;
                int nDerefRes = 0, nDerefVals = 0, nAttrs = 0, nVals = 0;
                struct berval ctrlval;
-               LDAPControl *ctrl, **ctrlsp;
+               LDAPControl *ctrl, *ctrlsp[2];
                AccessControlState acl_state = ACL_STATE_INIT;
                static char dummy = '\0';
                Entry *ebase;
@@ -471,26 +471,9 @@ deref_response( Operation *op, SlapReply *rs )
 
                ber_free_buf( ber );
 
-               i = 0;
-               if ( rs->sr_ctrls ) {
-                       for ( ; rs->sr_ctrls[ i ] != NULL; i++ )
-                               /* count'em */ ;
-               }
-               i += 2;
-               ctrlsp = op->o_tmpcalloc( i, sizeof(LDAPControl *), op->o_tmpmemctx );
-               i = 0;
-               if ( rs->sr_ctrls != NULL ) {
-                       for ( ; rs->sr_ctrls[ i ] != NULL; i++ ) {
-                               ctrlsp[ i ] = rs->sr_ctrls[ i ];
-                       }
-               }
-               ctrlsp[ i++ ] = ctrl;
-               ctrlsp[ i++ ] = NULL;
-               if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED ) {
-                       op->o_tmpfree( rs->sr_ctrls, op->o_tmpmemctx );
-               }
-               rs->sr_ctrls = ctrlsp;
-               rs->sr_flags |= REP_CTRLS_MUSTBEFREED;
+               ctrlsp[0] = ctrl;
+               ctrlsp[1] = NULL;
+               slap_add_ctrls( op, rs, ctrlsp );
 
                rc = SLAP_CB_CONTINUE;
 
index 24ee5a1207974a174fef8a67d8a3d9949af9e9d8..ae2753483dc8d581ce059a180d4ba8af9b3ab35c 100644 (file)
@@ -623,6 +623,10 @@ LDAP_SLAPD_V( struct slap_control_ids ) slap_cids;
 LDAP_SLAPD_F (void) slap_free_ctrls LDAP_P((
        Operation *op,
        LDAPControl **ctrls ));
+LDAP_SLAPD_F (int) slap_add_ctrls LDAP_P((
+       Operation *op,
+       SlapReply *rs,
+       LDAPControl **ctrls ));
 LDAP_SLAPD_F (int) slap_parse_ctrl LDAP_P((
        Operation *op,
        SlapReply *rs,