]> git.sur5r.net Git - openldap/commitdiff
save target errors for later evaluation
authorPierangelo Masarati <ando@openldap.org>
Wed, 31 Aug 2005 01:55:34 +0000 (01:55 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 31 Aug 2005 01:55:34 +0000 (01:55 +0000)
servers/slapd/back-meta/bind.c
servers/slapd/back-meta/conn.c
servers/slapd/back-meta/search.c

index d3861a4176fa32b4634156947dbc011a57b29504..424210da025ed2ea8c56730fe9bcfc880a977adc 100644 (file)
@@ -488,6 +488,7 @@ retry:;
                }
 
        } else {
+               rs->sr_err = rc;
                rc = slap_map_api2result( rs );
        }
 
@@ -580,8 +581,6 @@ meta_back_dobind(
                }
 
                if ( rc != LDAP_SUCCESS ) {
-                       rs->sr_err = slap_map_api2result( rs );
-
                        Debug( LDAP_DEBUG_ANY, "%s meta_back_dobind[%d]: "
                                        "(anonymous) err=%d\n",
                                        op->o_log_prefix, i, rc );
@@ -593,7 +592,8 @@ meta_back_dobind(
                         * due to technical reasons (remote host down?)
                         * so better clear the handle
                         */
-                       candidates[ i ].sr_tag = META_NOT_CANDIDATE;
+                       /* leave the target candidate, but record the error for later use */
+                       candidates[ i ].sr_err = rc;
                        if ( META_BACK_ONERR_STOP( mi ) ) {
                                bound = 0;
                                goto done;
@@ -666,8 +666,8 @@ meta_back_op_result(
        int                     i,
                                rerr = LDAP_SUCCESS;
        char                    *rmsg = NULL,
-                               *save_rmsg = NULL,
-                               *rmatch = NULL,
+                               *rmatch = NULL;
+       const char              *save_rmsg = NULL,
                                *save_rmatch = NULL;
        void                    *rmatch_ctx = NULL;
 
index 5f10ce40d22098c084969528b92e6015e673d4e2..6184946c8dab870e7ea6f76f7841bf05d5c8fd8e 100644 (file)
@@ -547,6 +547,8 @@ meta_back_get_candidate(
        return candidate;
 }
 
+static void    *meta_back_candidates_dummy;
+
 static void
 meta_back_candidates_keyfree(
        void            *key,
@@ -568,7 +570,7 @@ meta_back_candidates_get( Operation *op )
                void            *data = NULL;
 
                ldap_pvt_thread_pool_getkey( op->o_threadctx,
-                               meta_back_candidates_keyfree, &data, NULL );
+                               &meta_back_candidates_dummy, &data, NULL );
                mc = (metacandidates_t *)data;
 
        } else {
@@ -584,7 +586,7 @@ meta_back_candidates_get( Operation *op )
 
                        data = (void *)mc;
                        ldap_pvt_thread_pool_setkey( op->o_threadctx,
-                                       meta_back_candidates_keyfree, data,
+                                       &meta_back_candidates_dummy, data,
                                        meta_back_candidates_keyfree );
 
                } else {
@@ -728,9 +730,11 @@ meta_back_getconn(
                         * The target is activated; if needed, it is
                         * also init'd
                         */
-                       int lerr = meta_back_init_one_conn( op, rs, &mi->mi_targets[ i ],
-                                       &mc->mc_conns[ i ], sendok );
-                       if ( lerr == LDAP_SUCCESS ) {
+                       candidates[ i ].sr_err =
+                               meta_back_init_one_conn( op, rs,
+                                               &mi->mi_targets[ i ],
+                                               &mc->mc_conns[ i ], sendok );
+                       if ( candidates[ i ].sr_err == LDAP_SUCCESS ) {
                                candidates[ i ].sr_tag = META_CANDIDATE;
                                ncandidates++;
                                
@@ -742,7 +746,7 @@ meta_back_getconn(
                                 * be tried?
                                 */
                                candidates[ i ].sr_tag = META_NOT_CANDIDATE;
-                               err = lerr;
+                               err = candidates[ i ].sr_err;
                                continue;
                        }
                }
@@ -892,6 +896,7 @@ meta_back_getconn(
                        return NULL;
                }
 
+               candidates[ i ].sr_err = LDAP_SUCCESS;
                candidates[ i ].sr_tag = META_CANDIDATE;
                ncandidates++;
 
@@ -927,6 +932,7 @@ meta_back_getconn(
                                                &mc->mc_conns[ i ], sendok );
                                if ( lerr == LDAP_SUCCESS ) {
                                        candidates[ i ].sr_tag = META_CANDIDATE;
+                                       candidates[ i ].sr_err = LDAP_SUCCESS;
                                        ncandidates++;
 
                                        Debug( LDAP_DEBUG_TRACE, "%s: meta_back_init_one_conn(%d)\n",
@@ -942,7 +948,8 @@ meta_back_getconn(
                                        if ( new_conn ) {
                                                ( void )meta_clear_one_candidate( &mc->mc_conns[ i ] );
                                        }
-                                       candidates[ i ].sr_tag = META_NOT_CANDIDATE;
+                                       /* leave the target candidate, but record the error for later use */
+                                       candidates[ i ].sr_err = lerr;
                                        err = lerr;
 
                                        Debug( LDAP_DEBUG_ANY, "%s: meta_back_init_one_conn(%d) failed: %d\n",
index edf3975be43a8f24c5014cbae6d1334b97cb812f..55edc25767777b32ecacfee03d01f4637ee8e16f 100644 (file)
@@ -272,17 +272,17 @@ meta_back_search( Operation *op, SlapReply *rs )
                metasingleconn_t        *msc = &mc->mc_conns[ i ];
 
                candidates[ i ].sr_msgid = -1;
-
-               if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
-                       continue;
-               }
-
-               candidates[ i ].sr_err = LDAP_SUCCESS;
                candidates[ i ].sr_matched = NULL;
                candidates[ i ].sr_text = NULL;
                candidates[ i ].sr_ref = NULL;
                candidates[ i ].sr_ctrls = NULL;
 
+               if ( candidates[ i ].sr_tag != META_CANDIDATE
+                       || candidates[ i ].sr_err != LDAP_SUCCESS )
+               {
+                       continue;
+               }
+
                switch ( meta_back_search_start( op, rs, &dc, msc, i, candidates ) )
                {
                case 0:
@@ -333,9 +333,20 @@ meta_back_search( Operation *op, SlapReply *rs )
                        op->o_log_prefix, op->o_req_dn.bv_val,
                        op->ors_scope );
 
-               send_ldap_error( op, rs, LDAP_NO_SUCH_OBJECT, NULL );
-
+               /* FIXME: we're sending the first error we encounter;
+                * maybe we should pick the worst... */
                rc = LDAP_NO_SUCH_OBJECT;
+               for ( i = 0; i < mi->mi_ntargets; i++ ) {
+                       if ( candidates[ i ].sr_tag == META_CANDIDATE
+                               && candidates[ i ].sr_err != LDAP_SUCCESS )
+                       {
+                               rc = candidates[ i ].sr_err;
+                               break;
+                       }
+               }
+
+               send_ldap_error( op, rs, rc, NULL );
+
                goto finish;
        }