]> git.sur5r.net Git - openldap/commitdiff
avoid cycling twice in the control list
authorPierangelo Masarati <ando@openldap.org>
Sat, 29 Jan 2005 18:16:38 +0000 (18:16 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 29 Jan 2005 18:16:38 +0000 (18:16 +0000)
servers/slapd/backend.c
servers/slapd/controls.c
servers/slapd/proto-slap.h

index 8de9c895e24b50ca6ed2449a0b2124c5bb3e6bd0..6089a9c62ac5668fd9f44b25af3934e2423f72b4 100644 (file)
@@ -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;
 }
 
index c201273eb579f44430bcba861f4e04fab2ad8d58..f6696c35adabe406ec7cb57e51d6bcc7fb05e11c 100644 (file)
@@ -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(
index 133ecb8d00daf4cd2f744205ac5a79cfc04c9714..157b62343546236c2580b64ea2ec7f19b6f766e4 100644 (file)
@@ -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