From 66818be6377a665e21955621bedf9d34bda54beb Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 16 Oct 2000 23:11:41 +0000 Subject: [PATCH] Don't attempt to send abandon unless connection exists. If connection doesn't exist, return LDAP_SERVER_DOWN. --- libraries/libldap/abandon.c | 10 +++++++-- libraries/libldap/apitest.c | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/libraries/libldap/abandon.c b/libraries/libldap/abandon.c index 597ded2f84..fbb184722a 100644 --- a/libraries/libldap/abandon.c +++ b/libraries/libldap/abandon.c @@ -131,12 +131,18 @@ do_abandon( err = 0; if ( sendabandon ) { - /* create a message to send */ - if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) { + if( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) { + /* not connected */ + err = -1; + ld->ld_errno = LDAP_SERVER_DOWN; + + } else if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) { + /* BER element alocation failed */ err = -1; ld->ld_errno = LDAP_NO_MEMORY; } else { + /* create a message to send */ err = ber_printf( ber, "{iti", /* '}' */ ++ld->ld_msgid, LDAP_REQ_ABANDON, msgid ); diff --git a/libraries/libldap/apitest.c b/libraries/libldap/apitest.c index 0fe1de5ee5..17548cd2b3 100644 --- a/libraries/libldap/apitest.c +++ b/libraries/libldap/apitest.c @@ -188,5 +188,47 @@ main(int argc, char **argv) puts(" HOST NAME: "); } +#if 0 + /* API tests */ + { /* bindless unbind */ + LDAP *ld; + int rc; + + ld = ldap_init( "localhost", 389 ); + if( ld == NULL ) { + perror("ldap_init"); + return EXIT_FAILURE; + } + + rc = ldap_unbind( ld ); + if( rc != LDAP_SUCCESS ) { + perror("ldap_unbind"); + return EXIT_FAILURE; + } + } + { /* bindless unbind */ + LDAP *ld; + int rc; + + ld = ldap_init( "localhost", 389 ); + if( ld == NULL ) { + perror("ldap_init"); + return EXIT_FAILURE; + } + + rc = ldap_abandon_ext( ld, 0, NULL, NULL ); + if( rc != LDAP_SERVER_DOWN ) { + ldap_perror( ld, "ldap_abandon"); + return EXIT_FAILURE; + } + + rc = ldap_unbind( ld ); + if( rc != LDAP_SUCCESS ) { + perror("ldap_unbind"); + return EXIT_FAILURE; + } + } +#endif + return EXIT_SUCCESS; } -- 2.39.5