From 34af916e3f11b31f6a10a382b330d2f1197c9395 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sat, 24 Jun 2006 16:58:49 +0000 Subject: [PATCH] fix response sending while rebinding (ITS#4597) --- servers/slapd/back-ldap/add.c | 31 +++++++++++++++-------------- servers/slapd/back-ldap/back-ldap.h | 9 ++++++++- servers/slapd/back-ldap/bind.c | 23 ++++++++++++++++----- servers/slapd/back-ldap/compare.c | 19 +++++++++--------- servers/slapd/back-ldap/delete.c | 17 ++++++++-------- servers/slapd/back-ldap/modify.c | 29 ++++++++++++++------------- servers/slapd/back-ldap/modrdn.c | 21 +++++++++---------- 7 files changed, 87 insertions(+), 62 deletions(-) diff --git a/servers/slapd/back-ldap/add.c b/servers/slapd/back-ldap/add.c index cb46b16f35..e79f847bc6 100644 --- a/servers/slapd/back-ldap/add.c +++ b/servers/slapd/back-ldap/add.c @@ -36,18 +36,18 @@ ldap_back_add( Operation *op, SlapReply *rs ) { - ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private; - - ldapconn_t *lc; - int i = 0, - j = 0; - Attribute *a; - LDAPMod **attrs = NULL, - *attrs2 = NULL; - ber_int_t msgid; - int isupdate; - int do_retry = 1; - LDAPControl **ctrls = NULL; + ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private; + + ldapconn_t *lc; + int i = 0, + j = 0; + Attribute *a; + LDAPMod **attrs = NULL, + *attrs2 = NULL; + ber_int_t msgid; + int isupdate; + ldap_back_send_t retrying = LDAP_BACK_RETRYING; + LDAPControl **ctrls = NULL; rs->sr_err = LDAP_SUCCESS; @@ -104,9 +104,10 @@ retry: rs->sr_err = ldap_add_ext( lc->lc_ld, op->o_req_dn.bv_val, attrs, ctrls, NULL, &msgid ); rs->sr_err = ldap_back_op_result( lc, op, rs, msgid, - li->li_timeout[ LDAP_BACK_OP_ADD ], LDAP_BACK_SENDRESULT ); - if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) { - do_retry = 0; + li->li_timeout[ LDAP_BACK_OP_ADD ], + ( LDAP_BACK_SENDRESULT | retrying ) ); + if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) { + retrying &= ~LDAP_BACK_RETRYING; if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) { goto retry; } diff --git a/servers/slapd/back-ldap/back-ldap.h b/servers/slapd/back-ldap/back-ldap.h index 26528bcd6d..a1fb091f31 100644 --- a/servers/slapd/back-ldap/back-ldap.h +++ b/servers/slapd/back-ldap/back-ldap.h @@ -288,10 +288,17 @@ typedef enum ldap_back_send_t { LDAP_BACK_SENDERR = 0x02, LDAP_BACK_SENDRESULT = (LDAP_BACK_SENDOK|LDAP_BACK_SENDERR), LDAP_BACK_BINDING = 0x04, + LDAP_BACK_BIND_DONTSEND = (LDAP_BACK_BINDING), LDAP_BACK_BIND_SOK = (LDAP_BACK_BINDING|LDAP_BACK_SENDOK), LDAP_BACK_BIND_SERR = (LDAP_BACK_BINDING|LDAP_BACK_SENDERR), - LDAP_BACK_BIND_SRES = (LDAP_BACK_BINDING|LDAP_BACK_SENDRESULT) + LDAP_BACK_BIND_SRES = (LDAP_BACK_BINDING|LDAP_BACK_SENDRESULT), + + LDAP_BACK_RETRYING = 0x08, + LDAP_BACK_RETRY_DONTSEND = (LDAP_BACK_RETRYING), + LDAP_BACK_RETRY_SOK = (LDAP_BACK_RETRYING|LDAP_BACK_SENDOK), + LDAP_BACK_RETRY_SERR = (LDAP_BACK_RETRYING|LDAP_BACK_SENDERR), + LDAP_BACK_RETRY_SRES = (LDAP_BACK_RETRYING|LDAP_BACK_SENDRESULT) } ldap_back_send_t; /* define to use asynchronous StartTLS */ diff --git a/servers/slapd/back-ldap/bind.c b/servers/slapd/back-ldap/bind.c index b70d34d604..b71c8599f9 100644 --- a/servers/slapd/back-ldap/bind.c +++ b/servers/slapd/back-ldap/bind.c @@ -1340,15 +1340,24 @@ retry:; rs->sr_matched = match; } } - if ( LDAP_BACK_QUARANTINE( li ) ) { - ldap_back_quarantine( op, rs ); - } - if ( op->o_conn && - ( ( sendok & LDAP_BACK_SENDOK ) + + if ( rs->sr_err == LDAP_UNAVAILABLE ) { + if ( !( sendok & LDAP_BACK_RETRYING ) ) { + if ( LDAP_BACK_QUARANTINE( li ) ) { + ldap_back_quarantine( op, rs ); + } + if ( op->o_conn && ( sendok & LDAP_BACK_SENDERR ) ) { + send_ldap_result( op, rs ); + } + } + + } else if ( op->o_conn && + ( ( ( sendok & LDAP_BACK_SENDOK ) && ERR_OK( rs->sr_err ) ) || ( ( sendok & LDAP_BACK_SENDERR ) && rs->sr_err != LDAP_SUCCESS ) ) ) { send_ldap_result( op, rs ); } + if ( match ) { if ( rs->sr_matched != match ) { free( (char *)rs->sr_matched ); @@ -1356,21 +1365,25 @@ retry:; rs->sr_matched = NULL; ldap_memfree( match ); } + if ( text ) { ldap_memfree( text ); } rs->sr_text = NULL; + if ( rs->sr_ref ) { assert( refs != NULL ); ber_memvfree( (void **)refs ); op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx ); rs->sr_ref = NULL; } + if ( ctrls ) { assert( rs->sr_ctrls != NULL ); ldap_controls_free( ctrls ); rs->sr_ctrls = NULL; } + return( ERR_OK( rs->sr_err ) ? LDAP_SUCCESS : rs->sr_err ); } diff --git a/servers/slapd/back-ldap/compare.c b/servers/slapd/back-ldap/compare.c index b14de0d68d..11fd3eb9c3 100644 --- a/servers/slapd/back-ldap/compare.c +++ b/servers/slapd/back-ldap/compare.c @@ -36,13 +36,13 @@ ldap_back_compare( Operation *op, SlapReply *rs ) { - ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private; + ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private; - ldapconn_t *lc; - ber_int_t msgid; - int do_retry = 1; - LDAPControl **ctrls = NULL; - int rc = LDAP_SUCCESS; + ldapconn_t *lc; + ber_int_t msgid; + ldap_back_send_t retrying = LDAP_BACK_RETRYING; + LDAPControl **ctrls = NULL; + int rc = LDAP_SUCCESS; lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR ); if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) { @@ -63,9 +63,10 @@ retry: op->orc_ava->aa_desc->ad_cname.bv_val, &op->orc_ava->aa_value, ctrls, NULL, &msgid ); - rc = ldap_back_op_result( lc, op, rs, msgid, 0, LDAP_BACK_SENDRESULT ); - if ( rc == LDAP_UNAVAILABLE && do_retry ) { - do_retry = 0; + rc = ldap_back_op_result( lc, op, rs, msgid, 0, + ( LDAP_BACK_SENDRESULT | retrying ) ); + if ( rc == LDAP_UNAVAILABLE && retrying ) { + retrying &= ~LDAP_BACK_RETRYING; if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) { goto retry; } diff --git a/servers/slapd/back-ldap/delete.c b/servers/slapd/back-ldap/delete.c index 43e88540b4..f95660cace 100644 --- a/servers/slapd/back-ldap/delete.c +++ b/servers/slapd/back-ldap/delete.c @@ -38,11 +38,11 @@ ldap_back_delete( { ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private; - ldapconn_t *lc; - ber_int_t msgid; - LDAPControl **ctrls = NULL; - int do_retry = 1; - int rc = LDAP_SUCCESS; + ldapconn_t *lc; + ber_int_t msgid; + LDAPControl **ctrls = NULL; + ldap_back_send_t retrying = LDAP_BACK_RETRYING; + int rc = LDAP_SUCCESS; lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR ); @@ -63,9 +63,10 @@ retry: rs->sr_err = ldap_delete_ext( lc->lc_ld, op->o_req_dn.bv_val, ctrls, NULL, &msgid ); rc = ldap_back_op_result( lc, op, rs, msgid, - li->li_timeout[ LDAP_BACK_OP_DELETE], LDAP_BACK_SENDRESULT ); - if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) { - do_retry = 0; + li->li_timeout[ LDAP_BACK_OP_DELETE], + ( LDAP_BACK_SENDRESULT | retrying ) ); + if ( rs->sr_err == LDAP_SERVER_DOWN && retrying ) { + retrying &= ~LDAP_BACK_RETRYING; if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) { goto retry; } diff --git a/servers/slapd/back-ldap/modify.c b/servers/slapd/back-ldap/modify.c index 60ccc51687..7e6e7ecad5 100644 --- a/servers/slapd/back-ldap/modify.c +++ b/servers/slapd/back-ldap/modify.c @@ -36,17 +36,17 @@ ldap_back_modify( Operation *op, SlapReply *rs ) { - ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private; - - ldapconn_t *lc; - LDAPMod **modv = NULL, - *mods = NULL; - Modifications *ml; - int i, j, rc; - ber_int_t msgid; - int isupdate; - int do_retry = 1; - LDAPControl **ctrls = NULL; + ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private; + + ldapconn_t *lc; + LDAPMod **modv = NULL, + *mods = NULL; + Modifications *ml; + int i, j, rc; + ber_int_t msgid; + int isupdate; + ldap_back_send_t retrying = LDAP_BACK_RETRYING; + LDAPControl **ctrls = NULL; lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR ); if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) { @@ -111,9 +111,10 @@ retry: rs->sr_err = ldap_modify_ext( lc->lc_ld, op->o_req_dn.bv_val, modv, ctrls, NULL, &msgid ); rc = ldap_back_op_result( lc, op, rs, msgid, - li->li_timeout[ LDAP_BACK_OP_MODIFY], LDAP_BACK_SENDRESULT ); - if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) { - do_retry = 0; + li->li_timeout[ LDAP_BACK_OP_MODIFY], + ( LDAP_BACK_SENDRESULT | retrying ) ); + if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) { + retrying &= ~LDAP_BACK_RETRYING; if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) { goto retry; } diff --git a/servers/slapd/back-ldap/modrdn.c b/servers/slapd/back-ldap/modrdn.c index 2f92a0003d..37e1afe7e8 100644 --- a/servers/slapd/back-ldap/modrdn.c +++ b/servers/slapd/back-ldap/modrdn.c @@ -36,14 +36,14 @@ ldap_back_modrdn( Operation *op, SlapReply *rs ) { - ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private; + ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private; - ldapconn_t *lc; - ber_int_t msgid; - LDAPControl **ctrls = NULL; - int do_retry = 1; - int rc = LDAP_SUCCESS; - char *newSup = NULL; + ldapconn_t *lc; + ber_int_t msgid; + LDAPControl **ctrls = NULL; + ldap_back_send_t retrying = LDAP_BACK_RETRYING; + int rc = LDAP_SUCCESS; + char *newSup = NULL; lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR ); if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) { @@ -87,9 +87,10 @@ retry: op->orr_newrdn.bv_val, newSup, op->orr_deleteoldrdn, ctrls, NULL, &msgid ); rc = ldap_back_op_result( lc, op, rs, msgid, - li->li_timeout[ LDAP_BACK_OP_MODRDN ], LDAP_BACK_SENDRESULT ); - if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) { - do_retry = 0; + li->li_timeout[ LDAP_BACK_OP_MODRDN ], + ( LDAP_BACK_SENDRESULT | retrying ) ); + if ( rs->sr_err == LDAP_SERVER_DOWN && retrying ) { + retrying &= ~LDAP_BACK_RETRYING; if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) { goto retry; } -- 2.39.5