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 )
39 /* check client controls */
40 rc = ldap_int_client_controls( ld, cctrls );
41 if( rc != LDAP_SUCCESS ) return rc;
43 return ldap_ld_free( ld, 1, sctrls, cctrls );
50 LDAPControl **cctrls )
52 return ldap_unbind_ext( ld, sctrls, cctrls );
56 ldap_unbind( LDAP *ld )
58 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
60 return( ldap_unbind_ext( ld, NULL, NULL ) );
69 LDAPControl **cctrls )
71 LDAPMessage *lm, *next;
72 int err = LDAP_SUCCESS;
74 /* free LDAP structure and outstanding requests/responses */
75 while ( ld->ld_requests != NULL ) {
76 ldap_free_request( ld, ld->ld_requests );
79 /* free and unbind from all open connections */
80 while ( ld->ld_conns != NULL ) {
81 ldap_free_connection( ld, ld->ld_conns, 1, close );
84 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
90 if ( ld->ld_cache != NULL ) {
91 ldap_destroy_cache( ld );
94 #endif /* !LDAP_NOCACHE */
96 if ( ld->ld_error != NULL ) {
97 LDAP_FREE( ld->ld_error );
101 if ( ld->ld_matched != NULL ) {
102 LDAP_FREE( ld->ld_matched );
103 ld->ld_matched = NULL;
106 if ( ld->ld_abandoned != NULL ) {
107 LDAP_FREE( ld->ld_abandoned );
108 ld->ld_abandoned = NULL;
111 if ( ld->ld_selectinfo != NULL ) {
112 ldap_free_select_info( ld->ld_selectinfo );
113 ld->ld_selectinfo = NULL;
116 if ( ld->ld_options.ldo_defludp != NULL ) {
117 ldap_free_urllist( ld->ld_options.ldo_defludp );
118 ld->ld_options.ldo_defludp = NULL;
121 if ( ld->ld_options.ldo_tm_api != NULL ) {
122 LDAP_FREE( ld->ld_options.ldo_tm_api );
123 ld->ld_options.ldo_tm_api = NULL;
126 if ( ld->ld_options.ldo_tm_net != NULL ) {
127 LDAP_FREE( ld->ld_options.ldo_tm_net );
128 ld->ld_options.ldo_tm_net = NULL;
131 #ifdef HAVE_CYRUS_SASL
132 if ( ld->ld_options.ldo_def_sasl_mech != NULL ) {
133 LDAP_FREE( ld->ld_options.ldo_def_sasl_mech );
134 ld->ld_options.ldo_def_sasl_mech = NULL;
137 if ( ld->ld_options.ldo_def_sasl_realm != NULL ) {
138 LDAP_FREE( ld->ld_options.ldo_def_sasl_realm );
139 ld->ld_options.ldo_def_sasl_realm = NULL;
142 if ( ld->ld_options.ldo_def_sasl_authcid != NULL ) {
143 LDAP_FREE( ld->ld_options.ldo_def_sasl_authcid );
144 ld->ld_options.ldo_def_sasl_authcid = NULL;
147 if ( ld->ld_options.ldo_def_sasl_authzid != NULL ) {
148 LDAP_FREE( ld->ld_options.ldo_def_sasl_authzid );
149 ld->ld_options.ldo_def_sasl_authzid = NULL;
153 ber_sockbuf_free( ld->ld_sb );
155 LDAP_FREE( (char *) ld );
161 ldap_unbind_s( LDAP *ld )
163 return( ldap_unbind_ext( ld, NULL, NULL ) );
171 LDAPControl **sctrls,
172 LDAPControl **cctrls )
176 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
178 /* create a message to send */
179 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
180 return( ld->ld_errno );
184 if ( ber_printf( ber, "{itn" /*}*/, ++ld->ld_msgid,
185 LDAP_REQ_UNBIND ) == -1 ) {
186 ld->ld_errno = LDAP_ENCODING_ERROR;
188 return( ld->ld_errno );
191 /* Put Server Controls */
192 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
197 if ( ber_printf( ber, /*{*/ "N}", LDAP_REQ_UNBIND ) == -1 ) {
198 ld->ld_errno = LDAP_ENCODING_ERROR;
200 return( ld->ld_errno );
203 /* send the message */
204 if ( ber_flush( sb, ber, 1 ) == -1 ) {
205 ld->ld_errno = LDAP_SERVER_DOWN;
207 return( ld->ld_errno );
210 return( LDAP_SUCCESS );