From 56d1375194acf905fc91657ce60fd59ccd6f17ae Mon Sep 17 00:00:00 2001 From: Quanah Gibson-Mount Date: Mon, 21 Nov 2011 17:11:44 -0800 Subject: [PATCH] ITS#6548,#7092 Unbind,cleanup before client exit. Gets rid of "(connection lost)" in slapd statslog "closed" message. --- clients/tools/common.c | 75 ++++++++++++++++++++++--------------- clients/tools/common.h | 1 + clients/tools/ldapcompare.c | 4 +- clients/tools/ldapdelete.c | 4 +- clients/tools/ldapexop.c | 7 +--- clients/tools/ldapmodify.c | 8 +--- clients/tools/ldapmodrdn.c | 6 +-- clients/tools/ldappasswd.c | 9 ++--- clients/tools/ldapsearch.c | 66 ++++++++++++++++---------------- clients/tools/ldapwhoami.c | 9 ++--- 10 files changed, 90 insertions(+), 99 deletions(-) diff --git a/clients/tools/common.c b/clients/tools/common.c index f3369460c1..b54e2b5772 100644 --- a/clients/tools/common.c +++ b/clients/tools/common.c @@ -239,6 +239,10 @@ tool_init( tool_type_t type ) void tool_destroy( void ) { + static int destroyed; + if ( destroyed++ ) + return; + #ifdef HAVE_CYRUS_SASL sasl_done(); #endif @@ -1331,7 +1335,7 @@ dnssrv_free:; { fprintf( stderr, "Could not set LDAP_OPT_REFERRALS %s\n", referrals ? "on" : "off" ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } #ifdef HAVE_CYRUS_SASL @@ -1341,7 +1345,7 @@ dnssrv_free:; { fprintf( stderr, "Could not set LDAP_OPT_X_SASL_NOCANON %s\n", nocanon ? "on" : "off" ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } #endif if( ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) @@ -1349,7 +1353,7 @@ dnssrv_free:; { fprintf( stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n", protocol ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } if ( use_tls ) { @@ -1360,7 +1364,7 @@ dnssrv_free:; tool_perror( "ldap_start_tls", rc, NULL, NULL, msg, NULL ); ldap_memfree(msg); if ( use_tls > 1 ) { - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } } } @@ -1371,7 +1375,7 @@ dnssrv_free:; { fprintf( stderr, "Could not set LDAP_OPT_NETWORK_TIMEOUT %ld\n", (long)nettimeout.tv_sec ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } } } @@ -1405,8 +1409,8 @@ tool_bind( LDAP *ld ) if ( sessionTracking ) { LDAPControl c; - if (stValue.bv_val == NULL && st_value( ld, &stValue ) ) { - exit( EXIT_FAILURE ); + if ( BER_BVISNULL( &stValue) && st_value( ld, &stValue ) ) { + tool_exit( ld, EXIT_FAILURE ); } c.ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING; @@ -1430,7 +1434,7 @@ tool_bind( LDAP *ld ) if ( pw_file ) { if ( lutil_get_filed_password( pw_file, &passwd ) ) { - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } } else { @@ -1455,7 +1459,7 @@ tool_bind( LDAP *ld ) fprintf( stderr, "Could not set LDAP_OPT_X_SASL_SECPROPS: %s\n", sasl_secprops ); - exit( LDAP_LOCAL_ERROR ); + tool_exit( ld, LDAP_LOCAL_ERROR ); } } @@ -1477,11 +1481,11 @@ tool_bind( LDAP *ld ) tool_perror( "ldap_sasl_interactive_bind_s", rc, NULL, NULL, msg, NULL ); ldap_memfree(msg); - exit( rc ); + tool_exit( ld, rc ); } #else fprintf( stderr, "%s: not compiled with SASL support\n", prog ); - exit( LDAP_NOT_SUPPORTED ); + tool_exit( ld, LDAP_NOT_SUPPORTED ); #endif } else { int msgid, err, rc; @@ -1501,26 +1505,26 @@ tool_bind( LDAP *ld ) if ( msgid == -1 ) { tool_perror( "ldap_sasl_bind(SIMPLE)", rc, NULL, NULL, NULL, NULL ); - exit( rc ); + tool_exit( ld, rc ); } } rc = ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &result ); if ( rc == -1 ) { tool_perror( "ldap_result", -1, NULL, NULL, NULL, NULL ); - exit( LDAP_LOCAL_ERROR ); + tool_exit( ld, LDAP_LOCAL_ERROR ); } if ( rc == 0 ) { tool_perror( "ldap_result", LDAP_TIMEOUT, NULL, NULL, NULL, NULL ); - exit( LDAP_LOCAL_ERROR ); + tool_exit( ld, LDAP_LOCAL_ERROR ); } rc = ldap_parse_result( ld, result, &err, &matched, &info, &refs, &ctrls, 1 ); if ( rc != LDAP_SUCCESS ) { tool_perror( "ldap_bind parse result", rc, NULL, matched, info, refs ); - exit( LDAP_LOCAL_ERROR ); + tool_exit( ld, LDAP_LOCAL_ERROR ); } #ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST @@ -1570,7 +1574,7 @@ tool_bind( LDAP *ld ) if( info ) ber_memfree( info ); if( refs ) ber_memvfree( (void **)refs ); - if ( err != LDAP_SUCCESS ) exit( err ); + if ( err != LDAP_SUCCESS ) tool_exit( ld, err ); } } } @@ -1587,6 +1591,16 @@ tool_unbind( LDAP *ld ) (void) ldap_unbind_ext( ld, NULL, NULL ); } +void +tool_exit( LDAP *ld, int status ) +{ + if ( ld != NULL ) { + tool_unbind( ld ); + } + tool_destroy(); + exit( status ); +} + /* Set server controls. Add controls extra_c[0..count-1], if set. */ void @@ -1623,7 +1637,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) ctrls = (LDAPControl**) malloc(sizeof(c) + (count + unknown_ctrls_num + 1)*sizeof(LDAPControl*)); if ( ctrls == NULL ) { fprintf( stderr, "No memory\n" ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } if ( assertctl ) { @@ -1663,11 +1677,11 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) ber_init2( ber, NULL, LBER_USE_DER ); if ( ber_printf( ber, "s", proxydn ) == -1 ) { - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } if ( ber_flatten2( ber, &c[i].ldctl_value, 0 ) == -1 ) { - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ; @@ -1724,13 +1738,13 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) if( ber_printf( ber, "{v}", attrs ) == -1 ) { fprintf( stderr, "preread attrs encode failed.\n" ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } err = ber_flatten2( ber, &c[i].ldctl_value, 0 ); if( err < 0 ) { fprintf( stderr, "preread flatten failed (%d)\n", err ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_PRE_READ; @@ -1754,13 +1768,13 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) if( ber_printf( ber, "{v}", attrs ) == -1 ) { fprintf( stderr, "postread attrs encode failed.\n" ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } err = ber_flatten2( ber, &c[i].ldctl_value, 0 ); if( err < 0 ) { fprintf( stderr, "postread flatten failed (%d)\n", err ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_POST_READ; @@ -1783,7 +1797,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) if ( err == -1 ) { ber_free( ber, 1 ); fprintf( stderr, _("Chaining behavior control encoding error!\n") ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } if ( chainingContinuation > -1 ) { @@ -1791,7 +1805,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) if ( err == -1 ) { ber_free( ber, 1 ); fprintf( stderr, _("Chaining behavior control encoding error!\n") ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } } @@ -1799,11 +1813,11 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) if ( err == -1 ) { ber_free( ber, 1 ); fprintf( stderr, _("Chaining behavior control encoding error!\n") ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } if ( ber_flatten2( ber, &c[i].ldctl_value, 0 ) == -1 ) { - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } } else { @@ -1819,8 +1833,8 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) #ifdef LDAP_CONTROL_X_SESSION_TRACKING if ( sessionTracking ) { - if ( stValue.bv_val == NULL && st_value( ld, &stValue ) ) { - exit( EXIT_FAILURE ); + if ( BER_BVISNULL( &stValue ) && st_value( ld, &stValue ) ) { + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING; @@ -1852,7 +1866,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) free( ctrls ); if ( crit ) { - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } } @@ -2368,4 +2382,3 @@ tool_is_oid( const char *s ) return 1; } - diff --git a/clients/tools/common.h b/clients/tools/common.h index fbf5ed7314..7ed6a650c3 100644 --- a/clients/tools/common.h +++ b/clients/tools/common.h @@ -118,6 +118,7 @@ LDAP *tool_conn_setup LDAP_P(( int dont, void (*private_setup)( LDAP * ) )); void tool_bind LDAP_P(( LDAP * )); void tool_unbind LDAP_P(( LDAP * )); void tool_destroy LDAP_P(( void )); +void tool_exit LDAP_P(( LDAP *ld, int status )) LDAP_GCCATTR((noreturn)); void tool_server_controls LDAP_P(( LDAP *, LDAPControl *, int )); int tool_check_abandon LDAP_P(( LDAP *ld, int msgid )); void tool_perror LDAP_P(( diff --git a/clients/tools/ldapcompare.c b/clients/tools/ldapcompare.c index 24e1a75853..3b88f66404 100644 --- a/clients/tools/ldapcompare.c +++ b/clients/tools/ldapcompare.c @@ -260,9 +260,7 @@ main( int argc, char **argv ) free( bvalue.bv_val ); - tool_unbind( ld ); - tool_destroy(); - return rc; + tool_exit( ld, rc ); } diff --git a/clients/tools/ldapdelete.c b/clients/tools/ldapdelete.c index f1db45eaa2..1e823eec0b 100644 --- a/clients/tools/ldapdelete.c +++ b/clients/tools/ldapdelete.c @@ -218,9 +218,7 @@ main( int argc, char **argv ) fclose( fp ); } - tool_unbind( ld ); - tool_destroy(); - return retval; + tool_exit( ld, retval ); } diff --git a/clients/tools/ldapexop.c b/clients/tools/ldapexop.c index 6fc4d1e3c6..cf30a37947 100644 --- a/clients/tools/ldapexop.c +++ b/clients/tools/ldapexop.c @@ -213,7 +213,7 @@ main( int argc, char *argv[] ) struct timeval tv; if ( tool_check_abandon( ld, id ) ) { - return LDAP_CANCELLED; + tool_exit( ld, LDAP_CANCELLED ); } tv.tv_sec = 0; @@ -351,8 +351,5 @@ skip: /* disconnect from server */ if ( res ) ldap_msgfree( res ); - tool_unbind( ld ); - tool_destroy(); - - return code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE; + tool_exit( ld, code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE ); } diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index 3d867b7c93..88143434bc 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -388,12 +388,6 @@ main( int argc, char **argv ) } #endif - if ( !dont && ld != NULL ) { - tool_unbind( ld ); - } - - tool_destroy(); - fail:; if ( rejfp != NULL ) { fclose( rejfp ); @@ -403,7 +397,7 @@ fail:; ldif_close( ldiffp ); } - return( retval ); + tool_exit( ld, retval ); } diff --git a/clients/tools/ldapmodrdn.c b/clients/tools/ldapmodrdn.c index 42c37aa31b..1483d157c9 100644 --- a/clients/tools/ldapmodrdn.c +++ b/clients/tools/ldapmodrdn.c @@ -156,7 +156,7 @@ main(int argc, char **argv) { char *entrydn = NULL, *rdn = NULL, buf[ 4096 ]; FILE *fp = NULL; - LDAP *ld; + LDAP *ld = NULL; int rc, retval, havedn; tool_init( TOOL_MODRDN ); @@ -227,13 +227,11 @@ main(int argc, char **argv) } } - tool_unbind( ld ); - tool_destroy(); fail: if ( fp && fp != stdin ) fclose( fp ); if ( entrydn ) free( entrydn ); if ( rdn ) free( rdn ); - return( retval ); + tool_exit( ld, retval ); } static int domodrdn( diff --git a/clients/tools/ldappasswd.c b/clients/tools/ldappasswd.c index 81e9c76c95..1e350f153c 100644 --- a/clients/tools/ldappasswd.c +++ b/clients/tools/ldappasswd.c @@ -313,7 +313,7 @@ main( int argc, char *argv[] ) struct timeval tv; if ( tool_check_abandon( ld, id ) ) { - return LDAP_CANCELLED; + tool_exit( ld, LDAP_CANCELLED ); } tv.tv_sec = 0; @@ -322,7 +322,7 @@ main( int argc, char *argv[] ) rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res ); if ( rc < 0 ) { tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL ); - return rc; + tool_exit( ld, rc ); } if ( rc != 0 ) { @@ -409,8 +409,5 @@ main( int argc, char *argv[] ) done: /* disconnect from server */ - if ( ld ) - tool_unbind( ld ); - tool_destroy(); - return rc; + tool_exit( ld, rc ); } diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 0eb1922a90..d95d355698 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -767,7 +767,7 @@ private_conn_setup( LDAP *ld ) != LDAP_OPT_SUCCESS ) { fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } } @@ -898,7 +898,7 @@ getNextPage: if ( !fp && infile ) { if (( fp = fopen( infile, "r" )) == NULL ) { perror( infile ); - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } } save_nctrls = nctrls; @@ -922,7 +922,7 @@ getNextPage: #ifdef LDAP_CONTROL_DONTUSECOPY if ( dontUseCopy ) { if ( ctrl_add() ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY; @@ -935,7 +935,7 @@ getNextPage: if ( domainScope ) { if ( ctrl_add() ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_X_DOMAIN_SCOPE; @@ -947,22 +947,22 @@ getNextPage: if ( subentries ) { if ( ctrl_add() ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if (( seber = ber_alloc_t(LBER_USE_DER)) == NULL ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } err = ber_printf( seber, "b", abs(subentries) == 1 ? 0 : 1 ); if ( err == -1 ) { ber_free( seber, 1 ); fprintf( stderr, _("Subentries control encoding error!\n") ); - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if ( ber_flatten2( seber, &c[i].ldctl_value, 0 ) == -1 ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_SUBENTRIES; @@ -972,11 +972,11 @@ getNextPage: if ( ldapsync ) { if ( ctrl_add() ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if (( syncber = ber_alloc_t(LBER_USE_DER)) == NULL ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if ( sync_cookie.bv_len == 0 ) { @@ -989,11 +989,11 @@ getNextPage: if ( err == -1 ) { ber_free( syncber, 1 ); fprintf( stderr, _("ldap sync control encoding error!\n") ); - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if ( ber_flatten( syncber, &syncbvalp ) == -1 ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_SYNC; @@ -1004,21 +1004,21 @@ getNextPage: if ( valuesReturnFilter ) { if ( ctrl_add() ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if (( vrber = ber_alloc_t(LBER_USE_DER)) == NULL ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if ( ( err = ldap_put_vrFilter( vrber, vrFilter ) ) == -1 ) { ber_free( vrber, 1 ); fprintf( stderr, _("Bad ValuesReturnFilter: %s\n"), vrFilter ); - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if ( ber_flatten2( vrber, &c[i].ldctl_value, 0 ) == -1 ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_VALUESRETURNFILTER; @@ -1028,13 +1028,13 @@ getNextPage: if ( pagedResults ) { if ( ctrl_add() ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if ( ldap_create_page_control_value( ld, pageSize, &pr_cookie, &c[i].ldctl_value ) ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if ( pr_cookie.bv_val != NULL ) { @@ -1050,13 +1050,13 @@ getNextPage: if ( sss ) { if ( ctrl_add() ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if ( ldap_create_sort_control_value( ld, sss_keys, &c[i].ldctl_value ) ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_SORTREQUEST; @@ -1066,13 +1066,13 @@ getNextPage: if ( vlv ) { if ( ctrl_add() ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } if ( ldap_create_vlv_control_value( ld, &vlvInfo, &c[i].ldctl_value ) ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } c[i].ldctl_oid = LDAP_CONTROL_VLVREQUEST; @@ -1087,7 +1087,7 @@ getNextPage: assert( ds != NULL ); if ( ldap_create_deref_control_value( ld, ds, &derefval ) != LDAP_SUCCESS ) { - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } for ( i = 0; ds[ i ].derefAttr != NULL; i++ ) { @@ -1099,7 +1099,7 @@ getNextPage: } if ( ctrl_add() ) { - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } c[ i ].ldctl_iscritical = derefcrit > 1; @@ -1275,7 +1275,7 @@ getNextPage: if ( num != 1 ) { fprintf( stderr, _("Invalid value for PagedResultsControl, %s.\n"), buf); - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } pageSize = (ber_int_t)tmpSize; @@ -1306,7 +1306,7 @@ getNextPage: if ( buf[0] ) { i = parse_vlv( strdup( buf )); if ( i ) - return EXIT_FAILURE; + tool_exit( ld, EXIT_FAILURE ); } else { vlvInfo.ldvlv_attrvalue = NULL; vlvInfo.ldvlv_count = vlvCount; @@ -1320,8 +1320,6 @@ getNextPage: goto getNextPage; } - tool_unbind( ld ); - tool_destroy(); if ( base != NULL ) { ber_memfree( base ); } @@ -1348,7 +1346,7 @@ getNextPage: c = NULL; } - return( rc ); + tool_exit( ld, rc ); } @@ -1613,7 +1611,7 @@ print_entry( if( rc != LDAP_SUCCESS ) { fprintf(stderr, _("print_entry: %d\n"), rc ); tool_perror( "ldap_get_entry_controls", rc, NULL, NULL, NULL, NULL ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } if( ctrls ) { @@ -1711,7 +1709,7 @@ static void print_reference( if( rc != LDAP_SUCCESS ) { tool_perror( "ldap_parse_reference", rc, NULL, NULL, NULL, NULL ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } if( refs ) { @@ -1746,7 +1744,7 @@ static void print_extended( if( rc != LDAP_SUCCESS ) { tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } if ( ldif < 2 ) { @@ -1784,7 +1782,7 @@ static void print_partial( if( rc != LDAP_SUCCESS ) { tool_perror( "ldap_parse_intermediate", rc, NULL, NULL, NULL, NULL ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } if ( ldif < 2 ) { @@ -1834,7 +1832,7 @@ static int print_result( if( rc != LDAP_SUCCESS ) { tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL ); - exit( EXIT_FAILURE ); + tool_exit( ld, EXIT_FAILURE ); } diff --git a/clients/tools/ldapwhoami.c b/clients/tools/ldapwhoami.c index 4f4c9f6290..ff57fda808 100644 --- a/clients/tools/ldapwhoami.c +++ b/clients/tools/ldapwhoami.c @@ -151,7 +151,7 @@ main( int argc, char *argv[] ) struct timeval tv; if ( tool_check_abandon( ld, id ) ) { - return LDAP_CANCELLED; + tool_exit( ld, LDAP_CANCELLED ); } tv.tv_sec = 0; @@ -160,7 +160,7 @@ main( int argc, char *argv[] ) rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res ); if ( rc < 0 ) { tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL ); - return rc; + tool_exit( ld, rc ); } if ( rc != 0 ) { @@ -231,8 +231,5 @@ skip: ber_bvfree( authzid ); /* disconnect from server */ - tool_unbind( ld ); - tool_destroy(); - - return code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE; + tool_exit( ld, code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE ); } -- 2.39.2