3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1990 Regents of the University of Michigan.
13 /* An Unbind Request looks like this:
15 * UnbindRequest ::= NULL
17 * and has no response.
23 #include <ac/stdlib.h>
25 #include <ac/socket.h>
26 #include <ac/string.h>
35 LDAPControl **cctrls )
40 assert( LDAP_VALID( ld ) );
42 /* check client controls */
43 rc = ldap_int_client_controls( ld, cctrls );
44 if( rc != LDAP_SUCCESS ) return rc;
46 return ldap_ld_free( ld, 1, sctrls, cctrls );
53 LDAPControl **cctrls )
55 return ldap_unbind_ext( ld, sctrls, cctrls );
59 ldap_unbind( LDAP *ld )
62 LDAP_LOG ( OPERATION, ENTRY, "ldap_unbind\n", 0, 0, 0 );
64 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
67 return( ldap_unbind_ext( ld, NULL, NULL ) );
76 LDAPControl **cctrls )
78 LDAPMessage *lm, *next;
79 int err = LDAP_SUCCESS;
81 /* free LDAP structure and outstanding requests/responses */
83 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
85 while ( ld->ld_requests != NULL ) {
86 ldap_free_request( ld, ld->ld_requests );
89 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
92 /* free and unbind from all open connections */
93 while ( ld->ld_conns != NULL ) {
94 ldap_free_connection( ld, ld->ld_conns, 1, close );
98 ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex );
100 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
104 #ifdef LDAP_R_COMPILE
105 ldap_pvt_thread_mutex_unlock( &ld->ld_res_mutex );
108 if ( ld->ld_error != NULL ) {
109 LDAP_FREE( ld->ld_error );
113 if ( ld->ld_matched != NULL ) {
114 LDAP_FREE( ld->ld_matched );
115 ld->ld_matched = NULL;
118 if( ld->ld_referrals != NULL) {
119 LDAP_VFREE(ld->ld_referrals);
120 ld->ld_referrals = NULL;
123 if ( ld->ld_abandoned != NULL ) {
124 LDAP_FREE( ld->ld_abandoned );
125 ld->ld_abandoned = NULL;
128 if ( ld->ld_selectinfo != NULL ) {
129 ldap_free_select_info( ld->ld_selectinfo );
130 ld->ld_selectinfo = NULL;
133 if ( ld->ld_options.ldo_defludp != NULL ) {
134 ldap_free_urllist( ld->ld_options.ldo_defludp );
135 ld->ld_options.ldo_defludp = NULL;
138 if ( ld->ld_options.ldo_tm_api != NULL ) {
139 LDAP_FREE( ld->ld_options.ldo_tm_api );
140 ld->ld_options.ldo_tm_api = NULL;
143 if ( ld->ld_options.ldo_tm_net != NULL ) {
144 LDAP_FREE( ld->ld_options.ldo_tm_net );
145 ld->ld_options.ldo_tm_net = NULL;
148 #ifdef HAVE_CYRUS_SASL
149 if ( ld->ld_options.ldo_def_sasl_mech != NULL ) {
150 LDAP_FREE( ld->ld_options.ldo_def_sasl_mech );
151 ld->ld_options.ldo_def_sasl_mech = NULL;
154 if ( ld->ld_options.ldo_def_sasl_realm != NULL ) {
155 LDAP_FREE( ld->ld_options.ldo_def_sasl_realm );
156 ld->ld_options.ldo_def_sasl_realm = NULL;
159 if ( ld->ld_options.ldo_def_sasl_authcid != NULL ) {
160 LDAP_FREE( ld->ld_options.ldo_def_sasl_authcid );
161 ld->ld_options.ldo_def_sasl_authcid = NULL;
164 if ( ld->ld_options.ldo_def_sasl_authzid != NULL ) {
165 LDAP_FREE( ld->ld_options.ldo_def_sasl_authzid );
166 ld->ld_options.ldo_def_sasl_authzid = NULL;
170 ber_sockbuf_free( ld->ld_sb );
172 #ifdef LDAP_R_COMPILE
173 ldap_pvt_thread_mutex_destroy( &ld->ld_req_mutex );
174 ldap_pvt_thread_mutex_destroy( &ld->ld_res_mutex );
176 LDAP_FREE( (char *) ld );
182 ldap_unbind_s( LDAP *ld )
184 return( ldap_unbind_ext( ld, NULL, NULL ) );
192 LDAPControl **sctrls,
193 LDAPControl **cctrls )
199 LDAP_LOG ( OPERATION, ENTRY, "ldap_send_unbind\n", 0, 0, 0 );
201 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
204 #ifdef LDAP_CONNECTIONLESS
208 /* create a message to send */
209 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
210 return( ld->ld_errno );
213 LDAP_NEXT_MSGID( ld, id );
215 if ( ber_printf( ber, "{itn" /*}*/, id,
216 LDAP_REQ_UNBIND ) == -1 ) {
217 ld->ld_errno = LDAP_ENCODING_ERROR;
219 return( ld->ld_errno );
222 /* Put Server Controls */
223 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
228 if ( ber_printf( ber, /*{*/ "N}", LDAP_REQ_UNBIND ) == -1 ) {
229 ld->ld_errno = LDAP_ENCODING_ERROR;
231 return( ld->ld_errno );
234 #ifdef LDAP_R_COMPILE
235 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
237 ld->ld_errno = LDAP_SUCCESS;
238 /* send the message */
239 if ( ber_flush( sb, ber, 1 ) == -1 ) {
240 ld->ld_errno = LDAP_SERVER_DOWN;
243 #ifdef LDAP_R_COMPILE
244 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
247 return( ld->ld_errno );