From cfb12f536b30376c64a8652f6ffd5bd8d9940e69 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 15 Apr 2009 10:34:24 +0000 Subject: [PATCH] ITS#6056 pagedresults stacked control is not overlay-friendly, add slap_add_ctrls() function --- servers/slapd/back-bdb/search.c | 8 +++----- servers/slapd/controls.c | 31 +++++++++++++++++++++++++++++++ servers/slapd/overlays/deref.c | 25 ++++--------------------- servers/slapd/proto-slap.h | 4 ++++ 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 1f28e9fda2..def485ec9e 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -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 ); diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index d5dd764f83..93476070d1 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -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, diff --git a/servers/slapd/overlays/deref.c b/servers/slapd/overlays/deref.c index a25dc37296..d397c02385 100644 --- a/servers/slapd/overlays/deref.c +++ b/servers/slapd/overlays/deref.c @@ -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; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 24ee5a1207..ae2753483d 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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, -- 2.39.5