From 6d357288d6989c8e7fca7c35d8441c5e7167ab01 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Tue, 4 Apr 2006 17:55:27 +0000 Subject: [PATCH] allow time/size limit errors as soon as some data is returned; don't divide by zero if no entries were found --- tests/progs/slapd-read.c | 32 ++++++++++++++++++-------------- tests/progs/slapd-search.c | 18 ++++++++++++------ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/tests/progs/slapd-read.c b/tests/progs/slapd-read.c index ba610b7aa6..fae850381f 100644 --- a/tests/progs/slapd-read.c +++ b/tests/progs/slapd-read.c @@ -204,7 +204,7 @@ do_random( char *uri, char *manager, struct berval *passwd, int version = LDAP_VERSION3; int nvalues = 0; char **values = NULL; - LDAPMessage *res = NULL; + LDAPMessage *res = NULL, *e = NULL; attrs[ 0 ] = LDAP_NO_ATTRS; attrs[ 1 ] = NULL; @@ -239,21 +239,22 @@ do_random( char *uri, char *manager, struct berval *passwd, rc = ldap_search_ext_s( ld, sbase, LDAP_SCOPE_SUBTREE, filter, attrs, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &res ); - if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_search_ext_s" ); - - } else { + switch ( rc ) { + case LDAP_SIZELIMIT_EXCEEDED: + case LDAP_TIMELIMIT_EXCEEDED: + case LDAP_SUCCESS: nvalues = ldap_count_entries( ld, res ); - if ( nvalues > 0 ) { - LDAPMessage *e; + if ( nvalues == 0 ) { + break; + } - values = malloc( ( nvalues + 1 ) * sizeof( char * ) ); - for ( i = 0, e = ldap_first_entry( ld, res ); e != NULL; i++, e = ldap_next_entry( ld, e ) ) - { - values[ i ] = ldap_get_dn( ld, e ); - } - values[ i ] = NULL; + + values = malloc( ( nvalues + 1 ) * sizeof( char * ) ); + for ( i = 0, e = ldap_first_entry( ld, res ); e != NULL; i++, e = ldap_next_entry( ld, e ) ) + { + values[ i ] = ldap_get_dn( ld, e ); } + values[ i ] = NULL; ldap_msgfree( res ); @@ -266,8 +267,11 @@ do_random( char *uri, char *manager, struct berval *passwd, noattrs, 1, maxretries, delay, force, chaserefs ); } + + default: + tester_ldap_error( ld, "ldap_search_ext_s" ); + break; } - fprintf( stderr, " PID=%ld - Search done (%d).\n", (long) pid, rc ); diff --git a/tests/progs/slapd-search.c b/tests/progs/slapd-search.c index d33fcb4afb..8bb7067f4d 100644 --- a/tests/progs/slapd-search.c +++ b/tests/progs/slapd-search.c @@ -212,7 +212,7 @@ do_random( char *uri, char *manager, struct berval *passwd, int version = LDAP_VERSION3; int nvalues = 0; char **values = NULL; - LDAPMessage *res = NULL; + LDAPMessage *res = NULL, *e = NULL; attrs[ 0 ] = attr; attrs[ 1 ] = NULL; @@ -247,11 +247,14 @@ do_random( char *uri, char *manager, struct berval *passwd, rc = ldap_search_ext_s( ld, sbase, LDAP_SCOPE_SUBTREE, filter, attrs, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &res ); - if ( rc != LDAP_SUCCESS ) { - tester_ldap_error( ld, "ldap_search_ext_s" ); + switch ( rc ) { + case LDAP_SIZELIMIT_EXCEEDED: + case LDAP_TIMELIMIT_EXCEEDED: + case LDAP_SUCCESS: + if ( ldap_count_entries( ld, res ) == 0 ) { + break; + } - } else { - LDAPMessage *e; for ( e = ldap_first_entry( ld, res ); e != NULL; e = ldap_next_entry( ld, e ) ) { struct berval **v = ldap_get_values_len( ld, e, attr ); @@ -284,8 +287,11 @@ do_random( char *uri, char *manager, struct berval *passwd, do_search( uri, manager, passwd, sbase, buf, &ld, noattrs, 1, maxretries, delay, force, chaserefs ); } + + default: + tester_ldap_error( ld, "ldap_search_ext_s" ); + break; } - fprintf( stderr, " PID=%ld - Search done (%d).\n", (long) pid, rc ); -- 2.39.5