1998-08-09 08:43:13 +08:00
|
|
|
/*
|
1998-12-29 04:53:15 +08:00
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
/* Portions
|
1998-08-09 08:43:13 +08:00
|
|
|
* Copyright (c) 1990 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* unbind.c
|
|
|
|
*/
|
|
|
|
|
1999-06-04 03:22:33 +08:00
|
|
|
/* An Unbind Request looks like this:
|
|
|
|
*
|
|
|
|
* UnbindRequest ::= NULL
|
|
|
|
*
|
|
|
|
* and has no response.
|
|
|
|
*/
|
|
|
|
|
1998-10-25 11:13:43 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/stdlib.h>
|
1998-08-21 03:42:38 +08:00
|
|
|
|
1998-10-25 11:13:43 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
#include "ldap-int.h"
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
int
|
|
|
|
ldap_unbind_ext(
|
|
|
|
LDAP *ld,
|
|
|
|
LDAPControl **sctrls,
|
|
|
|
LDAPControl **cctrls )
|
|
|
|
{
|
|
|
|
return ldap_ld_free( ld, 1, sctrls, cctrls );
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
ldap_unbind( LDAP *ld )
|
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_unbind\n", 0, 0, 0 );
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
return( ldap_unbind_ext( ld, NULL, NULL ) );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ldap_ld_free(
|
|
|
|
LDAP *ld,
|
|
|
|
int close,
|
|
|
|
LDAPControl **sctrls,
|
|
|
|
LDAPControl **cctrls )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
LDAPMessage *lm, *next;
|
|
|
|
int err = LDAP_SUCCESS;
|
|
|
|
LDAPRequest *lr, *nextlr;
|
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
if ( ld->ld_cldapnaddr == 0 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
/* free LDAP structure and outstanding requests/responses */
|
|
|
|
for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
|
|
|
|
nextlr = lr->lr_next;
|
1998-08-09 11:04:12 +08:00
|
|
|
ldap_free_request( ld, lr );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* free and unbind from all open connections */
|
|
|
|
while ( ld->ld_conns != NULL ) {
|
1998-08-09 11:04:12 +08:00
|
|
|
ldap_free_connection( ld, ld->ld_conns, 1, close );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
for ( i = 0; i < ld->ld_cldapnaddr; ++i ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( ld->ld_cldapaddrs[ i ] );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( ld->ld_cldapaddrs );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
|
|
|
|
next = lm->lm_next;
|
|
|
|
ldap_msgfree( lm );
|
|
|
|
}
|
|
|
|
|
1998-10-25 11:13:43 +08:00
|
|
|
#ifndef LDAP_NOCACHE
|
1999-05-21 03:38:03 +08:00
|
|
|
if ( ld->ld_cache != NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ldap_destroy_cache( ld );
|
1999-05-21 03:38:03 +08:00
|
|
|
ld->ld_cache = NULL;
|
|
|
|
}
|
1998-10-25 11:13:43 +08:00
|
|
|
#endif /* !LDAP_NOCACHE */
|
1999-05-21 03:38:03 +08:00
|
|
|
|
|
|
|
if ( ld->ld_error != NULL ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( ld->ld_error );
|
1999-05-21 03:38:03 +08:00
|
|
|
ld->ld_error = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ld->ld_matched != NULL ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( ld->ld_matched );
|
1999-05-21 03:38:03 +08:00
|
|
|
ld->ld_matched = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ld->ld_host != NULL ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( ld->ld_host );
|
1999-05-21 03:38:03 +08:00
|
|
|
ld->ld_host = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ld->ld_ufnprefix != NULL ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( ld->ld_ufnprefix );
|
1999-05-21 03:38:03 +08:00
|
|
|
ld->ld_ufnprefix = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ld->ld_filtd != NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ldap_getfilter_free( ld->ld_filtd );
|
1999-05-21 03:38:03 +08:00
|
|
|
ld->ld_filtd = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ld->ld_abandoned != NULL ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( ld->ld_abandoned );
|
1999-05-21 03:38:03 +08:00
|
|
|
ld->ld_abandoned = NULL;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-05-21 03:38:03 +08:00
|
|
|
if ( ld->ld_selectinfo != NULL ) {
|
1998-08-09 11:04:12 +08:00
|
|
|
ldap_free_select_info( ld->ld_selectinfo );
|
1999-05-21 03:38:03 +08:00
|
|
|
ld->ld_selectinfo = NULL;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-05-21 03:38:03 +08:00
|
|
|
if ( ld->ld_options.ldo_defbase != NULL ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( ld->ld_options.ldo_defbase );
|
1999-05-21 03:38:03 +08:00
|
|
|
ld->ld_options.ldo_defbase = NULL;
|
|
|
|
}
|
1998-11-11 07:37:30 +08:00
|
|
|
|
1999-05-21 03:38:03 +08:00
|
|
|
if ( ld->ld_options.ldo_defhost != NULL ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( ld->ld_options.ldo_defhost );
|
1999-05-21 03:38:03 +08:00
|
|
|
ld->ld_options.ldo_defhost = NULL;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-08-04 03:27:22 +08:00
|
|
|
if ( ld->ld_options.ldo_tm_api != NULL ) {
|
|
|
|
LDAP_FREE( ld->ld_options.ldo_tm_api );
|
|
|
|
ld->ld_options.ldo_tm_api = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ld->ld_options.ldo_tm_net != NULL ) {
|
|
|
|
LDAP_FREE( ld->ld_options.ldo_tm_net );
|
|
|
|
ld->ld_options.ldo_tm_net = NULL;
|
|
|
|
}
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_pvt_sb_destroy( &(ld->ld_sb) );
|
1999-03-03 04:23:14 +08:00
|
|
|
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( (char *) ld );
|
1999-03-03 04:23:14 +08:00
|
|
|
|
1998-10-25 11:13:43 +08:00
|
|
|
WSACleanup();
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( err );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldap_unbind_s( LDAP *ld )
|
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
return( ldap_unbind_ext( ld, NULL, NULL ) );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ldap_send_unbind(
|
|
|
|
LDAP *ld,
|
|
|
|
Sockbuf *sb,
|
|
|
|
LDAPControl **sctrls,
|
|
|
|
LDAPControl **cctrls )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
BerElement *ber;
|
|
|
|
|
1998-08-09 11:04:12 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_send_unbind\n", 0, 0, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/* create a message to send */
|
1999-06-19 07:53:05 +08:00
|
|
|
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
return( ld->ld_errno );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill it in */
|
1999-06-19 07:53:05 +08:00
|
|
|
if ( ber_printf( ber, "{itn" /*}*/, ++ld->ld_msgid,
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAP_REQ_UNBIND ) == -1 ) {
|
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
|
|
|
ber_free( ber, 1 );
|
|
|
|
return( ld->ld_errno );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put Server Controls */
|
|
|
|
if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
|
|
|
|
ber_free( ber, 1 );
|
|
|
|
return ld->ld_errno;
|
|
|
|
}
|
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
if ( ber_printf( ber, /*{*/ "}", LDAP_REQ_UNBIND ) == -1 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
|
|
|
ber_free( ber, 1 );
|
|
|
|
return( ld->ld_errno );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send the message */
|
|
|
|
if ( ber_flush( sb, ber, 1 ) == -1 ) {
|
|
|
|
ld->ld_errno = LDAP_SERVER_DOWN;
|
|
|
|
ber_free( ber, 1 );
|
|
|
|
return( ld->ld_errno );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( LDAP_SUCCESS );
|
|
|
|
}
|