]> git.sur5r.net Git - openldap/commitdiff
improve referral handling
authorPierangelo Masarati <ando@openldap.org>
Thu, 23 Mar 2006 00:19:09 +0000 (00:19 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 23 Mar 2006 00:19:09 +0000 (00:19 +0000)
tests/progs/slapd-read.c
tests/progs/slapd-search.c
tests/progs/slapd-tester.c

index 493b4b74b2da343fc2ee15e784488cfb44af976e..78173dc60b97463a35a998a4348b169b6b8cfa89 100644 (file)
@@ -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 <uri> | ([-h <host>] -p <port>) "
                "-e <entry> "
+               "[-F] "
                "[-l <loops>] "
                "[-L <outerloops>] "
                "[-r <maxretries>] "
@@ -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 );
index 6357f7716f8a54edbd7b2c3a905d1cd5048bf297..4cbe5453078a9d0cafb52b0f17cedb9221777f6b 100644 (file)
 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 <searchbase> "
                "-f <searchfilter> "
                "[-a <attr>] "
+               "[-F] "
                "[-l <loops>] "
                "[-L <outerloops>] "
                "[-r <maxretries>] "
@@ -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;
 
index 8b818da5551fd092b8f2d1841a1052e61de7874d..e9a3d2832af2e21bfaf4fe2f1afbb470d953b168 100644 (file)
@@ -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;