From cd797f80899faba87f81892eeb6e4ffe6587bcdb Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sat, 29 Jan 2005 18:16:38 +0000 Subject: [PATCH] avoid cycling twice in the control list --- servers/slapd/backend.c | 47 ++++++++++++++++++++++++-------------- servers/slapd/controls.c | 13 ++++++----- servers/slapd/proto-slap.h | 2 +- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 8de9c895e2..6089a9c62a 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -873,9 +873,9 @@ backend_check_controls( if( ctrls ) { for( ; *ctrls != NULL ; ctrls++ ) { int cid; - if( slap_find_control_id( (*ctrls)->ldctl_oid, &cid ) == - LDAP_CONTROL_NOT_FOUND ) - { + + switch ( slap_global_control( op, (*ctrls)->ldctl_oid, &cid ) ) { + case LDAP_CONTROL_NOT_FOUND: /* unrecognized control */ if ( (*ctrls)->ldctl_iscritical ) { /* should not be reachable */ @@ -884,26 +884,39 @@ backend_check_controls( (*ctrls)->ldctl_oid, 0, 0 ); assert( 0 ); } + break; - } else if ( !slap_global_control( op, (*ctrls)->ldctl_oid ) && - !op->o_bd->be_ctrls[ cid ] ) - { - /* Per RFC 2251 (and LDAPBIS discussions), if the control - * is recognized and appropriate for the operation (which - * we've already verified), then the server should make - * use of the control when performing the operation. - * - * Here we find that operation extended by the control - * is not unavailable in a particular context, hence the - * return of unwillingToPerform. - */ - rs->sr_text = "control unavailable in context"; - rs->sr_err = LDAP_UNWILLING_TO_PERFORM; + case LDAP_COMPARE_FALSE: + if ( !op->o_bd->be_ctrls[ cid ] ) + { + /* Per RFC 2251 (and LDAPBIS discussions), if the control + * is recognized and appropriate for the operation (which + * we've already verified), then the server should make + * use of the control when performing the operation. + * + * Here we find that operation extended by the control + * is not unavailable in a particular context, hence the + * return of unwillingToPerform. + */ + rs->sr_text = "control unavailable in context"; + rs->sr_err = LDAP_UNWILLING_TO_PERFORM; + goto done; + } + break; + + case LDAP_COMPARE_TRUE: break; + + default: + /* unreachable */ + rs->sr_err = "unable to check control"; + rs->sr_err = LDAP_OTHER; + goto done; } } } +done:; return rs->sr_err; } diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index c201273eb5..f6696c35ad 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -381,7 +381,7 @@ slap_find_control_id( } int -slap_global_control( Operation *op, const char *oid ) +slap_global_control( Operation *op, const char *oid, int *cid ) { struct slap_control *ctrl = find_ctrl( oid ); @@ -390,22 +390,23 @@ slap_global_control( Operation *op, const char *oid ) Debug( LDAP_DEBUG_ANY, "slap_global_control: unrecognized control: %s\n", oid, 0, 0 ); - assert( 0 ); - return 0; + return LDAP_CONTROL_NOT_FOUND; } - if ( ctrl->sc_mask & SLAP_CTRL_GLOBAL ) return 1; + if ( cid ) *cid = ctrl->sc_cid; + + if ( ctrl->sc_mask & SLAP_CTRL_GLOBAL ) return LDAP_COMPARE_TRUE; if (( op->o_tag & LDAP_REQ_SEARCH ) && ( ctrl->sc_mask & SLAP_CTRL_GLOBAL_SEARCH )) { - return 1; + return LDAP_COMPARE_TRUE; } Debug( LDAP_DEBUG_ANY, "slap_global_control: unavailable control: %s\n", oid, 0, 0 ); - return 0; + return LDAP_COMPARE_FALSE; } void slap_free_ctrls( diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 133ecb8d00..157b623435 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -430,7 +430,7 @@ LDAP_SLAPD_F (int) get_supported_controls LDAP_P (( LDAP_SLAPD_F (int) slap_find_control_id LDAP_P (( const char *oid, int *cid )); LDAP_SLAPD_F (int) slap_global_control LDAP_P (( - Operation *op, const char *oid )); + Operation *op, const char *oid, int *cid )); /* * config.c -- 2.39.5