]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/conn.c
Fixed minor compile errors
[openldap] / servers / slapd / back-meta / conn.c
index 8289819a88ec55313a208228b866e94aa91aa91e..f13352e7bbd654911bb9dd80a4b7683b52b6ef21 100644 (file)
@@ -221,13 +221,14 @@ metaconn_free(
  */
 static int
 init_one_conn(
-               Connection *conn, 
-               Operation *op, 
-               struct metatarget *lt, 
-               struct metasingleconn *lsc
+               Operation               *op,
+               SlapReply               *rs,
+               struct metatarget       *lt, 
+               struct metasingleconn   *lsc
                )
 {
-       int err, vers;
+       int             vers;
+       dncookie        dc;
 
        /*
         * Already init'ed
@@ -239,63 +240,40 @@ init_one_conn(
        /*
         * Attempts to initialize the connection to the target ds
         */
-       err = ldap_initialize( &lsc->ld, lt->uri );
-       if ( err != LDAP_SUCCESS ) {
-               return ldap_back_map_result( err );
+       rs->sr_err = ldap_initialize( &lsc->ld, lt->uri );
+       if ( rs->sr_err != LDAP_SUCCESS ) {
+               return ldap_back_map_result( rs );
        }
 
        /*
         * Set LDAP version. This will always succeed: If the client
         * bound with a particular version, then so can we.
         */
-       vers = conn->c_protocol;
+       vers = op->o_conn->c_protocol;
        ldap_set_option( lsc->ld, LDAP_OPT_PROTOCOL_VERSION, &vers );
+       /* FIXME: configurable? */
+       ldap_set_option(lsc->ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON);
 
        /*
         * Sets a cookie for the rewrite session
         */
-       ( void )rewrite_session_init( lt->rwinfo, conn );
+       ( void )rewrite_session_init( lt->rwmap.rwm_rw, op->o_conn );
 
        /*
         * If the connection dn is not null, an attempt to rewrite it is made
         */
-       if ( conn->c_dn.bv_len != 0 ) {
+       if ( op->o_conn->c_dn.bv_len != 0 ) {
+               dc.rwmap = &lt->rwmap;
+               dc.conn = op->o_conn;
+               dc.rs = rs;
+               dc.ctx = "bindDn";
                
                /*
                 * Rewrite the bind dn if needed
                 */
-               lsc->bound_dn.bv_val = NULL;
-               switch ( rewrite_session( lt->rwinfo, "bindDn",
-                                       conn->c_dn.bv_val, conn, 
-                                       &lsc->bound_dn.bv_val ) ) {
-               case REWRITE_REGEXEC_OK:
-                       if ( lsc->bound_dn.bv_val == NULL ) {
-                               ber_dupbv( &lsc->bound_dn, &conn->c_dn );
-                       }
-#ifdef NEW_LOGGING
-                       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",
-                                       conn->c_dn.bv_val, lsc->bound_dn.bv_val, 0 );
-#endif /* !NEW_LOGGING */
-                       break;
-                       
-               case REWRITE_REGEXEC_UNWILLING:
-                       send_ldap_result( conn, op,
-                                       LDAP_UNWILLING_TO_PERFORM,
-                                       NULL, "Operation not allowed",
-                                       NULL, NULL );
-                       return LDAP_UNWILLING_TO_PERFORM;
-                       
-               case REWRITE_REGEXEC_ERR:
-                       send_ldap_result( conn, op,
-                                       LDAP_OTHER,
-                                       NULL, "Rewrite error",
-                                       NULL, NULL );
-                       return LDAP_OTHER;
+               if ( ldap_back_dn_massage( &dc, &op->o_conn->c_dn, &lsc->bound_dn) ) {
+                       send_ldap_result( op, rs );
+                       return rs->sr_err;
                }
 
                assert( lsc->bound_dn.bv_val );
@@ -327,19 +305,19 @@ init_one_conn(
  */
 struct metaconn *
 meta_back_getconn(
-               struct metainfo *li,
-               Connection      *conn,
                Operation       *op,
+               SlapReply       *rs,
                int             op_type,
                struct berval   *ndn,
                int             *candidate )
 {
+       struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
        struct metaconn *lc, lc_curr;
        int cached = -1, i = -1, err = LDAP_SUCCESS;
        int new_conn = 0;
 
        /* Searches for a metaconn in the avl tree */
-       lc_curr.conn = conn;
+       lc_curr.conn = op->o_conn;
        ldap_pvt_thread_mutex_lock( &li->conn_mutex );
        lc = (struct metaconn *)avl_find( li->conntree, 
                (caddr_t)&lc_curr, meta_back_conn_cmp );
@@ -348,7 +326,7 @@ meta_back_getconn(
        /* Looks like we didn't get a bind. Open a new session... */
        if ( !lc ) {
                lc = metaconn_alloc( li->ntargets );
-               lc->conn = conn;
+               lc->conn = op->o_conn;
                new_conn = 1;
        }
 
@@ -377,9 +355,7 @@ meta_back_getconn(
                                metaconn_free( lc );
                        }
 
-                       send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
-                               NULL, "", NULL, NULL );
-
+                       rs->sr_err = LDAP_NO_SUCH_OBJECT;
                        return NULL;
                }
                                
@@ -403,7 +379,7 @@ meta_back_getconn(
                 * also init'd. In case of error, init_one_conn
                 * sends the appropriate result.
                 */
-               err = init_one_conn( conn, op, li->targets[ i ],
+               err = init_one_conn( op, rs, li->targets[ i ],
                                &lc->conns[ i ] );
                if ( err != LDAP_SUCCESS ) {
                
@@ -433,7 +409,7 @@ meta_back_getconn(
                         * The target is activated; if needed, it is
                         * also init'd
                         */
-                       int lerr = init_one_conn( conn, op, li->targets[ i ],
+                       int lerr = init_one_conn( op, rs, li->targets[ i ],
                                        &lc->conns[ i ] );
                        if ( lerr != LDAP_SUCCESS ) {
                                
@@ -460,7 +436,7 @@ meta_back_getconn(
                                 * The target is activated; if needed, it is
                                 * also init'd
                                 */
-                               int lerr = init_one_conn( conn, op,
+                               int lerr = init_one_conn( op, rs,
                                                li->targets[ i ],
                                                &lc->conns[ i ] );
                                if ( lerr != LDAP_SUCCESS ) {
@@ -478,6 +454,10 @@ meta_back_getconn(
                }
        }
 
+       /* clear out init_one_conn non-fatal errors */
+       rs->sr_err = LDAP_SUCCESS;
+       rs->sr_text = NULL;
+
        if ( new_conn ) {
                
                /*
@@ -506,8 +486,8 @@ meta_back_getconn(
                 * Err could be -1 in case a duplicate metaconn is inserted
                 */
                if ( err != 0 ) {
-                       send_ldap_result( conn, op, LDAP_OTHER,
-                       NULL, "Internal server error", NULL, NULL );
+                       rs->sr_err = LDAP_OTHER;
+                       rs->sr_text = "Internal server error";
                        metaconn_free( lc );
                        return NULL;
                }