unbind.c revision 1.1.1.4 1 /* $NetBSD: unbind.c,v 1.1.1.4 2014/05/28 09:58:49 tron Exp $ */
2
3 /* unbind.c - ldap backend unbind function */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 1999-2014 The OpenLDAP Foundation.
8 * Portions Copyright 1999-2003 Howard Chu.
9 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted only as authorized by the OpenLDAP
14 * Public License.
15 *
16 * A copy of this license is available in the file LICENSE in the
17 * top-level directory of the distribution or, alternatively, at
18 * <http://www.OpenLDAP.org/license.html>.
19 */
20 /* ACKNOWLEDGEMENTS:
21 * This work was initially developed by the Howard Chu for inclusion
22 * in OpenLDAP Software and subsequently enhanced by Pierangelo
23 * Masarati.
24 */
25
26 #include "portable.h"
27
28 #include <stdio.h>
29
30 #include <ac/errno.h>
31 #include <ac/socket.h>
32 #include <ac/string.h>
33
34 #include "slap.h"
35 #include "back-ldap.h"
36
37 int
38 ldap_back_conn_destroy(
39 Backend *be,
40 Connection *conn
41 )
42 {
43 ldapinfo_t *li = (ldapinfo_t *) be->be_private;
44 ldapconn_t *lc = NULL, lc_curr;
45
46 Debug( LDAP_DEBUG_TRACE,
47 "=>ldap_back_conn_destroy: fetching conn %ld\n",
48 conn->c_connid, 0, 0 );
49
50 lc_curr.lc_conn = conn;
51
52 ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
53 #if LDAP_BACK_PRINT_CONNTREE > 0
54 ldap_back_print_conntree( li, ">>> ldap_back_conn_destroy" );
55 #endif /* LDAP_BACK_PRINT_CONNTREE */
56 while ( ( lc = avl_delete( &li->li_conninfo.lai_tree, (caddr_t)&lc_curr, ldap_back_conn_cmp ) ) != NULL )
57 {
58 assert( !LDAP_BACK_PCONN_ISPRIV( lc ) );
59 Debug( LDAP_DEBUG_TRACE,
60 "=>ldap_back_conn_destroy: destroying conn %lu "
61 "refcnt=%d flags=0x%08x\n",
62 lc->lc_conn->c_connid, lc->lc_refcnt, lc->lc_lcflags );
63
64 if ( lc->lc_refcnt > 0 ) {
65 /* someone else might be accessing the connection;
66 * mark for deletion */
67 LDAP_BACK_CONN_CACHED_CLEAR( lc );
68 LDAP_BACK_CONN_TAINTED_SET( lc );
69
70 } else {
71 ldap_back_conn_free( lc );
72 }
73 }
74 #if LDAP_BACK_PRINT_CONNTREE > 0
75 ldap_back_print_conntree( li, "<<< ldap_back_conn_destroy" );
76 #endif /* LDAP_BACK_PRINT_CONNTREE */
77 ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
78
79 return 0;
80 }
81