From: Howard Chu Date: Thu, 10 Nov 2005 23:22:40 +0000 (+0000) Subject: Add -F force option to continue after bind failures. Use gettimeofday X-Git-Tag: OPENLDAP_REL_ENG_2_2_MP~44 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2c8790aafc9341e23ce33670019365c66cddd177;p=openldap Add -F force option to continue after bind failures. Use gettimeofday for better timing resolution. --- diff --git a/tests/progs/slapd-bind.c b/tests/progs/slapd-bind.c index 7f6d28e9ec..f0e0903e64 100644 --- a/tests/progs/slapd-bind.c +++ b/tests/progs/slapd-bind.c @@ -30,6 +30,7 @@ #include #include #include +#include #define LDAP_DEPRECATED 1 #include @@ -38,10 +39,12 @@ #define LOOPS 100 static int -do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop ); +do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop, + int force ); static int -do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop ); +do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop, + int force ); /* This program can be invoked two ways: if -D is used to specify a Bind DN, * that DN will be used repeatedly for all of the Binds. If instead -b is used @@ -53,7 +56,7 @@ do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop ); static void usage( char *name ) { - fprintf( stderr, "usage: %s [-h ] -p port (-D |-b [-f ]) -w [-l ]\n", + fprintf( stderr, "usage: %s [-h ] -p port (-D |-b [-f ]) -w [-l ] [-F]\n", name ); exit( EXIT_FAILURE ); } @@ -71,8 +74,9 @@ main( int argc, char **argv ) char *pass = NULL; int port = -1; int loops = LOOPS; + int force = 0; - while ( (i = getopt( argc, argv, "b:H:h:p:D:w:l:f:" )) != EOF ) { + while ( (i = getopt( argc, argv, "b:H:h:p:D:w:l:f:F" )) != EOF ) { switch( i ) { case 'b': /* base DN of a tree of user DNs */ base = strdup( optarg ); @@ -105,6 +109,10 @@ main( int argc, char **argv ) filter = optarg; break; + case 'F': + force = 1; + break; + default: usage( argv[0] ); break; @@ -115,15 +123,16 @@ main( int argc, char **argv ) usage( argv[0] ); if ( base ) - do_base( uri, host, port, base, pass, ( 20 * loops )); + do_base( uri, host, port, base, pass, ( 20 * loops ), force ); else - do_bind( uri, host, port, dn, pass, ( 20 * loops )); + do_bind( uri, host, port, dn, pass, ( 20 * loops ), force ); exit( EXIT_SUCCESS ); } static int -do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop ) +do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop, + int force ) { LDAP *ld = NULL; int i, rc = -1; @@ -156,7 +165,7 @@ do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop ) ldap_perror( ld, "ldap_bind" ); } ldap_unbind( ld ); - if ( rc != LDAP_SUCCESS ) { + if ( rc != LDAP_SUCCESS && !force ) { break; } } @@ -169,7 +178,8 @@ do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop ) static int -do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop ) +do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop, + int force ) { LDAP *ld = NULL; int i = 0; @@ -180,7 +190,7 @@ do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop ) char **rdns = NULL; char *attrs[] = { "dn", NULL }; int nrdns = 0; - time_t beg, end; + struct timeval beg, end; srand(pid); @@ -246,12 +256,13 @@ do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop ) } ldap_unbind( ld ); + gettimeofday( &beg, NULL ); + if ( nrdns == 0 ) { fprintf( stderr, "No RDNs.\n" ); return 1; } - beg = time(0L); /* Ok, got list of RDNs, now start binding to each */ for (i=0; i