3 * Copyright 1998-2002 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 (( "unbind", LDAP_LEVEL_ENTRY, "ldap_unbind\n" ));
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 */
82 while ( ld->ld_requests != NULL ) {
83 ldap_free_request( ld, ld->ld_requests );
86 /* free and unbind from all open connections */
87 while ( ld->ld_conns != NULL ) {
88 ldap_free_connection( ld, ld->ld_conns, 1, close );
91 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
97 if ( ld->ld_cache != NULL ) {
98 ldap_destroy_cache( ld );
101 #endif /* !LDAP_NOCACHE */
103 if ( ld->ld_error != NULL ) {
104 LDAP_FREE( ld->ld_error );
108 if ( ld->ld_matched != NULL ) {
109 LDAP_FREE( ld->ld_matched );
110 ld->ld_matched = NULL;
113 if ( ld->ld_abandoned != NULL ) {
114 LDAP_FREE( ld->ld_abandoned );
115 ld->ld_abandoned = NULL;
118 if ( ld->ld_selectinfo != NULL ) {
119 ldap_free_select_info( ld->ld_selectinfo );
120 ld->ld_selectinfo = NULL;
123 if ( ld->ld_options.ldo_defludp != NULL ) {
124 ldap_free_urllist( ld->ld_options.ldo_defludp );
125 ld->ld_options.ldo_defludp = NULL;
128 if ( ld->ld_options.ldo_tm_api != NULL ) {
129 LDAP_FREE( ld->ld_options.ldo_tm_api );
130 ld->ld_options.ldo_tm_api = NULL;
133 if ( ld->ld_options.ldo_tm_net != NULL ) {
134 LDAP_FREE( ld->ld_options.ldo_tm_net );
135 ld->ld_options.ldo_tm_net = NULL;
138 #ifdef HAVE_CYRUS_SASL
139 if ( ld->ld_options.ldo_def_sasl_mech != NULL ) {
140 LDAP_FREE( ld->ld_options.ldo_def_sasl_mech );
141 ld->ld_options.ldo_def_sasl_mech = NULL;
144 if ( ld->ld_options.ldo_def_sasl_realm != NULL ) {
145 LDAP_FREE( ld->ld_options.ldo_def_sasl_realm );
146 ld->ld_options.ldo_def_sasl_realm = NULL;
149 if ( ld->ld_options.ldo_def_sasl_authcid != NULL ) {
150 LDAP_FREE( ld->ld_options.ldo_def_sasl_authcid );
151 ld->ld_options.ldo_def_sasl_authcid = NULL;
154 if ( ld->ld_options.ldo_def_sasl_authzid != NULL ) {
155 LDAP_FREE( ld->ld_options.ldo_def_sasl_authzid );
156 ld->ld_options.ldo_def_sasl_authzid = NULL;
160 ber_sockbuf_free( ld->ld_sb );
162 LDAP_FREE( (char *) ld );
168 ldap_unbind_s( LDAP *ld )
170 return( ldap_unbind_ext( ld, NULL, NULL ) );
178 LDAPControl **sctrls,
179 LDAPControl **cctrls )
184 LDAP_LOG (( "unbind", LDAP_LEVEL_ENTRY, "ldap_send_unbind\n" ));
186 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
189 #ifdef LDAP_CONNECTIONLESS
193 /* create a message to send */
194 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
195 return( ld->ld_errno );
199 if ( ber_printf( ber, "{itn" /*}*/, ++ld->ld_msgid,
200 LDAP_REQ_UNBIND ) == -1 ) {
201 ld->ld_errno = LDAP_ENCODING_ERROR;
203 return( ld->ld_errno );
206 /* Put Server Controls */
207 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
212 if ( ber_printf( ber, /*{*/ "N}", LDAP_REQ_UNBIND ) == -1 ) {
213 ld->ld_errno = LDAP_ENCODING_ERROR;
215 return( ld->ld_errno );
218 /* send the message */
219 if ( ber_flush( sb, ber, 1 ) == -1 ) {
220 ld->ld_errno = LDAP_SERVER_DOWN;
222 return( ld->ld_errno );
225 return( LDAP_SUCCESS );