2 * Copyright (c) 1990 Regents of the University of Michigan.
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
17 #include <ac/socket.h>
18 #include <ac/string.h>
27 ldap_unbind( LDAP *ld )
29 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
31 return( ldap_ld_free( ld, 1 ));
36 ldap_ld_free( LDAP *ld, int close )
38 LDAPMessage *lm, *next;
39 int err = LDAP_SUCCESS;
41 LDAPRequest *lr, *nextlr;
42 #endif /* LDAP_REFERRALS */
44 if ( ld->ld_sb.sb_naddr == 0 ) {
46 /* free LDAP structure and outstanding requests/responses */
47 for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
49 ldap_free_request( ld, lr );
52 /* free and unbind from all open connections */
53 while ( ld->ld_conns != NULL ) {
54 ldap_free_connection( ld, ld->ld_conns, 1, close );
56 #else /* LDAP_REFERRALS */
58 err = ldap_send_unbind( ld, &ld->ld_sb );
59 ldap_close_connection( &ld->ld_sb );
61 #endif /* LDAP_REFERRALS */
65 for ( i = 0; i < ld->ld_sb.sb_naddr; ++i ) {
66 free( ld->ld_sb.sb_addrs[ i ] );
68 free( ld->ld_sb.sb_addrs );
69 free( ld->ld_sb.sb_fromaddr );
72 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
78 if ( ld->ld_cache != NULL )
79 ldap_destroy_cache( ld );
80 #endif /* !NO_CACHE */
81 if ( ld->ld_error != NULL )
83 if ( ld->ld_matched != NULL )
84 free( ld->ld_matched );
85 if ( ld->ld_host != NULL )
87 if ( ld->ld_ufnprefix != NULL )
88 free( ld->ld_ufnprefix );
89 if ( ld->ld_filtd != NULL )
90 ldap_getfilter_free( ld->ld_filtd );
91 #ifndef LDAP_REFERRALS
92 if ( ld->ld_sb.sb_ber.ber_buf != NULL )
93 free( ld->ld_sb.sb_ber.ber_buf );
94 #endif /* !LDAP_REFERRALS */
95 if ( ld->ld_abandoned != NULL )
96 free( ld->ld_abandoned );
99 if ( ld->ld_selectinfo != NULL )
100 ldap_free_select_info( ld->ld_selectinfo );
101 #endif /* LDAP_REFERRALS */
103 if ( ld->ld_defhost != NULL )
104 free( ld->ld_defhost );
112 ldap_unbind_s( LDAP *ld )
114 return( ldap_ld_free( ld, 1 ));
119 ldap_send_unbind( LDAP *ld, Sockbuf *sb )
123 Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
125 /* create a message to send */
126 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
127 return( ld->ld_errno );
131 if ( ber_printf( ber, "{itn}", ++ld->ld_msgid,
132 LDAP_REQ_UNBIND ) == -1 ) {
133 ld->ld_errno = LDAP_ENCODING_ERROR;
135 return( ld->ld_errno );
138 /* send the message */
139 if ( ber_flush( sb, ber, 1 ) == -1 ) {
140 ld->ld_errno = LDAP_SERVER_DOWN;
142 return( ld->ld_errno );
145 return( LDAP_SUCCESS );