| 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-2024 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/errno.h> |
| 29 |
#include <ac/socket.h> |
| 30 |
#include <ac/string.h> |
| 31 |
|
| 32 |
#include "slap.h" |
| 33 |
#include "back-ldap.h" |
| 34 |
|
| 35 |
int |
| 36 |
ldap_back_conn_destroy( |
| 37 |
Backend *be, |
| 38 |
Connection *conn |
| 39 |
) |
| 40 |
{ |
| 41 |
ldapinfo_t *li = (ldapinfo_t *) be->be_private; |
| 42 |
ldapconn_t *lc = NULL, lc_curr; |
| 43 |
|
| 44 |
Debug( LDAP_DEBUG_TRACE, |
| 45 |
"=>ldap_back_conn_destroy: fetching conn %ld\n", |
| 46 |
conn->c_connid ); |
| 47 |
|
| 48 |
lc_curr.lc_conn = conn; |
| 49 |
|
| 50 |
ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex ); |
| 51 |
#if LDAP_BACK_PRINT_CONNTREE > 0 |
| 52 |
ldap_back_print_conntree( li, ">>> ldap_back_conn_destroy" ); |
| 53 |
#endif /* LDAP_BACK_PRINT_CONNTREE */ |
| 54 |
while ( ( lc = ldap_tavl_delete( &li->li_conninfo.lai_tree, (caddr_t)&lc_curr, ldap_back_conn_cmp ) ) != NULL ) |
| 55 |
{ |
| 56 |
assert( !LDAP_BACK_PCONN_ISPRIV( lc ) ); |
| 57 |
Debug( LDAP_DEBUG_TRACE, |
| 58 |
"=>ldap_back_conn_destroy: destroying conn %lu " |
| 59 |
"refcnt=%d flags=0x%08x\n", |
| 60 |
lc->lc_conn->c_connid, lc->lc_refcnt, lc->lc_lcflags ); |
| 61 |
|
| 62 |
if ( lc->lc_refcnt > 0 ) { |
| 63 |
/* someone else might be accessing the connection; |
| 64 |
* mark for deletion */ |
| 65 |
LDAP_BACK_CONN_CACHED_CLEAR( lc ); |
| 66 |
LDAP_BACK_CONN_TAINTED_SET( lc ); |
| 67 |
|
| 68 |
} else { |
| 69 |
ldap_back_conn_free( lc ); |
| 70 |
} |
| 71 |
} |
| 72 |
#if LDAP_BACK_PRINT_CONNTREE > 0 |
| 73 |
ldap_back_print_conntree( li, "<<< ldap_back_conn_destroy" ); |
| 74 |
#endif /* LDAP_BACK_PRINT_CONNTREE */ |
| 75 |
ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex ); |
| 76 |
|
| 77 |
return 0; |
| 78 |
} |