From: Pierangelo Masarati Date: Tue, 28 Mar 2006 00:14:11 +0000 (+0000) Subject: allow attrsonly; allow "random" read X-Git-Tag: OPENLDAP_REL_ENG_2_4_BP~103 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f30c613c5fa37d0890b5c0258231a3f1889ad1e9;p=openldap allow attrsonly; allow "random" read --- diff --git a/tests/progs/slapd-read.c b/tests/progs/slapd-read.c index b08910da5d..ba610b7aa6 100644 --- a/tests/progs/slapd-read.c +++ b/tests/progs/slapd-read.c @@ -39,8 +39,14 @@ #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 ) @@ -48,9 +54,13 @@ usage( char *name ) fprintf( stderr, "usage: %s " "-H | ([-h ] -p ) " + "-D " + "-w " "-e " - "[-F] " + "[-A] " "[-C] " + "[-F] " + "[-f filter] " "[-l ] " "[-L ] " "[-r ] " @@ -66,18 +76,26 @@ main( int argc, char **argv ) 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; @@ -96,10 +114,23 @@ main( int argc, char **argv ) } 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; @@ -146,27 +177,38 @@ main( int argc, char **argv ) 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" ); @@ -178,23 +220,16 @@ retry:; 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; @@ -202,11 +237,103 @@ retry:; 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 */ @@ -240,8 +367,15 @@ retry:; } 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 ); + } + } } diff --git a/tests/progs/slapd-search.c b/tests/progs/slapd-search.c index 1810eee30e..d33fcb4afb 100644 --- a/tests/progs/slapd-search.c +++ b/tests/progs/slapd-search.c @@ -40,12 +40,12 @@ 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 @@ -59,8 +59,9 @@ usage( char *name ) "-b " "-f " "[-a ] " - "[-F] " + "[-A] " "[-C] " + "[-F] " "[-l ] " "[-L ] " "[-r ] " @@ -87,11 +88,16 @@ main( int argc, char **argv ) 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; @@ -181,11 +187,11 @@ main( int argc, char **argv ) 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 ); } } @@ -195,7 +201,7 @@ main( int argc, char **argv ) 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; @@ -275,7 +281,7 @@ do_random( char *uri, char *manager, struct berval *passwd, 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 ); } } @@ -287,10 +293,11 @@ do_random( char *uri, char *manager, struct berval *passwd, 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; @@ -344,7 +351,7 @@ retry:; 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 ); diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index 024ca3acdf..8f98a8abc5 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -59,7 +59,7 @@ 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 ); @@ -114,6 +114,7 @@ main( int argc, char **argv ) struct dirent *file; int friendly = 0; int chaserefs = 0; + int noattrs = 0; /* search */ char *sfile = NULL; char *sreqs[MAXREQS]; @@ -129,6 +130,7 @@ main( int argc, char **argv ) char *rreqs[MAXREQS]; int rnum = 0; char *rargs[MAXARGS]; + char *rflts[MAXREQS]; int ranum; char rcmd[MAXPATHLEN]; char rloops[] = "18446744073709551615UL"; @@ -170,8 +172,12 @@ main( int argc, char **argv ) 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; @@ -288,12 +294,12 @@ main( int argc, char **argv ) /* 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 */ @@ -365,6 +371,9 @@ main( int argc, char **argv ) if ( chaserefs ) { sargs[sanum++] = "-C"; } + if ( noattrs ) { + sargs[sanum++] = "-A"; + } sargs[sanum++] = "-b"; sargs[sanum++] = NULL; /* will hold the search base */ sargs[sanum++] = "-f"; @@ -392,6 +401,10 @@ main( int argc, char **argv ) 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"; @@ -406,9 +419,16 @@ main( int argc, char **argv ) 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 @@ -569,57 +589,64 @@ main( int argc, char **argv ) 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 ); @@ -684,7 +711,7 @@ get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[ static int -get_read_entries( char *filename, char *entries[] ) +get_read_entries( char *filename, char *entries[], char *filters[] ) { FILE *fp; int entry = 0; @@ -697,7 +724,32 @@ get_read_entries( char *filename, char *entries[] ) 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 );