]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/unbind.c
First round of imports from HEAD
[openldap] / servers / slapd / back-ldap / unbind.c
1 /* unbind.c - ldap backend unbind function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7 /* This is an altered version */
8 /*
9  * Copyright 1999, Howard Chu, All rights reserved. <hyc@highlandsun.com>
10  * 
11  * Permission is granted to anyone to use this software for any purpose
12  * on any computer system, and to alter it and redistribute it, subject
13  * to the following restrictions:
14  * 
15  * 1. The author is not responsible for the consequences of use of this
16  *    software, no matter how awful, even if they arise from flaws in it.
17  * 
18  * 2. The origin of this software must not be misrepresented, either by
19  *    explicit claim or by omission.  Since few users ever read sources,
20  *    credits should appear in the documentation.
21  * 
22  * 3. Altered versions must be plainly marked as such, and must not be
23  *    misrepresented as being the original software.  Since few users
24  *    ever read sources, credits should appear in the documentation.
25  * 
26  * 4. This notice may not be removed or altered.
27  *
28  *
29  *
30  * Copyright 2000, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
31  *
32  * This software is being modified by Pierangelo Masarati.
33  * The previously reported conditions apply to the modified code as well.
34  * Changes in the original code are highlighted where required.
35  * Credits for the original code go to the author, Howard Chu.
36  */
37
38 #include "portable.h"
39
40 #include <stdio.h>
41
42 #include <ac/socket.h>
43 #include <ac/string.h>
44
45 #include "slap.h"
46 #include "back-ldap.h"
47
48 int
49 ldap_back_conn_destroy(
50     Backend             *be,
51     Connection          *conn
52 )
53 {
54         struct ldapinfo *li = (struct ldapinfo *) be->be_private;
55         struct ldapconn *lc, lc_curr;
56
57 #ifdef NEW_LOGGING
58         LDAP_LOG( BACK_LDAP, INFO,
59                 "ldap_back_conn_destroy: fetching conn %ld\n", conn->c_connid, 0, 0 );
60 #else /* !NEW_LOGGING */
61         Debug( LDAP_DEBUG_TRACE,
62                 "=>ldap_back_conn_destroy: fetching conn %ld\n",
63                 conn->c_connid, 0, 0 );
64 #endif /* !NEW_LOGGING */
65
66         lc_curr.conn = conn;
67         
68         ldap_pvt_thread_mutex_lock( &li->conn_mutex );
69         lc = avl_delete( &li->conntree, (caddr_t)&lc_curr, ldap_back_conn_cmp );
70         ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
71
72         if (lc) {
73 #ifdef NEW_LOGGING
74                 LDAP_LOG( BACK_LDAP, DETAIL1, 
75                         "ldap_back_conn_destroy: destroying conn %ld\n", 
76                         conn->c_connid, 0, 0 );
77 #else /* !NEW_LOGGING */
78                 Debug( LDAP_DEBUG_TRACE,
79                         "=>ldap_back_conn_destroy: destroying conn %ld\n",
80                         lc->conn->c_connid, 0, 0 );
81 #endif
82
83 #ifdef ENABLE_REWRITE
84                 /*
85                  * Cleanup rewrite session
86                  */
87                 rewrite_session_delete( li->rwinfo, conn );
88 #endif /* ENABLE_REWRITE */
89
90                 /*
91                  * Needs a test because the handler may be corrupted,
92                  * and calling ldap_unbind on a corrupted header results
93                  * in a segmentation fault
94                  */
95                 ldap_unbind(lc->ld);
96                 if ( lc->bound_dn.bv_val ) {
97                         ch_free( lc->bound_dn.bv_val );
98                 }
99                 if ( lc->cred.bv_val ) {
100                         ch_free( lc->cred.bv_val );
101                 }
102                 ch_free( lc );
103         }
104
105         /* no response to unbind */
106
107         return 0;
108 }