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.
17 #include <ac/socket.h>
18 #include <ac/string.h>
27 LDAPControl **cctrls )
29 return ldap_ld_free( ld, 1, sctrls, cctrls );
33 ldap_unbind( LDAP *ld )
35 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
37 return( ldap_unbind_ext( ld, NULL, NULL ) );
46 LDAPControl **cctrls )
48 LDAPMessage *lm, *next;
49 int err = LDAP_SUCCESS;
50 LDAPRequest *lr, *nextlr;
52 if ( ld->ld_cldapnaddr == 0 ) {
53 /* free LDAP structure and outstanding requests/responses */
54 for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
56 ldap_free_request( ld, lr );
59 /* free and unbind from all open connections */
60 while ( ld->ld_conns != NULL ) {
61 ldap_free_connection( ld, ld->ld_conns, 1, close );
66 for ( i = 0; i < ld->ld_cldapnaddr; ++i ) {
67 LDAP_FREE( ld->ld_cldapaddrs[ i ] );
69 LDAP_FREE( ld->ld_cldapaddrs );
72 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
78 if ( ld->ld_cache != NULL ) {
79 ldap_destroy_cache( ld );
82 #endif /* !LDAP_NOCACHE */
84 if ( ld->ld_error != NULL ) {
85 LDAP_FREE( ld->ld_error );
89 if ( ld->ld_matched != NULL ) {
90 LDAP_FREE( ld->ld_matched );
91 ld->ld_matched = NULL;
94 if ( ld->ld_host != NULL ) {
95 LDAP_FREE( ld->ld_host );
99 if ( ld->ld_ufnprefix != NULL ) {
100 LDAP_FREE( ld->ld_ufnprefix );
101 ld->ld_ufnprefix = NULL;
104 if ( ld->ld_filtd != NULL ) {
105 ldap_getfilter_free( ld->ld_filtd );
109 if ( ld->ld_abandoned != NULL ) {
110 LDAP_FREE( ld->ld_abandoned );
111 ld->ld_abandoned = NULL;
114 if ( ld->ld_selectinfo != NULL ) {
115 ldap_free_select_info( ld->ld_selectinfo );
116 ld->ld_selectinfo = NULL;
119 if ( ld->ld_options.ldo_defbase != NULL ) {
120 LDAP_FREE( ld->ld_options.ldo_defbase );
121 ld->ld_options.ldo_defbase = NULL;
124 if ( ld->ld_options.ldo_defhost != NULL ) {
125 LDAP_FREE( ld->ld_options.ldo_defhost );
126 ld->ld_options.ldo_defhost = NULL;
129 ber_pvt_sb_destroy( &(ld->ld_sb) );
131 LDAP_FREE( (char *) ld );
139 ldap_unbind_s( LDAP *ld )
141 return( ldap_unbind_ext( ld, NULL, NULL ) );
149 LDAPControl **sctrls,
150 LDAPControl **cctrls )
154 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
156 /* create a message to send */
157 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
158 return( ld->ld_errno );
162 if ( ber_printf( ber, "{itn", ++ld->ld_msgid,
163 LDAP_REQ_UNBIND ) == -1 ) {
164 ld->ld_errno = LDAP_ENCODING_ERROR;
166 return( ld->ld_errno );
169 /* Put Server Controls */
170 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
175 if ( ber_printf( ber, "}", ++ld->ld_msgid,
176 LDAP_REQ_UNBIND ) == -1 ) {
177 ld->ld_errno = LDAP_ENCODING_ERROR;
179 return( ld->ld_errno );
182 /* send the message */
183 if ( ber_flush( sb, ber, 1 ) == -1 ) {
184 ld->ld_errno = LDAP_SERVER_DOWN;
186 return( ld->ld_errno );
189 return( LDAP_SUCCESS );