Added a tool_perror2() to avoid some redundant calls.
}
}
+int tool_perror2(
+ LDAP *ld,
+ const char *func )
+{
+ int err;
+ char *msg = NULL;
+
+ ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void*)&err );
+ ldap_get_option( ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*)&msg );
+ tool_perror( func, err, NULL, NULL, msg, NULL );
+ ldap_memfree( msg );
+ return err;
+}
void
tool_args( int argc, char **argv )
ldap_msgfree( result );
if ( ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &result ) == -1 || !result ) {
- ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void*)&err );
- ldap_get_option( ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*)&info );
- tool_perror( "ldap_sasl_interactive_bind",
- err, NULL, NULL, info, NULL );
- ldap_memfree( info );
+ err = tool_perror2( ld, "ldap_sasl_interactive_bind" );
tool_exit( ld, err );
}
} while ( rc == LDAP_SASL_BIND_IN_PROGRESS );
/* simple bind */
rc = ldap_sasl_bind( ld, binddn, LDAP_SASL_SIMPLE, &passwd,
sctrlsp, NULL, &msgid );
- if ( msgid == -1 ) {
- tool_perror( "ldap_sasl_bind(SIMPLE)", rc,
- NULL, NULL, NULL, NULL );
+ if ( rc == -1 ) {
+ rc = tool_perror2( ld, "ldap_sasl_bind(SIMPLE)" );
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 );
+ tool_perror2( ld, "ldap_result" );
tool_exit( ld, LDAP_LOCAL_ERROR );
}
const char *matched,
const char *info,
char **refs ));
+int tool_perror2 LDAP_P((
+ LDAP *ld,
+ const char *func ));
void tool_print_ctrls LDAP_P(( LDAP *ld, LDAPControl **ctrls ));
int tool_write_ldif LDAP_P(( int type, char *name, char *value, ber_len_t vallen ));
int tool_is_oid LDAP_P(( const char *s ));
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
- tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
+ rc = tool_perror2( ld, "ldap_result" );
return rc;
}
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
- tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
+ rc = tool_perror2( ld, "ldap_result" );
return rc;
}
char *dn = ldap_get_dn( ld, e );
if( dn == NULL ) {
- ldap_get_option( ld, LDAP_OPT_RESULT_CODE, &rc );
- tool_perror( "ldap_prune", rc, NULL, NULL, NULL, NULL );
+ rc = tool_perror2( ld, "ldap_prune" );
goto leave;
}
rc = ldap_whoami( ld, NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
- tool_perror( "ldap_extended_operation", rc, NULL, NULL, NULL, NULL );
+ tool_perror( "ldap_whoami", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
rc = ldap_refresh( ld, &dn, ttl, NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
- tool_perror( "ldap_extended_operation", rc, NULL, NULL, NULL, NULL );
+ tool_perror( "ldap_refresh", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
- tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
+ tool_perror2( ld, "ldap_result" );
rc = EXIT_FAILURE;
goto skip;
}
}
if ( rc == -1 ) {
- ldap_get_option( ld, LDAP_OPT_RESULT_CODE, &rc );
- tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
+ rc = tool_perror2( ld, "ldap_result" );
return rc;
}
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
- tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
+ rc = tool_perror2( ld, "ldap_result" );
return rc;
}
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
- tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
+ rc = tool_perror2( ld, "ldap_result" );
tool_exit( ld, rc );
}
ldap_msgfree(res);
if (ldap_result(ld, msgid, LDAP_MSG_ALL, NULL, &res) == -1 || !res) {
- ldap_get_option(ld, LDAP_OPT_RESULT_CODE, (void*) &rc);
- ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void*) &text);
- tool_perror( "ldap_verify_credentials_interactive", rc, NULL, NULL, text, NULL);
- ldap_memfree(text);
+ rc = tool_perror2( ld, "ldap_verify_credentials_interactive" );
tool_exit(ld, rc);
}
} while (rc == LDAP_SASL_BIND_IN_PROGRESS);
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
- tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
+ rc = tool_perror2( ld, "ldap_result" );
tool_exit( ld, rc );
}
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
- tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
+ rc = tool_perror2( ld, "ldap_result" );
tool_exit( ld, rc );
}