]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/conn.c
Fix prev commit, return generated passwd
[openldap] / servers / slapd / back-meta / conn.c
index ba4d50fc93c22d3b3e574a8868a07846a32f7ed9..c68cde490fa8e7ca343260531e6c7e477e3fe194 100644 (file)
@@ -1,7 +1,24 @@
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1999-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * 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.
+ */
+/* This is an altered version */
+/*
  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
  *
  * This work has been developed to fulfill the requirements
@@ -97,8 +114,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 +204,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;
@@ -227,7 +252,9 @@ init_one_conn(
                struct metasingleconn   *lsc
                )
 {
+       struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
        int             vers;
+       dncookie        dc;
 
        /*
         * Already init'ed
@@ -253,6 +280,18 @@ 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
         */
@@ -262,51 +301,17 @@ init_one_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->rwmap.rwm_rw, "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;
                }