ldap_pvt_textdomain(OPENLDAP_PACKAGE);
}
+void
+tool_destroy( void )
+{
+#ifdef HAVE_CYRUS_SASL
+ sasl_done();
+#endif
+#ifdef HAVE_TLS
+ ldap_pvt_tls_destroy();
+#endif
+}
+
void
tool_common_usage( void )
{
}
}
+void
+tool_unbind( LDAP *ld )
+{
+ int err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, NULL );
+
+ if ( err != LDAP_OPT_SUCCESS ) {
+ fprintf( stderr, "Could not unset controls\n");
+ }
+
+ (void) ldap_unbind_ext( ld, NULL, NULL );
+}
+
/* Set server controls. Add controls extra_c[0..count-1], if set. */
void
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;
+ rc = EXIT_FAILURE;
+ goto done;
}
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;
}