unbind.c revision 1.4 1 1.3 christos /* $NetBSD: unbind.c,v 1.4 2025/09/05 21:16:27 christos Exp $ */
2 1.2 christos
3 1.1 lukem /* unbind.c - ldap backend unbind function */
4 1.2 christos /* $OpenLDAP$ */
5 1.1 lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 1.1 lukem *
7 1.4 christos * Copyright 1999-2024 The OpenLDAP Foundation.
8 1.1 lukem * Portions Copyright 1999-2003 Howard Chu.
9 1.1 lukem * Portions Copyright 2000-2003 Pierangelo Masarati.
10 1.1 lukem * All rights reserved.
11 1.1 lukem *
12 1.1 lukem * Redistribution and use in source and binary forms, with or without
13 1.1 lukem * modification, are permitted only as authorized by the OpenLDAP
14 1.1 lukem * Public License.
15 1.1 lukem *
16 1.1 lukem * A copy of this license is available in the file LICENSE in the
17 1.1 lukem * top-level directory of the distribution or, alternatively, at
18 1.1 lukem * <http://www.OpenLDAP.org/license.html>.
19 1.1 lukem */
20 1.1 lukem /* ACKNOWLEDGEMENTS:
21 1.1 lukem * This work was initially developed by the Howard Chu for inclusion
22 1.1 lukem * in OpenLDAP Software and subsequently enhanced by Pierangelo
23 1.1 lukem * Masarati.
24 1.1 lukem */
25 1.1 lukem
26 1.2 christos #include <sys/cdefs.h>
27 1.3 christos __RCSID("$NetBSD: unbind.c,v 1.4 2025/09/05 21:16:27 christos Exp $");
28 1.2 christos
29 1.1 lukem #include "portable.h"
30 1.1 lukem
31 1.1 lukem #include <stdio.h>
32 1.1 lukem
33 1.1 lukem #include <ac/errno.h>
34 1.1 lukem #include <ac/socket.h>
35 1.1 lukem #include <ac/string.h>
36 1.1 lukem
37 1.1 lukem #include "slap.h"
38 1.1 lukem #include "back-ldap.h"
39 1.1 lukem
40 1.1 lukem int
41 1.1 lukem ldap_back_conn_destroy(
42 1.1 lukem Backend *be,
43 1.1 lukem Connection *conn
44 1.1 lukem )
45 1.1 lukem {
46 1.1 lukem ldapinfo_t *li = (ldapinfo_t *) be->be_private;
47 1.1 lukem ldapconn_t *lc = NULL, lc_curr;
48 1.1 lukem
49 1.1 lukem Debug( LDAP_DEBUG_TRACE,
50 1.1 lukem "=>ldap_back_conn_destroy: fetching conn %ld\n",
51 1.3 christos conn->c_connid );
52 1.1 lukem
53 1.1 lukem lc_curr.lc_conn = conn;
54 1.1 lukem
55 1.1 lukem ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
56 1.1 lukem #if LDAP_BACK_PRINT_CONNTREE > 0
57 1.1 lukem ldap_back_print_conntree( li, ">>> ldap_back_conn_destroy" );
58 1.1 lukem #endif /* LDAP_BACK_PRINT_CONNTREE */
59 1.3 christos while ( ( lc = ldap_tavl_delete( &li->li_conninfo.lai_tree, (caddr_t)&lc_curr, ldap_back_conn_cmp ) ) != NULL )
60 1.1 lukem {
61 1.2 christos assert( !LDAP_BACK_PCONN_ISPRIV( lc ) );
62 1.1 lukem Debug( LDAP_DEBUG_TRACE,
63 1.2 christos "=>ldap_back_conn_destroy: destroying conn %lu "
64 1.1 lukem "refcnt=%d flags=0x%08x\n",
65 1.2 christos lc->lc_conn->c_connid, lc->lc_refcnt, lc->lc_lcflags );
66 1.1 lukem
67 1.1 lukem if ( lc->lc_refcnt > 0 ) {
68 1.1 lukem /* someone else might be accessing the connection;
69 1.1 lukem * mark for deletion */
70 1.1 lukem LDAP_BACK_CONN_CACHED_CLEAR( lc );
71 1.1 lukem LDAP_BACK_CONN_TAINTED_SET( lc );
72 1.1 lukem
73 1.1 lukem } else {
74 1.1 lukem ldap_back_conn_free( lc );
75 1.1 lukem }
76 1.1 lukem }
77 1.1 lukem #if LDAP_BACK_PRINT_CONNTREE > 0
78 1.1 lukem ldap_back_print_conntree( li, "<<< ldap_back_conn_destroy" );
79 1.1 lukem #endif /* LDAP_BACK_PRINT_CONNTREE */
80 1.1 lukem ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
81 1.1 lukem
82 1.1 lukem return 0;
83 1.1 lukem }
84