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 * Portions Copyright (C) The Internet Society (1997)
14 * ASN.1 fragments are from RFC 2251; see RFC for full legal notices.
17 /* An Unbind Request looks like this:
19 * UnbindRequest ::= NULL
21 * and has no response.
27 #include <ac/stdlib.h>
29 #include <ac/socket.h>
30 #include <ac/string.h>
39 LDAPControl **cctrls )
44 assert( LDAP_VALID( ld ) );
46 /* check client controls */
47 rc = ldap_int_client_controls( ld, cctrls );
48 if( rc != LDAP_SUCCESS ) return rc;
50 return ldap_ld_free( ld, 1, sctrls, cctrls );
57 LDAPControl **cctrls )
59 return ldap_unbind_ext( ld, sctrls, cctrls );
63 ldap_unbind( LDAP *ld )
66 LDAP_LOG ( OPERATION, ENTRY, "ldap_unbind\n", 0, 0, 0 );
68 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
71 return( ldap_unbind_ext( ld, NULL, NULL ) );
80 LDAPControl **cctrls )
82 LDAPMessage *lm, *next;
83 int err = LDAP_SUCCESS;
85 /* free LDAP structure and outstanding requests/responses */
87 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
89 while ( ld->ld_requests != NULL ) {
90 ldap_free_request( ld, ld->ld_requests );
93 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
96 /* free and unbind from all open connections */
97 while ( ld->ld_conns != NULL ) {
98 ldap_free_connection( ld, ld->ld_conns, 1, close );
101 #ifdef LDAP_R_COMPILE
102 ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex );
104 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
108 #ifdef LDAP_R_COMPILE
109 ldap_pvt_thread_mutex_unlock( &ld->ld_res_mutex );
112 if ( ld->ld_error != NULL ) {
113 LDAP_FREE( ld->ld_error );
117 if ( ld->ld_matched != NULL ) {
118 LDAP_FREE( ld->ld_matched );
119 ld->ld_matched = NULL;
122 if( ld->ld_referrals != NULL) {
123 LDAP_VFREE(ld->ld_referrals);
124 ld->ld_referrals = NULL;
127 if ( ld->ld_abandoned != NULL ) {
128 LDAP_FREE( ld->ld_abandoned );
129 ld->ld_abandoned = NULL;
132 if ( ld->ld_selectinfo != NULL ) {
133 ldap_free_select_info( ld->ld_selectinfo );
134 ld->ld_selectinfo = NULL;
137 if ( ld->ld_options.ldo_defludp != NULL ) {
138 ldap_free_urllist( ld->ld_options.ldo_defludp );
139 ld->ld_options.ldo_defludp = NULL;
142 if ( ld->ld_options.ldo_tm_api != NULL ) {
143 LDAP_FREE( ld->ld_options.ldo_tm_api );
144 ld->ld_options.ldo_tm_api = NULL;
147 if ( ld->ld_options.ldo_tm_net != NULL ) {
148 LDAP_FREE( ld->ld_options.ldo_tm_net );
149 ld->ld_options.ldo_tm_net = NULL;
152 #ifdef HAVE_CYRUS_SASL
153 if ( ld->ld_options.ldo_def_sasl_mech != NULL ) {
154 LDAP_FREE( ld->ld_options.ldo_def_sasl_mech );
155 ld->ld_options.ldo_def_sasl_mech = NULL;
158 if ( ld->ld_options.ldo_def_sasl_realm != NULL ) {
159 LDAP_FREE( ld->ld_options.ldo_def_sasl_realm );
160 ld->ld_options.ldo_def_sasl_realm = NULL;
163 if ( ld->ld_options.ldo_def_sasl_authcid != NULL ) {
164 LDAP_FREE( ld->ld_options.ldo_def_sasl_authcid );
165 ld->ld_options.ldo_def_sasl_authcid = NULL;
168 if ( ld->ld_options.ldo_def_sasl_authzid != NULL ) {
169 LDAP_FREE( ld->ld_options.ldo_def_sasl_authzid );
170 ld->ld_options.ldo_def_sasl_authzid = NULL;
174 ber_sockbuf_free( ld->ld_sb );
176 #ifdef LDAP_R_COMPILE
177 ldap_pvt_thread_mutex_destroy( &ld->ld_req_mutex );
178 ldap_pvt_thread_mutex_destroy( &ld->ld_res_mutex );
180 LDAP_FREE( (char *) ld );
186 ldap_unbind_s( LDAP *ld )
188 return( ldap_unbind_ext( ld, NULL, NULL ) );
196 LDAPControl **sctrls,
197 LDAPControl **cctrls )
203 LDAP_LOG ( OPERATION, ENTRY, "ldap_send_unbind\n", 0, 0, 0 );
205 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
208 #ifdef LDAP_CONNECTIONLESS
212 /* create a message to send */
213 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
214 return( ld->ld_errno );
217 LDAP_NEXT_MSGID( ld, id );
219 if ( ber_printf( ber, "{itn" /*}*/, id,
220 LDAP_REQ_UNBIND ) == -1 ) {
221 ld->ld_errno = LDAP_ENCODING_ERROR;
223 return( ld->ld_errno );
226 /* Put Server Controls */
227 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
232 if ( ber_printf( ber, /*{*/ "N}", LDAP_REQ_UNBIND ) == -1 ) {
233 ld->ld_errno = LDAP_ENCODING_ERROR;
235 return( ld->ld_errno );
238 #ifdef LDAP_R_COMPILE
239 ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
241 ld->ld_errno = LDAP_SUCCESS;
242 /* send the message */
243 if ( ber_flush( sb, ber, 1 ) == -1 ) {
244 ld->ld_errno = LDAP_SERVER_DOWN;
247 #ifdef LDAP_R_COMPILE
248 ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
251 return( ld->ld_errno );