From feca42277fbb95c2b471b30d1f1d164c271fa523 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 9 Jan 2006 14:21:33 +0000 Subject: [PATCH] add bind to stress tests --- tests/data/do_bind.0 | 6 +++ tests/progs/slapd-bind.c | 96 +++++++++++++++++++---------------- tests/progs/slapd-tester.c | 101 ++++++++++++++++++++++++++++++------- 3 files changed, 141 insertions(+), 62 deletions(-) create mode 100644 tests/data/do_bind.0 diff --git a/tests/data/do_bind.0 b/tests/data/do_bind.0 new file mode 100644 index 0000000000..df2c85e263 --- /dev/null +++ b/tests/data/do_bind.0 @@ -0,0 +1,6 @@ +cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com +bjensen +cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com +bjorn +cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com +jaj diff --git a/tests/progs/slapd-bind.c b/tests/progs/slapd-bind.c index 5d2f203ff0..207c332591 100644 --- a/tests/progs/slapd-bind.c +++ b/tests/progs/slapd-bind.c @@ -32,19 +32,30 @@ #include #include -#define LDAP_DEPRECATED 1 #include #include #define LOOPS 100 +static void +do_error( LDAP *ld, const char *func ) +{ + int err; + const char *text = "Success"; + + ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&err ); + if ( err != LDAP_SUCCESS ) { + ldap_get_option( ld, LDAP_OPT_ERROR_STRING, (void *)&text ); + } + + fprintf( stderr, "%s: (%d) %s\n", func, err, text == NULL ? "" : text ); +} + static int -do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop, - int force ); +do_bind( char *uri, char *dn, struct berval *pass, int maxloop, int force ); static int -do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop, - int force ); +do_base( char *uri, char *base, struct berval *pass, int maxloop, int force ); /* This program can be invoked two ways: if -D is used to specify a Bind DN, * that DN will be used repeatedly for all of the Binds. If instead -b is used @@ -67,11 +78,12 @@ int main( int argc, char **argv ) { int i; - char *uri = NULL; + char *uri = NULL, + uribuf[ BUFSIZ ]; char *host = "localhost"; char *dn = NULL; char *base = NULL; - char *pass = NULL; + struct berval pass = { 0, NULL }; int port = -1; int loops = LOOPS; int force = 0; @@ -84,10 +96,11 @@ main( int argc, char **argv ) case 'H': /* the server uri */ uri = strdup( optarg ); - break; + break; + case 'h': /* the servers host */ host = strdup( optarg ); - break; + break; case 'p': /* the servers port */ if ( lutil_atoi( &port, optarg ) != 0 ) { @@ -100,7 +113,8 @@ main( int argc, char **argv ) break; case 'w': - pass = strdup( optarg ); + pass.bv_val = strdup( optarg ); + pass.bv_len = strlen( optarg ); break; case 'l': /* the number of loops */ @@ -123,20 +137,26 @@ main( int argc, char **argv ) } } - if ( port == -1 && uri == NULL ) + if ( port == -1 && uri == NULL ) { usage( argv[0] ); + } + + if ( uri == NULL ) { + snprintf( uribuf, sizeof( uribuf ), "ldap://%s:%d", host, port ); + uri = uribuf; + } - if ( base ) - do_base( uri, host, port, base, pass, ( 20 * loops ), force ); - else - do_bind( uri, host, port, dn, pass, ( 20 * loops ), force ); + if ( base ) { + do_base( uri, base, &pass, ( 20 * loops ), force ); + } else { + do_bind( uri, dn, &pass, ( 20 * loops ), force ); + } exit( EXIT_SUCCESS ); } static int -do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop, - int force ) +do_bind( char *uri, char *dn, struct berval *pass, int maxloop, int force ) { LDAP *ld = NULL; int i, rc = -1; @@ -147,13 +167,9 @@ do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop, (long) pid, maxloop, dn ); for ( i = 0; i < maxloop; i++ ) { - if ( uri ) { - ldap_initialize( &ld, uri ); - } else { - ld = ldap_init( host, port ); - } + ldap_initialize( &ld, uri ); if ( ld == NULL ) { - perror( "ldap_init" ); + perror( "ldap_initialize" ); rc = -1; break; } @@ -164,11 +180,11 @@ do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop, &version ); } - rc = ldap_bind_s( ld, dn, pass, LDAP_AUTH_SIMPLE ); + rc = ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, pass, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_bind" ); + do_error( ld, "ldap_bind" ); } - ldap_unbind( ld ); + ldap_unbind_ext( ld, NULL, NULL ); if ( rc != LDAP_SUCCESS && !force ) { break; } @@ -182,8 +198,7 @@ do_bind( char *uri, char *host, int port, char *dn, char *pass, int maxloop, static int -do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop, - int force ) +do_base( char *uri, char *base, struct berval *pass, int maxloop, int force ) { LDAP *ld = NULL; int i = 0; @@ -199,36 +214,29 @@ do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop, #else struct timeval beg, end; #endif + int version = LDAP_VERSION3; srand(pid); - if ( uri ) { - ldap_initialize( &ld, uri ); - } else { - ld = ldap_init( host, port ); - } + ldap_initialize( &ld, uri ); if ( ld == NULL ) { - perror( "ldap_init" ); + perror( "ldap_initialize" ); exit( EXIT_FAILURE ); } - { - int version = LDAP_VERSION3; - (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, - &version ); - } + (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version ); (void) ldap_set_option( ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF ); - rc = ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ); + rc = ldap_sasl_bind_s( ld, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_bind" ); + do_error( ld, "ldap_bind" ); exit( EXIT_FAILURE ); } rc = ldap_search_ext( ld, base, LDAP_SCOPE_ONE, filter, attrs, 0, NULL, NULL, 0, 0, &msgid ); if ( rc != LDAP_SUCCESS ) { - ldap_perror( ld, "ldap_search_ex" ); + do_error( ld, "ldap_search_ext" ); exit( EXIT_FAILURE ); } @@ -262,7 +270,7 @@ do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop, ldap_msgfree( res ); if ( done ) break; } - ldap_unbind( ld ); + ldap_unbind_ext( ld, NULL, NULL ); #ifdef _WIN32 beg = GetTickCount(); @@ -282,7 +290,7 @@ do_base( char *uri, char *host, int port, char *base, char *pass, int maxloop, ptr = lutil_strcopy(dn, rdns[j]); *ptr++ = ','; strcpy(ptr, base); - if ( do_bind( uri, host, port, dn, pass, 1, force ) && !force ) + if ( do_bind( uri, dn, pass, 1, force ) && !force ) break; } #ifdef _WIN32 diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index 81d50575b5..e0e4fab7fa 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -41,6 +41,7 @@ #define ADDCMD "slapd-addel" #define MODRDNCMD "slapd-modrdn" #define MODIFYCMD "slapd-modify" +#define BINDCMD "slapd-bind" #define MAXARGS 100 #define MAXREQS 5000 #define LOOPS "100" @@ -51,6 +52,7 @@ #define TADDFILE "do_add." #define TMODRDNFILE "do_modrdn.0" #define TMODIFYFILE "do_modify.0" +#define TBINDFILE "do_bind.0" static char *get_file_name( char *dirname, char *filename ); static int get_search_filters( char *filename, char *filters[], char *bases[] ); @@ -102,40 +104,53 @@ main( int argc, char **argv ) char *loops = LOOPS; char *retries = RETRIES; char *delay = "0"; - DIR *datadir; + DIR *datadir; struct dirent *file; + int friendly = 0; + /* search */ char *sfile = NULL; char *sreqs[MAXREQS]; char *sbase[MAXREQS]; - int snum = 0; - char *rfile = NULL; - char *rreqs[MAXREQS]; - int rnum = 0; - char *afiles[MAXREQS]; - int anum = 0; - char *mfile = NULL; - char *mreqs[MAXREQS]; - int mnum = 0; + int snum = 0; char *sargs[MAXARGS]; - int sanum; + int sanum; char scmd[MAXPATHLEN]; + /* read */ + char *rfile = NULL; + char *rreqs[MAXREQS]; + int rnum = 0; char *rargs[MAXARGS]; - int ranum; + int ranum; char rcmd[MAXPATHLEN]; + /* addel */ + char *afiles[MAXREQS]; + int anum = 0; char *aargs[MAXARGS]; - int aanum; + int aanum; char acmd[MAXPATHLEN]; + /* modrdn */ + char *mfile = NULL; + char *mreqs[MAXREQS]; + int mnum = 0; char *margs[MAXARGS]; int manum; char mcmd[MAXPATHLEN]; - char *modargs[MAXARGS]; - int modanum; - char modcmd[MAXPATHLEN]; + /* modify */ char *modfile = NULL; char *modreqs[MAXREQS]; char *moddn[MAXREQS]; int modnum = 0; - int friendly = 0; + char *modargs[MAXARGS]; + int modanum; + char modcmd[MAXPATHLEN]; + /* bind */ + char *bfile = NULL; + char *breqs[MAXREQS]; + char *bcreds[MAXREQS]; + int bnum = 0; + char *bargs[MAXARGS]; + int banum; + char bcmd[MAXPATHLEN]; while ( (i = getopt( argc, argv, "D:d:FH:h:j:l:P:p:r:t:w:" )) != EOF ) { switch( i ) { @@ -230,6 +245,9 @@ main( int argc, char **argv ) && ( anum < MAXREQS )) { afiles[anum++] = get_file_name( dirname, file->d_name ); continue; + } else if ( !strcasecmp( file->d_name, TBINDFILE )) { + bfile = get_file_name( dirname, file->d_name ); + continue; } } @@ -249,11 +267,17 @@ main( int argc, char **argv ) if ( mfile ) { mnum = get_read_entries( mfile, mreqs ); } + /* look for modify requests */ if ( modfile ) { modnum = get_search_filters( modfile, modreqs, moddn ); } + /* look for bind requests */ + if ( bfile ) { + bnum = get_search_filters( bfile, bcreds, breqs ); + } + /* * generate the search clients */ @@ -418,8 +442,41 @@ main( int argc, char **argv ) aargs[aanum++] = NULL; /* will hold the add data file */ aargs[aanum++] = NULL; - for ( j = 0; j < MAXREQS; j++ ) { + /* + * generate the bind clients + */ + + banum = 0; + snprintf( bcmd, sizeof bcmd, "%s" LDAP_DIRSEP BINDCMD, + progdir ); + bargs[banum++] = bcmd; + if ( uri ) { + bargs[banum++] = "-H"; + bargs[banum++] = uri; + } else { + bargs[banum++] = "-h"; + bargs[banum++] = host; + bargs[banum++] = "-p"; + bargs[banum++] = port; + } + bargs[banum++] = "-l"; + bargs[banum++] = loops; +#if 0 + bargs[banum++] = "-r"; + bargs[banum++] = retries; + bargs[banum++] = "-t"; + bargs[banum++] = delay; +#endif + if ( friendly ) { + bargs[banum++] = "-F"; + } + bargs[banum++] = "-D"; + bargs[banum++] = NULL; + bargs[banum++] = "-w"; + bargs[banum++] = NULL; + bargs[banum++] = NULL; + for ( j = 0; j < MAXREQS; j++ ) { if ( j < snum ) { sargs[sanum - 2] = sreqs[j]; @@ -456,6 +513,14 @@ main( int argc, char **argv ) } + if ( j < bnum ) { + + bargs[banum - 4] = breqs[j]; + bargs[banum - 2] = bcreds[j]; + fork_child( bcmd, bargs ); + + } + } wait4kids( -1 ); -- 2.39.5