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