#include <ac/wait.h>
#include <ac/time.h>
-#define LDAP_DEPRECATED 1
#include <ldap.h>
#include <lutil.h>
#define LOOPS 100
+static void
+do_error( LDAP *ld, const char *func )
+{
+ int err;
+ const char *text = "Success";
+
+ ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&err );
+ if ( err != LDAP_SUCCESS ) {
+ ldap_get_option( ld, LDAP_OPT_ERROR_STRING, (void *)&text );
+ }
+
+ fprintf( stderr, "%s: (%d) %s\n", func, err, text == NULL ? "" : text );
+}
+
static int
-do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop,
- int force );
+do_bind( char *uri, char *dn, struct berval *pass, int maxloop, int force );
static int
-do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop,
- int force );
+do_base( char *uri, char *base, struct berval *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
main( int argc, char **argv )
{
int i;
- char *uri = NULL;
+ char *uri = NULL,
+ uribuf[ BUFSIZ ];
char *host = "localhost";
char *dn = NULL;
char *base = NULL;
- char *pass = NULL;
+ struct berval pass = { 0, NULL };
int port = -1;
int loops = LOOPS;
int force = 0;
case 'H': /* the server uri */
uri = strdup( optarg );
- break;
+ break;
+
case 'h': /* the servers host */
host = strdup( optarg );
- break;
+ break;
case 'p': /* the servers port */
if ( lutil_atoi( &port, optarg ) != 0 ) {
break;
case 'w':
- pass = strdup( optarg );
+ pass.bv_val = strdup( optarg );
+ pass.bv_len = strlen( optarg );
break;
case 'l': /* the number of loops */
}
}
- if ( port == -1 && uri == NULL )
+ if ( port == -1 && uri == NULL ) {
usage( argv[0] );
+ }
+
+ if ( uri == NULL ) {
+ snprintf( uribuf, sizeof( uribuf ), "ldap://%s:%d", host, port );
+ uri = uribuf;
+ }
- if ( base )
- do_base( uri, host, port, base, pass, ( 20 * loops ), force );
- else
- do_bind( uri, host, port, dn, pass, ( 20 * loops ), force );
+ if ( base ) {
+ do_base( uri, base, &pass, ( 20 * loops ), force );
+ } else {
+ do_bind( uri, dn, &pass, ( 20 * loops ), force );
+ }
exit( EXIT_SUCCESS );
}
static int
-do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop,
- int force )
+do_bind( char *uri, char *dn, struct berval *pass, int maxloop, int force )
{
LDAP *ld = NULL;
int i, rc = -1;
(long) pid, maxloop, dn );
for ( i = 0; i < maxloop; i++ ) {
- if ( uri ) {
- ldap_initialize( &ld, uri );
- } else {
- ld = ldap_init( host, port );
- }
+ ldap_initialize( &ld, uri );
if ( ld == NULL ) {
- perror( "ldap_init" );
+ perror( "ldap_initialize" );
rc = -1;
break;
}
&version );
}
- rc = ldap_bind_s( ld, dn, pass, LDAP_AUTH_SIMPLE );
+ rc = ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, pass, NULL, NULL, NULL );
if ( rc != LDAP_SUCCESS ) {
- ldap_perror( ld, "ldap_bind" );
+ do_error( ld, "ldap_bind" );
}
- ldap_unbind( ld );
+ ldap_unbind_ext( ld, NULL, NULL );
if ( rc != LDAP_SUCCESS && !force ) {
break;
}
static int
-do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop,
- int force )
+do_base( char *uri, char *base, struct berval *pass, int maxloop, int force )
{
LDAP *ld = NULL;
int i = 0;
#else
struct timeval beg, end;
#endif
+ int version = LDAP_VERSION3;
srand(pid);
- if ( uri ) {
- ldap_initialize( &ld, uri );
- } else {
- ld = ldap_init( host, port );
- }
+ ldap_initialize( &ld, uri );
if ( ld == NULL ) {
- perror( "ldap_init" );
+ perror( "ldap_initialize" );
exit( EXIT_FAILURE );
}
- {
- int version = LDAP_VERSION3;
- (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
- &version );
- }
+ (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
(void) ldap_set_option( ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF );
- rc = ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE );
+ rc = ldap_sasl_bind_s( ld, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL );
if ( rc != LDAP_SUCCESS ) {
- ldap_perror( ld, "ldap_bind" );
+ do_error( ld, "ldap_bind" );
exit( EXIT_FAILURE );
}
rc = ldap_search_ext( ld, base, LDAP_SCOPE_ONE,
filter, attrs, 0, NULL, NULL, 0, 0, &msgid );
if ( rc != LDAP_SUCCESS ) {
- ldap_perror( ld, "ldap_search_ex" );
+ do_error( ld, "ldap_search_ext" );
exit( EXIT_FAILURE );
}
ldap_msgfree( res );
if ( done ) break;
}
- ldap_unbind( ld );
+ ldap_unbind_ext( ld, NULL, NULL );
#ifdef _WIN32
beg = GetTickCount();
ptr = lutil_strcopy(dn, rdns[j]);
*ptr++ = ',';
strcpy(ptr, base);
- if ( do_bind( uri, host, port, dn, pass, 1, force ) && !force )
+ if ( do_bind( uri, dn, pass, 1, force ) && !force )
break;
}
#ifdef _WIN32
#define ADDCMD "slapd-addel"
#define MODRDNCMD "slapd-modrdn"
#define MODIFYCMD "slapd-modify"
+#define BINDCMD "slapd-bind"
#define MAXARGS 100
#define MAXREQS 5000
#define LOOPS "100"
#define TADDFILE "do_add."
#define TMODRDNFILE "do_modrdn.0"
#define TMODIFYFILE "do_modify.0"
+#define TBINDFILE "do_bind.0"
static char *get_file_name( char *dirname, char *filename );
static int get_search_filters( char *filename, char *filters[], char *bases[] );
char *loops = LOOPS;
char *retries = RETRIES;
char *delay = "0";
- DIR *datadir;
+ DIR *datadir;
struct dirent *file;
+ int friendly = 0;
+ /* search */
char *sfile = NULL;
char *sreqs[MAXREQS];
char *sbase[MAXREQS];
- int snum = 0;
- char *rfile = NULL;
- char *rreqs[MAXREQS];
- int rnum = 0;
- char *afiles[MAXREQS];
- int anum = 0;
- char *mfile = NULL;
- char *mreqs[MAXREQS];
- int mnum = 0;
+ int snum = 0;
char *sargs[MAXARGS];
- int sanum;
+ int sanum;
char scmd[MAXPATHLEN];
+ /* read */
+ char *rfile = NULL;
+ char *rreqs[MAXREQS];
+ int rnum = 0;
char *rargs[MAXARGS];
- int ranum;
+ int ranum;
char rcmd[MAXPATHLEN];
+ /* addel */
+ char *afiles[MAXREQS];
+ int anum = 0;
char *aargs[MAXARGS];
- int aanum;
+ int aanum;
char acmd[MAXPATHLEN];
+ /* modrdn */
+ char *mfile = NULL;
+ char *mreqs[MAXREQS];
+ int mnum = 0;
char *margs[MAXARGS];
int manum;
char mcmd[MAXPATHLEN];
- char *modargs[MAXARGS];
- int modanum;
- char modcmd[MAXPATHLEN];
+ /* modify */
char *modfile = NULL;
char *modreqs[MAXREQS];
char *moddn[MAXREQS];
int modnum = 0;
- int friendly = 0;
+ char *modargs[MAXARGS];
+ int modanum;
+ char modcmd[MAXPATHLEN];
+ /* bind */
+ char *bfile = NULL;
+ char *breqs[MAXREQS];
+ char *bcreds[MAXREQS];
+ int bnum = 0;
+ char *bargs[MAXARGS];
+ int banum;
+ char bcmd[MAXPATHLEN];
while ( (i = getopt( argc, argv, "D:d:FH:h:j:l:P:p:r:t:w:" )) != EOF ) {
switch( i ) {
&& ( anum < MAXREQS )) {
afiles[anum++] = get_file_name( dirname, file->d_name );
continue;
+ } else if ( !strcasecmp( file->d_name, TBINDFILE )) {
+ bfile = get_file_name( dirname, file->d_name );
+ continue;
}
}
if ( mfile ) {
mnum = get_read_entries( mfile, mreqs );
}
+
/* look for modify requests */
if ( modfile ) {
modnum = get_search_filters( modfile, modreqs, moddn );
}
+ /* look for bind requests */
+ if ( bfile ) {
+ bnum = get_search_filters( bfile, bcreds, breqs );
+ }
+
/*
* generate the search clients
*/
aargs[aanum++] = NULL; /* will hold the add data file */
aargs[aanum++] = NULL;
- for ( j = 0; j < MAXREQS; j++ ) {
+ /*
+ * generate the bind clients
+ */
+
+ banum = 0;
+ snprintf( bcmd, sizeof bcmd, "%s" LDAP_DIRSEP BINDCMD,
+ progdir );
+ bargs[banum++] = bcmd;
+ if ( uri ) {
+ bargs[banum++] = "-H";
+ bargs[banum++] = uri;
+ } else {
+ bargs[banum++] = "-h";
+ bargs[banum++] = host;
+ bargs[banum++] = "-p";
+ bargs[banum++] = port;
+ }
+ bargs[banum++] = "-l";
+ bargs[banum++] = loops;
+#if 0
+ bargs[banum++] = "-r";
+ bargs[banum++] = retries;
+ bargs[banum++] = "-t";
+ bargs[banum++] = delay;
+#endif
+ if ( friendly ) {
+ bargs[banum++] = "-F";
+ }
+ bargs[banum++] = "-D";
+ bargs[banum++] = NULL;
+ bargs[banum++] = "-w";
+ bargs[banum++] = NULL;
+ bargs[banum++] = NULL;
+ for ( j = 0; j < MAXREQS; j++ ) {
if ( j < snum ) {
sargs[sanum - 2] = sreqs[j];
}
+ if ( j < bnum ) {
+
+ bargs[banum - 4] = breqs[j];
+ bargs[banum - 2] = bcreds[j];
+ fork_child( bcmd, bargs );
+
+ }
+
}
wait4kids( -1 );