From: Pierangelo Masarati Date: Thu, 12 Jan 2006 21:26:54 +0000 (+0000) Subject: improve tester_ldap_error X-Git-Tag: OPENLDAP_REL_ENG_2_4_BP~333 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4c39d2c5a0f9afda04715ac2a120a89937926293;p=openldap improve tester_ldap_error --- diff --git a/tests/progs/slapd-common.c b/tests/progs/slapd-common.c index ec401084fa..4bcc23644f 100644 --- a/tests/progs/slapd-common.c +++ b/tests/progs/slapd-common.c @@ -53,16 +53,59 @@ tester_uri( char *uri, char *host, int port ) 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