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 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
51 LDAPRequest *lr, *nextlr;
52 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
54 if ( ld->ld_cldapnaddr == 0 ) {
55 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
56 /* free LDAP structure and outstanding requests/responses */
57 for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
59 ldap_free_request( ld, lr );
62 /* free and unbind from all open connections */
63 while ( ld->ld_conns != NULL ) {
64 ldap_free_connection( ld, ld->ld_conns, 1, close );
66 #else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
68 err = ldap_send_unbind( ld, &ld->ld_sb, sctrls, cctrls );
69 ldap_close_connection( &ld->ld_sb );
71 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
75 for ( i = 0; i < ld->ld_cldapnaddr; ++i ) {
76 free( ld->ld_cldapaddrs[ i ] );
78 free( ld->ld_cldapaddrs );
81 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
87 if ( ld->ld_cache != NULL ) {
88 ldap_destroy_cache( ld );
91 #endif /* !LDAP_NOCACHE */
93 if ( ld->ld_error != NULL ) {
98 if ( ld->ld_matched != NULL ) {
99 free( ld->ld_matched );
100 ld->ld_matched = NULL;
103 if ( ld->ld_host != NULL ) {
108 if ( ld->ld_ufnprefix != NULL ) {
109 free( ld->ld_ufnprefix );
110 ld->ld_ufnprefix = NULL;
113 if ( ld->ld_filtd != NULL ) {
114 ldap_getfilter_free( ld->ld_filtd );
118 if ( ld->ld_abandoned != NULL ) {
119 free( ld->ld_abandoned );
120 ld->ld_abandoned = NULL;
123 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
124 if ( ld->ld_selectinfo != NULL ) {
125 ldap_free_select_info( ld->ld_selectinfo );
126 ld->ld_selectinfo = NULL;
129 ber_clear( &(ld->ld_ber), 1 );
130 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
132 if ( ld->ld_options.ldo_defbase != NULL ) {
133 free( ld->ld_options.ldo_defbase );
134 ld->ld_options.ldo_defbase = NULL;
137 if ( ld->ld_options.ldo_defhost != NULL ) {
138 free( ld->ld_options.ldo_defhost );
139 ld->ld_options.ldo_defhost = NULL;
142 ber_pvt_sb_destroy( &(ld->ld_sb) );
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 )) == NULLBER ) {
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, "}", ++ld->ld_msgid,
189 LDAP_REQ_UNBIND ) == -1 ) {
190 ld->ld_errno = LDAP_ENCODING_ERROR;
192 return( ld->ld_errno );
195 /* send the message */
196 if ( ber_flush( sb, ber, 1 ) == -1 ) {
197 ld->ld_errno = LDAP_SERVER_DOWN;
199 return( ld->ld_errno );
202 return( LDAP_SUCCESS );