]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/conn.c
works now
[openldap] / servers / slapd / back-meta / conn.c
index 58dc1f04482b13e94f9dea5ba0147f47f1090105..00f1d9e9612fafed8de176e53758cf70037547ba 100644 (file)
@@ -1,67 +1,23 @@
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
- *
- * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
- *
- * This work has been developed to fulfill the requirements
- * of SysNet s.n.c. <http:www.sys-net.it> and it has been donated
- * to the OpenLDAP Foundation in the hope that it may be useful
- * to the Open Source community, but WITHOUT ANY WARRANTY.
- *
- * Permission is granted to anyone to use this software for any purpose
- * on any computer system, and to alter it and redistribute it, subject
- * to the following restrictions:
- *
- * 1. The author and SysNet s.n.c. are not responsible for the consequences
- *    of use of this software, no matter how awful, even if they arise from 
- *    flaws in it.
- *
- * 2. The origin of this software must not be misrepresented, either by
- *    explicit claim or by omission.  Since few users ever read sources,
- *    credits should appear in the documentation.
- *
- * 3. Altered versions must be plainly marked as such, and must not be
- *    misrepresented as being the original software.  Since few users
- *    ever read sources, credits should appear in the documentation.
- *    SysNet s.n.c. cannot be responsible for the consequences of the
- *    alterations.
- *
- * 4. This notice may not be removed or altered.
- *
- *
- * This software is based on the backend back-ldap, implemented
- * by Howard Chu <hyc@highlandsun.com>, and modified by Mark Valence
- * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
- * contributors. The contribution of the original software to the present
- * implementation is acknowledged in this copyright statement.
- *
- * A special acknowledgement goes to Howard for the overall architecture
- * (and for borrowing large pieces of code), and to Mark, who implemented
- * from scratch the attribute/objectclass mapping.
- *
- * The original copyright statement follows.
- *
- * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
- *
- * Permission is granted to anyone to use this software for any purpose
- * on any computer system, and to alter it and redistribute it, subject
- * to the following restrictions:
- *
- * 1. The author is not responsible for the consequences of use of this
- *    software, no matter how awful, even if they arise from flaws in it.
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * 2. The origin of this software must not be misrepresented, either by
- *    explicit claim or by omission.  Since few users ever read sources,
- *    credits should appear in the documentation.
+ * Copyright 1999-2004 The OpenLDAP Foundation.
+ * Portions Copyright 2001-2003 Pierangelo Masarati.
+ * Portions Copyright 1999-2003 Howard Chu.
+ * All rights reserved.
  *
- * 3. Altered versions must be plainly marked as such, and must not be
- *    misrepresented as being the original software.  Since few users
- *    ever read sources, credits should appear in the
- *    documentation.
- *
- * 4. This notice may not be removed or altered.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
  *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by the Howard Chu for inclusion
+ * in OpenLDAP Software and subsequently enhanced by Pierangelo
+ * Masarati.
  */
 
 #include "portable.h"
