2 * Copyright (c) 1990 Regents of the University of Michigan.
9 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
19 #if defined( DOS ) || defined( _WIN32 )
25 #include <sys/types.h>
27 #include <sys/socket.h>
37 ldap_unbind( LDAP *ld )
39 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
41 return( ldap_ld_free( ld, 1 ));
46 ldap_ld_free( LDAP *ld, int close )
48 LDAPMessage *lm, *next;
49 int err = LDAP_SUCCESS;
51 LDAPRequest *lr, *nextlr;
52 #endif /* LDAP_REFERRALS */
54 if ( ld->ld_sb.sb_naddr == 0 ) {
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_REFERRALS */
68 err = ldap_send_unbind( ld, &ld->ld_sb );
69 ldap_close_connection( &ld->ld_sb );
71 #endif /* LDAP_REFERRALS */
75 for ( i = 0; i < ld->ld_sb.sb_naddr; ++i ) {
76 free( ld->ld_sb.sb_addrs[ i ] );
78 free( ld->ld_sb.sb_addrs );
79 free( ld->ld_sb.sb_fromaddr );
82 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
88 if ( ld->ld_cache != NULL )
89 ldap_destroy_cache( ld );
90 #endif /* !NO_CACHE */
91 if ( ld->ld_error != NULL )
93 if ( ld->ld_matched != NULL )
94 free( ld->ld_matched );
95 if ( ld->ld_host != NULL )
97 if ( ld->ld_ufnprefix != NULL )
98 free( ld->ld_ufnprefix );
99 if ( ld->ld_filtd != NULL )
100 ldap_getfilter_free( ld->ld_filtd );
101 #ifndef LDAP_REFERRALS
102 if ( ld->ld_sb.sb_ber.ber_buf != NULL )
103 free( ld->ld_sb.sb_ber.ber_buf );
104 #endif /* !LDAP_REFERRALS */
105 if ( ld->ld_abandoned != NULL )
106 free( ld->ld_abandoned );
108 #ifdef LDAP_REFERRALS
109 if ( ld->ld_selectinfo != NULL )
110 ldap_free_select_info( ld->ld_selectinfo );
111 #endif /* LDAP_REFERRALS */
113 if ( ld->ld_defhost != NULL )
114 free( ld->ld_defhost );
122 ldap_unbind_s( LDAP *ld )
124 return( ldap_ld_free( ld, 1 ));
129 ldap_send_unbind( LDAP *ld, Sockbuf *sb )
133 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
135 /* create a message to send */
136 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
137 return( ld->ld_errno );
141 if ( ber_printf( ber, "{itn}", ++ld->ld_msgid,
142 LDAP_REQ_UNBIND ) == -1 ) {
143 ld->ld_errno = LDAP_ENCODING_ERROR;
145 return( ld->ld_errno );
148 /* send the message */
149 if ( ber_flush( sb, ber, 1 ) == -1 ) {
150 ld->ld_errno = LDAP_SERVER_DOWN;
152 return( ld->ld_errno );
155 return( LDAP_SUCCESS );