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