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";
18 #if defined( DOS ) || defined( _WIN32 )
24 #include <sys/types.h>
26 #include <sys/socket.h>
36 ldap_unbind( LDAP *ld )
38 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
40 return( ldap_ld_free( ld, 1 ));
45 ldap_ld_free( LDAP *ld, int close )
47 LDAPMessage *lm, *next;
48 int err = LDAP_SUCCESS;
50 LDAPRequest *lr, *nextlr;
51 #endif /* LDAP_REFERRALS */
53 if ( ld->ld_sb.sb_naddr == 0 ) {
55 /* free LDAP structure and outstanding requests/responses */
56 for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
58 ldap_free_request( ld, lr );
61 /* free and unbind from all open connections */
62 while ( ld->ld_conns != NULL ) {
63 ldap_free_connection( ld, ld->ld_conns, 1, close );
65 #else /* LDAP_REFERRALS */
67 err = ldap_send_unbind( ld, &ld->ld_sb );
68 ldap_close_connection( &ld->ld_sb );
70 #endif /* LDAP_REFERRALS */
74 for ( i = 0; i < ld->ld_sb.sb_naddr; ++i ) {
75 free( ld->ld_sb.sb_addrs[ i ] );
77 free( ld->ld_sb.sb_addrs );
78 free( ld->ld_sb.sb_fromaddr );
81 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
87 if ( ld->ld_cache != NULL )
88 ldap_destroy_cache( ld );
89 #endif /* !NO_CACHE */
90 if ( ld->ld_error != NULL )
92 if ( ld->ld_matched != NULL )
93 free( ld->ld_matched );
94 if ( ld->ld_host != NULL )
96 if ( ld->ld_ufnprefix != NULL )
97 free( ld->ld_ufnprefix );
98 if ( ld->ld_filtd != NULL )
99 ldap_getfilter_free( ld->ld_filtd );
100 #ifndef LDAP_REFERRALS
101 if ( ld->ld_sb.sb_ber.ber_buf != NULL )
102 free( ld->ld_sb.sb_ber.ber_buf );
103 #endif /* !LDAP_REFERRALS */
104 if ( ld->ld_abandoned != NULL )
105 free( ld->ld_abandoned );
107 #ifdef LDAP_REFERRALS
108 if ( ld->ld_selectinfo != NULL )
109 ldap_free_select_info( ld->ld_selectinfo );
110 #endif /* LDAP_REFERRALS */
112 if ( ld->ld_defhost != NULL )
113 free( ld->ld_defhost );
121 ldap_unbind_s( LDAP *ld )
123 return( ldap_ld_free( ld, 1 ));
128 ldap_send_unbind( LDAP *ld, Sockbuf *sb )
132 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
134 /* create a message to send */
135 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
136 return( ld->ld_errno );
140 if ( ber_printf( ber, "{itn}", ++ld->ld_msgid,
141 LDAP_REQ_UNBIND ) == -1 ) {
142 ld->ld_errno = LDAP_ENCODING_ERROR;
144 return( ld->ld_errno );
147 /* send the message */
148 if ( ber_flush( sb, ber, 1 ) == -1 ) {
149 ld->ld_errno = LDAP_SERVER_DOWN;
151 return( ld->ld_errno );
154 return( LDAP_SUCCESS );