]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/conn.c
Improve schema error messages
[openldap] / servers / slapd / back-meta / conn.c
index f840eeff15ab3241aaf843136943488cec454ac2..739af0e44b5ab6c1ebf767d319027dfdac17327d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1998-2001 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  *
  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
@@ -199,7 +199,7 @@ metaconn_alloc( int ntargets )
                }
        }
 
-       lc->bound_target = -1;
+       lc->bound_target = META_BOUND_NONE;
 
        return lc;
 }
@@ -257,11 +257,6 @@ init_one_conn(
         * Attempts to initialize the connection to the target ds
         */
        err = ldap_initialize( &lsc->ld, lt->uri );
-
-       /*
-        * In case of failure, the error is mapped back from client
-        * to server error code
-        */
        if ( err != LDAP_SUCCESS ) {
                return ldap_back_map_result( err );
        }
@@ -280,26 +275,27 @@ init_one_conn(
        /*
         * If the connection dn is not null, an attempt to rewrite it is made
         */
-       if ( conn->c_cdn != NULL && conn->c_cdn[ 0 ] != '\0' ) {
+       if ( conn->c_dn.bv_len != 0 ) {
+               
                /*
                 * Rewrite the bind dn if needed
                 */
-               lsc->bound_dn = NULL;
+               lsc->bound_dn.bv_val = NULL;
                switch ( rewrite_session( lt->rwinfo, "bindDn",
-                                       conn->c_cdn, conn,
-                                       &lsc->bound_dn ) ) {
+                                       conn->c_dn.bv_val, conn, 
+                                       &lsc->bound_dn.bv_val ) ) {
                case REWRITE_REGEXEC_OK:
-                       if ( lsc->bound_dn == NULL ) {
-                               lsc->bound_dn = ch_strdup( conn->c_cdn );
+                       if ( lsc->bound_dn.bv_val == NULL ) {
+                               ber_dupbv( &lsc->bound_dn, &conn->c_dn );
                        }
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
-                                       "[rw] bindDn: \"%s\" -> \"%s\"\n",
-                                       conn->c_cdn, lsc->bound_dn ));
+                       LDAP_LOG( BACK_META, DETAIL1,
+                               "[rw] bindDn: \"%s\" -> \"%s\"\n",
+                               conn->c_dn.bv_val, lsc->bound_dn.bv_val, 0 );
 #else /* !NEW_LOGGING */
                        Debug( LDAP_DEBUG_ARGS,
-                                       "rw> bindDn: \"%s\" -> \"%s\"\n%s",
-                                       conn->c_cdn, lsc->bound_dn, "" );
+                                       "rw> bindDn: \"%s\" -> \"%s\"\n",
+                                       conn->c_dn.bv_val, lsc->bound_dn.bv_val, 0 );
 #endif /* !NEW_LOGGING */
                        break;
                        
@@ -308,13 +304,20 @@ init_one_conn(
                                        LDAP_UNWILLING_TO_PERFORM,
                                        NULL, "Unwilling to perform",
                                        NULL, NULL );
-                       /* continues to the next case */
+                       return LDAP_UNWILLING_TO_PERFORM;
                        
                case REWRITE_REGEXEC_ERR:
+                       send_ldap_result( conn, op,
+                                       LDAP_OPERATIONS_ERROR,
+                                       NULL, "Operations error",
+                                       NULL, NULL );
                        return LDAP_OPERATIONS_ERROR;
                }
+
+               assert( lsc->bound_dn.bv_val );
+
        } else {
-               lsc->bound_dn = NULL;
+               ber_str2bv( "", 0, 1, &lsc->bound_dn );
        }
 
        lsc->bound = META_UNBOUND;
