From: Pierangelo Masarati Date: Thu, 23 Mar 2006 00:19:09 +0000 (+0000) Subject: improve referral handling X-Git-Tag: OPENLDAP_REL_ENG_2_4_BP~117 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=86941d0c70f29b0a1ccbbc44b353ec1fe53843d9;p=openldap improve referral handling --- diff --git a/tests/progs/slapd-read.c b/tests/progs/slapd-read.c index 493b4b74b2..78173dc60b 100644 --- a/tests/progs/slapd-read.c +++ b/tests/progs/slapd-read.c @@ -40,7 +40,7 @@ static void do_read( char *uri, char *entry, int maxloop, - int maxretries, int delay ); + int maxretries, int delay, int force ); static void usage( char *name ) @@ -49,6 +49,7 @@ usage( char *name ) "usage: %s " "-H | ([-h ] -p ) " "-e " + "[-F] " "[-l ] " "[-L ] " "[-r ] " @@ -69,10 +70,11 @@ main( int argc, char **argv ) int outerloops = 1; int retries = RETRIES; int delay = 0; + int force = 0; tester_init( "slapd-read" ); - while ( (i = getopt( argc, argv, "H:h:p:e:l:L:r:t:" )) != EOF ) { + while ( (i = getopt( argc, argv, "H:h:p:e:Fl:L:r:t:" )) != EOF ) { switch( i ) { case 'H': /* the server uri */ uri = strdup( optarg ); @@ -92,6 +94,10 @@ main( int argc, char **argv ) entry = strdup( optarg ); break; + case 'F': + force++; + break; + case 'l': /* the number of loops */ if ( lutil_atoi( &loops, optarg ) != 0 ) { usage( argv[0] ); @@ -134,7 +140,7 @@ main( int argc, char **argv ) uri = tester_uri( uri, host, port ); for ( i = 0; i < outerloops; i++ ) { - do_read( uri, entry, loops, retries, delay ); + do_read( uri, entry, loops, retries, delay, force ); } exit( EXIT_SUCCESS ); @@ -143,7 +149,7 @@ main( int argc, char **argv ) static void do_read( char *uri, char *entry, int maxloop, - int maxretries, int delay ) + int maxretries, int delay, int force ) { LDAP *ld = NULL; int i = 0, do_retry = maxretries; @@ -152,6 +158,7 @@ do_read( char *uri, char *entry, int maxloop, int rc = LDAP_SUCCESS; int version = LDAP_VERSION3; struct berval passwd = { 0, "" }; + int first = 1; retry:; ldap_initialize( &ld, uri ); @@ -188,24 +195,43 @@ retry:; } for ( ; i < maxloop; i++ ) { - LDAPMessage *res; + LDAPMessage *res = NULL; rc = ldap_search_ext_s( ld, entry, LDAP_SCOPE_BASE, NULL, attrs, 1, NULL, NULL, NULL, LDAP_NO_LIMIT, &res ); - if ( rc != LDAP_SUCCESS ) { + switch ( rc ) { + case LDAP_REFERRAL: + /* don't log: it's intended */ + if ( force >= 2 ) { + if ( !first ) { + break; + } + first = 0; + } + tester_ldap_error( ld, "ldap_search_ext_s" ); + /* fallthru */ + + case LDAP_SUCCESS: + break; + + default: tester_ldap_error( ld, "ldap_search_ext_s" ); if ( rc == LDAP_BUSY && do_retry > 0 ) { do_retry--; goto retry; } - if ( rc != LDAP_NO_SUCH_OBJECT ) break; - continue; - + if ( rc != LDAP_NO_SUCH_OBJECT ) { + goto done; + } + break; } - ldap_msgfree( res ); + if ( res != NULL ) { + ldap_msgfree( res ); + } } +done:; fprintf( stderr, " PID=%ld - Read done (%d).\n", (long) pid, rc ); ldap_unbind_ext( ld, NULL, NULL ); diff --git a/tests/progs/slapd-search.c b/tests/progs/slapd-search.c index 6357f7716f..4cbe545307 100644 --- a/tests/progs/slapd-search.c +++ b/tests/progs/slapd-search.c @@ -41,12 +41,12 @@ static void do_search( char *uri, char *manager, struct berval *passwd, char *sbase, char *filter, LDAP **ldp, - int innerloop, int maxretries, int delay ); + int innerloop, int maxretries, int delay, int force ); static void do_random( char *uri, char *manager, struct berval *passwd, char *sbase, char *filter, char *attr, int innerloop, - int maxretries, int delay ); + int maxretries, int delay, int force ); static void usage( char *name ) @@ -59,6 +59,7 @@ usage( char *name ) "-b " "-f " "[-a ] " + "[-F] " "[-l ] " "[-L ] " "[-r ] " @@ -83,10 +84,11 @@ main( int argc, char **argv ) int outerloops = 1; int retries = RETRIES; int delay = 0; + int force = 0; tester_init( "slapd-search" ); - while ( (i = getopt( argc, argv, "a:b:D:f:H:h:l:L:p:w:r:t:" )) != EOF ) { + while ( (i = getopt( argc, argv, "a:b:D:f:FH:h:l:L:p:w:r:t:" )) != EOF ) { switch( i ) { case 'H': /* the server uri */ uri = strdup( optarg ); @@ -123,6 +125,10 @@ main( int argc, char **argv ) filter = strdup( optarg ); break; + case 'F': + force++; + break; + case 'l': /* number of loops */ if ( lutil_atoi( &loops, optarg ) != 0 ) { usage( argv[0] ); @@ -169,11 +175,11 @@ main( int argc, char **argv ) for ( i = 0; i < outerloops; i++ ) { if ( attr != NULL ) { do_random( uri, manager, &passwd, sbase, filter, attr, - loops, retries, delay ); + loops, retries, delay, force ); } else { do_search( uri, manager, &passwd, sbase, filter, NULL, - loops, retries, delay ); + loops, retries, delay, force ); } } @@ -184,7 +190,7 @@ main( int argc, char **argv ) static void do_random( char *uri, char *manager, struct berval *passwd, char *sbase, char *filter, char *attr, - int innerloop, int maxretries, int delay ) + int innerloop, int maxretries, int delay, int force ) { LDAP *ld = NULL; int i = 0, do_retry = maxretries; @@ -258,7 +264,7 @@ do_random( char *uri, char *manager, struct berval *passwd, snprintf( buf, sizeof( buf ), "(%s=%s)", attr, values[ rand() % nvalues ] ); do_search( uri, manager, passwd, sbase, buf, &ld, - 1, maxretries, delay ); + 1, maxretries, delay, force ); } } @@ -272,7 +278,7 @@ do_random( char *uri, char *manager, struct berval *passwd, static void do_search( char *uri, char *manager, struct berval *passwd, char *sbase, char *filter, LDAP **ldp, - int innerloop, int maxretries, int delay ) + int innerloop, int maxretries, int delay, int force ) { LDAP *ld = ldp ? *ldp : NULL; int i = 0, do_retry = maxretries; @@ -280,6 +286,7 @@ do_search( char *uri, char *manager, struct berval *passwd, pid_t pid = getpid(); int rc = LDAP_SUCCESS; int version = LDAP_VERSION3; + int first = 1; retry:; if ( ld == NULL ) { @@ -319,26 +326,45 @@ retry:; } for ( ; i < innerloop; i++ ) { - LDAPMessage *res; + LDAPMessage *res = NULL; rc = ldap_search_ext_s( ld, sbase, LDAP_SCOPE_SUBTREE, - filter, attrs, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &res ); - if ( rc != LDAP_SUCCESS ) { + filter, attrs, 0, NULL, NULL, + NULL, LDAP_NO_LIMIT, &res ); + if ( res != NULL ) { + ldap_msgfree( res ); + } + + switch ( rc ) { + case LDAP_REFERRAL: + /* don't log: it's intended */ + if ( force >= 2 ) { + if ( !first ) { + break; + } + first = 0; + } + tester_ldap_error( ld, "ldap_search_ext_s" ); + /* fallthru */ + + case LDAP_SUCCESS: + break; + + default: tester_ldap_error( ld, "ldap_search_ext_s" ); if ( rc == LDAP_BUSY && do_retry > 0 ) { ldap_unbind_ext( ld, NULL, NULL ); do_retry--; goto retry; } - if ( rc != LDAP_NO_SUCH_OBJECT ) break; - continue; - + if ( rc != LDAP_NO_SUCH_OBJECT ) { + goto done; + } + break; } - - ldap_msgfree( res ); } - +done:; if ( ldp != NULL ) { *ldp = ld; diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index 8b818da555..e9a3d2832a 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -352,6 +352,9 @@ main( int argc, char **argv ) sargs[sanum++] = retries; sargs[sanum++] = "-t"; sargs[sanum++] = delay; + if ( friendly ) { + sargs[sanum++] = friendlyOpt; + } sargs[sanum++] = "-b"; sargs[sanum++] = NULL; /* will hold the search base */ sargs[sanum++] = "-f"; @@ -383,6 +386,9 @@ main( int argc, char **argv ) rargs[ranum++] = retries; rargs[ranum++] = "-t"; rargs[ranum++] = delay; + if ( friendly ) { + rargs[ranum++] = friendlyOpt; + } rargs[ranum++] = "-e"; rargs[ranum++] = NULL; /* will hold the read entry */ rargs[ranum++] = NULL;