/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1999-2006 The OpenLDAP Foundation.
+ * Copyright 1999-2008 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include <stdio.h>
-#include <ac/stdlib.h>
+#include "ac/stdlib.h"
-#include <ac/ctype.h>
-#include <ac/param.h>
-#include <ac/socket.h>
-#include <ac/string.h>
-#include <ac/unistd.h>
-#include <ac/wait.h>
+#include "ac/ctype.h"
+#include "ac/param.h"
+#include "ac/socket.h"
+#include "ac/string.h"
+#include "ac/unistd.h"
+#include "ac/wait.h"
-#include <ldap.h>
-#include <lutil.h>
+#include "ldap.h"
+#include "lutil.h"
+#include "ldap_pvt.h"
#include "slapd-common.h"
static void
do_search( char *uri, char *manager, struct berval *passwd,
- char *sbase, char *filter, LDAP **ldp, int noattrs,
+ char *sbase, int scope, char *filter, LDAP **ldp,
+ char **attrs, int noattrs, int nobind,
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 noattrs, int innerloop,
- int maxretries, int delay, int force, int chaserefs );
+ char *sbase, int scope, char *filter, char *attr,
+ char **attrs, int noattrs, int nobind,
+ int innerloop, int maxretries, int delay, int force, int chaserefs );
static void
-usage( char *name )
+usage( char *name, char o )
{
+ if ( o != '\0' ) {
+ fprintf( stderr, "unknown/incorrect option \"%c\"\n", o );
+ }
+
fprintf( stderr,
"usage: %s "
"-H <uri> | ([-h <host>] -p <port>) "
"-D <manager> "
"-w <passwd> "
"-b <searchbase> "
+ "-s <scope> "
"-f <searchfilter> "
"[-a <attr>] "
"[-A] "
"[-C] "
"[-F] "
+ "[-N] "
"[-i <ignore>] "
"[-l <loops>] "
"[-L <outerloops>] "
"[-r <maxretries>] "
- "[-t <delay>]\n",
+ "[-t <delay>] "
+ "[<attrs>] "
+ "\n",
name );
exit( EXIT_FAILURE );
}
char *manager = NULL;
struct berval passwd = { 0, NULL };
char *sbase = NULL;
+ int scope = LDAP_SCOPE_SUBTREE;
char *filter = NULL;
char *attr = NULL;
+ char *srchattrs[] = { "cn", "sn", NULL };
+ char **attrs = srchattrs;
int loops = LOOPS;
int outerloops = 1;
int retries = RETRIES;
int force = 0;
int chaserefs = 0;
int noattrs = 0;
+ int nobind = 0;
tester_init( "slapd-search", TESTER_SEARCH );
/* by default, tolerate referrals and no such object */
tester_ignore_str2errlist( "REFERRAL,NO_SUCH_OBJECT" );
- while ( (i = getopt( argc, argv, "Aa:b:CD:f:FH:h:i:l:L:p:w:r:t:" )) != EOF ) {
- switch( i ) {
+ while ( ( i = getopt( argc, argv, "Aa:b:CD:f:FH:h:i:l:L:Np:r:s:t:T:w:" ) ) != EOF )
+ {
+ switch ( i ) {
case 'A':
noattrs++;
break;
tester_ignore_str2errlist( optarg );
break;
+ case 'N':
+ nobind++;
+ break;
+
case 'p': /* the servers port */
if ( lutil_atoi( &port, optarg ) != 0 ) {
- usage( argv[0] );
+ usage( argv[0], i );
}
break;
case 'l': /* number of loops */
if ( lutil_atoi( &loops, optarg ) != 0 ) {
- usage( argv[0] );
+ usage( argv[0], i );
}
break;
case 'L': /* number of loops */
if ( lutil_atoi( &outerloops, optarg ) != 0 ) {
- usage( argv[0] );
+ usage( argv[0], i );
}
break;
case 'r': /* number of retries */
if ( lutil_atoi( &retries, optarg ) != 0 ) {
- usage( argv[0] );
+ usage( argv[0], i );
}
break;
case 't': /* delay in seconds */
if ( lutil_atoi( &delay, optarg ) != 0 ) {
- usage( argv[0] );
+ usage( argv[0], i );
+ }
+ break;
+
+ case 'T':
+ attrs = ldap_str2charray( optarg, "," );
+ if ( attrs == NULL ) {
+ usage( argv[0], i );
+ }
+ break;
+
+ case 's':
+ scope = ldap_pvt_str2scope( optarg );
+ if ( scope == -1 ) {
+ usage( argv[0], i );
}
break;
default:
- usage( argv[0] );
+ usage( argv[0], i );
break;
}
}
if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 && uri == NULL ))
- usage( argv[0] );
+ usage( argv[0], '\0' );
if ( *filter == '\0' ) {
}
+ if ( argv[optind] != NULL ) {
+ attrs = &argv[optind];
+ }
+
uri = tester_uri( uri, host, port );
for ( i = 0; i < outerloops; i++ ) {
if ( attr != NULL ) {
- do_random( uri, manager, &passwd, sbase, filter, attr,
- noattrs, loops, retries, delay, force, chaserefs );
+ do_random( uri, manager, &passwd,
+ sbase, scope, filter, attr,
+ attrs, noattrs, nobind,
+ loops, retries, delay, force, chaserefs );
} else {
- do_search( uri, manager, &passwd, sbase, filter, NULL,
- noattrs, loops, retries, delay, force, chaserefs );
+ do_search( uri, manager, &passwd,
+ sbase, scope, filter, NULL,
+ attrs, noattrs, nobind,
+ loops, retries, delay, force, chaserefs );
}
}
static void
do_random( char *uri, char *manager, struct berval *passwd,
- char *sbase, char *filter, char *attr, int noattrs,
+ char *sbase, int scope, char *filter, char *attr,
+ char **srchattrs, int noattrs, int nobind,
int innerloop, int maxretries, int delay, int force, int chaserefs )
{
LDAP *ld = NULL;
int i = 0, do_retry = maxretries;
char *attrs[ 2 ];
- pid_t pid = getpid();
int rc = LDAP_SUCCESS;
int version = LDAP_VERSION3;
int nvalues = 0;
(long) pid, innerloop, sbase, filter, attr );
}
- 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", NULL );
- switch ( rc ) {
- case LDAP_BUSY:
- case LDAP_UNAVAILABLE:
- /* fallthru */
- default:
- break;
+ if ( nobind == 0 ) {
+ 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", NULL );
+ switch ( rc ) {
+ case LDAP_BUSY:
+ case LDAP_UNAVAILABLE:
+ /* fallthru */
+ default:
+ break;
+ }
+ exit( EXIT_FAILURE );
}
- exit( EXIT_FAILURE );
}
rc = ldap_search_ext_s( ld, sbase, LDAP_SCOPE_SUBTREE,
ldap_msgfree( res );
+ if ( !values ) {
+ fprintf( stderr, " PID=%ld - Search base=\"%s\" filter=\"%s\" got %d values.\n",
+ (long) pid, sbase, filter, nvalues );
+ exit(EXIT_FAILURE);
+ }
+
if ( do_retry == maxretries ) {
fprintf( stderr, " PID=%ld - Search base=\"%s\" filter=\"%s\" got %d values.\n",
(long) pid, sbase, filter, nvalues );
for ( i = 0; i < innerloop; i++ ) {
char buf[ BUFSIZ ];
+#if 0 /* use high-order bits for better randomness (Numerical Recipes in "C") */
+ int r = rand() % nvalues;
+#endif
+ int r = ((double)nvalues)*rand()/(RAND_MAX + 1.0);
- snprintf( buf, sizeof( buf ), "(%s=%s)", attr, values[ rand() % nvalues ] );
+ snprintf( buf, sizeof( buf ), "(%s=%s)", attr, values[ r ] );
- do_search( uri, manager, passwd, sbase, buf, &ld, noattrs,
- 1, maxretries, delay, force, chaserefs );
+ do_search( uri, manager, passwd,
+ sbase, scope, buf, &ld,
+ srchattrs, noattrs, nobind,
+ 1, maxretries, delay, force, chaserefs );
}
break;
break;
}
- fprintf( stderr, " PID=%ld - Search done (%d).\n", (long) pid, rc );
+ fprintf( stderr, " PID=%ld - Search done (%d).\n", (long) pid, rc );
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,
- int noattrs, int innerloop, int maxretries, int delay,
- int force, int chaserefs )
+ char *sbase, int scope, char *filter, LDAP **ldp,
+ char **attrs, int noattrs, int nobind,
+ int innerloop, int maxretries, int delay, int force, int chaserefs )
{
LDAP *ld = ldp ? *ldp : NULL;
int i = 0, do_retry = maxretries;
- char *attrs[] = { "cn", "sn", NULL };
- pid_t pid = getpid();
int rc = LDAP_SUCCESS;
int version = LDAP_VERSION3;
char buf[ BUFSIZ ];
chaserefs ? LDAP_OPT_ON : LDAP_OPT_OFF );
if ( do_retry == maxretries ) {
- fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
- (long) pid, innerloop, sbase, filter );
+ fprintf( stderr,
+ "PID=%ld - Search(%d): "
+ "base=\"%s\" scope=%s filter=\"%s\" "
+ "attrs=%s%s.\n",
+ (long) pid, innerloop,
+ sbase, ldap_pvt_scope2str( scope ), filter,
+ attrs[0], attrs[1] ? " (more...)" : "" );
}
- rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL );
- if ( rc != LDAP_SUCCESS ) {
- snprintf( buf, sizeof( buf ),
- "bindDN=\"%s\"", manager );
- tester_ldap_error( ld, "ldap_sasl_bind_s", buf );
- 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 );
+ if ( nobind == 0 ) {
+ rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL );
+ if ( rc != LDAP_SUCCESS ) {
+ snprintf( buf, sizeof( buf ),
+ "bindDN=\"%s\"", manager );
+ tester_ldap_error( ld, "ldap_sasl_bind_s", buf );
+ switch ( rc ) {
+ case LDAP_BUSY:
+ case LDAP_UNAVAILABLE:
+ if ( do_retry > 0 ) {
+ ldap_unbind_ext( ld, NULL, NULL );
+ ld = NULL;
+ do_retry--;
+ if ( delay != 0 ) {
+ sleep( delay );
+ }
+ goto retry;
}
- goto retry;
+ /* fallthru */
+ default:
+ break;
}
- /* fallthru */
- default:
- break;
+ exit( EXIT_FAILURE );
}
- exit( EXIT_FAILURE );
}
}
for ( ; i < innerloop; i++ ) {
LDAPMessage *res = NULL;
- rc = ldap_search_ext_s( ld, sbase, LDAP_SCOPE_SUBTREE,
+ rc = ldap_search_ext_s( ld, sbase, scope,
filter, attrs, noattrs, NULL, NULL,
NULL, LDAP_NO_LIMIT, &res );
if ( res != NULL ) {
*ldp = ld;
} else {
- fprintf( stderr, " PID=%ld - Search done (%d).\n", (long) pid, rc );
+ fprintf( stderr, " PID=%ld - Search done (%d).\n", (long) pid, rc );
if ( ld != NULL ) {
ldap_unbind_ext( ld, NULL, NULL );