]> 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-2003 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* ACKNOWLEDGEMENTS:
16  * This work was initially developed by the Howard Chu for inclusion
17  * in OpenLDAP Software and subsequently enhanced by Pierangelo
18  * Masarati.
19  */
20 /* This is an altered version */
21 /*
22  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
23  * 
24  * This work has been developed to fulfill the requirements
25  * of SysNet s.n.c. <http:www.sys-net.it> and it has been donated
26  * to the OpenLDAP Foundation in the hope that it may be useful
27  * to the Open Source community, but WITHOUT ANY WARRANTY.
28  *
29  * Permission is granted to anyone to use this software for any purpose
30  * on any computer system, and to alter it and redistribute it, subject
31  * to the following restrictions:
32  *
33  * 1. The author and SysNet s.n.c. are not responsible for the consequences
34  *    of use of this software, no matter how awful, even if they arise from 
35  *    flaws in it.
36  *
37  * 2. The origin of this software must not be misrepresented, either by
38  *    explicit claim or by omission.  Since few users ever read sources,
39  *    credits should appear in the documentation.
40  *
41  * 3. Altered versions must be plainly marked as such, and must not be
42  *    misrepresented as being the original software.  Since few users
43  *    ever read sources, credits should appear in the documentation.
44  *    SysNet s.n.c. cannot be responsible for the consequences of the
45  *    alterations.
46  *
47  * 4. This notice may not be removed or altered.
48  *
49  *
50  * This software is based on the backend back-ldap, implemented
51  * by Howard Chu <hyc@highlandsun.com>, and modified by Mark Valence
52  * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
53  * contributors. The contribution of the original software to the present
54  * implementation is acknowledged in this copyright statement.
55  *
56  * A special acknowledgement goes to Howard for the overall architecture
57  * (and for borrowing large pieces of code), and to Mark, who implemented
58  * from scratch the attribute/objectclass mapping.
59  *
60  * The original copyright statement follows.
61  *
62  * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
63  *
64  * Permission is granted to anyone to use this software for any purpose
65  * on any computer system, and to alter it and redistribute it, subject
66  * to the following restrictions:
67  *
68  * 1. The author is not responsible for the consequences of use of this
69  *    software, no matter how awful, even if they arise from flaws in it.
70  *
71  * 2. The origin of this software must not be misrepresented, either by
72  *    explicit claim or by omission.  Since few users ever read sources,
73  *    credits should appear in the documentation.
74  *
75  * 3. Altered versions must be plainly marked as such, and must not be
76  *    misrepresented as being the original software.  Since few users
77  *    ever read sources, credits should appear in the
78  *    documentation.
79  *
80  * 4. This notice may not be removed or altered.
81  *
82  */
83
84 #include "portable.h"
85
86 #include <stdio.h>
87
88 #include <ac/socket.h>
89 #include <ac/string.h>
90
91 #include "slap.h"
92 #include "../back-ldap/back-ldap.h"
93 #include "back-meta.h"
94
95 int
96 meta_back_conn_destroy(
97                 Backend         *be,
98                 Connection      *conn
99 )
100 {
101         struct metainfo *li = ( struct metainfo * )be->be_private;
102         struct metaconn *lc, lc_curr;
103
104 #ifdef NEW_LOGGING
105         LDAP_LOG( BACK_META, ENTRY,
106                 "meta_back_conn_destroy: fetching conn %ld\n", conn->c_connid, 0, 0 );
107 #else /* !NEW_LOGGING */
108         Debug( LDAP_DEBUG_TRACE,
109                 "=>meta_back_conn_destroy: fetching conn %ld\n%s%s",
110                 conn->c_connid, "", "" );
111 #endif /* !NEW_LOGGING */
112         
113         lc_curr.conn = conn;
114         
115         ldap_pvt_thread_mutex_lock( &li->conn_mutex );
116         lc = avl_delete( &li->conntree, ( caddr_t )&lc_curr,
117                         meta_back_conn_cmp );
118         ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
119
120         if ( lc ) {
121                 int i;
122                 
123 #ifdef NEW_LOGGING
124                 LDAP_LOG( BACK_META, INFO,
125                         "meta_back_conn_destroy: destroying conn %ld\n",
126                         lc->conn->c_connid, 0, 0 );
127 #else /* !NEW_LOGGING */
128                 Debug( LDAP_DEBUG_TRACE,
129                         "=>meta_back_conn_destroy: destroying conn %ld\n%s%s",
130                         lc->conn->c_connid, "", "" );
131 #endif /* !NEW_LOGGING */
132                 
133                 /*
134                  * Cleanup rewrite session
135                  */
136                 for ( i = 0; i < li->ntargets; ++i ) {
137                         if ( lc->conns[ i ].ld == NULL ) {
138                                 continue;
139                         }
140
141                         rewrite_session_delete( li->targets[ i ]->rwmap.rwm_rw, conn );
142                         meta_clear_one_candidate( &lc->conns[ i ], 1 );
143                 }
144
145                 free( lc->conns );
146                 free( lc );
147         }
148
149         /* no response to unbind */
150
151         return 0;
152 }
153