3 * Copyright 1998-1999 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 )
37 return ldap_ld_free( ld, 1, sctrls, cctrls );
41 ldap_unbind( LDAP *ld )
43 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
45 return( ldap_unbind_ext( ld, NULL, NULL ) );
54 LDAPControl **cctrls )
56 LDAPMessage *lm, *next;
57 int err = LDAP_SUCCESS;
58 LDAPRequest *lr, *nextlr;
60 if ( ld->ld_cldapnaddr == 0 ) {
61 /* free LDAP structure and outstanding requests/responses */
62 for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
64 ldap_free_request( ld, lr );
67 /* free and unbind from all open connections */
68 while ( ld->ld_conns != NULL ) {
69 ldap_free_connection( ld, ld->ld_conns, 1, close );
74 for ( i = 0; i < ld->ld_cldapnaddr; ++i ) {
75 LDAP_FREE( ld->ld_cldapaddrs[ i ] );
77 LDAP_FREE( ld->ld_cldapaddrs );
80 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
86 if ( ld->ld_cache != NULL ) {
87 ldap_destroy_cache( ld );
90 #endif /* !LDAP_NOCACHE */
92 if ( ld->ld_error != NULL ) {
93 LDAP_FREE( ld->ld_error );
97 if ( ld->ld_matched != NULL ) {
98 LDAP_FREE( ld->ld_matched );
99 ld->ld_matched = NULL;
102 if ( ld->ld_host != NULL ) {
103 LDAP_FREE( ld->ld_host );
107 if ( ld->ld_ufnprefix != NULL ) {
108 LDAP_FREE( ld->ld_ufnprefix );
109 ld->ld_ufnprefix = NULL;
112 if ( ld->ld_filtd != NULL ) {
113 ldap_getfilter_free( ld->ld_filtd );
117 if ( ld->ld_abandoned != NULL ) {
118 LDAP_FREE( ld->ld_abandoned );
119 ld->ld_abandoned = NULL;
122 if ( ld->ld_selectinfo != NULL ) {
123 ldap_free_select_info( ld->ld_selectinfo );
124 ld->ld_selectinfo = NULL;
127 if ( ld->ld_options.ldo_defbase != NULL ) {
128 LDAP_FREE( ld->ld_options.ldo_defbase );
129 ld->ld_options.ldo_defbase = NULL;
132 if ( ld->ld_options.ldo_defhost != NULL ) {
133 LDAP_FREE( ld->ld_options.ldo_defhost );
134 ld->ld_options.ldo_defhost = NULL;
137 if ( ld->ld_options.ldo_tm_api != NULL ) {
138 LDAP_FREE( ld->ld_options.ldo_tm_api );
139 ld->ld_options.ldo_tm_api = NULL;
142 if ( ld->ld_options.ldo_tm_net != NULL ) {
143 LDAP_FREE( ld->ld_options.ldo_tm_net );
144 ld->ld_options.ldo_tm_net = NULL;
147 ber_pvt_sb_destroy( &(ld->ld_sb) );
149 LDAP_FREE( (char *) ld );
157 ldap_unbind_s( LDAP *ld )
159 return( ldap_unbind_ext( ld, NULL, NULL ) );
167 LDAPControl **sctrls,
168 LDAPControl **cctrls )
172 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
174 /* create a message to send */
175 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
176 return( ld->ld_errno );
180 if ( ber_printf( ber, "{itn" /*}*/, ++ld->ld_msgid,
181 LDAP_REQ_UNBIND ) == -1 ) {
182 ld->ld_errno = LDAP_ENCODING_ERROR;
184 return( ld->ld_errno );
187 /* Put Server Controls */
188 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
193 if ( ber_printf( ber, /*{*/ "}", LDAP_REQ_UNBIND ) == -1 ) {
194 ld->ld_errno = LDAP_ENCODING_ERROR;
196 return( ld->ld_errno );
199 /* send the message */
200 if ( ber_flush( sb, ber, 1 ) == -1 ) {
201 ld->ld_errno = LDAP_SERVER_DOWN;
203 return( ld->ld_errno );
206 return( LDAP_SUCCESS );