if ( rejfile != NULL ) {
if (( rejfp = fopen( rejfile, "w" )) == NULL ) {
perror( rejfile );
- return( EXIT_FAILURE );
+ retval = EXIT_FAILURE;
+ goto fail;
}
} else {
rejfp = NULL;
if ( infile != NULL ) {
if (( ldiffp = ldif_open( infile, "r" )) == NULL ) {
perror( infile );
- return( EXIT_FAILURE );
+ retval = EXIT_FAILURE;
+ goto fail;
}
} else {
ldifdummy.fp = stdin;
if ( pw_file || want_bindpw ) {
if ( pw_file ) {
rc = lutil_get_filed_password( pw_file, &passwd );
- if( rc ) return EXIT_FAILURE;
+ if ( rc ) {
+ retval = EXIT_FAILURE;
+ goto fail;
+ }
} else {
passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
rc = ldap_txn_start_s( ld, NULL, NULL, &txn_id );
if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_txn_start_s", rc, NULL, NULL, NULL, NULL );
- if( txn > 1 ) return EXIT_FAILURE;
+ if( txn > 1 ) {
+ retval = EXIT_FAILURE;
+ goto fail;
+ }
txn = 0;
}
}
len = strlen( rbuf );
if (( rejbuf = (char *)ber_memalloc( len+1 )) == NULL ) {
perror( "malloc" );
- exit( EXIT_FAILURE );
+ retval = EXIT_FAILURE;
+ goto fail;
}
memcpy( rejbuf, rbuf, len+1 );
}
}
#endif
- if ( !dont ) {
+ if ( !dont && ld != NULL ) {
tool_unbind( ld );
}
+ tool_destroy();
+
+fail:;
if ( rejfp != NULL ) {
fclose( rejfp );
}
- tool_destroy();
+ if ( ldiffp != NULL && ldiffp != &ldifdummy ) {
+ ldif_close( ldiffp );
+ }
+
return( retval );
}