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>
25 ldap_unbind( LDAP *ld )
27 Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
29 return( ldap_ld_free( ld, 1 ));
34 ldap_ld_free( LDAP *ld, int close )
36 LDAPMessage *lm, *next;
37 int err = LDAP_SUCCESS;
39 LDAPRequest *lr, *nextlr;
40 #endif /* LDAP_REFERRALS */
42 if ( ld->ld_sb.sb_naddr == 0 ) {
44 /* free LDAP structure and outstanding requests/responses */
45 for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
47 ldap_free_request( ld, lr );
50 /* free and unbind from all open connections */
51 while ( ld->ld_conns != NULL ) {
52 ldap_free_connection( ld, ld->ld_conns, 1, close );
54 #else /* LDAP_REFERRALS */
56 err = ldap_send_unbind( ld, &ld->ld_sb );
57 ldap_close_connection( &ld->ld_sb );
59 #endif /* LDAP_REFERRALS */
63 for ( i = 0; i < ld->ld_sb.sb_naddr; ++i ) {
64 free( ld->ld_sb.sb_addrs[ i ] );
66 free( ld->ld_sb.sb_addrs );
67 free( ld->ld_sb.sb_fromaddr );
70 for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
76 if ( ld->ld_cache != NULL )
77 ldap_destroy_cache( ld );
78 #endif /* !LDAP_NOCACHE */
79 if ( ld->ld_error != NULL )
81 if ( ld->ld_matched != NULL )
82 free( ld->ld_matched );
83 if ( ld->ld_host != NULL )
85 if ( ld->ld_ufnprefix != NULL )
86 free( ld->ld_ufnprefix );
87 if ( ld->ld_filtd != NULL )
88 ldap_getfilter_free( ld->ld_filtd );
89 #ifndef LDAP_REFERRALS
90 if ( ld->ld_sb.sb_ber.ber_buf != NULL )
91 free( ld->ld_sb.sb_ber.ber_buf );
92 #endif /* !LDAP_REFERRALS */
93 if ( ld->ld_abandoned != NULL )
94 free( ld->ld_abandoned );
97 if ( ld->ld_selectinfo != NULL )
98 ldap_free_select_info( ld->ld_selectinfo );
99 #endif /* LDAP_REFERRALS */
101 if ( ld->ld_defhost != NULL )
102 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 );