avoid cycling twice in the control list

This commit is contained in:
Pierangelo Masarati 2005-01-29 18:16:38 +00:00
parent 0056109b82
commit cd797f8089
3 changed files with 39 additions and 25 deletions

View file

@ -873,9 +873,9 @@ backend_check_controls(
if( ctrls ) { if( ctrls ) {
for( ; *ctrls != NULL ; ctrls++ ) { for( ; *ctrls != NULL ; ctrls++ ) {
int cid; 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 */ /* unrecognized control */
if ( (*ctrls)->ldctl_iscritical ) { if ( (*ctrls)->ldctl_iscritical ) {
/* should not be reachable */ /* should not be reachable */
@ -884,26 +884,39 @@ backend_check_controls(
(*ctrls)->ldctl_oid, 0, 0 ); (*ctrls)->ldctl_oid, 0, 0 );
assert( 0 ); assert( 0 );
} }
} 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;
break; break;
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; return rs->sr_err;
} }

View file

@ -381,7 +381,7 @@ slap_find_control_id(
} }
int 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 ); struct slap_control *ctrl = find_ctrl( oid );
@ -390,22 +390,23 @@ slap_global_control( Operation *op, const char *oid )
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"slap_global_control: unrecognized control: %s\n", "slap_global_control: unrecognized control: %s\n",
oid, 0, 0 ); oid, 0, 0 );
assert( 0 ); return LDAP_CONTROL_NOT_FOUND;
return 0;
} }
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 ) && if (( op->o_tag & LDAP_REQ_SEARCH ) &&
( ctrl->sc_mask & SLAP_CTRL_GLOBAL_SEARCH )) ( ctrl->sc_mask & SLAP_CTRL_GLOBAL_SEARCH ))
{ {
return 1; return LDAP_COMPARE_TRUE;
} }
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"slap_global_control: unavailable control: %s\n", "slap_global_control: unavailable control: %s\n",
oid, 0, 0 ); oid, 0, 0 );
return 0; return LDAP_COMPARE_FALSE;
} }
void slap_free_ctrls( void slap_free_ctrls(

View file

@ -430,7 +430,7 @@ LDAP_SLAPD_F (int) get_supported_controls LDAP_P ((
LDAP_SLAPD_F (int) slap_find_control_id LDAP_P (( LDAP_SLAPD_F (int) slap_find_control_id LDAP_P ((
const char *oid, int *cid )); const char *oid, int *cid ));
LDAP_SLAPD_F (int) slap_global_control LDAP_P (( LDAP_SLAPD_F (int) slap_global_control LDAP_P ((
Operation *op, const char *oid )); Operation *op, const char *oid, int *cid ));
/* /*
* config.c * config.c