From: Pierangelo Masarati Date: Sat, 8 Apr 2006 11:01:01 +0000 (+0000) Subject: allow extra message in errors X-Git-Tag: OPENLDAP_REL_ENG_2_4_0ALPHA~10^2~10 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=484ba6834b87d4816ecc0a980aa40510884ece18;p=openldap allow extra message in errors --- diff --git a/tests/progs/slapd-addel.c b/tests/progs/slapd-addel.c index f199eab12e..ff131b1879 100644 --- a/tests/progs/slapd-addel.c +++ b/tests/progs/slapd-addel.c @@ -208,19 +208,19 @@ addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen ) if ( pmods == NULL || pmods[ i ] == NULL ) { if (( pmods = (LDAPMod **)realloc( pmods, (i + 2) * sizeof( LDAPMod * ))) == NULL ) { - tester_perror( "realloc" ); + tester_perror( "realloc", NULL ); exit( EXIT_FAILURE ); } *pmodsp = pmods; pmods[ i + 1 ] = NULL; if (( pmods[ i ] = (LDAPMod *)calloc( 1, sizeof( LDAPMod ))) == NULL ) { - tester_perror( "calloc" ); + tester_perror( "calloc", NULL ); exit( EXIT_FAILURE ); } pmods[ i ]->mod_op = modop; if (( pmods[ i ]->mod_type = strdup( attr )) == NULL ) { - tester_perror( "strdup" ); + tester_perror( "strdup", NULL ); exit( EXIT_FAILURE ); } } @@ -235,20 +235,20 @@ addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen ) if (( pmods[ i ]->mod_bvalues = (struct berval **)ber_memrealloc( pmods[ i ]->mod_bvalues, (j + 2) * sizeof( struct berval * ))) == NULL ) { - tester_perror( "ber_memrealloc" ); + tester_perror( "ber_memrealloc", NULL ); exit( EXIT_FAILURE ); } pmods[ i ]->mod_bvalues[ j + 1 ] = NULL; if (( bvp = (struct berval *)ber_memalloc( sizeof( struct berval ))) == NULL ) { - tester_perror( "ber_memalloc" ); + tester_perror( "ber_memalloc", NULL ); exit( EXIT_FAILURE ); } pmods[ i ]->mod_bvalues[ j ] = bvp; bvp->bv_len = vlen; if (( bvp->bv_val = (char *)malloc( vlen + 1 )) == NULL ) { - tester_perror( "malloc" ); + tester_perror( "malloc", NULL ); exit( EXIT_FAILURE ); } AC_MEMCPY( bvp->bv_val, value, vlen ); @@ -321,7 +321,7 @@ do_addel( retry:; ldap_initialize( &ld, uri ); if ( ld == NULL ) { - tester_perror( "ldap_initialize" ); + tester_perror( "ldap_initialize", NULL ); exit( EXIT_FAILURE ); } @@ -336,7 +336,7 @@ retry:; rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_sasl_bind_s" ); + tester_ldap_error( ld, "ldap_sasl_bind_s", NULL ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -359,7 +359,7 @@ retry:; /* add the entry */ rc = ldap_add_ext_s( ld, entry, attrs, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_add_ext_s" ); + tester_ldap_error( ld, "ldap_add_ext_s", NULL ); switch ( rc ) { case LDAP_ALREADY_EXISTS: /* NOTE: this likely means @@ -392,7 +392,7 @@ retry:; /* now delete the entry again */ rc = ldap_delete_ext_s( ld, entry, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_delete_ext_s" ); + tester_ldap_error( ld, "ldap_delete_ext_s", NULL ); switch ( rc ) { case LDAP_NO_SUCH_OBJECT: /* NOTE: this likely means diff --git a/tests/progs/slapd-bind.c b/tests/progs/slapd-bind.c index 9ac746d967..58ff55d7d2 100644 --- a/tests/progs/slapd-bind.c +++ b/tests/progs/slapd-bind.c @@ -201,7 +201,7 @@ do_bind( char *uri, char *dn, struct berval *pass, int maxloop, int version = LDAP_VERSION3; ldap_initialize( &ld, uri ); if ( ld == NULL ) { - tester_perror( "ldap_initialize" ); + tester_perror( "ldap_initialize", NULL ); rc = -1; break; } @@ -228,7 +228,7 @@ do_bind( char *uri, char *dn, struct berval *pass, int maxloop, /* fallthru */ default: - tester_ldap_error( ld, "ldap_sasl_bind_s" ); + tester_ldap_error( ld, "ldap_sasl_bind_s", NULL ); } if ( !noinit ) { @@ -280,7 +280,7 @@ do_base( char *uri, struct berval *base, struct berval *pass, int maxloop, ldap_initialize( &ld, uri ); if ( ld == NULL ) { - tester_perror( "ldap_initialize" ); + tester_perror( "ldap_initialize", NULL ); exit( EXIT_FAILURE ); } @@ -290,14 +290,14 @@ do_base( char *uri, struct berval *base, struct berval *pass, int maxloop, rc = ldap_sasl_bind_s( ld, NULL, LDAP_SASL_SIMPLE, &pw, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_sasl_bind_s" ); + tester_ldap_error( ld, "ldap_sasl_bind_s", NULL ); exit( EXIT_FAILURE ); } rc = ldap_search_ext( ld, base->bv_val, LDAP_SCOPE_ONE, filter, attrs, 0, NULL, NULL, 0, 0, &msgid ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_search_ext" ); + tester_ldap_error( ld, "ldap_search_ext", NULL ); exit( EXIT_FAILURE ); } diff --git a/tests/progs/slapd-common.c b/tests/progs/slapd-common.c index bed9d05c25..3724794a8b 100644 --- a/tests/progs/slapd-common.c +++ b/tests/progs/slapd-common.c @@ -51,7 +51,7 @@ tester_uri( char *uri, char *host, int port ) } void -tester_ldap_error( LDAP *ld, const char *fname ) +tester_ldap_error( LDAP *ld, const char *fname, const char *msg ) { int err; char *text = NULL; @@ -62,9 +62,10 @@ tester_ldap_error( LDAP *ld, const char *fname ) ldap_get_option( ld, LDAP_OPT_ERROR_STRING, (void *)&text ); } - fprintf( stderr, "%s: %s: %s (%d) %s\n", + fprintf( stderr, "%s: %s: %s (%d) %s %s\n", progname, fname, ldap_err2string( err ), err, - text == NULL ? "" : text ); + text == NULL ? "" : text, + msg ? msg : "" ); if ( text ) { ldap_memfree( text ); @@ -111,14 +112,15 @@ tester_ldap_error( LDAP *ld, const char *fname ) } void -tester_perror( const char *fname ) +tester_perror( const char *fname, const char *msg ) { int save_errno = errno; char buf[ BUFSIZ ]; - fprintf( stderr, "%s: %s: (%d) %s\n", + fprintf( stderr, "%s: %s: (%d) %s %s\n", progname, fname, save_errno, - AC_STRERROR_R( save_errno, buf, sizeof( buf ) ) ); + AC_STRERROR_R( save_errno, buf, sizeof( buf ) ), + msg ? msg : "" ); } void diff --git a/tests/progs/slapd-common.h b/tests/progs/slapd-common.h index 4036092b28..e1142ead0a 100644 --- a/tests/progs/slapd-common.h +++ b/tests/progs/slapd-common.h @@ -23,7 +23,7 @@ extern void tester_init( const char *pname ); extern char * tester_uri( char *uri, char *host, int port ); extern void tester_error( const char *msg ); -extern void tester_perror( const char *fname ); -extern void tester_ldap_error( LDAP *ld, const char *fname ); +extern void tester_perror( const char *fname, const char *msg ); +extern void tester_ldap_error( LDAP *ld, const char *fname, const char *msg ); #endif /* SLAPD_COMMON_H */ diff --git a/tests/progs/slapd-modify.c b/tests/progs/slapd-modify.c index 6d19b07dcd..887d9462db 100644 --- a/tests/progs/slapd-modify.c +++ b/tests/progs/slapd-modify.c @@ -215,7 +215,7 @@ do_modify( char *uri, char *manager, retry:; ldap_initialize( &ld, uri ); if ( ld == NULL ) { - tester_perror( "ldap_initialize" ); + tester_perror( "ldap_initialize", NULL ); exit( EXIT_FAILURE ); } @@ -230,7 +230,7 @@ retry:; rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_sasl_bind_s" ); + tester_ldap_error( ld, "ldap_sasl_bind_s", NULL ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -252,7 +252,7 @@ retry:; mod.mod_op = LDAP_MOD_ADD; rc = ldap_modify_ext_s( ld, entry, mods, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_modify_ext_s" ); + tester_ldap_error( ld, "ldap_modify_ext_s", NULL ); switch ( rc ) { case LDAP_TYPE_OR_VALUE_EXISTS: /* NOTE: this likely means @@ -279,7 +279,7 @@ retry:; mod.mod_op = LDAP_MOD_DELETE; rc = ldap_modify_ext_s( ld, entry, mods, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_modify_ext_s" ); + tester_ldap_error( ld, "ldap_modify_ext_s", NULL ); switch ( rc ) { case LDAP_NO_SUCH_ATTRIBUTE: /* NOTE: this likely means diff --git a/tests/progs/slapd-modrdn.c b/tests/progs/slapd-modrdn.c index 2080ac4aab..515e58efca 100644 --- a/tests/progs/slapd-modrdn.c +++ b/tests/progs/slapd-modrdn.c @@ -206,7 +206,7 @@ do_modrdn( char *uri, char *manager, retry:; ldap_initialize( &ld, uri ); if ( ld == NULL ) { - tester_perror( "ldap_initialize" ); + tester_perror( "ldap_initialize", NULL ); exit( EXIT_FAILURE ); } @@ -221,7 +221,7 @@ retry:; rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_sasl_bind_s" ); + tester_ldap_error( ld, "ldap_sasl_bind_s", NULL ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -242,7 +242,7 @@ retry:; for ( ; i < maxloop; i++ ) { rc = ldap_rename_s( ld, DNs[0], rdns[0], NULL, 0, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_rename_s" ); + tester_ldap_error( ld, "ldap_rename_s", NULL ); switch ( rc ) { case LDAP_NO_SUCH_OBJECT: /* NOTE: this likely means @@ -267,7 +267,7 @@ retry:; } rc = ldap_rename_s( ld, DNs[1], rdns[1], NULL, 1, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_rename_s" ); + tester_ldap_error( ld, "ldap_rename_s", NULL ); switch ( rc ) { case LDAP_NO_SUCH_OBJECT: /* NOTE: this likely means diff --git a/tests/progs/slapd-read.c b/tests/progs/slapd-read.c index 9bece47cd1..c94878acee 100644 --- a/tests/progs/slapd-read.c +++ b/tests/progs/slapd-read.c @@ -211,7 +211,7 @@ do_random( char *uri, char *manager, struct berval *passwd, ldap_initialize( &ld, uri ); if ( ld == NULL ) { - tester_perror( "ldap_initialize" ); + tester_perror( "ldap_initialize", NULL ); exit( EXIT_FAILURE ); } @@ -226,7 +226,7 @@ do_random( char *uri, char *manager, struct berval *passwd, rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_sasl_bind_s" ); + tester_ldap_error( ld, "ldap_sasl_bind_s", NULL ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -246,7 +246,7 @@ do_random( char *uri, char *manager, struct berval *passwd, nvalues = ldap_count_entries( ld, res ); if ( nvalues == 0 ) { if ( rc ) { - tester_ldap_error( ld, "ldap_search_ext_s" ); + tester_ldap_error( ld, "ldap_search_ext_s", NULL ); } break; } @@ -272,7 +272,7 @@ do_random( char *uri, char *manager, struct berval *passwd, break; default: - tester_ldap_error( ld, "ldap_search_ext_s" ); + tester_ldap_error( ld, "ldap_search_ext_s", NULL ); break; } @@ -300,7 +300,7 @@ retry:; if ( ld == NULL ) { ldap_initialize( &ld, uri ); if ( ld == NULL ) { - tester_perror( "ldap_initialize" ); + tester_perror( "ldap_initialize", NULL ); exit( EXIT_FAILURE ); } @@ -315,7 +315,7 @@ retry:; rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_sasl_bind_s" ); + tester_ldap_error( ld, "ldap_sasl_bind_s", NULL ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -350,14 +350,14 @@ retry:; } first = 0; } - tester_ldap_error( ld, "ldap_search_ext_s" ); + tester_ldap_error( ld, "ldap_search_ext_s", NULL ); /* fallthru */ case LDAP_SUCCESS: break; default: - tester_ldap_error( ld, "ldap_search_ext_s" ); + tester_ldap_error( ld, "ldap_search_ext_s", NULL ); if ( rc == LDAP_BUSY && do_retry > 0 ) { do_retry--; goto retry; diff --git a/tests/progs/slapd-search.c b/tests/progs/slapd-search.c index 8504f32710..51d0ff2d7d 100644 --- a/tests/progs/slapd-search.c +++ b/tests/progs/slapd-search.c @@ -219,7 +219,7 @@ do_random( char *uri, char *manager, struct berval *passwd, ldap_initialize( &ld, uri ); if ( ld == NULL ) { - tester_perror( "ldap_initialize" ); + tester_perror( "ldap_initialize", NULL ); exit( EXIT_FAILURE ); } @@ -234,7 +234,7 @@ do_random( char *uri, char *manager, struct berval *passwd, rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_sasl_bind_s" ); + tester_ldap_error( ld, "ldap_sasl_bind_s", NULL ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -253,7 +253,7 @@ do_random( char *uri, char *manager, struct berval *passwd, case LDAP_SUCCESS: if ( ldap_count_entries( ld, res ) == 0 ) { if ( rc ) { - tester_ldap_error( ld, "ldap_search_ext_s" ); + tester_ldap_error( ld, "ldap_search_ext_s", NULL ); } break; } @@ -293,7 +293,7 @@ do_random( char *uri, char *manager, struct berval *passwd, break; default: - tester_ldap_error( ld, "ldap_search_ext_s" ); + tester_ldap_error( ld, "ldap_search_ext_s", NULL ); break; } @@ -317,12 +317,14 @@ do_search( char *uri, char *manager, struct berval *passwd, int rc = LDAP_SUCCESS; int version = LDAP_VERSION3; int first = 1; + char buf[ BUFSIZ ]; + retry:; if ( ld == NULL ) { ldap_initialize( &ld, uri ); if ( ld == NULL ) { - tester_perror( "ldap_initialize" ); + tester_perror( "ldap_initialize", NULL ); exit( EXIT_FAILURE ); } @@ -337,7 +339,9 @@ retry:; rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_sasl_bind_s" ); + snprintf( buf, sizeof( buf ), + "bindDN=\"%s\"", manager ); + tester_ldap_error( ld, "ldap_sasl_bind_s", buf ); switch ( rc ) { case LDAP_BUSY: case LDAP_UNAVAILABLE: @@ -376,14 +380,17 @@ retry:; } first = 0; } - tester_ldap_error( ld, "ldap_search_ext_s" ); + tester_ldap_error( ld, "ldap_search_ext_s", NULL ); /* fallthru */ case LDAP_SUCCESS: break; default: - tester_ldap_error( ld, "ldap_search_ext_s" ); + snprintf( buf, sizeof( buf ), + "base=\"%s\" filter=\"%s\"\n", + sbase, filter ); + tester_ldap_error( ld, "ldap_search_ext_s", buf ); if ( rc == LDAP_BUSY && do_retry > 0 ) { ldap_unbind_ext( ld, NULL, NULL ); do_retry--; diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index d6dbd71f00..6000f96512 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -783,12 +783,12 @@ fork_child( char *prog, char **args ) args = arg2; } #endif execvp( prog, args ); - tester_perror( "execvp" ); + tester_perror( "execvp", NULL ); exit( EXIT_FAILURE ); break; case -1: /* trouble */ - tester_perror( "fork" ); + tester_perror( "fork", NULL ); break; default: /* parent */ @@ -858,7 +858,7 @@ fork_child( char *prog, char **args ) rc = _spawnvp( _P_NOWAIT, prog, args ); if ( rc == -1 ) { - tester_perror( "_spawnvp" ); + tester_perror( "_spawnvp", NULL ); } else { children[nkids++] = (HANDLE)rc; }