@@ -97,8 +53,7 @@ meta_back_conn_cmp(
        struct metaconn *lc1 = ( struct metaconn * )c1;
         struct metaconn *lc2 = ( struct metaconn * )c2;
        
-       return ( ( lc1->conn < lc2->conn ) ? -1 :
-                       ( ( lc1->conn > lc2-> conn ) ? 1 : 0 ) );
+       return SLAP_PTRCMP( lc1->conn, lc2->conn );
 }
 
 /*
@@ -188,6 +143,15 @@ metaconn_alloc( int ntargets )
        }
        lc->conns[ ntargets ].candidate = META_LAST_CONN;
 
+       for ( ; ntargets-- > 0; ) {
+               lc->conns[ ntargets ].ld = NULL;
+               lc->conns[ ntargets ].bound_dn.bv_val = NULL;
+               lc->conns[ ntargets ].bound_dn.bv_len = 0;
+               lc->conns[ ntargets ].cred.bv_val = NULL;
+               lc->conns[ ntargets ].cred.bv_len = 0;
+               lc->conns[ ntargets ].bound = META_UNBOUND;
+       }
+
        lc->bound_target = META_BOUND_NONE;
 
        return lc;
@@ -221,13 +185,15 @@ metaconn_free(
  */
 static int
 init_one_conn(
-               Operation *op,
-               SlapReply *rs,
+               Operation               *op,
+               SlapReply               *rs,
                struct metatarget       *lt, 
                struct metasingleconn   *lsc
                )
 {
-       int             err, vers;
+       struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
+       int             vers;
+       dncookie        dc;
 
        /*
         * Already init'ed
@@ -239,9 +205,9 @@ 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 slap_map_api2result( rs );
        }
 
        /*
@@ -253,63 +219,46 @@ init_one_conn(
        /* FIXME: configurable? */
        ldap_set_option(lsc->ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON);
 
+       /*
+        * Set the network timeout if set
+        */
+       if (li->network_timeout != 0){
+               struct timeval network_timeout;
+
+               network_timeout.tv_usec = 0;
+               network_timeout.tv_sec = li->network_timeout;
+
+               ldap_set_option( lsc->ld, LDAP_OPT_NETWORK_TIMEOUT, (void *) &network_timeout);
+       }
+
        /*
         * Sets a cookie for the rewrite session
         */
-       ( void )rewrite_session_init( lt->rwinfo, op->o_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 ( 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",
-                                       op->o_conn->c_dn.bv_val, op->o_conn, 
-                                       &lsc->bound_dn.bv_val ) ) {
-               case REWRITE_REGEXEC_OK:
-                       if ( lsc->bound_dn.bv_val == NULL ) {
-                               ber_dupbv( &lsc->bound_dn, &op->o_conn->c_dn );
-                       }
-#ifdef NEW_LOGGING
-                       LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] bindDn: \"%s\" -> \"%s\"\n",
-                               op->o_conn->c_dn.bv_val,
-                               lsc->bound_dn.bv_val, 0 );
-#else /* !NEW_LOGGING */
-                       Debug( LDAP_DEBUG_ARGS,
-                                       "rw> bindDn: \"%s\" -> \"%s\"\n",
-                                       op->o_conn->c_dn.bv_val,
-                                       lsc->bound_dn.bv_val, 0 );
-#endif /* !NEW_LOGGING */
-                       break;
-                       
-               case REWRITE_REGEXEC_UNWILLING:
-                       rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-                       rs->sr_text = "Operation not allowed";
-#if 0
-                       send_ldap_result( conn, op,
-                                       LDAP_UNWILLING_TO_PERFORM,
-                                       NULL, "Operation not allowed",
-                                       NULL, NULL );
-#endif
-                       return rs->sr_err;
-                       
-               case REWRITE_REGEXEC_ERR:
-                       rs->sr_err = LDAP_OTHER;
-                       rs->sr_text = "Rewrite error";
-#if 0
-                       send_ldap_result( conn, op,
-                                       LDAP_OTHER,
-                                       NULL, "Rewrite error",
-                                       NULL, NULL );
-#endif
+               if ( ldap_back_dn_massage( &dc, &op->o_conn->c_dn,
+                                       &lsc->bound_dn) ) {
+                       send_ldap_result( op, rs );
                        return rs->sr_err;
                }
 
+               /* copy the DN idf needed */
+               if ( lsc->bound_dn.bv_val == op->o_conn->c_dn.bv_val ) {
+                       ber_dupbv( &lsc->bound_dn, &op->o_conn->c_dn );
+               }
+
                assert( lsc->bound_dn.bv_val );
 
        } else {
@@ -339,13 +288,13 @@ init_one_conn(
  */
 struct metaconn *
 meta_back_getconn(
-               struct metainfo *li,
                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;
@@ -393,15 +342,9 @@ meta_back_getconn(
                        return NULL;
                }
                                
-#ifdef NEW_LOGGING
-               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->bv_val, "" );
-#endif /* !NEW_LOGGING */
 
                /*
                 * Clear all other candidates
@@ -507,14 +450,9 @@ meta_back_getconn(
                
                ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
 
-#ifdef NEW_LOGGING
-               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",
                        lc->conn->c_connid, "", "" );
-#endif /* !NEW_LOGGING */
                
                /*
                 * Err could be -1 in case a duplicate metaconn is inserted
@@ -526,14 +464,9 @@ meta_back_getconn(
                        return NULL;
                }
        } else {
-#ifdef NEW_LOGGING
-               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",
                        lc->conn->c_connid, "", "" );
-#endif /* !NEW_LOGGING */
        }
        
        return lc;