1 /* $NetBSD: unbind.c,v 1.1.1.3 2010/12/12 15:23:13 adam Exp $ */ 2 3 /* OpenLDAP: pkg/ldap/servers/slapd/back-meta/unbind.c,v 1.30.2.8 2010/04/13 20:23:31 kurt Exp */ 4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 1999-2010 The OpenLDAP Foundation. 7 * Portions Copyright 2001-2003 Pierangelo Masarati. 8 * Portions Copyright 1999-2003 Howard Chu. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted only as authorized by the OpenLDAP 13 * Public License. 14 * 15 * A copy of this license is available in the file LICENSE in the 16 * top-level directory of the distribution or, alternatively, at 17 * <http://www.OpenLDAP.org/license.html>. 18 */ 19 /* ACKNOWLEDGEMENTS: 20 * This work was initially developed by the Howard Chu for inclusion 21 * in OpenLDAP Software and subsequently enhanced by Pierangelo 22 * Masarati. 23 */ 24 25 #include "portable.h" 26 27 #include <stdio.h> 28 29 #include <ac/errno.h> 30 #include <ac/socket.h> 31 #include <ac/string.h> 32 33 #include "slap.h" 34 #include "../back-ldap/back-ldap.h" 35 #include "back-meta.h" 36 37 int 38 meta_back_conn_destroy( 39 Backend *be, 40 Connection *conn ) 41 { 42 metainfo_t *mi = ( metainfo_t * )be->be_private; 43 metaconn_t *mc, 44 mc_curr = {{ 0 }}; 45 int i; 46 47 48 Debug( LDAP_DEBUG_TRACE, 49 "=>meta_back_conn_destroy: fetching conn=%ld DN=\"%s\"\n", 50 conn->c_connid, 51 BER_BVISNULL( &conn->c_ndn ) ? "" : conn->c_ndn.bv_val, 0 ); 52 53 mc_curr.mc_conn = conn; 54 55 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex ); 56 #if META_BACK_PRINT_CONNTREE > 0 57 meta_back_print_conntree( mi, ">>> meta_back_conn_destroy" ); 58 #endif /* META_BACK_PRINT_CONNTREE */ 59 while ( ( mc = avl_delete( &mi->mi_conninfo.lai_tree, ( caddr_t )&mc_curr, meta_back_conn_cmp ) ) != NULL ) 60 { 61 assert( !LDAP_BACK_PCONN_ISPRIV( mc ) ); 62 Debug( LDAP_DEBUG_TRACE, 63 "=>meta_back_conn_destroy: destroying conn %lu " 64 "refcnt=%d flags=0x%08x\n", 65 mc->mc_conn->c_connid, mc->mc_refcnt, mc->msc_mscflags ); 66 67 if ( mc->mc_refcnt > 0 ) { 68 /* someone else might be accessing the connection; 69 * mark for deletion */ 70 LDAP_BACK_CONN_CACHED_CLEAR( mc ); 71 LDAP_BACK_CONN_TAINTED_SET( mc ); 72 73 } else { 74 meta_back_conn_free( mc ); 75 } 76 } 77 #if META_BACK_PRINT_CONNTREE > 0 78 meta_back_print_conntree( mi, "<<< meta_back_conn_destroy" ); 79 #endif /* META_BACK_PRINT_CONNTREE */ 80 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex ); 81 82 /* 83 * Cleanup rewrite session 84 */ 85 for ( i = 0; i < mi->mi_ntargets; ++i ) { 86 rewrite_session_delete( mi->mi_targets[ i ]->mt_rwmap.rwm_rw, conn ); 87 } 88 89 return 0; 90 } 91 92