ITS#6548,#7092 Unbind,cleanup before client exit.

Gets rid of "(connection lost)" in slapd statslog "closed" message.
This commit is contained in:
Hallvard Furuseth 2011-11-20 13:52:40 +01:00
parent 26d881a93c
commit ef76d419ec
11 changed files with 93 additions and 105 deletions

View file

@ -252,6 +252,10 @@ tool_init( tool_type_t type )
void void
tool_destroy( void ) tool_destroy( void )
{ {
static int destroyed;
if ( destroyed++ )
return;
#ifdef HAVE_CYRUS_SASL #ifdef HAVE_CYRUS_SASL
sasl_done(); sasl_done();
#endif #endif
@ -1401,7 +1405,7 @@ dnssrv_free:;
{ {
fprintf( stderr, "Could not set LDAP_OPT_REFERRALS %s\n", fprintf( stderr, "Could not set LDAP_OPT_REFERRALS %s\n",
referrals ? "on" : "off" ); referrals ? "on" : "off" );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
#ifdef HAVE_CYRUS_SASL #ifdef HAVE_CYRUS_SASL
@ -1411,7 +1415,7 @@ dnssrv_free:;
{ {
fprintf( stderr, "Could not set LDAP_OPT_X_SASL_NOCANON %s\n", fprintf( stderr, "Could not set LDAP_OPT_X_SASL_NOCANON %s\n",
nocanon ? "on" : "off" ); nocanon ? "on" : "off" );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
#endif #endif
if( ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) if( ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &protocol )
@ -1419,7 +1423,7 @@ dnssrv_free:;
{ {
fprintf( stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n", fprintf( stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n",
protocol ); protocol );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
if ( use_tls ) { if ( use_tls ) {
@ -1430,7 +1434,7 @@ dnssrv_free:;
tool_perror( "ldap_start_tls", rc, NULL, NULL, msg, NULL ); tool_perror( "ldap_start_tls", rc, NULL, NULL, msg, NULL );
ldap_memfree(msg); ldap_memfree(msg);
if ( use_tls > 1 ) { if ( use_tls > 1 ) {
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
} }
} }
@ -1441,7 +1445,7 @@ dnssrv_free:;
{ {
fprintf( stderr, "Could not set LDAP_OPT_NETWORK_TIMEOUT %ld\n", fprintf( stderr, "Could not set LDAP_OPT_NETWORK_TIMEOUT %ld\n",
(long)nettimeout.tv_sec ); (long)nettimeout.tv_sec );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
} }
} }
@ -1500,7 +1504,7 @@ tool_bind( LDAP *ld )
LDAPControl c; LDAPControl c;
if ( BER_BVISNULL( &stValue) && st_value( ld, &stValue ) ) { if ( BER_BVISNULL( &stValue) && st_value( ld, &stValue ) ) {
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
c.ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING; c.ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING;
@ -1524,7 +1528,7 @@ tool_bind( LDAP *ld )
if ( pw_file ) { if ( pw_file ) {
if ( lutil_get_filed_password( pw_file, &passwd ) ) { if ( lutil_get_filed_password( pw_file, &passwd ) ) {
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
} else { } else {
@ -1549,7 +1553,7 @@ tool_bind( LDAP *ld )
fprintf( stderr, fprintf( stderr,
"Could not set LDAP_OPT_X_SASL_SECPROPS: %s\n", "Could not set LDAP_OPT_X_SASL_SECPROPS: %s\n",
sasl_secprops ); sasl_secprops );
exit( LDAP_LOCAL_ERROR ); tool_exit( ld, LDAP_LOCAL_ERROR );
} }
} }
@ -1576,7 +1580,7 @@ tool_bind( LDAP *ld )
tool_perror( "ldap_sasl_interactive_bind", tool_perror( "ldap_sasl_interactive_bind",
err, NULL, NULL, info, NULL ); err, NULL, NULL, info, NULL );
ldap_memfree( info ); ldap_memfree( info );
exit( err ); tool_exit( ld, err );
} }
} while ( rc == LDAP_SASL_BIND_IN_PROGRESS ); } while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
@ -1587,11 +1591,11 @@ tool_bind( LDAP *ld )
tool_perror( "ldap_sasl_interactive_bind", tool_perror( "ldap_sasl_interactive_bind",
rc, NULL, NULL, info, NULL ); rc, NULL, NULL, info, NULL );
ldap_memfree( info ); ldap_memfree( info );
exit( rc ); tool_exit( ld, rc );
} }
#else #else
fprintf( stderr, "%s: not compiled with SASL support\n", prog ); fprintf( stderr, "%s: not compiled with SASL support\n", prog );
exit( LDAP_NOT_SUPPORTED ); tool_exit( ld, LDAP_NOT_SUPPORTED );
#endif #endif
} else { } else {
/* simple bind */ /* simple bind */
@ -1600,18 +1604,18 @@ tool_bind( LDAP *ld )
if ( msgid == -1 ) { if ( msgid == -1 ) {
tool_perror( "ldap_sasl_bind(SIMPLE)", rc, tool_perror( "ldap_sasl_bind(SIMPLE)", rc,
NULL, NULL, NULL, NULL ); NULL, NULL, NULL, NULL );
exit( rc ); tool_exit( ld, rc );
} }
rc = ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &result ); rc = ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &result );
if ( rc == -1 ) { if ( rc == -1 ) {
tool_perror( "ldap_result", -1, NULL, NULL, NULL, NULL ); tool_perror( "ldap_result", -1, NULL, NULL, NULL, NULL );
exit( LDAP_LOCAL_ERROR ); tool_exit( ld, LDAP_LOCAL_ERROR );
} }
if ( rc == 0 ) { if ( rc == 0 ) {
tool_perror( "ldap_result", LDAP_TIMEOUT, NULL, NULL, NULL, NULL ); tool_perror( "ldap_result", LDAP_TIMEOUT, NULL, NULL, NULL, NULL );
exit( LDAP_LOCAL_ERROR ); tool_exit( ld, LDAP_LOCAL_ERROR );
} }
} }
@ -1619,7 +1623,7 @@ tool_bind( LDAP *ld )
&ctrls, 1 ); &ctrls, 1 );
if ( rc != LDAP_SUCCESS ) { if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_bind parse result", rc, NULL, matched, info, refs ); 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 #ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
@ -1682,7 +1686,7 @@ tool_bind( LDAP *ld )
if( info ) ber_memfree( info ); if( info ) ber_memfree( info );
if( refs ) ber_memvfree( (void **)refs ); if( refs ) ber_memvfree( (void **)refs );
if ( err != LDAP_SUCCESS ) exit( err ); if ( err != LDAP_SUCCESS ) tool_exit( ld, err );
} }
} }
@ -1698,6 +1702,16 @@ tool_unbind( LDAP *ld )
(void) ldap_unbind_ext( ld, NULL, NULL ); (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. */ /* Set server controls. Add controls extra_c[0..count-1], if set. */
void void
@ -1734,7 +1748,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
ctrls = (LDAPControl**) malloc(sizeof(c) + (count + unknown_ctrls_num + 1)*sizeof(LDAPControl*)); ctrls = (LDAPControl**) malloc(sizeof(c) + (count + unknown_ctrls_num + 1)*sizeof(LDAPControl*));
if ( ctrls == NULL ) { if ( ctrls == NULL ) {
fprintf( stderr, "No memory\n" ); fprintf( stderr, "No memory\n" );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
if ( assertctl ) { if ( assertctl ) {
@ -1774,11 +1788,11 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
ber_init2( ber, NULL, LBER_USE_DER ); ber_init2( ber, NULL, LBER_USE_DER );
if ( ber_printf( ber, "s", proxydn ) == -1 ) { 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 ) { 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; c[i].ldctl_oid = LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ;
@ -1835,13 +1849,13 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
if( ber_printf( ber, "{v}", attrs ) == -1 ) { if( ber_printf( ber, "{v}", attrs ) == -1 ) {
fprintf( stderr, "preread attrs encode failed.\n" ); fprintf( stderr, "preread attrs encode failed.\n" );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
err = ber_flatten2( ber, &c[i].ldctl_value, 0 ); err = ber_flatten2( ber, &c[i].ldctl_value, 0 );
if( err < 0 ) { if( err < 0 ) {
fprintf( stderr, "preread flatten failed (%d)\n", err ); fprintf( stderr, "preread flatten failed (%d)\n", err );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
c[i].ldctl_oid = LDAP_CONTROL_PRE_READ; c[i].ldctl_oid = LDAP_CONTROL_PRE_READ;
@ -1865,13 +1879,13 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
if( ber_printf( ber, "{v}", attrs ) == -1 ) { if( ber_printf( ber, "{v}", attrs ) == -1 ) {
fprintf( stderr, "postread attrs encode failed.\n" ); fprintf( stderr, "postread attrs encode failed.\n" );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
err = ber_flatten2( ber, &c[i].ldctl_value, 0 ); err = ber_flatten2( ber, &c[i].ldctl_value, 0 );
if( err < 0 ) { if( err < 0 ) {
fprintf( stderr, "postread flatten failed (%d)\n", err ); fprintf( stderr, "postread flatten failed (%d)\n", err );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
c[i].ldctl_oid = LDAP_CONTROL_POST_READ; c[i].ldctl_oid = LDAP_CONTROL_POST_READ;
@ -1894,7 +1908,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
if ( err == -1 ) { if ( err == -1 ) {
ber_free( ber, 1 ); ber_free( ber, 1 );
fprintf( stderr, _("Chaining behavior control encoding error!\n") ); fprintf( stderr, _("Chaining behavior control encoding error!\n") );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
if ( chainingContinuation > -1 ) { if ( chainingContinuation > -1 ) {
@ -1902,7 +1916,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
if ( err == -1 ) { if ( err == -1 ) {
ber_free( ber, 1 ); ber_free( ber, 1 );
fprintf( stderr, _("Chaining behavior control encoding error!\n") ); fprintf( stderr, _("Chaining behavior control encoding error!\n") );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
} }
@ -1910,11 +1924,11 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
if ( err == -1 ) { if ( err == -1 ) {
ber_free( ber, 1 ); ber_free( ber, 1 );
fprintf( stderr, _("Chaining behavior control encoding error!\n") ); 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 ) { if ( ber_flatten2( ber, &c[i].ldctl_value, 0 ) == -1 ) {
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
} else { } else {
@ -1931,7 +1945,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
#ifdef LDAP_CONTROL_X_SESSION_TRACKING #ifdef LDAP_CONTROL_X_SESSION_TRACKING
if ( sessionTracking ) { if ( sessionTracking ) {
if ( BER_BVISNULL( &stValue ) && st_value( ld, &stValue ) ) { if ( BER_BVISNULL( &stValue ) && st_value( ld, &stValue ) ) {
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
c[i].ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING; c[i].ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING;
@ -1963,7 +1977,7 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
free( ctrls ); free( ctrls );
if ( crit ) { if ( crit ) {
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
} }
@ -2497,4 +2511,3 @@ tool_is_oid( const char *s )
return 1; return 1;
} }

View file

@ -119,6 +119,7 @@ LDAP *tool_conn_setup LDAP_P(( int dont, void (*private_setup)( LDAP * ) ));
void tool_bind LDAP_P(( LDAP * )); void tool_bind LDAP_P(( LDAP * ));
void tool_unbind LDAP_P(( LDAP * )); void tool_unbind LDAP_P(( LDAP * ));
void tool_destroy LDAP_P(( void )); 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 )); void tool_server_controls LDAP_P(( LDAP *, LDAPControl *, int ));
int tool_check_abandon LDAP_P(( LDAP *ld, int msgid )); int tool_check_abandon LDAP_P(( LDAP *ld, int msgid ));
void tool_perror LDAP_P(( void tool_perror LDAP_P((

View file

@ -260,9 +260,7 @@ main( int argc, char **argv )
free( bvalue.bv_val ); free( bvalue.bv_val );
tool_unbind( ld ); tool_exit( ld, rc );
tool_destroy();
return rc;
} }

View file

@ -218,9 +218,7 @@ main( int argc, char **argv )
fclose( fp ); fclose( fp );
} }
tool_unbind( ld ); tool_exit( ld, retval );
tool_destroy();
return retval;
} }

View file

@ -213,7 +213,7 @@ main( int argc, char *argv[] )
struct timeval tv; struct timeval tv;
if ( tool_check_abandon( ld, id ) ) { if ( tool_check_abandon( ld, id ) ) {
return LDAP_CANCELLED; tool_exit( ld, LDAP_CANCELLED );
} }
tv.tv_sec = 0; tv.tv_sec = 0;
@ -351,8 +351,5 @@ skip:
/* disconnect from server */ /* disconnect from server */
if ( res ) if ( res )
ldap_msgfree( res ); ldap_msgfree( res );
tool_unbind( ld ); tool_exit( ld, code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE );
tool_destroy();
return code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View file

@ -363,12 +363,6 @@ main( int argc, char **argv )
} }
#endif #endif
if ( !dont && ld != NULL ) {
tool_unbind( ld );
}
tool_destroy();
fail:; fail:;
if ( rejfp != NULL ) { if ( rejfp != NULL ) {
fclose( rejfp ); fclose( rejfp );
@ -378,7 +372,7 @@ fail:;
ldif_close( ldiffp ); ldif_close( ldiffp );
} }
return( retval ); tool_exit( ld, retval );
} }

View file

@ -156,7 +156,7 @@ main(int argc, char **argv)
{ {
char *entrydn = NULL, *rdn = NULL, buf[ 4096 ]; char *entrydn = NULL, *rdn = NULL, buf[ 4096 ];
FILE *fp = NULL; FILE *fp = NULL;
LDAP *ld; LDAP *ld = NULL;
int rc, retval, havedn; int rc, retval, havedn;
tool_init( TOOL_MODRDN ); tool_init( TOOL_MODRDN );
@ -227,13 +227,11 @@ main(int argc, char **argv)
} }
} }
tool_unbind( ld );
tool_destroy();
fail: fail:
if ( fp && fp != stdin ) fclose( fp ); if ( fp && fp != stdin ) fclose( fp );
if ( entrydn ) free( entrydn ); if ( entrydn ) free( entrydn );
if ( rdn ) free( rdn ); if ( rdn ) free( rdn );
return( retval ); tool_exit( ld, retval );
} }
static int domodrdn( static int domodrdn(

View file

@ -313,7 +313,7 @@ main( int argc, char *argv[] )
struct timeval tv; struct timeval tv;
if ( tool_check_abandon( ld, id ) ) { if ( tool_check_abandon( ld, id ) ) {
return LDAP_CANCELLED; tool_exit( ld, LDAP_CANCELLED );
} }
tv.tv_sec = 0; 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 ); rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) { if ( rc < 0 ) {
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL ); tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
return rc; tool_exit( ld, rc );
} }
if ( rc != 0 ) { if ( rc != 0 ) {
@ -409,8 +409,5 @@ main( int argc, char *argv[] )
done: done:
/* disconnect from server */ /* disconnect from server */
if ( ld ) tool_exit( ld, rc );
tool_unbind( ld );
tool_destroy();
return rc;
} }

View file

@ -777,7 +777,7 @@ private_conn_setup( LDAP *ld )
!= LDAP_OPT_SUCCESS ) != LDAP_OPT_SUCCESS )
{ {
fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref ); fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
} }
@ -908,7 +908,7 @@ getNextPage:
if ( !fp && infile ) { if ( !fp && infile ) {
if (( fp = fopen( infile, "r" )) == NULL ) { if (( fp = fopen( infile, "r" )) == NULL ) {
perror( infile ); perror( infile );
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
} }
save_nctrls = nctrls; save_nctrls = nctrls;
@ -932,7 +932,7 @@ getNextPage:
#ifdef LDAP_CONTROL_DONTUSECOPY #ifdef LDAP_CONTROL_DONTUSECOPY
if ( dontUseCopy ) { if ( dontUseCopy ) {
if ( ctrl_add() ) { if ( ctrl_add() ) {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY; c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
@ -945,7 +945,7 @@ getNextPage:
if ( domainScope ) { if ( domainScope ) {
if ( ctrl_add() ) { if ( ctrl_add() ) {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
c[i].ldctl_oid = LDAP_CONTROL_X_DOMAIN_SCOPE; c[i].ldctl_oid = LDAP_CONTROL_X_DOMAIN_SCOPE;
@ -957,22 +957,22 @@ getNextPage:
if ( subentries ) { if ( subentries ) {
if ( ctrl_add() ) { if ( ctrl_add() ) {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
if (( seber = ber_alloc_t(LBER_USE_DER)) == NULL ) { 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 ); err = ber_printf( seber, "b", abs(subentries) == 1 ? 0 : 1 );
if ( err == -1 ) { if ( err == -1 ) {
ber_free( seber, 1 ); ber_free( seber, 1 );
fprintf( stderr, _("Subentries control encoding error!\n") ); 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 ) { 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; c[i].ldctl_oid = LDAP_CONTROL_SUBENTRIES;
@ -982,11 +982,11 @@ getNextPage:
if ( ldapsync ) { if ( ldapsync ) {
if ( ctrl_add() ) { if ( ctrl_add() ) {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
if (( syncber = ber_alloc_t(LBER_USE_DER)) == NULL ) { if (( syncber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
if ( sync_cookie.bv_len == 0 ) { if ( sync_cookie.bv_len == 0 ) {
@ -999,11 +999,11 @@ getNextPage:
if ( err == -1 ) { if ( err == -1 ) {
ber_free( syncber, 1 ); ber_free( syncber, 1 );
fprintf( stderr, _("ldap sync control encoding error!\n") ); fprintf( stderr, _("ldap sync control encoding error!\n") );
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
if ( ber_flatten( syncber, &syncbvalp ) == -1 ) { if ( ber_flatten( syncber, &syncbvalp ) == -1 ) {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
c[i].ldctl_oid = LDAP_CONTROL_SYNC; c[i].ldctl_oid = LDAP_CONTROL_SYNC;
@ -1014,21 +1014,21 @@ getNextPage:
if ( valuesReturnFilter ) { if ( valuesReturnFilter ) {
if ( ctrl_add() ) { if ( ctrl_add() ) {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
if (( vrber = ber_alloc_t(LBER_USE_DER)) == NULL ) { 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 ) { if ( ( err = ldap_put_vrFilter( vrber, vrFilter ) ) == -1 ) {
ber_free( vrber, 1 ); ber_free( vrber, 1 );
fprintf( stderr, _("Bad ValuesReturnFilter: %s\n"), vrFilter ); 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 ) { 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; c[i].ldctl_oid = LDAP_CONTROL_VALUESRETURNFILTER;
@ -1038,13 +1038,13 @@ getNextPage:
if ( pagedResults ) { if ( pagedResults ) {
if ( ctrl_add() ) { if ( ctrl_add() ) {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
if ( ldap_create_page_control_value( ld, if ( ldap_create_page_control_value( ld,
pageSize, &pr_cookie, &c[i].ldctl_value ) ) pageSize, &pr_cookie, &c[i].ldctl_value ) )
{ {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
if ( pr_cookie.bv_val != NULL ) { if ( pr_cookie.bv_val != NULL ) {
@ -1060,13 +1060,13 @@ getNextPage:
if ( sss ) { if ( sss ) {
if ( ctrl_add() ) { if ( ctrl_add() ) {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
if ( ldap_create_sort_control_value( ld, if ( ldap_create_sort_control_value( ld,
sss_keys, &c[i].ldctl_value ) ) sss_keys, &c[i].ldctl_value ) )
{ {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
c[i].ldctl_oid = LDAP_CONTROL_SORTREQUEST; c[i].ldctl_oid = LDAP_CONTROL_SORTREQUEST;
@ -1076,13 +1076,13 @@ getNextPage:
if ( vlv ) { if ( vlv ) {
if ( ctrl_add() ) { if ( ctrl_add() ) {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
if ( ldap_create_vlv_control_value( ld, if ( ldap_create_vlv_control_value( ld,
&vlvInfo, &c[i].ldctl_value ) ) &vlvInfo, &c[i].ldctl_value ) )
{ {
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
c[i].ldctl_oid = LDAP_CONTROL_VLVREQUEST; c[i].ldctl_oid = LDAP_CONTROL_VLVREQUEST;
@ -1097,7 +1097,7 @@ getNextPage:
assert( ds != NULL ); assert( ds != NULL );
if ( ldap_create_deref_control_value( ld, ds, &derefval ) != LDAP_SUCCESS ) { 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++ ) { for ( i = 0; ds[ i ].derefAttr != NULL; i++ ) {
@ -1109,7 +1109,7 @@ getNextPage:
} }
if ( ctrl_add() ) { if ( ctrl_add() ) {
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
c[ i ].ldctl_iscritical = derefcrit > 1; c[ i ].ldctl_iscritical = derefcrit > 1;
@ -1285,7 +1285,7 @@ getNextPage:
if ( num != 1 ) { if ( num != 1 ) {
fprintf( stderr, fprintf( stderr,
_("Invalid value for PagedResultsControl, %s.\n"), buf); _("Invalid value for PagedResultsControl, %s.\n"), buf);
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} }
pageSize = (ber_int_t)tmpSize; pageSize = (ber_int_t)tmpSize;
@ -1316,7 +1316,7 @@ getNextPage:
if ( buf[0] ) { if ( buf[0] ) {
i = parse_vlv( strdup( buf )); i = parse_vlv( strdup( buf ));
if ( i ) if ( i )
return EXIT_FAILURE; tool_exit( ld, EXIT_FAILURE );
} else { } else {
vlvInfo.ldvlv_attrvalue = NULL; vlvInfo.ldvlv_attrvalue = NULL;
vlvInfo.ldvlv_count = vlvCount; vlvInfo.ldvlv_count = vlvCount;
@ -1330,8 +1330,6 @@ getNextPage:
goto getNextPage; goto getNextPage;
} }
tool_unbind( ld );
tool_destroy();
if ( base != NULL ) { if ( base != NULL ) {
ber_memfree( base ); ber_memfree( base );
} }
@ -1358,7 +1356,7 @@ getNextPage:
c = NULL; c = NULL;
} }
return( rc ); tool_exit( ld, rc );
} }
@ -1623,7 +1621,7 @@ print_entry(
if( rc != LDAP_SUCCESS ) { if( rc != LDAP_SUCCESS ) {
fprintf(stderr, _("print_entry: %d\n"), rc ); fprintf(stderr, _("print_entry: %d\n"), rc );
tool_perror( "ldap_get_entry_controls", rc, NULL, NULL, NULL, NULL ); tool_perror( "ldap_get_entry_controls", rc, NULL, NULL, NULL, NULL );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
if( ctrls ) { if( ctrls ) {
@ -1721,7 +1719,7 @@ static void print_reference(
if( rc != LDAP_SUCCESS ) { if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_reference", rc, NULL, NULL, NULL, NULL ); tool_perror( "ldap_parse_reference", rc, NULL, NULL, NULL, NULL );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
if( refs ) { if( refs ) {
@ -1756,7 +1754,7 @@ static void print_extended(
if( rc != LDAP_SUCCESS ) { if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL ); tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
if ( ldif < 2 ) { if ( ldif < 2 ) {
@ -1794,7 +1792,7 @@ static void print_partial(
if( rc != LDAP_SUCCESS ) { if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_intermediate", rc, NULL, NULL, NULL, NULL ); tool_perror( "ldap_parse_intermediate", rc, NULL, NULL, NULL, NULL );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }
if ( ldif < 2 ) { if ( ldif < 2 ) {
@ -1844,7 +1842,7 @@ static int print_result(
if( rc != LDAP_SUCCESS ) { if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL ); tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL );
exit( EXIT_FAILURE ); tool_exit( ld, EXIT_FAILURE );
} }

View file

@ -382,7 +382,7 @@ main( int argc, char *argv[] )
ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*) &text); ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*) &text);
tool_perror( "ldap_verify_credentials_interactive", rc, NULL, NULL, text, NULL); tool_perror( "ldap_verify_credentials_interactive", rc, NULL, NULL, text, NULL);
ldap_memfree(text); ldap_memfree(text);
exit(rc); tool_exit(ld, rc);
} }
} while (rc == LDAP_SASL_BIND_IN_PROGRESS); } while (rc == LDAP_SASL_BIND_IN_PROGRESS);
@ -415,7 +415,7 @@ main( int argc, char *argv[] )
struct timeval tv; struct timeval tv;
if ( tool_check_abandon( ld, id ) ) { if ( tool_check_abandon( ld, id ) ) {
return LDAP_CANCELLED; tool_exit( ld, LDAP_CANCELLED );
} }
tv.tv_sec = 0; tv.tv_sec = 0;
@ -424,7 +424,7 @@ main( int argc, char *argv[] )
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res ); rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) { if ( rc < 0 ) {
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL ); tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
return rc; tool_exit( ld, rc );
} }
if ( rc != 0 ) { if ( rc != 0 ) {
@ -504,8 +504,5 @@ skip:
free( cred.bv_val ); free( cred.bv_val );
/* disconnect from server */ /* disconnect from server */
tool_unbind( ld ); tool_exit( ld, code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE );
tool_destroy();
return code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View file

@ -151,7 +151,7 @@ main( int argc, char *argv[] )
struct timeval tv; struct timeval tv;
if ( tool_check_abandon( ld, id ) ) { if ( tool_check_abandon( ld, id ) ) {
return LDAP_CANCELLED; tool_exit( ld, LDAP_CANCELLED );
} }
tv.tv_sec = 0; 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 ); rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) { if ( rc < 0 ) {
tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL ); tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
return rc; tool_exit( ld, rc );
} }
if ( rc != 0 ) { if ( rc != 0 ) {
@ -231,8 +231,5 @@ skip:
ber_bvfree( authzid ); ber_bvfree( authzid );
/* disconnect from server */ /* disconnect from server */
tool_unbind( ld ); tool_exit( ld, code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE );
tool_destroy();
return code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
} }