#define RETRIES 0
static void
-do_read( char *uri, char *entry, int maxloop,
- int maxretries, int delay, int force, int chaserefs );
+do_read( char *uri, char *manager, struct berval *passwd,
+ char *entry, LDAP **ld, int noattrs, int maxloop,
+ int maxretries, int delay, int force, int chaserefs );
+
+static void
+do_random( char *uri, char *manager, struct berval *passwd,
+ char *sbase, char *filter, int noattrs,
+ int innerloop, int maxretries, int delay, int force, int chaserefs );
static void
usage( char *name )
fprintf( stderr,
"usage: %s "
"-H <uri> | ([-h <host>] -p <port>) "
+ "-D <manager> "
+ "-w <passwd> "
"-e <entry> "
- "[-F] "
+ "[-A] "
"[-C] "
+ "[-F] "
+ "[-f filter] "
"[-l <loops>] "
"[-L <outerloops>] "
"[-r <maxretries>] "
char *uri = NULL;
char *host = "localhost";
int port = -1;
+ char *manager = NULL;
+ struct berval passwd = { 0, NULL };
char *entry = NULL;
+ char *filter = NULL;
int loops = LOOPS;
int outerloops = 1;
int retries = RETRIES;
int delay = 0;
int force = 0;
int chaserefs = 0;
+ int noattrs = 0;
tester_init( "slapd-read" );
- while ( (i = getopt( argc, argv, "CH:h:p:e:Fl:L:r:t:" )) != EOF ) {
+ while ( (i = getopt( argc, argv, "ACD:H:h:p:e:Ff:l:L:r:t:w:" )) != EOF ) {
switch( i ) {
+ case 'A':
+ noattrs++;
+ break;
+
case 'C':
chaserefs++;
break;
}
break;
+ case 'D': /* the servers manager */
+ manager = strdup( optarg );
+ break;
+
+ case 'w': /* the server managers password */
+ passwd.bv_val = strdup( optarg );
+ passwd.bv_len = strlen( optarg );
+ break;
+
case 'e': /* DN to search for */
entry = strdup( optarg );
break;
+ case 'f': /* the search request */
+ filter = strdup( optarg );
+ break;
+
case 'F':
force++;
break;
uri = tester_uri( uri, host, port );
for ( i = 0; i < outerloops; i++ ) {
- do_read( uri, entry, loops, retries, delay, force, chaserefs );
+ if ( filter != NULL ) {
+ do_random( uri, manager, &passwd, entry, filter,
+ noattrs, loops, retries, delay, force,
+ chaserefs );
+
+ } else {
+ do_read( uri, manager, &passwd, entry, NULL, noattrs,
+ loops, retries, delay, force, chaserefs );
+ }
}
exit( EXIT_SUCCESS );
}
-
static void
-do_read( char *uri, char *entry, int maxloop,
- int maxretries, int delay, int force, int chaserefs )
+do_random( char *uri, char *manager, struct berval *passwd,
+ char *sbase, char *filter, int noattrs,
+ int innerloop, int maxretries, int delay, int force, int chaserefs )
{
LDAP *ld = NULL;
int i = 0, do_retry = maxretries;
- char *attrs[] = { "1.1", NULL };
+ char *attrs[ 2 ];
pid_t pid = getpid();
int rc = LDAP_SUCCESS;
int version = LDAP_VERSION3;
- struct berval passwd = { 0, "" };
- int first = 1;
-
-retry:;
+ int nvalues = 0;
+ char **values = NULL;
+ LDAPMessage *res = NULL;
+
+ attrs[ 0 ] = LDAP_NO_ATTRS;
+ attrs[ 1 ] = NULL;
+
ldap_initialize( &ld, uri );
if ( ld == NULL ) {
tester_perror( "ldap_initialize" );
chaserefs ? LDAP_OPT_ON : LDAP_OPT_OFF );
if ( do_retry == maxretries ) {
- fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
- (long) pid, maxloop, entry );
+ fprintf( stderr, "PID=%ld - Read(%d): base=\"%s\", filter=\"%s\".\n",
+ (long) pid, innerloop, sbase, filter );
}
- rc = ldap_sasl_bind_s( ld, NULL, LDAP_SASL_SIMPLE, &passwd, NULL, NULL, NULL );
+ rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL );
if ( rc != LDAP_SUCCESS ) {
tester_ldap_error( ld, "ldap_sasl_bind_s" );
switch ( rc ) {
case LDAP_BUSY:
case LDAP_UNAVAILABLE:
- if ( do_retry > 0 ) {
- do_retry--;
- if ( delay > 0 ) {
- sleep( delay );
- }
- goto retry;
- }
/* fallthru */
default:
break;
exit( EXIT_FAILURE );
}
+ rc = ldap_search_ext_s( ld, sbase, LDAP_SCOPE_SUBTREE,
+ filter, attrs, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &res );
+ if ( rc != LDAP_SUCCESS ) {
+ tester_ldap_error( ld, "ldap_search_ext_s" );
+
+ } else {
+ nvalues = ldap_count_entries( ld, res );
+ if ( nvalues > 0 ) {
+ LDAPMessage *e;
+
+ values = malloc( ( nvalues + 1 ) * sizeof( char * ) );
+ for ( i = 0, e = ldap_first_entry( ld, res ); e != NULL; i++, e = ldap_next_entry( ld, e ) )
+ {
+ values[ i ] = ldap_get_dn( ld, e );
+ }
+ values[ i ] = NULL;
+ }
+
+ ldap_msgfree( res );
+
+ if ( do_retry == maxretries ) {
+ fprintf( stderr, "PID=%ld - got %d values.\n", (long) pid, nvalues );
+ }
+
+ for ( i = 0; i < innerloop; i++ ) {
+ do_read( uri, manager, passwd, values[ rand() % nvalues ], &ld,
+ noattrs, 1, maxretries, delay, force,
+ chaserefs );
+ }
+ }
+
+
+ fprintf( stderr, " PID=%ld - Search done (%d).\n", (long) pid, rc );
+
+ if ( ld != NULL ) {
+ ldap_unbind_ext( ld, NULL, NULL );
+ }
+}
+
+static void
+do_read( char *uri, char *manager, struct berval *passwd, char *entry,
+ LDAP **ldp, int noattrs, int maxloop,
+ int maxretries, int delay, int force, int chaserefs )
+{
+ LDAP *ld = ldp ? *ldp : NULL;
+ int i = 0, do_retry = maxretries;
+ char *attrs[] = { "1.1", NULL };
+ pid_t pid = getpid();
+ int rc = LDAP_SUCCESS;
+ int version = LDAP_VERSION3;
+ int first = 1;
+
+retry:;
+ if ( ld == NULL ) {
+ ldap_initialize( &ld, uri );
+ if ( ld == NULL ) {
+ tester_perror( "ldap_initialize" );
+ exit( EXIT_FAILURE );
+ }
+
+ (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
+ (void) ldap_set_option( ld, LDAP_OPT_REFERRALS,
+ chaserefs ? LDAP_OPT_ON : LDAP_OPT_OFF );
+
+ if ( do_retry == maxretries ) {
+ fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
+ (long) pid, maxloop, entry );
+ }
+
+ rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL );
+ if ( rc != LDAP_SUCCESS ) {
+ tester_ldap_error( ld, "ldap_sasl_bind_s" );
+ switch ( rc ) {
+ case LDAP_BUSY:
+ case LDAP_UNAVAILABLE:
+ if ( do_retry > 0 ) {
+ ldap_unbind_ext( ld, NULL, NULL );
+ do_retry--;
+ if ( delay != 0 ) {
+ sleep( delay );
+ }
+ goto retry;
+ }
+ /* fallthru */
+ default:
+ break;
+ }
+ exit( EXIT_FAILURE );
+ }
+ }
+
for ( ; i < maxloop; i++ ) {
LDAPMessage *res = NULL;
rc = ldap_search_ext_s( ld, entry, LDAP_SCOPE_BASE,
- NULL, attrs, 1, NULL, NULL, NULL, LDAP_NO_LIMIT, &res );
+ NULL, attrs, noattrs, NULL, NULL, NULL,
+ LDAP_NO_LIMIT, &res );
switch ( rc ) {
case LDAP_REFERRAL:
/* don't log: it's intended */
}
done:;
- fprintf( stderr, " PID=%ld - Read done (%d).\n", (long) pid, rc );
+ if ( ldp != NULL ) {
+ *ldp = ld;
+
+ } else {
+ fprintf( stderr, " PID=%ld - Read done (%d).\n", (long) pid, rc );
- ldap_unbind_ext( ld, NULL, NULL );
+ if ( ld != NULL ) {
+ ldap_unbind_ext( ld, NULL, NULL );
+ }
+ }
}
static void
do_search( char *uri, char *manager, struct berval *passwd,
- char *sbase, char *filter, LDAP **ldp,
+ char *sbase, char *filter, LDAP **ldp, int noattrs,
int innerloop, int maxretries, int delay, int force, int chaserefs );
static void
do_random( char *uri, char *manager, struct berval *passwd,
- char *sbase, char *filter, char *attr, int innerloop,
+ char *sbase, char *filter, char *attr, int noattrs, int innerloop,
int maxretries, int delay, int force, int chaserefs );
static void
"-b <searchbase> "
"-f <searchfilter> "
"[-a <attr>] "
- "[-F] "
+ "[-A] "
"[-C] "
+ "[-F] "
"[-l <loops>] "
"[-L <outerloops>] "
"[-r <maxretries>] "
int delay = 0;
int force = 0;
int chaserefs = 0;
+ int noattrs = 0;
tester_init( "slapd-search" );
- while ( (i = getopt( argc, argv, "a:b:CD:f:FH:h:l:L:p:w:r:t:" )) != EOF ) {
+ while ( (i = getopt( argc, argv, "Aa:b:CD:f:FH:h:l:L:p:w:r:t:" )) != EOF ) {
switch( i ) {
+ case 'A':
+ noattrs++;
+ break;
+
case 'C':
chaserefs++;
break;
for ( i = 0; i < outerloops; i++ ) {
if ( attr != NULL ) {
do_random( uri, manager, &passwd, sbase, filter, attr,
- loops, retries, delay, force, chaserefs );
+ noattrs, loops, retries, delay, force, chaserefs );
} else {
do_search( uri, manager, &passwd, sbase, filter, NULL,
- loops, retries, delay, force, chaserefs );
+ noattrs, loops, retries, delay, force, chaserefs );
}
}
static void
do_random( char *uri, char *manager, struct berval *passwd,
- char *sbase, char *filter, char *attr,
+ char *sbase, char *filter, char *attr, int noattrs,
int innerloop, int maxretries, int delay, int force, int chaserefs )
{
LDAP *ld = NULL;
snprintf( buf, sizeof( buf ), "(%s=%s)", attr, values[ rand() % nvalues ] );
- do_search( uri, manager, passwd, sbase, buf, &ld,
+ do_search( uri, manager, passwd, sbase, buf, &ld, noattrs,
1, maxretries, delay, force, chaserefs );
}
}
ldap_unbind_ext( ld, NULL, NULL );
}
}
+
static void
do_search( char *uri, char *manager, struct berval *passwd,
char *sbase, char *filter, LDAP **ldp,
- int innerloop, int maxretries, int delay,
+ int noattrs, int innerloop, int maxretries, int delay,
int force, int chaserefs )
{
LDAP *ld = ldp ? *ldp : NULL;
LDAPMessage *res = NULL;
rc = ldap_search_ext_s( ld, sbase, LDAP_SCOPE_SUBTREE,
- filter, attrs, 0, NULL, NULL,
+ filter, attrs, noattrs, NULL, NULL,
NULL, LDAP_NO_LIMIT, &res );
if ( res != NULL ) {
ldap_msgfree( res );
static char *get_file_name( char *dirname, char *filename );
static int get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[] );
-static int get_read_entries( char *filename, char *entries[] );
+static int get_read_entries( char *filename, char *entries[], char *filters[] );
static void fork_child( char *prog, char **args );
static void wait4kids( int nkidval );
struct dirent *file;
int friendly = 0;
int chaserefs = 0;
+ int noattrs = 0;
/* search */
char *sfile = NULL;
char *sreqs[MAXREQS];
char *rreqs[MAXREQS];
int rnum = 0;
char *rargs[MAXARGS];
+ char *rflts[MAXREQS];
int ranum;
char rcmd[MAXPATHLEN];
char rloops[] = "18446744073709551615UL";
tester_init( "slapd-tester" );
- while ( (i = getopt( argc, argv, "CD:d:FH:h:j:l:L:P:p:r:t:w:" )) != EOF ) {
+ while ( (i = getopt( argc, argv, "ACD:d:FH:h:j:l:L:P:p:r:t:w:" )) != EOF ) {
switch( i ) {
+ case 'A':
+ noattrs++;
+ break;
+
case 'C':
chaserefs++;
break;
/* look for read requests */
if ( rfile ) {
- rnum = get_read_entries( rfile, rreqs );
+ rnum = get_read_entries( rfile, rreqs, rflts );
}
/* look for modrdn requests */
if ( mfile ) {
- mnum = get_read_entries( mfile, mreqs );
+ mnum = get_read_entries( mfile, mreqs, NULL );
}
/* look for modify requests */
if ( chaserefs ) {
sargs[sanum++] = "-C";
}
+ if ( noattrs ) {
+ sargs[sanum++] = "-A";
+ }
sargs[sanum++] = "-b";
sargs[sanum++] = NULL; /* will hold the search base */
sargs[sanum++] = "-f";
rargs[ranum++] = "-p";
rargs[ranum++] = port;
}
+ rargs[ranum++] = "-D";
+ rargs[ranum++] = manager;
+ rargs[ranum++] = "-w";
+ rargs[ranum++] = passwd;
rargs[ranum++] = "-l";
rargs[ranum++] = rloops;
rargs[ranum++] = "-L";
if ( chaserefs ) {
rargs[ranum++] = "-C";
}
+ if ( noattrs ) {
+ rargs[ranum++] = "-A";
+ }
rargs[ranum++] = "-e";
rargs[ranum++] = NULL; /* will hold the read entry */
+
rargs[ranum++] = NULL;
+ rargs[ranum] = NULL; /* might hold the filter arg */
+
+ rargs[ranum + 1] = NULL;
/*
* generate the modrdn clients
bargs[banum++] = NULL;
for ( j = 0; j < MAXREQS; j++ ) {
- if ( j < snum ) {
+ if ( snum ) {
+ int jj = j % snum;
- sargs[sanum - 2] = sreqs[j];
- sargs[sanum - 4] = sbase[j];
- if ( sattrs[j] != NULL ) {
+ sargs[sanum - 2] = sreqs[jj];
+ sargs[sanum - 4] = sbase[jj];
+ if ( sattrs[jj] != NULL ) {
sargs[sanum - 1] = "-a";
- sargs[sanum] = sattrs[j];
+ sargs[sanum] = sattrs[jj];
} else {
sargs[sanum - 1] = NULL;
}
fork_child( scmd, sargs );
-
}
- if ( j < rnum ) {
+ if ( rnum ) {
+ int jj = j % rnum;
- rargs[ranum - 2] = rreqs[j];
- fork_child( rcmd, rargs );
+ rargs[ranum - 2] = rreqs[jj];
+ if ( rflts[jj] != NULL ) {
+ rargs[ranum - 1] = "-f";
+ rargs[ranum] = rflts[jj];
+ } else {
+ rargs[ranum - 1] = NULL;
+ }
+ fork_child( rcmd, rargs );
}
- if ( j < mnum ) {
+ if ( mnum ) {
+ int jj = j % mnum;
- margs[manum - 2] = mreqs[j];
+ margs[manum - 2] = mreqs[jj];
fork_child( mcmd, margs );
-
}
- if ( j < modnum ) {
- modargs[modanum - 4] = moddn[j];
- modargs[modanum - 2] = modreqs[j];
- fork_child( modcmd, modargs );
+ if ( modnum ) {
+ int jj = j % modnum;
+ modargs[modanum - 4] = moddn[jj];
+ modargs[modanum - 2] = modreqs[jj];
+ fork_child( modcmd, modargs );
}
- if ( j < anum ) {
+ if ( anum ) {
+ int jj = j % anum;
- aargs[aanum - 2] = afiles[j];
+ aargs[aanum - 2] = afiles[jj];
fork_child( acmd, aargs );
-
}
- if ( j < bnum ) {
+ if ( bnum ) {
+ int jj = j % bnum;
- bargs[banum - 4] = breqs[j];
- bargs[banum - 2] = bcreds[j];
+ bargs[banum - 4] = breqs[jj];
+ bargs[banum - 2] = bcreds[jj];
fork_child( bcmd, bargs );
-
}
-
}
wait4kids( -1 );
static int
-get_read_entries( char *filename, char *entries[] )
+get_read_entries( char *filename, char *entries[], char *filters[] )
{
FILE *fp;
int entry = 0;
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
*nl = '\0';
- entries[entry++] = ArgDup( line );
+ if ( filters != NULL && line[0] == '+' ) {
+ LDAPURLDesc *lud;
+
+ if ( ldap_url_parse( &line[1], &lud ) != LDAP_URL_SUCCESS ) {
+ return -1;
+ }
+
+ if ( lud->lud_dn == NULL || lud->lud_dn[ 0 ] == '\0' ) {
+ return -1;
+ }
+
+ entries[entry] = ArgDup( lud->lud_dn );
+
+ if ( lud->lud_filter ) {
+ filters[entry] = ArgDup( lud->lud_filter );
+
+ } else {
+ filters[entry] = ArgDup( "(objectClass=*)" );
+ }
+
+
+ } else {
+ entries[entry] = ArgDup( line );
+ }
+
+ entry++;
}
fclose( fp );