]> git.sur5r.net Git - openldap/commitdiff
allow extra message in errors
authorPierangelo Masarati <ando@openldap.org>
Sat, 8 Apr 2006 11:01:01 +0000 (11:01 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 8 Apr 2006 11:01:01 +0000 (11:01 +0000)
tests/progs/slapd-addel.c
tests/progs/slapd-bind.c
tests/progs/slapd-common.c
tests/progs/slapd-common.h
tests/progs/slapd-modify.c
tests/progs/slapd-modrdn.c
tests/progs/slapd-read.c
tests/progs/slapd-search.c
tests/progs/slapd-tester.c

index f199eab12e2b937b6099f083e78e017711ea9afb..ff131b1879bbec38583c3deb72c7d750d63431e6 100644 (file)
@@ -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
index 9ac746d9670f3cd8233fc63b2e7e1f8b4dc05855..58ff55d7d2fe8e97f5ae2939084bdd9897b870a8 100644 (file)
@@ -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 );
        }
 
index bed9d05c256ee290ac1f39b30dc4d165a31882c6..3724794a8b1797fc32b93e31c24d295ed656bf62 100644 (file)
@@ -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
index 4036092b28bcce2ed7b2c5a9105ed70c45efe9b6..e1142ead0a8c285a404cbc2c5b405ddf8e3ecdf6 100644 (file)
@@ -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 */
index 6d19b07dcd66fc82523b2f037750f6ab1142d0b5..887d9462db30743275751ac6c28811fbf998c809 100644 (file)
@@ -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
index 2080ac4aab5f2e70d5297e20ade2a8f6d8da77c2..515e58efca2a4cd361096c7c0fa249650feef611 100644 (file)
@@ -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
index 9bece47cd108dc181a1f0966b8d96b1800d10c3c..c94878acee718b52a15e703f749b20a80b30c645 100644 (file)
@@ -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;
index 8504f327105e3bd821907ba733f73331417141b5..51d0ff2d7d36241ab3d56e06c6cf3c557150d402 100644 (file)
@@ -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--;
index d6dbd71f0005307a761f02bf39739c7ed35779e8..6000f965120281c8409c0ffe27e0928071f57e4e 100644 (file)
@@ -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;
        }