#include <ac/string.h>
#include <ac/unistd.h>
#include <ac/wait.h>
+#include <ac/time.h>
#define LDAP_DEPRECATED 1
#include <ldap.h>
#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
static void
usage( char *name )
{
- fprintf( stderr, "usage: %s [-h <host>] -p port (-D <dn>|-b <baseDN> [-f <searchfilter>]) -w <passwd> [-l <loops>]\n",
+ fprintf( stderr, "usage: %s [-h <host>] -p port (-D <dn>|-b <baseDN> [-f <searchfilter>]) -w <passwd> [-l <loops>] [-F]\n",
name );
exit( EXIT_FAILURE );
}
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 );
filter = optarg;
break;
+ case 'F':
+ force = 1;
+ break;
+
default:
usage( argv[0] );
break;
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;
ldap_perror( ld, "ldap_bind" );
}
ldap_unbind( ld );
- if ( rc != LDAP_SUCCESS ) {
+ if ( rc != LDAP_SUCCESS && !force ) {
break;
}
}
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;
char **rdns = NULL;
char *attrs[] = { "dn", NULL };
int nrdns = 0;
- time_t beg, end;
+ struct timeval beg, end;
srand(pid);
}
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<maxloop; i++) {
char dn[BUFSIZ], *ptr;
ptr = lutil_strcopy(dn, rdns[j]);
*ptr++ = ',';
strcpy(ptr, base);
- if ( do_bind( uri, host, port, dn, pass, 1 ))
+ if ( do_bind( uri, host, port, dn, pass, 1, force ) && !force )
break;
}
- end = time(0L);
- fprintf( stderr, "Done %d Binds in %d seconds.\n", i, end - beg );
+ gettimeofday( &end, NULL );
+ end.tv_usec -= beg.tv_usec;
+ if (end.tv_usec < 0 ) {
+ end.tv_usec += 1000000;
+ end.tv_sec -= 1;
+ }
+ end.tv_sec -= beg.tv_sec;
+
+ fprintf( stderr, "Done %d Binds in %d.%06d seconds.\n", i,
+ end.tv_sec, end.tv_usec );
return 0;
}