]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/unbind.c
ITS#3032: retry when GSSAPI creds are not available
[openldap] / servers / slapd / back-ldap / unbind.c
1 /* unbind.c - ldap backend unbind function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1999-2004 The OpenLDAP Foundation.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * Portions Copyright 2000-2003 Pierangelo Masarati.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by the Howard Chu for inclusion
20  * in OpenLDAP Software and subsequently enhanced by Pierangelo
21  * Masarati.
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27
28 #include <ac/socket.h>
29 #include <ac/string.h>
30
31 #include "slap.h"
32 #include "back-ldap.h"
33
34 int
35 ldap_back_conn_destroy(
36     Backend             *be,
37     Connection          *conn
38 )
39 {
40         struct ldapinfo *li = (struct ldapinfo *) be->be_private;
41         struct ldapconn *lc, lc_curr;
42
43 #ifdef NEW_LOGGING
44         LDAP_LOG( BACK_LDAP, INFO,
45                 "ldap_back_conn_destroy: fetching conn %ld\n", conn->c_connid, 0, 0 );
46 #else /* !NEW_LOGGING */
47         Debug( LDAP_DEBUG_TRACE,
48                 "=>ldap_back_conn_destroy: fetching conn %ld\n",
49                 conn->c_connid, 0, 0 );
50 #endif /* !NEW_LOGGING */
51
52         lc_curr.conn = conn;
53         lc_curr.local_dn = conn->c_ndn;
54         
55         ldap_pvt_thread_mutex_lock( &li->conn_mutex );
56         lc = avl_delete( &li->conntree, (caddr_t)&lc_curr, ldap_back_conn_cmp );
57         ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
58
59         if (lc) {
60 #ifdef NEW_LOGGING
61                 LDAP_LOG( BACK_LDAP, DETAIL1, 
62                         "ldap_back_conn_destroy: destroying conn %ld\n", 
63                         conn->c_connid, 0, 0 );
64 #else /* !NEW_LOGGING */
65                 Debug( LDAP_DEBUG_TRACE,
66                         "=>ldap_back_conn_destroy: destroying conn %ld\n",
67                         lc->conn->c_connid, 0, 0 );
68 #endif
69
70 #ifdef ENABLE_REWRITE
71                 /*
72                  * Cleanup rewrite session
73                  */
74                 rewrite_session_delete( li->rwmap.rwm_rw, conn );
75 #endif /* ENABLE_REWRITE */
76
77                 /*
78                  * Needs a test because the handler may be corrupted,
79                  * and calling ldap_unbind on a corrupted header results
80                  * in a segmentation fault
81                  */
82                 ldap_back_conn_free( lc );
83         }
84
85         /* no response to unbind */
86
87         return 0;
88 }