2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1990 Regents of the University of Michigan.
12 /* An Unbind Request looks like this:
14 * UnbindRequest ::= NULL
16 * and has no response.
22 #include <ac/stdlib.h>
24 #include <ac/socket.h>
25 #include <ac/string.h>
34 LDAPControl **cctrls )
36 return ldap_ld_free( ld, 1, sctrls, cctrls );
40 ldap_unbind( LDAP *ld )
42 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
44 return( ldap_unbind_ext( ld, NULL, NULL ) );
53 LDAPControl **cctrls )
55 LDAPMessage *lm, *next;
56 int err = LDAP_SUCCESS;
57 LDAPRequest *lr, *nextlr;
59 if ( ld->ld_cldapnaddr == 0 ) {
60 /* free LDAP structure and outstanding requests/responses */
61 for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
63 ldap_free_request( ld, lr );
66 /* free and unbind from all open connections */
67 while ( ld->ld_conns != NULL ) {
68 ldap_free_connection( ld, ld->ld_conns, 1, close );
73 for ( i = 0; i < ld->ld_cldapnaddr; ++i ) {
74 LDAP_FREE( ld->ld_cldapaddrs[ i ] );
76 LDAP_FREE( ld->ld_cldapaddrs );
79 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
85 if ( ld->ld_cache != NULL ) {
86 ldap_destroy_cache( ld );
89 #endif /* !LDAP_NOCACHE */
91 if ( ld->ld_error != NULL ) {
92 LDAP_FREE( ld->ld_error );
96 if ( ld->ld_matched != NULL ) {
97 LDAP_FREE( ld->ld_matched );
98 ld->ld_matched = NULL;
101 if ( ld->ld_host != NULL ) {
102 LDAP_FREE( ld->ld_host );
106 if ( ld->ld_ufnprefix != NULL ) {
107 LDAP_FREE( ld->ld_ufnprefix );
108 ld->ld_ufnprefix = NULL;
111 if ( ld->ld_filtd != NULL ) {
112 ldap_getfilter_free( ld->ld_filtd );
116 if ( ld->ld_abandoned != NULL ) {
117 LDAP_FREE( ld->ld_abandoned );
118 ld->ld_abandoned = NULL;
121 if ( ld->ld_selectinfo != NULL ) {
122 ldap_free_select_info( ld->ld_selectinfo );
123 ld->ld_selectinfo = NULL;
126 if ( ld->ld_options.ldo_defbase != NULL ) {
127 LDAP_FREE( ld->ld_options.ldo_defbase );
128 ld->ld_options.ldo_defbase = NULL;
131 if ( ld->ld_options.ldo_defhost != NULL ) {
132 LDAP_FREE( ld->ld_options.ldo_defhost );
133 ld->ld_options.ldo_defhost = NULL;
136 if ( ld->ld_options.ldo_tm_api != NULL ) {
137 LDAP_FREE( ld->ld_options.ldo_tm_api );
138 ld->ld_options.ldo_tm_api = NULL;
141 if ( ld->ld_options.ldo_tm_net != NULL ) {
142 LDAP_FREE( ld->ld_options.ldo_tm_net );
143 ld->ld_options.ldo_tm_net = NULL;
146 ber_pvt_sb_destroy( &(ld->ld_sb) );
148 LDAP_FREE( (char *) ld );
156 ldap_unbind_s( LDAP *ld )
158 return( ldap_unbind_ext( ld, NULL, NULL ) );
166 LDAPControl **sctrls,
167 LDAPControl **cctrls )
171 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
173 /* create a message to send */
174 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
175 return( ld->ld_errno );
179 if ( ber_printf( ber, "{itn" /*}*/, ++ld->ld_msgid,
180 LDAP_REQ_UNBIND ) == -1 ) {
181 ld->ld_errno = LDAP_ENCODING_ERROR;
183 return( ld->ld_errno );
186 /* Put Server Controls */
187 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
192 if ( ber_printf( ber, /*{*/ "}", LDAP_REQ_UNBIND ) == -1 ) {
193 ld->ld_errno = LDAP_ENCODING_ERROR;
195 return( ld->ld_errno );
198 /* send the message */
199 if ( ber_flush( sb, ber, 1 ) == -1 ) {
200 ld->ld_errno = LDAP_SERVER_DOWN;
202 return( ld->ld_errno );
205 return( LDAP_SUCCESS );