@@ -341,12 +344,11 @@ init_one_conn(
 struct metaconn *
 meta_back_getconn(
                struct metainfo *li,
-               Connection *conn,
-               Operation *op,
-               int op_type,
-               const char *ndn,
-               int *candidate
-               )
+               Connection      *conn,
+               Operation       *op,
+               int             op_type,
+               struct berval   *ndn,
+               int             *candidate )
 {
        struct metaconn *lc, lc_curr;
        int vers, cached = -1, i = -1, err = LDAP_SUCCESS;
@@ -400,13 +402,13 @@ meta_back_getconn(
                }
                                
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
-                               "meta_back_getconn: got target %d"
-                               " for ndn=\"%s\" from cache\n", i, ndn ));
+               LDAP_LOG( BACK_META, INFO,
+                       "meta_back_getconn: got target %d for ndn=\"%s\" from cache\n", 
+                       i, ndn->bv_val, 0 );
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_CACHE,
        "==>meta_back_getconn: got target %d for ndn=\"%s\" from cache\n%s",
-                               i, ndn, "" );
+                               i, ndn->bv_val, "" );
 #endif /* !NEW_LOGGING */
 
                /*
@@ -416,7 +418,8 @@ meta_back_getconn(
 
                /*
                 * The target is activated; if needed, it is
-                * also init'd
+                * also init'd. In case of error, init_one_conn
+                * sends the appropriate result.
                 */
                err = init_one_conn( conn, op, li->targets[ i ],
                                vers, lc->conns[ i ] );
@@ -431,9 +434,6 @@ meta_back_getconn(
                        if ( new_conn ) {
                                metaconn_free( lc );
                        }
-
-                       send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,                                      NULL, "internal server error", NULL, NULL );
-
                        return NULL;
                }
 
@@ -441,15 +441,38 @@ meta_back_getconn(
                        *candidate = i;
                }
 
+       /*
+        * require all connections ...
+        */
+       } else if (op_type == META_OP_REQUIRE_ALL) {
+               for ( i = 0; i < li->ntargets; i++ ) {
+
+                       /*
+                        * The target is activated; if needed, it is
+                        * also init'd
+                        */
+                       int lerr = init_one_conn( conn, op, li->targets[ i ],
+                                       vers, lc->conns[ i ] );
+                       if ( lerr != LDAP_SUCCESS ) {
+                               
+                               /*
+                                * FIXME: in case one target cannot
+                                * be init'd, should the other ones
+                                * be tried?
+                                */
+                               ( void )meta_clear_one_candidate( lc->conns[ i ], 1 );
+                               err = lerr;
+                               continue;
+                       }
+               }
+
        /*
         * if no unique candidate ...
         */
        } else {
-               int ndnlen = strlen( ndn );     
                for ( i = 0; i < li->ntargets; i++ ) {
                        if ( i == cached 
-               || meta_back_is_candidate( li->targets[ i ]->suffix,
-                                       ndn, ndnlen ) ) {
+               || meta_back_is_candidate( &li->targets[ i ]->suffix, ndn ) ) {
 
                                /*
                                 * The target is activated; if needed, it is
@@ -489,9 +512,8 @@ meta_back_getconn(
                ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
 
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
-                               "meta_back_getconn: conn %ld inserted\n",
-                               lc->conn->c_connid ));
+               LDAP_LOG( BACK_META, INFO,
+                       "meta_back_getconn: conn %ld inserted\n", lc->conn->c_connid, 0, 0);
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_TRACE,
                        "=>meta_back_getconn: conn %ld inserted\n%s%s",
@@ -503,15 +525,14 @@ meta_back_getconn(
                 */
                if ( err != 0 ) {
                        send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
-                       NULL, "internal server error", NULL, NULL );
+                       NULL, "Internal server error", NULL, NULL );
                        metaconn_free( lc );
                        return NULL;
                }
        } else {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
-                               "meta_back_getconn: conn %ld fetched\n",
-                               lc->conn->c_connid ));
+               LDAP_LOG( BACK_META, INFO,
+                       "meta_back_getconn: conn %ld fetched\n", lc->conn->c_connid, 0, 0 );
 #else /* !NEW_LOGGING */
                Debug( LDAP_DEBUG_TRACE,
                        "=>meta_back_getconn: conn %ld fetched\n%s%s",