1999-09-02 16:40:22 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 23:24:38 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2007-01-03 04:00:42 +08:00
|
|
|
* Copyright 1999-2007 The OpenLDAP Foundation.
|
2003-11-26 23:24:38 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
1999-09-02 08:56:32 +08:00
|
|
|
*/
|
2003-11-26 23:24:38 +08:00
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Kurt Spanier for inclusion
|
|
|
|
* in OpenLDAP Software.
|
|
|
|
*/
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
#include "ac/stdlib.h"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
#include "ac/ctype.h"
|
|
|
|
#include "ac/dirent.h"
|
|
|
|
#include "ac/param.h"
|
|
|
|
#include "ac/socket.h"
|
|
|
|
#include "ac/string.h"
|
|
|
|
#include "ac/unistd.h"
|
|
|
|
#include "ac/wait.h"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
|
1999-06-17 11:54:25 +08:00
|
|
|
#include "ldap_defaults.h"
|
2005-11-24 09:10:05 +08:00
|
|
|
#include "lutil.h"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2006-01-12 21:01:38 +08:00
|
|
|
#include "ldap.h"
|
2006-11-19 02:25:46 +08:00
|
|
|
#include "ldap_pvt.h"
|
|
|
|
#include "lber_pvt.h"
|
2006-01-12 21:01:38 +08:00
|
|
|
#include "slapd-common.h"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
#define SEARCHCMD "slapd-search"
|
|
|
|
#define READCMD "slapd-read"
|
|
|
|
#define ADDCMD "slapd-addel"
|
2003-02-22 20:01:59 +08:00
|
|
|
#define MODRDNCMD "slapd-modrdn"
|
2004-08-28 01:07:18 +08:00
|
|
|
#define MODIFYCMD "slapd-modify"
|
2006-01-09 22:21:33 +08:00
|
|
|
#define BINDCMD "slapd-bind"
|
2004-09-05 02:31:43 +08:00
|
|
|
#define MAXARGS 100
|
|
|
|
#define MAXREQS 5000
|
2006-03-04 00:02:34 +08:00
|
|
|
#define LOOPS 100
|
|
|
|
#define OUTERLOOPS "1"
|
2005-04-21 00:16:39 +08:00
|
|
|
#define RETRIES "0"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
#define TSEARCHFILE "do_search.0"
|
|
|
|
#define TREADFILE "do_read.0"
|
|
|
|
#define TADDFILE "do_add."
|
2003-02-22 20:01:59 +08:00
|
|
|
#define TMODRDNFILE "do_modrdn.0"
|
2004-08-28 01:07:18 +08:00
|
|
|
#define TMODIFYFILE "do_modify.0"
|
2006-01-09 22:21:33 +08:00
|
|
|
#define TBINDFILE "do_bind.0"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
static char *get_file_name( char *dirname, char *filename );
|
2007-08-14 00:20:24 +08:00
|
|
|
static int get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[], LDAPURLDesc *luds[] );
|
2006-03-28 08:14:11 +08:00
|
|
|
static int get_read_entries( char *filename, char *entries[], char *filters[] );
|
2002-07-26 21:29:37 +08:00
|
|
|
static void fork_child( char *prog, char **args );
|
1999-02-15 18:49:20 +08:00
|
|
|
static void wait4kids( int nkidval );
|
|
|
|
|
|
|
|
static int maxkids = 20;
|
|
|
|
static int nkids;
|
|
|
|
|
2002-05-17 09:36:35 +08:00
|
|
|
#ifdef HAVE_WINSOCK
|
|
|
|
static HANDLE *children;
|
|
|
|
static char argbuf[BUFSIZ];
|
|
|
|
#define ArgDup(x) strdup(strcat(strcat(strcpy(argbuf,"\""),x),"\""))
|
|
|
|
#else
|
|
|
|
#define ArgDup(x) strdup(x)
|
|
|
|
#endif
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
static void
|
2006-11-19 02:25:46 +08:00
|
|
|
usage( char *name, char opt )
|
1999-02-15 18:49:20 +08:00
|
|
|
{
|
2006-11-19 02:25:46 +08:00
|
|
|
if ( opt ) {
|
|
|
|
fprintf( stderr, "%s: unable to handle option \'%c\'\n\n",
|
|
|
|
name, opt );
|
|
|
|
}
|
|
|
|
|
2005-08-18 00:19:58 +08:00
|
|
|
fprintf( stderr,
|
|
|
|
"usage: %s "
|
|
|
|
"-H <uri> | ([-h <host>] -p <port>) "
|
|
|
|
"-D <manager> "
|
|
|
|
"-w <passwd> "
|
|
|
|
"-d <datadir> "
|
2006-06-09 17:30:36 +08:00
|
|
|
"[-i <ignore>] "
|
2005-08-18 00:19:58 +08:00
|
|
|
"[-j <maxchild>] "
|
2006-11-19 02:25:46 +08:00
|
|
|
"[-l {<loops>|<type>=<loops>[,...]}] "
|
2006-03-04 00:02:34 +08:00
|
|
|
"[-L <outerloops>] "
|
2005-08-18 00:19:58 +08:00
|
|
|
"-P <progdir> "
|
2005-11-05 00:17:32 +08:00
|
|
|
"[-r <maxretries>] "
|
|
|
|
"[-t <delay>] "
|
2006-11-19 02:25:46 +08:00
|
|
|
"[-C] "
|
2006-03-25 18:13:30 +08:00
|
|
|
"[-F] "
|
2006-12-04 04:55:52 +08:00
|
|
|
"[-I] "
|
2006-11-19 02:25:46 +08:00
|
|
|
"[-N]\n",
|
2005-08-18 00:19:58 +08:00
|
|
|
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;
|
2003-02-13 16:02:40 +08:00
|
|
|
char *uri = NULL;
|
1999-02-15 18:49:20 +08:00
|
|
|
char *host = "localhost";
|
|
|
|
char *port = NULL;
|
|
|
|
char *manager = NULL;
|
|
|
|
char *passwd = NULL;
|
|
|
|
char *dirname = NULL;
|
1999-02-22 19:28:01 +08:00
|
|
|
char *progdir = NULL;
|
2006-03-04 00:02:34 +08:00
|
|
|
int loops = LOOPS;
|
|
|
|
char *outerloops = OUTERLOOPS;
|
2005-04-21 00:16:39 +08:00
|
|
|
char *retries = RETRIES;
|
2005-08-19 15:27:32 +08:00
|
|
|
char *delay = "0";
|
2006-01-09 22:21:33 +08:00
|
|
|
DIR *datadir;
|
1999-02-15 18:49:20 +08:00
|
|
|
struct dirent *file;
|
2006-01-09 22:21:33 +08:00
|
|
|
int friendly = 0;
|
2006-03-25 18:13:30 +08:00
|
|
|
int chaserefs = 0;
|
2006-03-28 08:14:11 +08:00
|
|
|
int noattrs = 0;
|
2006-11-19 02:25:46 +08:00
|
|
|
int nobind = 0;
|
2006-12-02 18:25:56 +08:00
|
|
|
int noinit = 1;
|
2006-06-09 17:30:36 +08:00
|
|
|
char *ignore = NULL;
|
2006-01-09 22:21:33 +08:00
|
|
|
/* search */
|
1999-02-15 18:49:20 +08:00
|
|
|
char *sfile = NULL;
|
|
|
|
char *sreqs[MAXREQS];
|
2006-03-25 16:10:31 +08:00
|
|
|
char *sattrs[MAXREQS];
|
2003-09-23 19:55:59 +08:00
|
|
|
char *sbase[MAXREQS];
|
2007-08-14 00:20:24 +08:00
|
|
|
LDAPURLDesc *slud[MAXREQS];
|
2006-01-09 22:21:33 +08:00
|
|
|
int snum = 0;
|
1999-02-15 18:49:20 +08:00
|
|
|
char *sargs[MAXARGS];
|
2006-01-09 22:21:33 +08:00
|
|
|
int sanum;
|
2007-08-14 00:20:24 +08:00
|
|
|
int sextra_args = 0;
|
1999-02-15 18:49:20 +08:00
|
|
|
char scmd[MAXPATHLEN];
|
2007-01-11 21:47:29 +08:00
|
|
|
/* static so that its address can be used in initializer below. */
|
|
|
|
static char sloops[] = "18446744073709551615UL";
|
2006-01-09 22:21:33 +08:00
|
|
|
/* read */
|
|
|
|
char *rfile = NULL;
|
|
|
|
char *rreqs[MAXREQS];
|
|
|
|
int rnum = 0;
|
1999-02-15 18:49:20 +08:00
|
|
|
char *rargs[MAXARGS];
|
2006-03-28 08:14:11 +08:00
|
|
|
char *rflts[MAXREQS];
|
2006-01-09 22:21:33 +08:00
|
|
|
int ranum;
|
2007-08-14 00:20:24 +08:00
|
|
|
int rextra_args = 0;
|
1999-02-15 18:49:20 +08:00
|
|
|
char rcmd[MAXPATHLEN];
|
2007-01-11 21:47:29 +08:00
|
|
|
static char rloops[] = "18446744073709551615UL";
|
2006-01-09 22:21:33 +08:00
|
|
|
/* addel */
|
|
|
|
char *afiles[MAXREQS];
|
|
|
|
int anum = 0;
|
1999-02-15 18:49:20 +08:00
|
|
|
char *aargs[MAXARGS];
|
2006-01-09 22:21:33 +08:00
|
|
|
int aanum;
|
1999-02-15 18:49:20 +08:00
|
|
|
char acmd[MAXPATHLEN];
|
2007-01-11 21:47:29 +08:00
|
|
|
static char aloops[] = "18446744073709551615UL";
|
2006-01-09 22:21:33 +08:00
|
|
|
/* modrdn */
|
2006-11-19 02:25:46 +08:00
|
|
|
char *nfile = NULL;
|
|
|
|
char *nreqs[MAXREQS];
|
|
|
|
int nnum = 0;
|
|
|
|
char *nargs[MAXARGS];
|
|
|
|
int nanum;
|
|
|
|
char ncmd[MAXPATHLEN];
|
2007-01-11 21:47:29 +08:00
|
|
|
static char nloops[] = "18446744073709551615UL";
|
2006-11-19 02:25:46 +08:00
|
|
|
/* modify */
|
2006-01-09 22:21:33 +08:00
|
|
|
char *mfile = NULL;
|
|
|
|
char *mreqs[MAXREQS];
|
2006-11-19 02:25:46 +08:00
|
|
|
char *mdn[MAXREQS];
|
2006-01-09 22:21:33 +08:00
|
|
|
int mnum = 0;
|
2003-02-22 20:01:59 +08:00
|
|
|
char *margs[MAXARGS];
|
|
|
|
int manum;
|
|
|
|
char mcmd[MAXPATHLEN];
|
2007-01-11 21:47:29 +08:00
|
|
|
static char mloops[] = "18446744073709551615UL";
|
2006-01-09 22:21:33 +08:00
|
|
|
/* bind */
|
|
|
|
char *bfile = NULL;
|
|
|
|
char *breqs[MAXREQS];
|
|
|
|
char *bcreds[MAXREQS];
|
2006-05-15 01:18:55 +08:00
|
|
|
char *battrs[MAXREQS];
|
2006-01-09 22:21:33 +08:00
|
|
|
int bnum = 0;
|
|
|
|
char *bargs[MAXARGS];
|
|
|
|
int banum;
|
|
|
|
char bcmd[MAXPATHLEN];
|
2007-01-11 21:47:29 +08:00
|
|
|
static char bloops[] = "18446744073709551615UL";
|
2006-11-19 02:25:46 +08:00
|
|
|
char **bargs_extra = NULL;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2006-01-22 00:27:15 +08:00
|
|
|
char *friendlyOpt = NULL;
|
2006-07-02 02:22:43 +08:00
|
|
|
int pw_ask = 0;
|
|
|
|
char *pw_file = NULL;
|
2006-01-22 00:27:15 +08:00
|
|
|
|
2006-11-19 02:25:46 +08:00
|
|
|
/* extra action to do after bind... */
|
|
|
|
typedef struct extra_t {
|
|
|
|
char *action;
|
|
|
|
struct extra_t *next;
|
|
|
|
} extra_t;
|
|
|
|
|
|
|
|
extra_t *extra = NULL;
|
|
|
|
int nextra = 0;
|
|
|
|
|
2006-06-09 17:30:36 +08:00
|
|
|
tester_init( "slapd-tester", TESTER_TESTER );
|
2006-01-12 21:01:38 +08:00
|
|
|
|
2006-11-19 02:25:46 +08:00
|
|
|
sloops[0] = '\0';
|
|
|
|
rloops[0] = '\0';
|
|
|
|
aloops[0] = '\0';
|
|
|
|
nloops[0] = '\0';
|
|
|
|
mloops[0] = '\0';
|
|
|
|
bloops[0] = '\0';
|
|
|
|
|
2006-12-04 05:34:24 +08:00
|
|
|
while ( ( i = getopt( argc, argv, "AB:CD:d:FH:h:Ii:j:L:l:NP:p:r:t:Ww:y:" ) ) != EOF )
|
|
|
|
{
|
|
|
|
switch ( i ) {
|
2006-03-28 08:14:11 +08:00
|
|
|
case 'A':
|
|
|
|
noattrs++;
|
|
|
|
break;
|
|
|
|
|
2006-12-04 05:34:24 +08:00
|
|
|
case 'B': {
|
2006-11-19 02:25:46 +08:00
|
|
|
char **p,
|
|
|
|
**b = ldap_str2charray( optarg, "," );
|
|
|
|
extra_t **epp;
|
|
|
|
|
|
|
|
for ( epp = &extra; *epp; epp = &(*epp)->next )
|
|
|
|
;
|
|
|
|
|
|
|
|
for ( p = b; p[0]; p++ ) {
|
|
|
|
*epp = calloc( 1, sizeof( extra_t ) );
|
|
|
|
(*epp)->action = p[0];
|
|
|
|
epp = &(*epp)->next;
|
|
|
|
nextra++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_memfree( b );
|
|
|
|
} break;
|
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'C':
|
|
|
|
chaserefs++;
|
|
|
|
break;
|
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
case 'D': /* slapd manager */
|
|
|
|
manager = ArgDup( optarg );
|
2003-02-13 16:02:40 +08:00
|
|
|
break;
|
2005-04-21 00:16:39 +08:00
|
|
|
|
|
|
|
case 'd': /* data directory */
|
|
|
|
dirname = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
2005-11-05 00:17:32 +08:00
|
|
|
case 'F':
|
|
|
|
friendly++;
|
|
|
|
break;
|
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
case 'H': /* slapd uri */
|
|
|
|
uri = strdup( optarg );
|
1999-02-15 18:49:20 +08:00
|
|
|
break;
|
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
case 'h': /* slapd host */
|
|
|
|
host = strdup( optarg );
|
|
|
|
break;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2006-12-02 18:25:56 +08:00
|
|
|
case 'I':
|
|
|
|
noinit = 0;
|
|
|
|
break;
|
|
|
|
|
2006-06-09 17:30:36 +08:00
|
|
|
case 'i':
|
|
|
|
ignore = optarg;
|
|
|
|
break;
|
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
case 'j': /* the number of parallel clients */
|
2005-11-24 09:10:05 +08:00
|
|
|
if ( lutil_atoi( &maxkids, optarg ) != 0 ) {
|
2006-11-19 02:25:46 +08:00
|
|
|
usage( argv[0], 'j' );
|
2005-11-24 09:10:05 +08:00
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
break;
|
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
case 'l': /* the number of loops per client */
|
2007-01-11 20:00:39 +08:00
|
|
|
if ( !isdigit( (unsigned char) optarg[0] ) ) {
|
2006-11-19 02:25:46 +08:00
|
|
|
char **p,
|
|
|
|
**l = ldap_str2charray( optarg, "," );
|
|
|
|
|
|
|
|
for ( p = l; p[0]; p++) {
|
|
|
|
struct {
|
|
|
|
struct berval type;
|
|
|
|
char *buf;
|
|
|
|
} types[] = {
|
|
|
|
{ BER_BVC( "add=" ), aloops },
|
|
|
|
{ BER_BVC( "bind=" ), bloops },
|
|
|
|
{ BER_BVC( "modify=" ), mloops },
|
|
|
|
{ BER_BVC( "modrdn=" ), nloops },
|
|
|
|
{ BER_BVC( "read=" ), rloops },
|
|
|
|
{ BER_BVC( "search=" ), sloops },
|
|
|
|
{ BER_BVNULL, NULL }
|
|
|
|
};
|
|
|
|
int c, n;
|
|
|
|
|
|
|
|
for ( c = 0; types[c].type.bv_val; c++ ) {
|
|
|
|
if ( strncasecmp( p[0], types[c].type.bv_val, types[c].type.bv_len ) == 0 ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( types[c].type.bv_val == NULL ) {
|
|
|
|
usage( argv[0], 'l' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( lutil_atoi( &n, &p[0][types[c].type.bv_len] ) != 0 ) {
|
|
|
|
usage( argv[0], 'l' );
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf( types[c].buf, sizeof( aloops ), "%d", n );
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_charray_free( l );
|
|
|
|
|
|
|
|
} else if ( lutil_atoi( &loops, optarg ) != 0 ) {
|
|
|
|
usage( argv[0], 'l' );
|
2006-03-04 00:02:34 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L': /* the number of outerloops per client */
|
|
|
|
outerloops = strdup( optarg );
|
2005-04-21 00:16:39 +08:00
|
|
|
break;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2006-11-19 02:25:46 +08:00
|
|
|
case 'N':
|
|
|
|
nobind++;
|
|
|
|
break;
|
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
case 'P': /* prog directory */
|
|
|
|
progdir = strdup( optarg );
|
1999-02-15 18:49:20 +08:00
|
|
|
break;
|
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
case 'p': /* the servers port number */
|
|
|
|
port = strdup( optarg );
|
1999-02-22 19:28:01 +08:00
|
|
|
break;
|
|
|
|
|
2005-08-19 15:27:32 +08:00
|
|
|
case 'r': /* the number of retries in case of error */
|
2005-04-21 00:16:39 +08:00
|
|
|
retries = strdup( optarg );
|
|
|
|
break;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2005-08-19 15:27:32 +08:00
|
|
|
case 't': /* the delay in seconds between each retry */
|
|
|
|
delay = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
case 'w': /* the managers passwd */
|
|
|
|
passwd = ArgDup( optarg );
|
2006-07-02 02:22:43 +08:00
|
|
|
memset( optarg, '*', strlen( optarg ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'W':
|
|
|
|
pw_ask++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'y':
|
|
|
|
pw_file = optarg;
|
2005-04-21 00:16:39 +08:00
|
|
|
break;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
default:
|
2006-11-19 02:25:46 +08:00
|
|
|
usage( argv[0], '\0' );
|
2005-04-21 00:16:39 +08:00
|
|
|
break;
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-23 19:55:59 +08:00
|
|
|
if (( dirname == NULL ) || ( port == NULL && uri == NULL ) ||
|
1999-02-22 19:28:01 +08:00
|
|
|
( manager == NULL ) || ( passwd == NULL ) || ( progdir == NULL ))
|
2006-12-04 05:34:24 +08:00
|
|
|
{
|
2006-11-19 02:25:46 +08:00
|
|
|
usage( argv[0], '\0' );
|
2006-12-04 05:34:24 +08:00
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2002-05-17 09:36:35 +08:00
|
|
|
#ifdef HAVE_WINSOCK
|
|
|
|
children = malloc( maxkids * sizeof(HANDLE) );
|
|
|
|
#endif
|
1999-02-15 18:49:20 +08:00
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2003-02-22 20:01:59 +08:00
|
|
|
/* look for search, read, modrdn, and add/delete files */
|
1999-02-15 18:49:20 +08:00
|
|
|
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;
|
2003-02-22 20:01:59 +08:00
|
|
|
} else if ( !strcasecmp( file->d_name, TMODRDNFILE )) {
|
2006-11-19 02:25:46 +08:00
|
|
|
nfile = get_file_name( dirname, file->d_name );
|
2003-02-22 20:01:59 +08:00
|
|
|
continue;
|
2004-08-28 01:07:18 +08:00
|
|
|
} else if ( !strcasecmp( file->d_name, TMODIFYFILE )) {
|
2006-11-19 02:25:46 +08:00
|
|
|
mfile = get_file_name( dirname, file->d_name );
|
2004-08-28 01:07:18 +08:00
|
|
|
continue;
|
1999-02-15 18:49:20 +08:00
|
|
|
} else if ( !strncasecmp( file->d_name, TADDFILE, strlen( TADDFILE ))
|
|
|
|
&& ( anum < MAXREQS )) {
|
|
|
|
afiles[anum++] = get_file_name( dirname, file->d_name );
|
|
|
|
continue;
|
2006-01-09 22:21:33 +08:00
|
|
|
} else if ( !strcasecmp( file->d_name, TBINDFILE )) {
|
|
|
|
bfile = get_file_name( dirname, file->d_name );
|
|
|
|
continue;
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-04 13:06:49 +08:00
|
|
|
closedir( datadir );
|
|
|
|
|
2006-07-02 02:22:43 +08:00
|
|
|
if ( pw_ask ) {
|
|
|
|
passwd = getpassphrase( _("Enter LDAP Password: ") );
|
|
|
|
|
|
|
|
} else if ( pw_file ) {
|
|
|
|
struct berval pw;
|
|
|
|
|
|
|
|
if ( lutil_get_filed_password( pw_file, &pw ) ) {
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
passwd = pw.bv_val;
|
|
|
|
}
|
|
|
|
|
2007-08-21 02:03:44 +08:00
|
|
|
if ( !sfile && !rfile && !nfile && !mfile && !bfile && !anum ) {
|
|
|
|
fprintf( stderr, "no data files found.\n" );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
/* look for search requests */
|
|
|
|
if ( sfile ) {
|
2007-08-14 00:20:24 +08:00
|
|
|
snum = get_search_filters( sfile, sreqs, sattrs, sbase, slud );
|
2007-08-21 02:03:44 +08:00
|
|
|
if ( snum < 0 ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"unable to parse file \"%s\" line %d\n",
|
|
|
|
sfile, -2*(snum + 1));
|
2007-08-16 19:34:55 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* look for read requests */
|
|
|
|
if ( rfile ) {
|
2006-03-28 08:14:11 +08:00
|
|
|
rnum = get_read_entries( rfile, rreqs, rflts );
|
2007-08-21 02:03:44 +08:00
|
|
|
if ( rnum < 0 ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"unable to parse file \"%s\" line %d\n",
|
|
|
|
rfile, -2*(rnum + 1) );
|
2007-08-16 19:34:55 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
2003-02-22 20:01:59 +08:00
|
|
|
/* look for modrdn requests */
|
2006-11-19 02:25:46 +08:00
|
|
|
if ( nfile ) {
|
|
|
|
nnum = get_read_entries( nfile, nreqs, NULL );
|
2007-08-21 02:03:44 +08:00
|
|
|
if ( nnum < 0 ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"unable to parse file \"%s\" line %d\n",
|
|
|
|
nfile, -2*(nnum + 1) );
|
2007-08-16 19:34:55 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
2003-02-22 20:01:59 +08:00
|
|
|
}
|
2006-01-09 22:21:33 +08:00
|
|
|
|
2004-08-28 01:07:18 +08:00
|
|
|
/* look for modify requests */
|
2006-11-19 02:25:46 +08:00
|
|
|
if ( mfile ) {
|
2007-08-14 00:20:24 +08:00
|
|
|
mnum = get_search_filters( mfile, mreqs, NULL, mdn, NULL );
|
2007-08-21 02:03:44 +08:00
|
|
|
if ( mnum < 0 ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"unable to parse file \"%s\" line %d\n",
|
|
|
|
mfile, -2*(mnum + 1) );
|
2007-08-16 19:34:55 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
2004-08-28 01:07:18 +08:00
|
|
|
}
|
2003-02-22 20:01:59 +08:00
|
|
|
|
2006-01-09 22:21:33 +08:00
|
|
|
/* look for bind requests */
|
|
|
|
if ( bfile ) {
|
2007-08-14 00:20:24 +08:00
|
|
|
bnum = get_search_filters( bfile, bcreds, battrs, breqs, NULL );
|
2007-08-21 02:03:44 +08:00
|
|
|
if ( bnum < 0 ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"unable to parse file \"%s\" line %d\n",
|
|
|
|
bfile, -2*(bnum + 1) );
|
2007-08-16 19:34:55 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
2006-01-09 22:21:33 +08:00
|
|
|
}
|
|
|
|
|
2006-01-22 00:27:15 +08:00
|
|
|
/* setup friendly option */
|
|
|
|
|
|
|
|
switch ( friendly ) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
friendlyOpt = "-F";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* NOTE: right now we don't need it more than twice */
|
|
|
|
case 2:
|
|
|
|
friendlyOpt = "-FF";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-11-19 02:25:46 +08:00
|
|
|
if ( sloops[0] == '\0' ) snprintf( sloops, sizeof( sloops ), "%d", 10 * loops );
|
|
|
|
if ( rloops[0] == '\0' ) snprintf( rloops, sizeof( rloops ), "%d", 20 * loops );
|
|
|
|
if ( aloops[0] == '\0' ) snprintf( aloops, sizeof( aloops ), "%d", loops );
|
|
|
|
if ( nloops[0] == '\0' ) snprintf( nloops, sizeof( nloops ), "%d", loops );
|
|
|
|
if ( mloops[0] == '\0' ) snprintf( mloops, sizeof( mloops ), "%d", loops );
|
|
|
|
if ( bloops[0] == '\0' ) snprintf( bloops, sizeof( bloops ), "%d", 20 * loops );
|
2006-03-04 00:02:34 +08:00
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
/*
|
|
|
|
* generate the search clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
sanum = 0;
|
2002-07-24 02:31:42 +08:00
|
|
|
snprintf( scmd, sizeof scmd, "%s" LDAP_DIRSEP SEARCHCMD,
|
|
|
|
progdir );
|
1999-02-15 18:49:20 +08:00
|
|
|
sargs[sanum++] = scmd;
|
2003-02-13 16:02:40 +08:00
|
|
|
if ( uri ) {
|
|
|
|
sargs[sanum++] = "-H";
|
|
|
|
sargs[sanum++] = uri;
|
|
|
|
} else {
|
|
|
|
sargs[sanum++] = "-h";
|
|
|
|
sargs[sanum++] = host;
|
|
|
|
sargs[sanum++] = "-p";
|
|
|
|
sargs[sanum++] = port;
|
|
|
|
}
|
2004-09-05 02:31:43 +08:00
|
|
|
sargs[sanum++] = "-D";
|
|
|
|
sargs[sanum++] = manager;
|
|
|
|
sargs[sanum++] = "-w";
|
|
|
|
sargs[sanum++] = passwd;
|
1999-02-15 18:49:20 +08:00
|
|
|
sargs[sanum++] = "-l";
|
2006-03-04 00:02:34 +08:00
|
|
|
sargs[sanum++] = sloops;
|
|
|
|
sargs[sanum++] = "-L";
|
|
|
|
sargs[sanum++] = outerloops;
|
2005-04-21 00:16:39 +08:00
|
|
|
sargs[sanum++] = "-r";
|
|
|
|
sargs[sanum++] = retries;
|
2005-08-19 15:27:32 +08:00
|
|
|
sargs[sanum++] = "-t";
|
|
|
|
sargs[sanum++] = delay;
|
2006-03-23 08:19:09 +08:00
|
|
|
if ( friendly ) {
|
|
|
|
sargs[sanum++] = friendlyOpt;
|
|
|
|
}
|
2006-03-25 18:13:30 +08:00
|
|
|
if ( chaserefs ) {
|
|
|
|
sargs[sanum++] = "-C";
|
|
|
|
}
|
2006-03-28 08:14:11 +08:00
|
|
|
if ( noattrs ) {
|
|
|
|
sargs[sanum++] = "-A";
|
|
|
|
}
|
2006-11-19 02:25:46 +08:00
|
|
|
if ( nobind ) {
|
|
|
|
sargs[sanum++] = "-N";
|
|
|
|
}
|
2006-06-09 17:30:36 +08:00
|
|
|
if ( ignore ) {
|
|
|
|
sargs[sanum++] = "-i";
|
|
|
|
sargs[sanum++] = ignore;
|
|
|
|
}
|
2003-09-23 19:55:59 +08:00
|
|
|
sargs[sanum++] = "-b";
|
|
|
|
sargs[sanum++] = NULL; /* will hold the search base */
|
2007-08-14 00:20:24 +08:00
|
|
|
sargs[sanum++] = "-s";
|
|
|
|
sargs[sanum++] = NULL; /* will hold the search scope */
|
1999-02-15 18:49:20 +08:00
|
|
|
sargs[sanum++] = "-f";
|
|
|
|
sargs[sanum++] = NULL; /* will hold the search request */
|
2006-03-25 16:10:31 +08:00
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
sargs[sanum++] = NULL;
|
2007-08-14 00:20:24 +08:00
|
|
|
sargs[sanum++] = NULL; /* might hold the "attr" request */
|
|
|
|
sextra_args += 2;
|
2006-03-25 16:10:31 +08:00
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
sargs[sanum] = NULL;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* generate the read clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
ranum = 0;
|
2002-07-24 02:31:42 +08:00
|
|
|
snprintf( rcmd, sizeof rcmd, "%s" LDAP_DIRSEP READCMD,
|
|
|
|
progdir );
|
1999-02-15 18:49:20 +08:00
|
|
|
rargs[ranum++] = rcmd;
|
2003-02-13 16:02:40 +08:00
|
|
|
if ( uri ) {
|
|
|
|
rargs[ranum++] = "-H";
|
|
|
|
rargs[ranum++] = uri;
|
|
|
|
} else {
|
|
|
|
rargs[ranum++] = "-h";
|
|
|
|
rargs[ranum++] = host;
|
|
|
|
rargs[ranum++] = "-p";
|
|
|
|
rargs[ranum++] = port;
|
|
|
|
}
|
2006-03-28 08:14:11 +08:00
|
|
|
rargs[ranum++] = "-D";
|
|
|
|
rargs[ranum++] = manager;
|
|
|
|
rargs[ranum++] = "-w";
|
|
|
|
rargs[ranum++] = passwd;
|
1999-02-15 18:49:20 +08:00
|
|
|
rargs[ranum++] = "-l";
|
2006-03-04 00:02:34 +08:00
|
|
|
rargs[ranum++] = rloops;
|
|
|
|
rargs[ranum++] = "-L";
|
|
|
|
rargs[ranum++] = outerloops;
|
2005-04-21 00:16:39 +08:00
|
|
|
rargs[ranum++] = "-r";
|
|
|
|
rargs[ranum++] = retries;
|
2005-08-19 15:27:32 +08:00
|
|
|
rargs[ranum++] = "-t";
|
|
|
|
rargs[ranum++] = delay;
|
2006-03-23 08:19:09 +08:00
|
|
|
if ( friendly ) {
|
|
|
|
rargs[ranum++] = friendlyOpt;
|
|
|
|
}
|
2006-03-25 18:13:30 +08:00
|
|
|
if ( chaserefs ) {
|
|
|
|
rargs[ranum++] = "-C";
|
|
|
|
}
|
2006-03-28 08:14:11 +08:00
|
|
|
if ( noattrs ) {
|
|
|
|
rargs[ranum++] = "-A";
|
|
|
|
}
|
2006-06-09 17:30:36 +08:00
|
|
|
if ( ignore ) {
|
|
|
|
rargs[ranum++] = "-i";
|
|
|
|
rargs[ranum++] = ignore;
|
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
rargs[ranum++] = "-e";
|
|
|
|
rargs[ranum++] = NULL; /* will hold the read entry */
|
2006-03-28 08:14:11 +08:00
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
rargs[ranum++] = NULL;
|
2007-08-14 00:20:24 +08:00
|
|
|
rargs[ranum++] = NULL; /* might hold the filter arg */
|
|
|
|
rextra_args += 2;
|
2006-03-28 08:14:11 +08:00
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
rargs[ranum] = NULL;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2003-02-22 20:01:59 +08:00
|
|
|
/*
|
|
|
|
* generate the modrdn clients
|
|
|
|
*/
|
|
|
|
|
2006-11-19 02:25:46 +08:00
|
|
|
nanum = 0;
|
|
|
|
snprintf( ncmd, sizeof ncmd, "%s" LDAP_DIRSEP MODRDNCMD,
|
|
|
|
progdir );
|
|
|
|
nargs[nanum++] = ncmd;
|
|
|
|
if ( uri ) {
|
|
|
|
nargs[nanum++] = "-H";
|
|
|
|
nargs[nanum++] = uri;
|
|
|
|
} else {
|
|
|
|
nargs[nanum++] = "-h";
|
|
|
|
nargs[nanum++] = host;
|
|
|
|
nargs[nanum++] = "-p";
|
|
|
|
nargs[nanum++] = port;
|
|
|
|
}
|
|
|
|
nargs[nanum++] = "-D";
|
|
|
|
nargs[nanum++] = manager;
|
|
|
|
nargs[nanum++] = "-w";
|
|
|
|
nargs[nanum++] = passwd;
|
|
|
|
nargs[nanum++] = "-l";
|
|
|
|
nargs[nanum++] = nloops;
|
|
|
|
nargs[nanum++] = "-L";
|
|
|
|
nargs[nanum++] = outerloops;
|
|
|
|
nargs[nanum++] = "-r";
|
|
|
|
nargs[nanum++] = retries;
|
|
|
|
nargs[nanum++] = "-t";
|
|
|
|
nargs[nanum++] = delay;
|
|
|
|
if ( friendly ) {
|
|
|
|
nargs[nanum++] = friendlyOpt;
|
|
|
|
}
|
|
|
|
if ( chaserefs ) {
|
|
|
|
nargs[nanum++] = "-C";
|
|
|
|
}
|
|
|
|
if ( ignore ) {
|
|
|
|
nargs[nanum++] = "-i";
|
|
|
|
nargs[nanum++] = ignore;
|
|
|
|
}
|
|
|
|
nargs[nanum++] = "-e";
|
|
|
|
nargs[nanum++] = NULL; /* will hold the modrdn entry */
|
2007-08-14 00:20:24 +08:00
|
|
|
nargs[nanum] = NULL;
|
2006-11-19 02:25:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* generate the modify clients
|
|
|
|
*/
|
|
|
|
|
2003-02-22 20:01:59 +08:00
|
|
|
manum = 0;
|
2006-11-19 02:25:46 +08:00
|
|
|
snprintf( mcmd, sizeof mcmd, "%s" LDAP_DIRSEP MODIFYCMD,
|
2003-02-22 20:01:59 +08:00
|
|
|
progdir );
|
|
|
|
margs[manum++] = mcmd;
|
|
|
|
if ( uri ) {
|
|
|
|
margs[manum++] = "-H";
|
|
|
|
margs[manum++] = uri;
|
|
|
|
} else {
|
|
|
|
margs[manum++] = "-h";
|
|
|
|
margs[manum++] = host;
|
|
|
|
margs[manum++] = "-p";
|
|
|
|
margs[manum++] = port;
|
|
|
|
}
|
|
|
|
margs[manum++] = "-D";
|
|
|
|
margs[manum++] = manager;
|
|
|
|
margs[manum++] = "-w";
|
|
|
|
margs[manum++] = passwd;
|
|
|
|
margs[manum++] = "-l";
|
2006-03-04 00:02:34 +08:00
|
|
|
margs[manum++] = mloops;
|
|
|
|
margs[manum++] = "-L";
|
|
|
|
margs[manum++] = outerloops;
|
2005-04-21 00:16:39 +08:00
|
|
|
margs[manum++] = "-r";
|
|
|
|
margs[manum++] = retries;
|
2005-08-19 15:27:32 +08:00
|
|
|
margs[manum++] = "-t";
|
|
|
|
margs[manum++] = delay;
|
2005-11-05 00:17:32 +08:00
|
|
|
if ( friendly ) {
|
2006-01-22 00:27:15 +08:00
|
|
|
margs[manum++] = friendlyOpt;
|
2005-11-05 00:17:32 +08:00
|
|
|
}
|
2006-03-25 18:13:30 +08:00
|
|
|
if ( chaserefs ) {
|
|
|
|
margs[manum++] = "-C";
|
|
|
|
}
|
2006-06-09 17:30:36 +08:00
|
|
|
if ( ignore ) {
|
|
|
|
margs[manum++] = "-i";
|
|
|
|
margs[manum++] = ignore;
|
|
|
|
}
|
2003-02-22 20:01:59 +08:00
|
|
|
margs[manum++] = "-e";
|
2006-11-19 02:25:46 +08:00
|
|
|
margs[manum++] = NULL; /* will hold the modify entry */
|
|
|
|
margs[manum++] = "-a";;
|
|
|
|
margs[manum++] = NULL; /* will hold the ava */
|
2007-08-14 00:20:24 +08:00
|
|
|
margs[manum] = NULL;
|
2003-02-22 20:01:59 +08:00
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
/*
|
|
|
|
* generate the add/delete clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
aanum = 0;
|
2002-07-24 02:31:42 +08:00
|
|
|
snprintf( acmd, sizeof acmd, "%s" LDAP_DIRSEP ADDCMD,
|
|
|
|
progdir );
|
1999-02-15 18:49:20 +08:00
|
|
|
aargs[aanum++] = acmd;
|
2003-02-13 16:02:40 +08:00
|
|
|
if ( uri ) {
|
|
|
|
aargs[aanum++] = "-H";
|
|
|
|
aargs[aanum++] = uri;
|
|
|
|
} else {
|
|
|
|
aargs[aanum++] = "-h";
|
|
|
|
aargs[aanum++] = host;
|
|
|
|
aargs[aanum++] = "-p";
|
|
|
|
aargs[aanum++] = port;
|
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
aargs[aanum++] = "-D";
|
|
|
|
aargs[aanum++] = manager;
|
|
|
|
aargs[aanum++] = "-w";
|
|
|
|
aargs[aanum++] = passwd;
|
|
|
|
aargs[aanum++] = "-l";
|
2006-03-04 00:02:34 +08:00
|
|
|
aargs[aanum++] = aloops;
|
|
|
|
aargs[aanum++] = "-L";
|
|
|
|
aargs[aanum++] = outerloops;
|
2005-04-21 00:16:39 +08:00
|
|
|
aargs[aanum++] = "-r";
|
|
|
|
aargs[aanum++] = retries;
|
2005-08-19 15:27:32 +08:00
|
|
|
aargs[aanum++] = "-t";
|
|
|
|
aargs[aanum++] = delay;
|
2005-11-05 00:17:32 +08:00
|
|
|
if ( friendly ) {
|
2006-01-22 00:27:15 +08:00
|
|
|
aargs[aanum++] = friendlyOpt;
|
2005-11-05 00:17:32 +08:00
|
|
|
}
|
2006-03-25 18:13:30 +08:00
|
|
|
if ( chaserefs ) {
|
|
|
|
aargs[aanum++] = "-C";
|
|
|
|
}
|
2006-06-09 17:30:36 +08:00
|
|
|
if ( ignore ) {
|
|
|
|
aargs[aanum++] = "-i";
|
|
|
|
aargs[aanum++] = ignore;
|
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
aargs[aanum++] = "-f";
|
|
|
|
aargs[aanum++] = NULL; /* will hold the add data file */
|
2007-08-14 00:20:24 +08:00
|
|
|
aargs[aanum] = NULL;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2006-01-09 22:21:33 +08:00
|
|
|
/*
|
|
|
|
* generate the bind clients
|
|
|
|
*/
|
|
|
|
|
|
|
|
banum = 0;
|
|
|
|
snprintf( bcmd, sizeof bcmd, "%s" LDAP_DIRSEP BINDCMD,
|
|
|
|
progdir );
|
|
|
|
bargs[banum++] = bcmd;
|
2006-12-02 18:25:56 +08:00
|
|
|
if ( !noinit ) {
|
|
|
|
bargs[banum++] = "-I"; /* init on each bind */
|
|
|
|
}
|
2006-01-09 22:21:33 +08:00
|
|
|
if ( uri ) {
|
|
|
|
bargs[banum++] = "-H";
|
|
|
|
bargs[banum++] = uri;
|
|
|
|
} else {
|
|
|
|
bargs[banum++] = "-h";
|
|
|
|
bargs[banum++] = host;
|
|
|
|
bargs[banum++] = "-p";
|
|
|
|
bargs[banum++] = port;
|
|
|
|
}
|
|
|
|
bargs[banum++] = "-l";
|
2006-03-04 00:02:34 +08:00
|
|
|
bargs[banum++] = bloops;
|
|
|
|
bargs[banum++] = "-L";
|
|
|
|
bargs[banum++] = outerloops;
|
2006-01-09 22:21:33 +08:00
|
|
|
#if 0
|
|
|
|
bargs[banum++] = "-r";
|
|
|
|
bargs[banum++] = retries;
|
|
|
|
bargs[banum++] = "-t";
|
|
|
|
bargs[banum++] = delay;
|
|
|
|
#endif
|
|
|
|
if ( friendly ) {
|
2006-01-22 00:27:15 +08:00
|
|
|
bargs[banum++] = friendlyOpt;
|
2006-01-09 22:21:33 +08:00
|
|
|
}
|
2006-03-25 18:13:30 +08:00
|
|
|
if ( chaserefs ) {
|
|
|
|
bargs[banum++] = "-C";
|
|
|
|
}
|
2006-06-09 17:30:36 +08:00
|
|
|
if ( ignore ) {
|
|
|
|
bargs[banum++] = "-i";
|
|
|
|
bargs[banum++] = ignore;
|
|
|
|
}
|
2006-11-19 02:25:46 +08:00
|
|
|
if ( nextra ) {
|
|
|
|
bargs[banum++] = "-B";
|
|
|
|
bargs_extra = &bargs[banum++];
|
|
|
|
}
|
2006-01-09 22:21:33 +08:00
|
|
|
bargs[banum++] = "-D";
|
|
|
|
bargs[banum++] = NULL;
|
|
|
|
bargs[banum++] = "-w";
|
|
|
|
bargs[banum++] = NULL;
|
2007-08-14 00:20:24 +08:00
|
|
|
bargs[banum] = NULL;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2006-03-28 19:51:40 +08:00
|
|
|
#define DOREQ(n,j) ((n) && ((maxkids > (n)) ? ((j) < maxkids ) : ((j) < (n))))
|
|
|
|
|
2006-01-09 22:21:33 +08:00
|
|
|
for ( j = 0; j < MAXREQS; j++ ) {
|
2007-08-14 00:20:24 +08:00
|
|
|
/* search */
|
2006-03-28 19:51:40 +08:00
|
|
|
if ( DOREQ( snum, j ) ) {
|
2006-03-28 08:14:11 +08:00
|
|
|
int jj = j % snum;
|
2007-08-14 00:20:24 +08:00
|
|
|
int x = sanum - sextra_args;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
/* base */
|
|
|
|
if ( sbase[jj] != NULL ) {
|
|
|
|
sargs[sanum - 7] = sbase[jj];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
sargs[sanum - 7] = slud[jj]->lud_dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scope */
|
|
|
|
if ( slud[jj] != NULL ) {
|
|
|
|
sargs[sanum - 5] = (char *)ldap_pvt_scope2str( slud[jj]->lud_scope );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
sargs[sanum - 5] = "sub";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* filter */
|
|
|
|
if ( sreqs[jj] != NULL ) {
|
|
|
|
sargs[sanum - 3] = sreqs[jj];
|
|
|
|
|
|
|
|
} else if ( slud[jj]->lud_filter != NULL ) {
|
|
|
|
sargs[sanum - 3] = slud[jj]->lud_filter;
|
2006-03-25 16:10:31 +08:00
|
|
|
|
|
|
|
} else {
|
2007-08-14 00:20:24 +08:00
|
|
|
sargs[sanum - 3] = "(objectClass=*)";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* extras */
|
|
|
|
sargs[x] = NULL;
|
|
|
|
|
|
|
|
/* attr */
|
|
|
|
if ( sattrs[jj] != NULL ) {
|
|
|
|
sargs[x++] = "-a";
|
|
|
|
sargs[x++] = sattrs[jj];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attrs */
|
|
|
|
if ( slud[jj] != NULL && slud[jj]->lud_attrs != NULL ) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; slud[jj]->lud_attrs[ i ] != NULL && x + i < MAXARGS - 1; i++ ) {
|
|
|
|
sargs[x + i] = slud[jj]->lud_attrs[ i ];
|
|
|
|
}
|
|
|
|
sargs[x + i] = NULL;
|
2006-03-25 16:10:31 +08:00
|
|
|
}
|
2007-08-14 00:20:24 +08:00
|
|
|
|
2002-05-17 09:44:02 +08:00
|
|
|
fork_child( scmd, sargs );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
/* read */
|
2006-03-28 19:51:40 +08:00
|
|
|
if ( DOREQ( rnum, j ) ) {
|
2006-03-28 08:14:11 +08:00
|
|
|
int jj = j % rnum;
|
2007-08-14 00:20:24 +08:00
|
|
|
int x = ranum - rextra_args;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
rargs[ranum - 3] = rreqs[jj];
|
2006-03-28 08:14:11 +08:00
|
|
|
if ( rflts[jj] != NULL ) {
|
2007-08-14 00:20:24 +08:00
|
|
|
rargs[x++] = "-f";
|
|
|
|
rargs[x++] = rflts[jj];
|
2006-03-28 08:14:11 +08:00
|
|
|
}
|
2007-08-14 00:20:24 +08:00
|
|
|
rargs[x] = NULL;
|
2006-03-28 08:14:11 +08:00
|
|
|
fork_child( rcmd, rargs );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
/* rename */
|
2006-11-19 02:25:46 +08:00
|
|
|
if ( j < nnum ) {
|
2007-08-14 00:20:24 +08:00
|
|
|
nargs[nanum - 1] = nreqs[j];
|
2006-11-19 02:25:46 +08:00
|
|
|
fork_child( ncmd, nargs );
|
|
|
|
}
|
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
/* modify */
|
2006-04-01 05:35:56 +08:00
|
|
|
if ( j < mnum ) {
|
2007-08-14 00:20:24 +08:00
|
|
|
margs[manum - 3] = mdn[j];
|
|
|
|
margs[manum - 1] = mreqs[j];
|
2003-02-22 20:01:59 +08:00
|
|
|
fork_child( mcmd, margs );
|
2004-08-28 01:07:18 +08:00
|
|
|
}
|
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
/* add/delete */
|
2006-04-01 05:35:56 +08:00
|
|
|
if ( j < anum ) {
|
2007-08-14 00:20:24 +08:00
|
|
|
aargs[aanum - 1] = afiles[j];
|
2002-05-17 09:44:02 +08:00
|
|
|
fork_child( acmd, aargs );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
/* bind */
|
2006-03-28 19:51:40 +08:00
|
|
|
if ( DOREQ( bnum, j ) ) {
|
2006-03-28 08:14:11 +08:00
|
|
|
int jj = j % bnum;
|
2006-01-09 22:21:33 +08:00
|
|
|
|
2006-11-19 02:25:46 +08:00
|
|
|
if ( nextra ) {
|
|
|
|
int n = ((double)nextra)*rand()/(RAND_MAX + 1.0);
|
|
|
|
extra_t *e;
|
|
|
|
|
|
|
|
for ( e = extra; n-- > 0; e = e->next )
|
|
|
|
;
|
|
|
|
*bargs_extra = e->action;
|
|
|
|
}
|
|
|
|
|
2006-05-15 01:18:55 +08:00
|
|
|
if ( battrs[jj] != NULL ) {
|
2007-08-14 00:20:24 +08:00
|
|
|
bargs[banum - 3] = manager ? manager : "";
|
|
|
|
bargs[banum - 1] = passwd ? passwd : "";
|
|
|
|
|
2007-09-27 07:08:38 +08:00
|
|
|
bargs[banum + 0] = "-b";
|
|
|
|
bargs[banum + 1] = breqs[jj];
|
|
|
|
bargs[banum + 2] = "-f";
|
|
|
|
bargs[banum + 3] = bcreds[jj];
|
|
|
|
bargs[banum + 4] = "-a";
|
|
|
|
bargs[banum + 5] = battrs[jj];
|
2007-10-03 15:02:28 +08:00
|
|
|
bargs[banum + 6] = NULL;
|
2007-08-14 00:20:24 +08:00
|
|
|
|
2006-07-02 00:45:44 +08:00
|
|
|
} else {
|
2007-08-14 00:20:24 +08:00
|
|
|
bargs[banum - 3] = breqs[jj];
|
|
|
|
bargs[banum - 1] = bcreds[jj];
|
|
|
|
bargs[banum] = NULL;
|
2006-05-15 01:18:55 +08:00
|
|
|
}
|
2006-06-09 17:30:36 +08:00
|
|
|
|
2006-01-09 22:21:33 +08:00
|
|
|
fork_child( bcmd, bargs );
|
2007-08-14 00:20:24 +08:00
|
|
|
bargs[banum] = NULL;
|
2006-01-09 22:21:33 +08:00
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
2002-07-24 02:31:42 +08:00
|
|
|
snprintf( buf, sizeof buf, "%s" LDAP_DIRSEP "%s",
|
|
|
|
dirname, filename );
|
1999-02-15 18:49:20 +08:00
|
|
|
return( strdup( buf ));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2007-08-14 00:20:24 +08:00
|
|
|
get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[], LDAPURLDesc *luds[] )
|
1999-02-15 18:49:20 +08:00
|
|
|
{
|
|
|
|
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 ))) {
|
2007-08-14 00:20:24 +08:00
|
|
|
char *nl;
|
|
|
|
int got_URL = 0;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
|
|
|
|
*nl = '\0';
|
2007-08-14 00:20:24 +08:00
|
|
|
|
|
|
|
if ( luds ) luds[filter] = NULL;
|
|
|
|
|
|
|
|
if ( luds && strncmp( line, "ldap:///", STRLENOF( "ldap:///" ) ) == 0 ) {
|
|
|
|
LDAPURLDesc *lud;
|
|
|
|
|
|
|
|
got_URL = 1;
|
|
|
|
bases[filter] = NULL;
|
|
|
|
if ( ldap_url_parse( line, &lud ) != LDAP_URL_SUCCESS ) {
|
2007-08-21 02:03:44 +08:00
|
|
|
filter = -filter - 1;
|
2007-08-16 19:34:55 +08:00
|
|
|
break;
|
2007-08-14 00:20:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( lud->lud_dn == NULL || lud->lud_exts != NULL ) {
|
2007-08-21 02:03:44 +08:00
|
|
|
filter = -filter - 1;
|
2007-08-21 06:24:48 +08:00
|
|
|
ldap_free_urldesc( lud );
|
2007-08-16 19:34:55 +08:00
|
|
|
break;
|
2007-08-14 00:20:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
luds[filter] = lud;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
bases[filter] = ArgDup( line );
|
|
|
|
}
|
2003-09-23 19:55:59 +08:00
|
|
|
fgets( line, BUFSIZ, fp );
|
|
|
|
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
|
|
|
|
*nl = '\0';
|
|
|
|
|
2006-03-25 16:10:31 +08:00
|
|
|
filters[filter] = ArgDup( line );
|
|
|
|
if ( attrs ) {
|
|
|
|
if ( filters[filter][0] == '+') {
|
|
|
|
char *sep = strchr( filters[filter], ':' );
|
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
attrs[ filter ] = &filters[ filter ][ 1 ];
|
2006-03-25 16:10:31 +08:00
|
|
|
if ( sep != NULL ) {
|
|
|
|
sep[ 0 ] = '\0';
|
|
|
|
/* NOTE: don't free this! */
|
|
|
|
filters[ filter ] = &sep[ 1 ];
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2007-08-14 00:20:24 +08:00
|
|
|
attrs[ filter ] = NULL;
|
2006-03-25 16:10:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
filter++;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
fclose( fp );
|
|
|
|
}
|
|
|
|
|
2007-08-16 19:34:55 +08:00
|
|
|
return filter;
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2006-03-28 08:14:11 +08:00
|
|
|
get_read_entries( char *filename, char *entries[], char *filters[] )
|
1999-02-15 18:49:20 +08:00
|
|
|
{
|
|
|
|
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';
|
2006-03-28 08:14:11 +08:00
|
|
|
if ( filters != NULL && line[0] == '+' ) {
|
|
|
|
LDAPURLDesc *lud;
|
|
|
|
|
|
|
|
if ( ldap_url_parse( &line[1], &lud ) != LDAP_URL_SUCCESS ) {
|
2007-08-21 02:03:44 +08:00
|
|
|
entry = -entry - 1;
|
2006-03-31 17:18:38 +08:00
|
|
|
break;
|
2006-03-28 08:14:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( lud->lud_dn == NULL || lud->lud_dn[ 0 ] == '\0' ) {
|
2006-03-31 17:18:38 +08:00
|
|
|
ldap_free_urldesc( lud );
|
2007-08-21 02:03:44 +08:00
|
|
|
entry = -entry - 1;
|
2006-03-31 17:18:38 +08:00
|
|
|
break;
|
2006-03-28 08:14:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
entries[entry] = ArgDup( lud->lud_dn );
|
|
|
|
|
|
|
|
if ( lud->lud_filter ) {
|
|
|
|
filters[entry] = ArgDup( lud->lud_filter );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
filters[entry] = ArgDup( "(objectClass=*)" );
|
|
|
|
}
|
2006-03-31 17:18:38 +08:00
|
|
|
ldap_free_urldesc( lud );
|
2006-03-28 08:14:11 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
entries[entry] = ArgDup( line );
|
|
|
|
}
|
|
|
|
|
|
|
|
entry++;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
fclose( fp );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( entry );
|
|
|
|
}
|
|
|
|
|
2002-05-17 09:36:35 +08:00
|
|
|
#ifndef HAVE_WINSOCK
|
1999-02-15 18:49:20 +08:00
|
|
|
static void
|
2002-07-26 21:29:37 +08:00
|
|
|
fork_child( char *prog, char **args )
|
1999-02-15 18:49:20 +08:00
|
|
|
{
|
2006-11-19 02:25:46 +08:00
|
|
|
/* note: obscures global pid var; intended */
|
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 */
|
2002-07-26 21:29:37 +08:00
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
/* The __LIBASCII execvp only handles ASCII "prog",
|
|
|
|
* we still need to translate the arg vec ourselves.
|
|
|
|
*/
|
|
|
|
{ char *arg2[MAXREQS];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; args[i]; i++) {
|
|
|
|
arg2[i] = ArgDup(args[i]);
|
|
|
|
__atoe(arg2[i]);
|
|
|
|
}
|
|
|
|
arg2[i] = NULL;
|
|
|
|
args = arg2; }
|
|
|
|
#endif
|
1999-02-15 18:49:20 +08:00
|
|
|
execvp( prog, args );
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "execvp", NULL );
|
2007-10-03 15:02:28 +08:00
|
|
|
{ int i;
|
|
|
|
for (i=0; args[i]; i++);
|
|
|
|
fprintf(stderr,"%d args\n", i);
|
|
|
|
for (i=0; args[i]; i++)
|
|
|
|
fprintf(stderr,"%d %s\n", i, args[i]);
|
|
|
|
}
|
|
|
|
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case -1: /* trouble */
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "fork", NULL );
|
1999-02-15 18:49:20 +08:00
|
|
|
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--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-05-17 09:36:35 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
static void
|
|
|
|
wait4kids( int nkidval )
|
|
|
|
{
|
|
|
|
int rc, i;
|
|
|
|
|
|
|
|
while ( nkids >= nkidval ) {
|
|
|
|
rc = WaitForMultipleObjects( nkids, children, FALSE, INFINITE );
|
|
|
|
for ( i=rc - WAIT_OBJECT_0; i<nkids-1; i++)
|
|
|
|
children[i] = children[i+1];
|
|
|
|
nkids--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-07-26 21:29:37 +08:00
|
|
|
fork_child( char *prog, char **args )
|
2002-05-17 09:36:35 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
wait4kids( maxkids );
|
|
|
|
|
|
|
|
rc = _spawnvp( _P_NOWAIT, prog, args );
|
|
|
|
|
|
|
|
if ( rc == -1 ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "_spawnvp", NULL );
|
2002-05-17 09:36:35 +08:00
|
|
|
} else {
|
|
|
|
children[nkids++] = (HANDLE)rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|