From ac8c1f2a268d3a8a2f4c1a4332b6ace2330a8342 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 30 Mar 2006 23:49:51 +0000 Subject: [PATCH] fix multiple response messages; add overall sleep time --- doc/man/man5/slapo-retcode.5 | 6 ++++ servers/slapd/overlays/retcode.c | 51 +++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/doc/man/man5/slapo-retcode.5 b/doc/man/man5/slapo-retcode.5 index 2a0fbf4bb9..1ee77d919c 100644 --- a/doc/man/man5/slapo-retcode.5 +++ b/doc/man/man5/slapo-retcode.5 @@ -73,6 +73,12 @@ response code. .B retcode\-indir Enables exploitation of in-directory stored errAbsObject. May result in a lot of unnecessary overhead. +.TP +.B retcode\-sleep [-] +Defines a sleep time in seconds that is spent before actually handling +any operation. +If negative, a random time between 0 and the absolute value of the argument +is used. .SH SCHEMA The diff --git a/servers/slapd/overlays/retcode.c b/servers/slapd/overlays/retcode.c index cad6b86bed..8b09f73361 100644 --- a/servers/slapd/overlays/retcode.c +++ b/servers/slapd/overlays/retcode.c @@ -77,6 +77,8 @@ typedef struct retcode_t { struct berval rd_pdn; struct berval rd_npdn; + int rd_sleep; + retcode_item_t *rd_item; unsigned rd_flags; @@ -202,7 +204,6 @@ retcode_op_internal( Operation *op, SlapReply *rs ) slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; Operation op2 = *op; - SlapReply rs2 = { 0 }; BackendDB db = *op->o_bd; slap_callback sc = { 0 }; retcode_cb_t rdc; @@ -236,7 +237,8 @@ retcode_op_internal( Operation *op, SlapReply *rs ) sc.sc_private = &rdc; op2.o_callback = ≻ - rc = op2.o_bd->be_search( &op2, &rs2 ); + rc = op2.o_bd->be_search( &op2, rs ); + op->o_abandon = op2.o_abandon; filter_free_x( &op2, op2.ors_filter ); ber_memfree_x( op2.ors_filterstr.bv_val, op2.o_tmpmemctx ); @@ -259,6 +261,14 @@ retcode_op_func( Operation *op, SlapReply *rs ) slap_callback *cb = NULL; + /* sleep as required */ + if ( rd->rd_sleep < 0 ) { + sleep( rand() % ( - rd->rd_sleep ) ); + + } else if ( rd->rd_sleep > 0 ) { + sleep( rd->rd_sleep ); + } + if ( !dnIsSuffix( &op->o_req_ndn, &rd->rd_npdn ) ) { if ( RETCODE_INDIR( rd ) ) { switch ( op->o_tag ) { @@ -275,10 +285,18 @@ retcode_op_func( Operation *op, SlapReply *rs ) case LDAP_REQ_SEARCH: if ( op->ors_scope == LDAP_SCOPE_BASE ) { rs->sr_err = retcode_op_internal( op, rs ); - if ( rs->sr_err == SLAP_CB_CONTINUE ) { + switch ( rs->sr_err ) { + case SLAP_CB_CONTINUE: + if ( rs->sr_nentries == 0 ) { + break; + } rs->sr_err = LDAP_SUCCESS; + /* fallthru */ + + default: + send_ldap_result( op, rs ); + break; } - send_ldap_result( op, rs ); return rs->sr_err; } break; @@ -874,6 +892,31 @@ retcode_db_config( } else if ( strcasecmp( argv0, "indir" ) == 0 ) { rd->rd_flags |= RETCODE_FINDIR; + } else if ( strcasecmp( argv0, "sleep" ) == 0 ) { + switch ( argc ) { + case 1: + fprintf( stderr, "%s: line %d: retcode: " + "\"retcode-sleep