1999-09-02 16:40:22 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-09-02 08:56:32 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1999-02-15 18:49:20 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
1999-03-29 09:40:17 +08:00
|
|
|
#include <ac/dirent.h>
|
1999-02-15 18:49:20 +08:00
|
|
|
#include <ac/socket.h>
|
1999-03-29 09:40:17 +08:00
|
|
|
#include <ac/string.h>
|
1999-02-15 18:49:20 +08:00
|
|
|
#include <ac/unistd.h>
|
|
|
|
#include <ac/wait.h>
|
|
|
|
|
1999-03-29 09:40:17 +08:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
1999-02-15 18:49:20 +08:00
|
|
|
#include <sys/param.h>
|
1999-03-29 09:40:17 +08:00
|
|
|
#endif
|
1999-02-15 18:49:20 +08:00
|
|
|
|
1999-06-17 11:54:25 +08:00
|
|
|
#include "ldap_defaults.h"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define SEARCHCMD "slapd-search"
|
|
|
|
#define READCMD "slapd-read"
|
|
|
|
#define ADDCMD "slapd-addel"
|
|
|
|
#define MAXARGS 100
|
|
|
|
#define MAXREQS 20
|
|
|
|
#define LOOPS "100"
|
|
|
|
|
|
|
|
#define TSEARCHFILE "do_search.0"
|
|
|
|
#define TREADFILE "do_read.0"
|
|
|
|
#define TADDFILE "do_add."
|
|
|
|
|
|
|
|
static char *get_file_name( char *dirname, char *filename );
|
|
|
|
static int get_search_filters( char *filename, char *filters[] );
|
|
|
|
static int get_read_entries( char *filename, char *entries[] );
|
|
|
|
static void fork_child( char *prog, char *args[] );
|
|
|
|
static void wait4kids( int nkidval );
|
|
|
|
|
|
|
|
static int maxkids = 20;
|
|
|
|
static int nkids;
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage( char *name )
|
|
|
|
{
|
1999-02-22 19:28:01 +08:00
|
|
|
fprintf( stderr, "usage: %s [-h <host>] -p <port> -D <manager> -w <passwd> -d <datadir> -b <baseDN> [-j <maxchild>] [-l <loops>] -P <progdir>\n", name );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
char *host = "localhost";
|
|
|
|
char *port = NULL;
|
|
|
|
char *manager = NULL;
|
|
|
|
char *passwd = NULL;
|
|
|
|
char *dirname = NULL;
|
|
|
|
char *sbase = NULL;
|
1999-02-22 19:28:01 +08:00
|
|
|
char *progdir = NULL;
|
1999-02-15 18:49:20 +08:00
|
|
|
char *loops = LOOPS;
|
|
|
|
DIR *datadir;
|
|
|
|
struct dirent *file;
|
|
|
|
char *sfile = NULL;
|
|
|
|
char *sreqs[MAXREQS];
|
|
|
|
int snum = 0;
|
|
|
|
char *rfile = NULL;
|
|
|
|
char *rreqs[MAXREQS];
|
|
|
|
int rnum = 0;
|
|
|
|
char *afiles[MAXREQS];
|
|
|
|
int anum = 0;
|
|
|
|
char *sargs[MAXARGS];
|
|
|
|
int sanum;
|
|
|
|
char scmd[MAXPATHLEN];
|
|
|
|
char *rargs[MAXARGS];
|
|
|
|
int ranum;
|
|
|
|
char rcmd[MAXPATHLEN];
|
|
|
|
char *aargs[MAXARGS];
|
|
|
|
int aanum;
|
|
|
|
char acmd[MAXPATHLEN];
|
|
|
|
|
1999-02-22 19:28:01 +08:00
|
|
|
while ( (i = getopt( argc, argv, "h:p:D:w:b:d:j:l:P:" )) != EOF ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
switch( i ) {
|
|
|
|
case 'h': /* slapd host */
|
|
|
|
host = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p': /* the servers port number */
|
|
|
|
port = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D': /* slapd manager */
|
|
|
|
manager = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w': /* the managers passwd */
|
|
|
|
passwd = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b': /* the base DN */
|
|
|
|
sbase = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd': /* data directory */
|
|
|
|
dirname = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
1999-02-22 19:28:01 +08:00
|
|
|
case 'P': /* prog directory */
|
|
|
|
progdir = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
case 'j': /* the number of parallel clients */
|
|
|
|
maxkids = atoi( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l': /* the number of loops per client */
|
|
|
|
loops = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage( argv[0] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (( dirname == NULL ) || ( sbase == NULL ) || ( port == NULL ) ||
|
1999-02-22 19:28:01 +08:00
|
|
|
( manager == NULL ) || ( passwd == NULL ) || ( progdir == NULL ))
|
1999-02-15 18:49:20 +08:00
|
|
|
usage( argv[0] );
|
|
|
|
|
|
|
|
/* get the file list */
|
|
|
|
if ( ( datadir = opendir( dirname )) == NULL ) {
|
|
|
|
|
|
|
|
fprintf( stderr, "%s: couldn't open data directory \"%s\".\n",
|
|
|
|
argv[0], dirname );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for search, read, and add/delete files */
|
|
|
|
for ( file = readdir( datadir ); file; file = readdir( datadir )) {
|
|
|
|
|
|
|
|
if ( !strcasecmp( file->d_name, TSEARCHFILE )) {
|
|
|
|
sfile = get_file_name( dirname, file->d_name );
|
|
|
|
continue;
|
|
|
|
} else if ( !strcasecmp( file->d_name, TREADFILE )) {
|
|
|
|
rfile = get_file_name( dirname, file->d_name );
|
|
|
|
continue;
|
|
|
|
} else if ( !strncasecmp( file->d_name, TADDFILE, strlen( TADDFILE ))
|
|
|
|
&& ( anum < MAXREQS )) {
|
|
|
|
afiles[anum++] = get_file_name( dirname, file->d_name );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-04 13:06:49 +08:00
|
|
|
closedir( datadir );
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
/* look for search requests */
|
|
|
|
if ( sfile ) {
|
|
|
|
snum = get_search_filters( sfile, sreqs );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for read requests */
|
|
|
|
if ( rfile ) {
|
|
|
|
rnum = get_read_entries( rfile, rreqs );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* generate the search clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
sanum = 0;
|
1999-06-17 11:54:25 +08:00
|
|
|
sprintf( scmd, "%s%s%s", progdir, LDAP_DIRSEP, SEARCHCMD );
|
1999-02-15 18:49:20 +08:00
|
|
|
sargs[sanum++] = scmd;
|
|
|
|
sargs[sanum++] = "-h";
|
|
|
|
sargs[sanum++] = host;
|
|
|
|
sargs[sanum++] = "-p";
|
|
|
|
sargs[sanum++] = port;
|
|
|
|
sargs[sanum++] = "-b";
|
|
|
|
sargs[sanum++] = sbase;
|
|
|
|
sargs[sanum++] = "-l";
|
|
|
|
sargs[sanum++] = loops;
|
|
|
|
sargs[sanum++] = "-f";
|
|
|
|
sargs[sanum++] = NULL; /* will hold the search request */
|
|
|
|
sargs[sanum++] = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* generate the read clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
ranum = 0;
|
1999-06-17 11:54:25 +08:00
|
|
|
sprintf( rcmd, "%s%s%s", progdir, LDAP_DIRSEP, READCMD );
|
1999-02-15 18:49:20 +08:00
|
|
|
rargs[ranum++] = rcmd;
|
|
|
|
rargs[ranum++] = "-h";
|
|
|
|
rargs[ranum++] = host;
|
|
|
|
rargs[ranum++] = "-p";
|
|
|
|
rargs[ranum++] = port;
|
|
|
|
rargs[ranum++] = "-l";
|
|
|
|
rargs[ranum++] = loops;
|
|
|
|
rargs[ranum++] = "-e";
|
|
|
|
rargs[ranum++] = NULL; /* will hold the read entry */
|
|
|
|
rargs[ranum++] = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* generate the add/delete clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
aanum = 0;
|
1999-06-17 11:54:25 +08:00
|
|
|
sprintf( acmd, "%s%s%s", progdir, LDAP_DIRSEP, ADDCMD );
|
1999-02-15 18:49:20 +08:00
|
|
|
aargs[aanum++] = acmd;
|
|
|
|
aargs[aanum++] = "-h";
|
|
|
|
aargs[aanum++] = host;
|
|
|
|
aargs[aanum++] = "-p";
|
|
|
|
aargs[aanum++] = port;
|
|
|
|
aargs[aanum++] = "-D";
|
|
|
|
aargs[aanum++] = manager;
|
|
|
|
aargs[aanum++] = "-w";
|
|
|
|
aargs[aanum++] = passwd;
|
|
|
|
aargs[aanum++] = "-l";
|
|
|
|
aargs[aanum++] = loops;
|
|
|
|
aargs[aanum++] = "-f";
|
|
|
|
aargs[aanum++] = NULL; /* will hold the add data file */
|
|
|
|
aargs[aanum++] = NULL;
|
|
|
|
|
|
|
|
for ( j = 0; j < MAXREQS; j++ ) {
|
|
|
|
|
|
|
|
if ( j < snum ) {
|
|
|
|
|
|
|
|
sargs[sanum - 2] = sreqs[j];
|
|
|
|
fork_child( scmd, sargs );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( j < rnum ) {
|
|
|
|
|
|
|
|
rargs[ranum - 2] = rreqs[j];
|
|
|
|
fork_child( rcmd, rargs );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( j < anum ) {
|
|
|
|
|
|
|
|
aargs[aanum - 2] = afiles[j];
|
|
|
|
fork_child( acmd, aargs );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
wait4kids( -1 );
|
|
|
|
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_file_name( char *dirname, char *filename )
|
|
|
|
{
|
|
|
|
char buf[MAXPATHLEN];
|
|
|
|
|
1999-06-17 11:54:25 +08:00
|
|
|
sprintf( buf, "%s%s%s", dirname, LDAP_DIRSEP, filename );
|
1999-02-15 18:49:20 +08:00
|
|
|
return( strdup( buf ));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_search_filters( char *filename, char *filters[] )
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
int filter = 0;
|
|
|
|
|
1999-03-04 21:22:06 +08:00
|
|
|
if ( (fp = fopen( filename, "r" )) != NULL ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
char line[BUFSIZ];
|
|
|
|
|
|
|
|
while (( filter < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) {
|
|
|
|
char *nl;
|
|
|
|
|
|
|
|
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
|
|
|
|
*nl = '\0';
|
|
|
|
filters[filter++] = strdup( line );
|
|
|
|
|
|
|
|
}
|
|
|
|
fclose( fp );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( filter );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_read_entries( char *filename, char *entries[] )
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
int entry = 0;
|
|
|
|
|
1999-03-04 21:22:06 +08:00
|
|
|
if ( (fp = fopen( filename, "r" )) != NULL ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
char line[BUFSIZ];
|
|
|
|
|
|
|
|
while (( entry < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) {
|
|
|
|
char *nl;
|
|
|
|
|
|
|
|
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
|
|
|
|
*nl = '\0';
|
|
|
|
entries[entry++] = strdup( line );
|
|
|
|
|
|
|
|
}
|
|
|
|
fclose( fp );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( entry );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
fork_child( char *prog, char *args[] )
|
|
|
|
{
|
1999-03-29 09:40:17 +08:00
|
|
|
pid_t pid;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
wait4kids( maxkids );
|
|
|
|
|
|
|
|
switch ( pid = fork() ) {
|
|
|
|
case 0: /* child */
|
|
|
|
execvp( prog, args );
|
|
|
|
fprintf( stderr, "%s: ", prog );
|
|
|
|
perror( "execv" );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case -1: /* trouble */
|
|
|
|
fprintf( stderr, "Could not fork to run %s\n", prog );
|
|
|
|
perror( "fork" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* parent */
|
|
|
|
nkids++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wait4kids( int nkidval )
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
while ( nkids >= nkidval ) {
|
|
|
|
wait( &status );
|
1999-03-29 09:40:17 +08:00
|
|
|
|
|
|
|
if ( WIFSTOPPED(status) ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
fprintf( stderr,
|
|
|
|
"stopping: child stopped with signal %d\n",
|
1999-03-29 09:40:17 +08:00
|
|
|
(int) WSTOPSIG(status) );
|
|
|
|
|
|
|
|
} else if ( WIFSIGNALED(status) ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
fprintf( stderr,
|
1999-03-29 09:40:17 +08:00
|
|
|
"stopping: child terminated with signal %d%s\n",
|
|
|
|
(int) WTERMSIG(status),
|
|
|
|
#ifdef WCOREDUMP
|
|
|
|
WCOREDUMP(status) ? ", core dumped" : ""
|
|
|
|
#else
|
|
|
|
""
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
exit( WEXITSTATUS(status) );
|
|
|
|
|
|
|
|
} else if ( WEXITSTATUS(status) != 0 ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
fprintf( stderr,
|
|
|
|
"stopping: child exited with status %d\n",
|
1999-03-29 09:40:17 +08:00
|
|
|
(int) WEXITSTATUS(status) );
|
|
|
|
exit( WEXITSTATUS(status) );
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
} else {
|
|
|
|
nkids--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|