use URI to configure client; enable attrlist in slapd-search

This commit is contained in:
Pierangelo Masarati 2007-08-13 16:20:24 +00:00
parent 723115d340
commit df7f9db8ac
8 changed files with 279 additions and 150 deletions

View file

@ -21,17 +21,17 @@
#include <stdio.h> #include <stdio.h>
#include <ac/stdlib.h> #include "ac/stdlib.h"
#include <ac/ctype.h> #include "ac/ctype.h"
#include <ac/param.h> #include "ac/param.h"
#include <ac/socket.h> #include "ac/socket.h"
#include <ac/string.h> #include "ac/string.h"
#include <ac/unistd.h> #include "ac/unistd.h"
#include <ac/wait.h> #include "ac/wait.h"
#include <ldap.h> #include "ldap.h"
#include <lutil.h> #include "lutil.h"
#include "slapd-common.h" #include "slapd-common.h"

View file

@ -21,21 +21,21 @@
#include <stdio.h> #include <stdio.h>
#include <ac/stdlib.h> #include "ac/stdlib.h"
#include <ac/time.h> #include "ac/time.h"
#include <ac/ctype.h> #include "ac/ctype.h"
#include <ac/param.h> #include "ac/param.h"
#include <ac/socket.h> #include "ac/socket.h"
#include <ac/string.h> #include "ac/string.h"
#include <ac/unistd.h> #include "ac/unistd.h"
#include <ac/wait.h> #include "ac/wait.h"
#include <ac/time.h> #include "ac/time.h"
#include <ldap.h> #include "ldap.h"
#include <lutil.h> #include "lutil.h"
#include <lber_pvt.h> #include "lber_pvt.h"
#include <ldap_pvt.h> #include "ldap_pvt.h"
#include "slapd-common.h" #include "slapd-common.h"

View file

@ -21,12 +21,12 @@
#include <stdio.h> #include <stdio.h>
#include <ac/stdlib.h> #include "ac/stdlib.h"
#include <ac/unistd.h> #include "ac/unistd.h"
#include <ac/string.h> #include "ac/string.h"
#include <ac/errno.h> #include "ac/errno.h"
#include <ldap.h> #include "ldap.h"
#include "ldap_pvt.h" #include "ldap_pvt.h"
#include "slapd-common.h" #include "slapd-common.h"

View file

@ -17,17 +17,17 @@
#include <stdio.h> #include <stdio.h>
#include <ac/stdlib.h> #include "ac/stdlib.h"
#include <ac/ctype.h> #include "ac/ctype.h"
#include <ac/param.h> #include "ac/param.h"
#include <ac/socket.h> #include "ac/socket.h"
#include <ac/string.h> #include "ac/string.h"
#include <ac/unistd.h> #include "ac/unistd.h"
#include <ac/wait.h> #include "ac/wait.h"
#include <ldap.h> #include "ldap.h"
#include <lutil.h> #include "lutil.h"
#include "slapd-common.h" #include "slapd-common.h"

View file

@ -21,17 +21,17 @@
#include <stdio.h> #include <stdio.h>
#include <ac/stdlib.h> #include "ac/stdlib.h"
#include <ac/ctype.h> #include "ac/ctype.h"
#include <ac/param.h> #include "ac/param.h"
#include <ac/socket.h> #include "ac/socket.h"
#include <ac/string.h> #include "ac/string.h"
#include <ac/unistd.h> #include "ac/unistd.h"
#include <ac/wait.h> #include "ac/wait.h"
#include <ldap.h> #include "ldap.h"
#include <lutil.h> #include "lutil.h"
#include "slapd-common.h" #include "slapd-common.h"

View file

