if( oldpwfile ) {
rc = lutil_get_filed_password( oldpwfile, &oldpw );
- if( rc ) return EXIT_FAILURE;
+ if( rc ) {
+ rc = EXIT_FAILURE;
+ goto done;
+ }
}
if( want_oldpw && oldpw.bv_val == NULL ) {
strcmp( oldpw.bv_val, ckoldpw ))
{
fprintf( stderr, _("passwords do not match\n") );
- return EXIT_FAILURE;
+ rc = EXIT_FAILURE;
+ goto done;
}
oldpw.bv_len = strlen( oldpw.bv_val );
if( newpwfile ) {
rc = lutil_get_filed_password( newpwfile, &newpw );
- if( rc ) return EXIT_FAILURE;
+ if( rc ) {
+ rc = EXIT_FAILURE;
+ goto done;
+ }
}
if( want_newpw && newpw.bv_val == NULL ) {
strcmp( newpw.bv_val, cknewpw ))
{
fprintf( stderr, _("passwords do not match\n") );
- return EXIT_FAILURE;
+ rc = EXIT_FAILURE;
+ goto done;
}
newpw.bv_len = strlen( newpw.bv_val );
if ( pw_file ) {
rc = lutil_get_filed_password( pw_file, &passwd );
- if( rc ) return EXIT_FAILURE;
+ if( rc ) {
+ rc = EXIT_FAILURE;
+ goto done;
+ }
} else if ( want_bindpw ) {
passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
if( ber == NULL ) {
perror( "ber_alloc_t" );
- ldap_unbind_ext( ld, NULL, NULL );
- return EXIT_FAILURE;
+ rc = EXIT_FAILURE;
+ goto done;
}
ber_printf( ber, "{" /*}*/ );
if( rc < 0 ) {
perror( "ber_flatten2" );
- ldap_unbind_ext( ld, NULL, NULL );
- return EXIT_FAILURE;
+ rc = EXIT_FAILURE;
+ goto done;
}
}
if ( not ) {
rc = LDAP_SUCCESS;
- goto skip;
+ goto done;
}
rc = ldap_extended_operation( ld,
if( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_extended_operation" );
- ldap_unbind_ext( ld, NULL, NULL );
- return EXIT_FAILURE;
+ rc = EXIT_FAILURE;
+ goto done;
}
- rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, NULL, &res );
- if ( rc < 0 ) {
- ldap_perror( ld, "ldappasswd: ldap_result" );
- return rc;
+ for ( ; ; ) {
+ struct timeval tv;
+
+ if ( tool_check_abandon( ld, id ) ) {
+ return LDAP_CANCELLED;
+ }
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 100000;
+
+ rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
+ if ( rc < 0 ) {
+ ldap_perror( ld, "ldappasswd: ldap_result" );
+ return rc;
+ }
+
+ if ( rc != 0 ) {
+ break;
+ }
}
rc = ldap_parse_result( ld, res,
if( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_parse_result" );
- return rc;
+ rc = EXIT_FAILURE;
+ goto done;
}
rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 1 );
if( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_parse_result" );
- return rc;
+ rc = EXIT_FAILURE;
+ goto done;
}
if( retdata != NULL ) {
if( ber == NULL ) {
perror( "ber_init" );
- ldap_unbind_ext( ld, NULL, NULL );
- return EXIT_FAILURE;
+ rc = EXIT_FAILURE;
+ goto done;
}
/* we should check the tag */
ber_memfree( retoid );
ber_bvfree( retdata );
-skip:
- /* disconnect from server */
- ldap_unbind_ext( ld, NULL, NULL );
+ rc = ( code == LDAP_SUCCESS ) ? EXIT_SUCCESS : EXIT_FAILURE;
- return code == LDAP_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
+done:
+ /* disconnect from server */
+ tool_unbind( ld );
+ tool_destroy();
+ return rc;
}