Gets rid of "(connection lost)" in slapd statslog "closed" message.
void
tool_destroy( void )
{
+ static int destroyed;
+ if ( destroyed++ )
+ return;
+
#ifdef HAVE_CYRUS_SASL
sasl_done();
#endif
{
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
{
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 )
{
fprintf( stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n",
protocol );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
if ( use_tls ) {
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 );
}
}
}
{
fprintf( stderr, "Could not set LDAP_OPT_NETWORK_TIMEOUT %ld\n",
(long)nettimeout.tv_sec );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
}
}
LDAPControl c;
if ( BER_BVISNULL( &stValue) && st_value( ld, &stValue ) ) {
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
c.ldctl_oid = LDAP_CONTROL_X_SESSION_TRACKING;
if ( pw_file ) {
if ( lutil_get_filed_password( pw_file, &passwd ) ) {
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
} else {
fprintf( stderr,
"Could not set LDAP_OPT_X_SASL_SECPROPS: %s\n",
sasl_secprops );
- exit( LDAP_LOCAL_ERROR );
+ tool_exit( ld, LDAP_LOCAL_ERROR );
}
}
tool_perror( "ldap_sasl_interactive_bind",
err, NULL, NULL, info, NULL );
ldap_memfree( info );
- exit( err );
+ tool_exit( ld, err );
}
} while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
tool_perror( "ldap_sasl_interactive_bind",
rc, NULL, NULL, info, NULL );
ldap_memfree( info );
- 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 {
/* simple bind */
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 );
}
}
&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
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 );
}
}
(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
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 ) {
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;
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;
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;
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 ) {
if ( err == -1 ) {
ber_free( ber, 1 );
fprintf( stderr, _("Chaining behavior control encoding error!\n") );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
}
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 {
#ifdef LDAP_CONTROL_X_SESSION_TRACKING
if ( sessionTracking ) {
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;
free( ctrls );
if ( crit ) {
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
}
return 1;
}
-
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((
free( bvalue.bv_val );
- tool_unbind( ld );
- tool_destroy();
- return rc;
+ tool_exit( ld, rc );
}
fclose( fp );
}
- tool_unbind( ld );
- tool_destroy();
- return retval;
+ tool_exit( ld, retval );
}
struct timeval tv;
if ( tool_check_abandon( ld, id ) ) {
- return LDAP_CANCELLED;
+ tool_exit( ld, LDAP_CANCELLED );
}
tv.tv_sec = 0;
/* 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 );
}
}
#endif
- if ( !dont && ld != NULL ) {
- tool_unbind( ld );
- }
-
- tool_destroy();
-
fail:;
if ( rejfp != NULL ) {
fclose( rejfp );
ldif_close( ldiffp );
}
- return( retval );
+ tool_exit( ld, retval );
}
{
char *entrydn = NULL, *rdn = NULL, buf[ 4096 ];
FILE *fp = NULL;
- LDAP *ld;
+ LDAP *ld = NULL;
int rc, retval, havedn;
tool_init( TOOL_MODRDN );
}
}
- 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(
struct timeval tv;
if ( tool_check_abandon( ld, id ) ) {
- return LDAP_CANCELLED;
+ tool_exit( ld, LDAP_CANCELLED );
}
tv.tv_sec = 0;
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 ) {
done:
/* disconnect from server */
- if ( ld )
- tool_unbind( ld );
- tool_destroy();
- return rc;
+ tool_exit( ld, rc );
}
!= LDAP_OPT_SUCCESS )
{
fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
}
if ( !fp && infile ) {
if (( fp = fopen( infile, "r" )) == NULL ) {
perror( infile );
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
}
save_nctrls = nctrls;
#ifdef LDAP_CONTROL_DONTUSECOPY
if ( dontUseCopy ) {
if ( ctrl_add() ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
if ( domainScope ) {
if ( ctrl_add() ) {
- return EXIT_FAILURE;
+ tool_exit( ld, EXIT_FAILURE );
}
c[i].ldctl_oid = LDAP_CONTROL_X_DOMAIN_SCOPE;
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;
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 ) {
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;
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;
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 ) {
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;
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;
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++ ) {
}
if ( ctrl_add() ) {
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
c[ i ].ldctl_iscritical = derefcrit > 1;
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;
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;
goto getNextPage;
}
- tool_unbind( ld );
- tool_destroy();
if ( base != NULL ) {
ber_memfree( base );
}
c = NULL;
}
- return( rc );
+ tool_exit( ld, rc );
}
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 ) {
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_reference", rc, NULL, NULL, NULL, NULL );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
if( refs ) {
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 ) {
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 ) {
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_result", rc, NULL, NULL, NULL, NULL );
- exit( EXIT_FAILURE );
+ tool_exit( ld, EXIT_FAILURE );
}
ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*) &text);
tool_perror( "ldap_verify_credentials_interactive", rc, NULL, NULL, text, NULL);
ldap_memfree(text);
- exit(rc);
+ tool_exit(ld, rc);
}
} while (rc == LDAP_SASL_BIND_IN_PROGRESS);
struct timeval tv;
if ( tool_check_abandon( ld, id ) ) {
- return LDAP_CANCELLED;
+ tool_exit( ld, LDAP_CANCELLED );
}
tv.tv_sec = 0;
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 ) {
free( cred.bv_val );
/* 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 );
}
struct timeval tv;
if ( tool_check_abandon( ld, id ) ) {
- return LDAP_CANCELLED;
+ tool_exit( ld, LDAP_CANCELLED );
}
tv.tv_sec = 0;
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 ) {
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 );
}