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_defludp != NULL ) {
128 ldap_free_urllist( ld->ld_options.ldo_defludp );
129 ld->ld_options.ldo_defludp = NULL;
132 if ( ld->ld_options.ldo_tm_api != NULL ) {
133 LDAP_FREE( ld->ld_options.ldo_tm_api );
134 ld->ld_options.ldo_tm_api = NULL;
137 if ( ld->ld_options.ldo_tm_net != NULL ) {
138 LDAP_FREE( ld->ld_options.ldo_tm_net );
139 ld->ld_options.ldo_tm_net = NULL;
142 ber_pvt_sb_destroy( &(ld->ld_sb) );
144 LDAP_FREE( (char *) ld );
152 ldap_unbind_s( LDAP *ld )
154 return( ldap_unbind_ext( ld, NULL, NULL ) );
162 LDAPControl **sctrls,
163 LDAPControl **cctrls )
167 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
169 /* create a message to send */
170 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
171 return( ld->ld_errno );
175 if ( ber_printf( ber, "{itn" /*}*/, ++ld->ld_msgid,
176 LDAP_REQ_UNBIND ) == -1 ) {
177 ld->ld_errno = LDAP_ENCODING_ERROR;
179 return( ld->ld_errno );
182 /* Put Server Controls */
183 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
188 if ( ber_printf( ber, /*{*/ "}", LDAP_REQ_UNBIND ) == -1 ) {
189 ld->ld_errno = LDAP_ENCODING_ERROR;
191 return( ld->ld_errno );
194 /* send the message */
195 if ( ber_flush( sb, ber, 1 ) == -1 ) {
196 ld->ld_errno = LDAP_SERVER_DOWN;
198 return( ld->ld_errno );
201 return( LDAP_SUCCESS );