Back to index

openldap  2.4.31
unbind.c
Go to the documentation of this file.
00001 /* unbind.c - ldap backend unbind function */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1999-2012 The OpenLDAP Foundation.
00006  * Portions Copyright 1999-2003 Howard Chu.
00007  * Portions Copyright 2000-2003 Pierangelo Masarati.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted only as authorized by the OpenLDAP
00012  * Public License.
00013  *
00014  * A copy of this license is available in the file LICENSE in the
00015  * top-level directory of the distribution or, alternatively, at
00016  * <http://www.OpenLDAP.org/license.html>.
00017  */
00018 /* ACKNOWLEDGEMENTS:
00019  * This work was initially developed by the Howard Chu for inclusion
00020  * in OpenLDAP Software and subsequently enhanced by Pierangelo
00021  * Masarati.
00022  */
00023 
00024 #include "portable.h"
00025 
00026 #include <stdio.h>
00027 
00028 #include <ac/errno.h>
00029 #include <ac/socket.h>
00030 #include <ac/string.h>
00031 
00032 #include "slap.h"
00033 #include "back-ldap.h"
00034 
00035 int
00036 ldap_back_conn_destroy(
00037               Backend              *be,
00038               Connection    *conn
00039 )
00040 {
00041        ldapinfo_t    *li = (ldapinfo_t *) be->be_private;
00042        ldapconn_t    *lc = NULL, lc_curr;
00043 
00044        Debug( LDAP_DEBUG_TRACE,
00045               "=>ldap_back_conn_destroy: fetching conn %ld\n",
00046               conn->c_connid, 0, 0 );
00047 
00048        lc_curr.lc_conn = conn;
00049        
00050        ldap_pvt_thread_mutex_lock( &li->li_conninfo.lai_mutex );
00051 #if LDAP_BACK_PRINT_CONNTREE > 0
00052        ldap_back_print_conntree( li, ">>> ldap_back_conn_destroy" );
00053 #endif /* LDAP_BACK_PRINT_CONNTREE */
00054        while ( ( lc = avl_delete( &li->li_conninfo.lai_tree, (caddr_t)&lc_curr, ldap_back_conn_cmp ) ) != NULL )
00055        {
00056               assert( !LDAP_BACK_PCONN_ISPRIV( lc ) );
00057               Debug( LDAP_DEBUG_TRACE,
00058                      "=>ldap_back_conn_destroy: destroying conn %lu "
00059                      "refcnt=%d flags=0x%08x\n",
00060                      lc->lc_conn->c_connid, lc->lc_refcnt, lc->lc_lcflags );
00061 
00062               if ( lc->lc_refcnt > 0 ) {
00063                      /* someone else might be accessing the connection;
00064                       * mark for deletion */
00065                      LDAP_BACK_CONN_CACHED_CLEAR( lc );
00066                      LDAP_BACK_CONN_TAINTED_SET( lc );
00067 
00068               } else {
00069                      ldap_back_conn_free( lc );
00070               }
00071        }
00072 #if LDAP_BACK_PRINT_CONNTREE > 0
00073        ldap_back_print_conntree( li, "<<< ldap_back_conn_destroy" );
00074 #endif /* LDAP_BACK_PRINT_CONNTREE */
00075        ldap_pvt_thread_mutex_unlock( &li->li_conninfo.lai_mutex );
00076 
00077        return 0;
00078 }