ID *lastid,
int tentries )
{
- LDAPControl ctrl, *ctrls[2];
+ LDAPControl *ctrls[2];
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
PagedResultsCookie respcookie;
"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 );
/* 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;
}
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 );
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,
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;
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;
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,