@ -21,17 +21,19 @@
#include <stdio.h> #include <stdio.h>
#include <ac/stdlib.h> #include "ac/stdlib.h"
#include <ac/ctype.h> #include "ac/ctype.h"
#include <ac/param.h> #include "ac/param.h"
#include <ac/socket.h> #include "ac/socket.h"
#include <ac/string.h> #include "ac/string.h"
#include <ac/unistd.h> #include "ac/unistd.h"
#include <ac/wait.h> #include "ac/wait.h"
#include <ldap.h> #include "ldap.h"
#include <lutil.h> #include "lutil.h"
#include "ldap_pvt.h"
#include "slapd-common.h" #include "slapd-common.h"
@ -40,12 +42,13 @@
static void static void
do_read( char *uri, char *manager, struct berval *passwd, do_read( char *uri, char *manager, struct berval *passwd,
char *entry, LDAP **ld, int noattrs, int nobind, int maxloop, char *entry, LDAP **ld,
char **attrs, int noattrs, int nobind, int maxloop,
int maxretries, int delay, int force, int chaserefs ); int maxretries, int delay, int force, int chaserefs );
static void static void
do_random( char *uri, char *manager, struct berval *passwd, do_random( char *uri, char *manager, struct berval *passwd,
char *sbase, char *filter, int noattrs, int nobind, char *sbase, char *filter, char **attrs, int noattrs, int nobind,
int innerloop, int maxretries, int delay, int force, int chaserefs ); int innerloop, int maxretries, int delay, int force, int chaserefs );
static void static void
@ -66,7 +69,10 @@ usage( char *name )
"[-l <loops>] " "[-l <loops>] "
"[-L <outerloops>] " "[-L <outerloops>] "
"[-r <maxretries>] " "[-r <maxretries>] "
"[-t <delay>]\n", "[-t <delay>] "
"[-T <attrs>] "
"[<attrs>] "
"\n",
name ); name );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
@ -88,6 +94,8 @@ main( int argc, char **argv )
int delay = 0; int delay = 0;
int force = 0; int force = 0;
int chaserefs = 0; int chaserefs = 0;
char *srchattrs[] = { "1.1", NULL };
char **attrs = srchattrs;
int noattrs = 0; int noattrs = 0;
int nobind = 0; int nobind = 0;
@ -96,7 +104,7 @@ main( int argc, char **argv )
/* by default, tolerate referrals and no such object */ /* by default, tolerate referrals and no such object */
tester_ignore_str2errlist( "REFERRAL,NO_SUCH_OBJECT" ); tester_ignore_str2errlist( "REFERRAL,NO_SUCH_OBJECT" );
while ( (i = getopt( argc, argv, "ACD:e:Ff:H:h:i:L:l:p:r:t:w:" )) != EOF ) { while ( (i = getopt( argc, argv, "ACD:e:Ff:H:h:i:L:l:p:r:t:T:w:" )) != EOF ) {
switch ( i ) { switch ( i ) {
case 'A': case 'A':
noattrs++; noattrs++;
@ -174,6 +182,13 @@ main( int argc, char **argv )
} }
break; break;
case 'T':
attrs = ldap_str2charray( optarg, "," );
if ( attrs == NULL ) {
usage( argv[0] );
}
break;
default: default:
usage( argv[0] ); usage( argv[0] );
break; break;
@ -189,17 +204,22 @@ main( int argc, char **argv )
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if ( argv[optind] != NULL ) {
attrs = &argv[optind];
}
uri = tester_uri( uri, host, port ); uri = tester_uri( uri, host, port );
for ( i = 0; i < outerloops; i++ ) { for ( i = 0; i < outerloops; i++ ) {
if ( filter != NULL ) { if ( filter != NULL ) {
do_random( uri, manager, &passwd, entry, filter, do_random( uri, manager, &passwd, entry, filter, attrs,
noattrs, nobind, loops, retries, delay, force, noattrs, nobind, loops, retries, delay, force,
chaserefs ); chaserefs );
} else { } else {
do_read( uri, manager, &passwd, entry, NULL, noattrs, nobind, do_read( uri, manager, &passwd, entry, NULL, attrs,
loops, retries, delay, force, chaserefs ); noattrs, nobind, loops, retries, delay, force,
chaserefs );
} }
} }
@ -208,7 +228,7 @@ main( int argc, char **argv )
static void static void
do_random( char *uri, char *manager, struct berval *passwd, do_random( char *uri, char *manager, struct berval *passwd,
char *sbase, char *filter, int noattrs, int nobind, char *sbase, char *filter, char **srchattrs, int noattrs, int nobind,
int innerloop, int maxretries, int delay, int force, int chaserefs ) int innerloop, int maxretries, int delay, int force, int chaserefs )
{ {
LDAP *ld = NULL; LDAP *ld = NULL;
@ -288,8 +308,8 @@ do_random( char *uri, char *manager, struct berval *passwd,
int r = ((double)nvalues)*rand()/(RAND_MAX + 1.0); int r = ((double)nvalues)*rand()/(RAND_MAX + 1.0);
do_read( uri, manager, passwd, values[ r ], &ld, do_read( uri, manager, passwd, values[ r ], &ld,
noattrs, nobind, 1, maxretries, delay, force, srchattrs, noattrs, nobind, 1, maxretries,
chaserefs ); delay, force, chaserefs );
} }
free( values ); free( values );
break; break;
@ -308,12 +328,11 @@ do_random( char *uri, char *manager, struct berval *passwd,
static void static void
do_read( char *uri, char *manager, struct berval *passwd, char *entry, do_read( char *uri, char *manager, struct berval *passwd, char *entry,
LDAP **ldp, int noattrs, int nobind, int maxloop, LDAP **ldp, char **attrs, int noattrs, int nobind, int maxloop,
int maxretries, int delay, int force, int chaserefs ) int maxretries, int delay, int force, int chaserefs )
{ {
LDAP *ld = ldp ? *ldp : NULL; LDAP *ld = ldp ? *ldp : NULL;
int i = 0, do_retry = maxretries; int i = 0, do_retry = maxretries;
char *attrs[] = { "1.1", NULL };
int rc = LDAP_SUCCESS; int rc = LDAP_SUCCESS;
int version = LDAP_VERSION3; int version = LDAP_VERSION3;

View file

@ -21,17 +21,18 @@
#include <stdio.h> #include <stdio.h>
#include <ac/stdlib.h> #include "ac/stdlib.h"
#include <ac/ctype.h> #include "ac/ctype.h"
#include <ac/param.h> #include "ac/param.h"
#include <ac/socket.h> #include "ac/socket.h"
#include <ac/string.h> #include "ac/string.h"
#include <ac/unistd.h> #include "ac/unistd.h"
#include <ac/wait.h> #include "ac/wait.h"
#include <ldap.h> #include "ldap.h"
#include <lutil.h> #include "lutil.h"
#include "ldap_pvt.h"
#include "slapd-common.h" #include "slapd-common.h"
@ -40,23 +41,30 @@
static void static void
do_search( char *uri, char *manager, struct berval *passwd, do_search( char *uri, char *manager, struct berval *passwd,
char *sbase, char *filter, LDAP **ldp, int noattrs, int nobind, char *sbase, int scope, char *filter, LDAP **ldp,
char **attrs, int noattrs, int nobind,
int innerloop, int maxretries, int delay, int force, int chaserefs ); int innerloop, int maxretries, int delay, int force, int chaserefs );
static void static void
do_random( char *uri, char *manager, struct berval *passwd, do_random( char *uri, char *manager, struct berval *passwd,
char *sbase, char *filter, char *attr, int noattrs, int nobind, char *sbase, int scope, char *filter, char *attr,
char **attrs, int noattrs, int nobind,
int innerloop, int maxretries, int delay, int force, int chaserefs ); int innerloop, int maxretries, int delay, int force, int chaserefs );
static void static void
usage( char *name ) usage( char *name, char o )
{ {
if ( o != '\0' ) {
fprintf( stderr, "unknown/incorrect option \"%c\"\n", o );
}
fprintf( stderr, fprintf( stderr,
"usage: %s " "usage: %s "
"-H <uri> | ([-h <host>] -p <port>) " "-H <uri> | ([-h <host>] -p <port>) "
"-D <manager> " "-D <manager> "
"-w <passwd> " "-w <passwd> "
"-b <searchbase> " "-b <searchbase> "
"-s <scope> "
"-f <searchfilter> " "-f <searchfilter> "
"[-a <attr>] " "[-a <attr>] "
"[-A] " "[-A] "
@ -67,7 +75,9 @@ usage( char *name )
"[-l <loops>] " "[-l <loops>] "
"[-L <outerloops>] " "[-L <outerloops>] "
"[-r <maxretries>] " "[-r <maxretries>] "
"[-t <delay>]\n", "[-t <delay>] "
"[<attrs>] "
"\n",
name ); name );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
@ -82,8 +92,11 @@ main( int argc, char **argv )
char *manager = NULL; char *manager = NULL;
struct berval passwd = { 0, NULL }; struct berval passwd = { 0, NULL };
char *sbase = NULL; char *sbase = NULL;
int scope = LDAP_SCOPE_SUBTREE;
char *filter = NULL; char *filter = NULL;
char *attr = NULL; char *attr = NULL;
char *srchattrs[] = { "cn", "sn", NULL };
char **attrs = srchattrs;
int loops = LOOPS; int loops = LOOPS;
int outerloops = 1; int outerloops = 1;
int retries = RETRIES; int retries = RETRIES;
@ -98,7 +111,7 @@ main( int argc, char **argv )
/* by default, tolerate referrals and no such object */ /* by default, tolerate referrals and no such object */
tester_ignore_str2errlist( "REFERRAL,NO_SUCH_OBJECT" ); tester_ignore_str2errlist( "REFERRAL,NO_SUCH_OBJECT" );
while ( ( i = getopt( argc, argv, "Aa:b:CD:f:FH:h:i:l:L:Np:r:t:w:" ) ) != EOF ) while ( ( i = getopt( argc, argv, "Aa:b:CD:f:FH:h:i:l:L:Np:r:s:t:T:w:" ) ) != EOF )
{ {
switch ( i ) { switch ( i ) {
case 'A': case 'A':
@ -127,7 +140,7 @@ main( int argc, char **argv )
case 'p': /* the servers port */ case 'p': /* the servers port */
if ( lutil_atoi( &port, optarg ) != 0 ) { if ( lutil_atoi( &port, optarg ) != 0 ) {
usage( argv[0] ); usage( argv[0], i );
} }
break; break;
@ -159,36 +172,50 @@ main( int argc, char **argv )
case 'l': /* number of loops */ case 'l': /* number of loops */
if ( lutil_atoi( &loops, optarg ) != 0 ) { if ( lutil_atoi( &loops, optarg ) != 0 ) {
usage( argv[0] ); usage( argv[0], i );
} }
break; break;
case 'L': /* number of loops */ case 'L': /* number of loops */
if ( lutil_atoi( &outerloops, optarg ) != 0 ) { if ( lutil_atoi( &outerloops, optarg ) != 0 ) {
usage( argv[0] ); usage( argv[0], i );
} }
break; break;
case 'r': /* number of retries */ case 'r': /* number of retries */
if ( lutil_atoi( &retries, optarg ) != 0 ) { if ( lutil_atoi( &retries, optarg ) != 0 ) {
usage( argv[0] ); usage( argv[0], i );
} }
break; break;
case 't': /* delay in seconds */ case 't': /* delay in seconds */
if ( lutil_atoi( &delay, optarg ) != 0 ) { 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; break;
default: default:
usage( argv[0] ); usage( argv[0], i );
break; break;
} }
} }
if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 && uri == NULL )) if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 && uri == NULL ))
usage( argv[0] ); usage( argv[0], '\0' );
if ( *filter == '\0' ) { if ( *filter == '\0' ) {
@ -198,16 +225,24 @@ main( int argc, char **argv )
} }
if ( argv[optind] != NULL ) {
attrs = &argv[optind];
}
uri = tester_uri( uri, host, port ); uri = tester_uri( uri, host, port );
for ( i = 0; i < outerloops; i++ ) { for ( i = 0; i < outerloops; i++ ) {
if ( attr != NULL ) { if ( attr != NULL ) {
do_random( uri, manager, &passwd, sbase, filter, attr, do_random( uri, manager, &passwd,
noattrs, nobind, loops, retries, delay, force, chaserefs ); sbase, scope, filter, attr,
attrs, noattrs, nobind,
loops, retries, delay, force, chaserefs );
} else { } else {
do_search( uri, manager, &passwd, sbase, filter, NULL, do_search( uri, manager, &passwd,
noattrs, nobind, loops, retries, delay, force, chaserefs ); sbase, scope, filter, NULL,
attrs, noattrs, nobind,
loops, retries, delay, force, chaserefs );
} }
} }
@ -217,7 +252,8 @@ main( int argc, char **argv )
static void static void
do_random( char *uri, char *manager, struct berval *passwd, do_random( char *uri, char *manager, struct berval *passwd,
char *sbase, char *filter, char *attr, int noattrs, int nobind, char *sbase, int scope, char *filter, char *attr,
char **srchattrs, int noattrs, int nobind,
int innerloop, int maxretries, int delay, int force, int chaserefs ) int innerloop, int maxretries, int delay, int force, int chaserefs )
{ {
LDAP *ld = NULL; LDAP *ld = NULL;
@ -315,7 +351,9 @@ do_random( char *uri, char *manager, struct berval *passwd,
snprintf( buf, sizeof( buf ), "(%s=%s)", attr, values[ r ] ); snprintf( buf, sizeof( buf ), "(%s=%s)", attr, values[ r ] );
do_search( uri, manager, passwd, sbase, buf, &ld, noattrs, nobind, do_search( uri, manager, passwd,
sbase, scope, buf, &ld,
srchattrs, noattrs, nobind,
1, maxretries, delay, force, chaserefs ); 1, maxretries, delay, force, chaserefs );
} }
break; break;
@ -334,12 +372,12 @@ do_random( char *uri, char *manager, struct berval *passwd,
static void static void
do_search( char *uri, char *manager, struct berval *passwd, do_search( char *uri, char *manager, struct berval *passwd,
char *sbase, char *filter, LDAP **ldp, int noattrs, int nobind, char *sbase, int scope, char *filter, LDAP **ldp,
char **attrs, int noattrs, int nobind,
int innerloop, int maxretries, int delay, int force, int chaserefs ) int innerloop, int maxretries, int delay, int force, int chaserefs )
{ {
LDAP *ld = ldp ? *ldp : NULL; LDAP *ld = ldp ? *ldp : NULL;
int i = 0, do_retry = maxretries; int i = 0, do_retry = maxretries;
char *attrs[] = { "cn", "sn", NULL };
int rc = LDAP_SUCCESS; int rc = LDAP_SUCCESS;
int version = LDAP_VERSION3; int version = LDAP_VERSION3;
char buf[ BUFSIZ ]; char buf[ BUFSIZ ];
@ -392,7 +430,7 @@ retry:;
for ( ; i < innerloop; i++ ) { for ( ; i < innerloop; i++ ) {
LDAPMessage *res = NULL; 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, filter, attrs, noattrs, NULL, NULL,
NULL, LDAP_NO_LIMIT, &res ); NULL, LDAP_NO_LIMIT, &res );
if ( res != NULL ) { if ( res != NULL ) {

View file

@ -21,15 +21,15 @@
#include <stdio.h> #include <stdio.h>
#include <ac/stdlib.h> #include "ac/stdlib.h"
#include <ac/ctype.h> #include "ac/ctype.h"
#include <ac/dirent.h> #include "ac/dirent.h"
#include <ac/param.h> #include "ac/param.h"
#include <ac/socket.h> #include "ac/socket.h"
#include <ac/string.h> #include "ac/string.h"
#include <ac/unistd.h> #include "ac/unistd.h"
#include <ac/wait.h> #include "ac/wait.h"
#include "ldap_defaults.h" #include "ldap_defaults.h"
@ -60,7 +60,7 @@
#define TBINDFILE "do_bind.0" #define TBINDFILE "do_bind.0"
static char *get_file_name( char *dirname, char *filename ); 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_search_filters( char *filename, char *filters[], char *attrs[], char *bases[], LDAPURLDesc *luds[] );
static int get_read_entries( char *filename, char *entries[], char *filters[] ); static int get_read_entries( char *filename, char *entries[], char *filters[] );
static void fork_child( char *prog, char **args ); static void fork_child( char *prog, char **args );
static void wait4kids( int nkidval ); static void wait4kids( int nkidval );
@ -133,9 +133,11 @@ main( int argc, char **argv )
char *sreqs[MAXREQS]; char *sreqs[MAXREQS];
char *sattrs[MAXREQS]; char *sattrs[MAXREQS];
char *sbase[MAXREQS]; char *sbase[MAXREQS];
LDAPURLDesc *slud[MAXREQS];
int snum = 0; int snum = 0;
char *sargs[MAXARGS]; char *sargs[MAXARGS];
int sanum; int sanum;
int sextra_args = 0;
char scmd[MAXPATHLEN]; char scmd[MAXPATHLEN];
/* static so that its address can be used in initializer below. */ /* static so that its address can be used in initializer below. */
static char sloops[] = "18446744073709551615UL"; static char sloops[] = "18446744073709551615UL";
@ -146,6 +148,7 @@ main( int argc, char **argv )
char *rargs[MAXARGS]; char *rargs[MAXARGS];
char *rflts[MAXREQS]; char *rflts[MAXREQS];
int ranum; int ranum;
int rextra_args = 0;
char rcmd[MAXPATHLEN]; char rcmd[MAXPATHLEN];
static char rloops[] = "18446744073709551615UL"; static char rloops[] = "18446744073709551615UL";
/* addel */ /* addel */
@ -414,7 +417,7 @@ main( int argc, char **argv )
/* look for search requests */ /* look for search requests */
if ( sfile ) { if ( sfile ) {
snum = get_search_filters( sfile, sreqs, sattrs, sbase ); snum = get_search_filters( sfile, sreqs, sattrs, sbase, slud );
} }
/* look for read requests */ /* look for read requests */
@ -429,12 +432,12 @@ main( int argc, char **argv )
/* look for modify requests */ /* look for modify requests */
if ( mfile ) { if ( mfile ) {
mnum = get_search_filters( mfile, mreqs, NULL, mdn ); mnum = get_search_filters( mfile, mreqs, NULL, mdn, NULL );
} }
/* look for bind requests */ /* look for bind requests */
if ( bfile ) { if ( bfile ) {
bnum = get_search_filters( bfile, bcreds, battrs, breqs ); bnum = get_search_filters( bfile, bcreds, battrs, breqs, NULL );
} }
/* setup friendly option */ /* setup friendly option */
@ -508,13 +511,16 @@ main( int argc, char **argv )
} }
sargs[sanum++] = "-b"; sargs[sanum++] = "-b";
sargs[sanum++] = NULL; /* will hold the search base */ sargs[sanum++] = NULL; /* will hold the search base */
sargs[sanum++] = "-s";
sargs[sanum++] = NULL; /* will hold the search scope */
sargs[sanum++] = "-f"; sargs[sanum++] = "-f";
sargs[sanum++] = NULL; /* will hold the search request */ sargs[sanum++] = NULL; /* will hold the search request */
sargs[sanum++] = NULL; sargs[sanum++] = NULL;
sargs[sanum] = NULL; /* might hold the "attr" request */ sargs[sanum++] = NULL; /* might hold the "attr" request */
sextra_args += 2;
sargs[sanum + 1] = NULL; sargs[sanum] = NULL;
/* /*
* generate the read clients * generate the read clients
@ -562,9 +568,10 @@ main( int argc, char **argv )
rargs[ranum++] = NULL; /* will hold the read entry */ rargs[ranum++] = NULL; /* will hold the read entry */
rargs[ranum++] = NULL; rargs[ranum++] = NULL;
rargs[ranum] = NULL; /* might hold the filter arg */ rargs[ranum++] = NULL; /* might hold the filter arg */
rextra_args += 2;
rargs[ranum + 1] = NULL; rargs[ranum] = NULL;
/* /*
* generate the modrdn clients * generate the modrdn clients
@ -607,7 +614,7 @@ main( int argc, char **argv )
} }
nargs[nanum++] = "-e"; nargs[nanum++] = "-e";
nargs[nanum++] = NULL; /* will hold the modrdn entry */ nargs[nanum++] = NULL; /* will hold the modrdn entry */
nargs[nanum++] = NULL; nargs[nanum] = NULL;
/* /*
* generate the modify clients * generate the modify clients
@ -652,7 +659,7 @@ main( int argc, char **argv )
margs[manum++] = NULL; /* will hold the modify entry */ margs[manum++] = NULL; /* will hold the modify entry */
margs[manum++] = "-a";; margs[manum++] = "-a";;
margs[manum++] = NULL; /* will hold the ava */ margs[manum++] = NULL; /* will hold the ava */
margs[manum++] = NULL; margs[manum] = NULL;
/* /*
* generate the add/delete clients * generate the add/delete clients
@ -695,7 +702,7 @@ main( int argc, char **argv )
} }
aargs[aanum++] = "-f"; aargs[aanum++] = "-f";
aargs[aanum++] = NULL; /* will hold the add data file */ aargs[aanum++] = NULL; /* will hold the add data file */
aargs[aanum++] = NULL; aargs[aanum] = NULL;
/* /*
* generate the bind clients * generate the bind clients
@ -745,56 +752,99 @@ main( int argc, char **argv )
bargs[banum++] = NULL; bargs[banum++] = NULL;
bargs[banum++] = "-w"; bargs[banum++] = "-w";
bargs[banum++] = NULL; bargs[banum++] = NULL;
bargs[banum++] = NULL; bargs[banum] = NULL;
#define DOREQ(n,j) ((n) && ((maxkids > (n)) ? ((j) < maxkids ) : ((j) < (n)))) #define DOREQ(n,j) ((n) && ((maxkids > (n)) ? ((j) < maxkids ) : ((j) < (n))))
for ( j = 0; j < MAXREQS; j++ ) { for ( j = 0; j < MAXREQS; j++ ) {
/* search */
if ( DOREQ( snum, j ) ) { if ( DOREQ( snum, j ) ) {
int jj = j % snum; int jj = j % snum;
int x = sanum - sextra_args;
sargs[sanum - 2] = sreqs[jj]; /* base */
sargs[sanum - 4] = sbase[jj]; if ( sbase[jj] != NULL ) {
if ( sattrs[jj] != NULL ) { sargs[sanum - 7] = sbase[jj];
sargs[sanum - 1] = "-a";
sargs[sanum] = sattrs[jj];
} else { } else {
sargs[sanum - 1] = NULL; 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;
} else {
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;
}
fork_child( scmd, sargs ); fork_child( scmd, sargs );
} }
/* read */
if ( DOREQ( rnum, j ) ) { if ( DOREQ( rnum, j ) ) {
int jj = j % rnum; int jj = j % rnum;
int x = ranum - rextra_args;
rargs[ranum - 2] = rreqs[jj]; rargs[ranum - 3] = rreqs[jj];
if ( rflts[jj] != NULL ) { if ( rflts[jj] != NULL ) {
rargs[ranum - 1] = "-f"; rargs[x++] = "-f";
rargs[ranum] = rflts[jj]; rargs[x++] = rflts[jj];
} else {
rargs[ranum - 1] = NULL;
} }
rargs[x] = NULL;
fork_child( rcmd, rargs ); fork_child( rcmd, rargs );
} }
/* rename */
if ( j < nnum ) { if ( j < nnum ) {
nargs[nanum - 2] = nreqs[j]; nargs[nanum - 1] = nreqs[j];
fork_child( ncmd, nargs ); fork_child( ncmd, nargs );
} }
/* modify */
if ( j < mnum ) { if ( j < mnum ) {
margs[manum - 4] = mdn[j]; margs[manum - 3] = mdn[j];
margs[manum - 2] = mreqs[j]; margs[manum - 1] = mreqs[j];
fork_child( mcmd, margs ); fork_child( mcmd, margs );
} }
/* add/delete */
if ( j < anum ) { if ( j < anum ) {
aargs[aanum - 2] = afiles[j]; aargs[aanum - 1] = afiles[j];
fork_child( acmd, aargs ); fork_child( acmd, aargs );
} }
/* bind */
if ( DOREQ( bnum, j ) ) { if ( DOREQ( bnum, j ) ) {
int jj = j % bnum; int jj = j % bnum;
@ -808,23 +858,24 @@ main( int argc, char **argv )
} }
if ( battrs[jj] != NULL ) { if ( battrs[jj] != NULL ) {
bargs[banum - 4] = manager ? manager : ""; bargs[banum - 3] = manager ? manager : "";
bargs[banum - 2] = passwd ? passwd : ""; bargs[banum - 1] = passwd ? passwd : "";
bargs[banum - 2] = "-b";
bargs[banum - 1] = breqs[jj];
bargs[banum + 0] = "-f";
bargs[banum + 1] = bcreds[jj];
bargs[banum + 2] = "-a";
bargs[banum + 3] = battrs[jj];
bargs[banum - 1] = "-b";
bargs[banum] = breqs[jj];
bargs[banum + 1] = "-f";
bargs[banum + 2] = bcreds[jj];
bargs[banum + 3] = "-a";
bargs[banum + 4] = battrs[jj];
} else { } else {
bargs[banum - 4] = breqs[jj]; bargs[banum - 3] = breqs[jj];
bargs[banum - 2] = bcreds[jj]; bargs[banum - 1] = bcreds[jj];
bargs[banum - 1] = NULL; bargs[banum] = NULL;
} }
fork_child( bcmd, bargs ); fork_child( bcmd, bargs );
bargs[banum - 1] = NULL; bargs[banum] = NULL;
} }
} }
@ -845,7 +896,7 @@ get_file_name( char *dirname, char *filename )
static int static int
get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[] ) get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[], LDAPURLDesc *luds[] )
{ {
FILE *fp; FILE *fp;
int filter = 0; int filter = 0;
@ -855,10 +906,31 @@ get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[
while (( filter < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) { while (( filter < MAXREQS ) && ( fgets( line, BUFSIZ, fp ))) {
char *nl; char *nl;
int got_URL = 0;
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
*nl = '\0'; *nl = '\0';
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 ) {
return 1;
}
if ( lud->lud_dn == NULL || lud->lud_exts != NULL ) {
return 1;
}
luds[filter] = lud;
} else {
bases[filter] = ArgDup( line ); bases[filter] = ArgDup( line );
}
fgets( line, BUFSIZ, fp ); fgets( line, BUFSIZ, fp );
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
*nl = '\0'; *nl = '\0';
@ -868,15 +940,15 @@ get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[
if ( filters[filter][0] == '+') { if ( filters[filter][0] == '+') {
char *sep = strchr( filters[filter], ':' ); char *sep = strchr( filters[filter], ':' );
if ( sep != NULL ) {
attrs[ filter ] = &filters[ filter ][ 1 ]; attrs[ filter ] = &filters[ filter ][ 1 ];
if ( sep != NULL ) {
sep[ 0 ] = '\0'; sep[ 0 ] = '\0';
/* NOTE: don't free this! */ /* NOTE: don't free this! */
filters[ filter ] = &sep[ 1 ]; filters[ filter ] = &sep[ 1 ];
} }
} else { } else {
attrs[ filter] = NULL; attrs[ filter ] = NULL;
} }
} }
filter++; filter++;