]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/unbind.c
Sync with HEAD
[openldap] / servers / slapd / back-meta / unbind.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2005 The OpenLDAP Foundation.
5  * Portions Copyright 2001-2003 Pierangelo Masarati.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * All rights reserved.
8  *
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.
12  *
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>.
16  */
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.
21  */
22
23 #include "portable.h"
24
25 #include <stdio.h>
26
27 #include <ac/errno.h>
28 #include <ac/socket.h>
29 #include <ac/string.h>
30
31 #include "slap.h"
32 #include "../back-ldap/back-ldap.h"
33 #include "back-meta.h"
34
35 int
36 meta_back_conn_destroy(
37         Backend         *be,
38         Connection      *conn )
39 {
40         metainfo_t      *mi = ( metainfo_t * )be->be_private;
41         metaconn_t      *mc,
42                         mc_curr = { 0 };
43         int             i;
44
45
46         Debug( LDAP_DEBUG_TRACE,
47                 "=>meta_back_conn_destroy: fetching conn %ld\n",
48                 conn->c_connid, 0, 0 );
49         
50         mc_curr.mc_conn = conn;
51         mc_curr.mc_local_ndn = conn->c_ndn;
52         
53         ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
54         mc = avl_delete( &mi->mi_conntree, ( caddr_t )&mc_curr,
55                         meta_back_conn_cmp );
56         ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
57
58         if ( mc ) {
59                 Debug( LDAP_DEBUG_TRACE,
60                         "=>meta_back_conn_destroy: destroying conn %ld\n",
61                         LDAP_BACK_PCONN_ID( mc->mc_conn ), 0, 0 );
62                 
63                 assert( mc->mc_refcnt == 0 );
64
65                 meta_back_conn_free( mc );
66         }
67
68         /*
69          * Cleanup rewrite session
70          */
71         for ( i = 0; i < mi->mi_ntargets; ++i ) {
72                 rewrite_session_delete( mi->mi_targets[ i ].mt_rwmap.rwm_rw, conn );
73         }
74
75         return 0;
76 }
77