void
tester_ldap_error( LDAP *ld, const char *fname )
{
- int err;
- const char *text = "Success";
+ int err;
+ char *text = NULL;
+ LDAPControl **ctrls = NULL;
ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&err );
if ( err != LDAP_SUCCESS ) {
ldap_get_option( ld, LDAP_OPT_ERROR_STRING, (void *)&text );
}
- fprintf( stderr, "%s: %s: (%d) %s\n",
- progname, fname, err, text == NULL ? "" : text );
+ fprintf( stderr, "%s: %s: %s (%d) %s\n",
+ progname, fname, ldap_err2string( err ), err,
+ text == NULL ? "" : text );
+
+ if ( text ) {
+ ldap_memfree( text );
+ text = NULL;
+ }
+
+ ldap_get_option( ld, LDAP_OPT_MATCHED_DN, (void *)&text );
+ if ( text != NULL ) {
+ fprintf( stderr, "\tmatched: %s\n", text );
+ ldap_memfree( text );
+ text = NULL;
+ }
+
+ ldap_get_option( ld, LDAP_OPT_SERVER_CONTROLS, (void *)&ctrls );
+ if ( ctrls != NULL ) {
+ int i;
+
+ fprintf( stderr, "\tcontrols:\n" );
+ for ( i = 0; ctrls[ i ] != NULL; i++ ) {
+ fprintf( stderr, "\t\t%s\n", ctrls[ i ]->ldctl_oid );
+ }
+ ldap_controls_free( ctrls );
+ ctrls = NULL;
+ }
+
+ if ( err == LDAP_REFERRAL ) {
+ char **refs = NULL;
+
+ ldap_get_option( ld, LDAP_OPT_REFERRAL_URLS, (void *)&refs );
+
+ if ( refs ) {
+ int i;
+
+ fprintf( stderr, "\treferral:\n" );
+ for ( i = 0; refs[ i ] != NULL; i++ ) {
+ fprintf( stderr, "\t\t%s\n", refs[ i ] );
+ }
+
+ ber_memvfree( (void **)refs );
+ }
+ }
}
void