Back to index

openldap  2.4.31
unbind.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1999-2012 The OpenLDAP Foundation.
00005  * Portions Copyright 2001-2003 Pierangelo Masarati.
00006  * Portions Copyright 1999-2003 Howard Chu.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in the file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 /* ACKNOWLEDGEMENTS:
00018  * This work was initially developed by the Howard Chu for inclusion
00019  * in OpenLDAP Software and subsequently enhanced by Pierangelo
00020  * Masarati.
00021  */
00022 
00023 #include "portable.h"
00024 
00025 #include <stdio.h>
00026 
00027 #include <ac/errno.h>
00028 #include <ac/socket.h>
00029 #include <ac/string.h>
00030 
00031 #include "slap.h"
00032 #include "../back-ldap/back-ldap.h"
00033 #include "back-meta.h"
00034 
00035 int
00036 meta_back_conn_destroy(
00037        Backend              *be,
00038        Connection    *conn )
00039 {
00040        metainfo_t    *mi = ( metainfo_t * )be->be_private;
00041        metaconn_t    *mc,
00042                      mc_curr = {{ 0 }};
00043        int           i;
00044 
00045 
00046        Debug( LDAP_DEBUG_TRACE,
00047               "=>meta_back_conn_destroy: fetching conn=%ld DN=\"%s\"\n",
00048               conn->c_connid,
00049               BER_BVISNULL( &conn->c_ndn ) ? "" : conn->c_ndn.bv_val, 0 );
00050        
00051        mc_curr.mc_conn = conn;
00052        
00053        ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
00054 #if META_BACK_PRINT_CONNTREE > 0
00055        meta_back_print_conntree( mi, ">>> meta_back_conn_destroy" );
00056 #endif /* META_BACK_PRINT_CONNTREE */
00057        while ( ( mc = avl_delete( &mi->mi_conninfo.lai_tree, ( caddr_t )&mc_curr, meta_back_conn_cmp ) ) != NULL )
00058        {
00059               assert( !LDAP_BACK_PCONN_ISPRIV( mc ) );
00060               Debug( LDAP_DEBUG_TRACE,
00061                      "=>meta_back_conn_destroy: destroying conn %lu "
00062                      "refcnt=%d flags=0x%08x\n",
00063                      mc->mc_conn->c_connid, mc->mc_refcnt, mc->msc_mscflags );
00064               
00065               if ( mc->mc_refcnt > 0 ) {
00066                      /* someone else might be accessing the connection;
00067                       * mark for deletion */
00068                      LDAP_BACK_CONN_CACHED_CLEAR( mc );
00069                      LDAP_BACK_CONN_TAINTED_SET( mc );
00070 
00071               } else {
00072                      meta_back_conn_free( mc );
00073               }
00074        }
00075 #if META_BACK_PRINT_CONNTREE > 0
00076        meta_back_print_conntree( mi, "<<< meta_back_conn_destroy" );
00077 #endif /* META_BACK_PRINT_CONNTREE */
00078        ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
00079 
00080        /*
00081         * Cleanup rewrite session
00082         */
00083        for ( i = 0; i < mi->mi_ntargets; ++i ) {
00084               rewrite_session_delete( mi->mi_targets[ i ]->mt_rwmap.rwm_rw, conn );
00085        }
00086 
00087        return 0;
00088 }
00089