From 0185c75c2fa3325e377025c9c7b9a7991461694b Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Fri, 27 Aug 2004 17:07:18 +0000 Subject: [PATCH] added new test slapd-modify (based on slapd-modrdn). Adds a single attribute to an entry and removes it again. --- tests/data/do_modify.0 | 8 ++ tests/progs/Makefile.in | 7 +- tests/progs/slapd-modify.c | 196 ++++++++++++++++++++++++++++++ tests/progs/slapd-tester.c | 52 ++++++++ tests/scripts/test008-concurrency | 2 +- 5 files changed, 262 insertions(+), 3 deletions(-) create mode 100644 tests/data/do_modify.0 create mode 100644 tests/progs/slapd-modify.c diff --git a/tests/data/do_modify.0 b/tests/data/do_modify.0 new file mode 100644 index 0000000000..fb919f57b8 --- /dev/null +++ b/tests/data/do_modify.0 @@ -0,0 +1,8 @@ +cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com +mail: bj@mailgw.example.com +cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com +cn: Björn +cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com +displayname: James Jones +cn=ITD Staff,ou=Groups,dc=example,dc=com +uniquemember: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com diff --git a/tests/progs/Makefile.in b/tests/progs/Makefile.in index c84d924858..9e63c0a832 100644 --- a/tests/progs/Makefile.in +++ b/tests/progs/Makefile.in @@ -13,10 +13,11 @@ ## top-level directory of the distribution or, alternatively, at ## . -PROGRAMS = slapd-tester slapd-search slapd-read slapd-addel slapd-modrdn +PROGRAMS = slapd-tester slapd-search slapd-read slapd-addel slapd-modrdn \ + slapd-modify SRCS = slapd-tester.c slapd-search.c slapd-read.c slapd-addel.c \ - slapd-modrdn.c + slapd-modrdn.c slapd-modify.c LDAP_INCDIR= ../../include LDAP_LIBDIR= ../../libraries @@ -44,3 +45,5 @@ slapd-addel: slapd-addel.o $(XLIBS) slapd-modrdn: slapd-modrdn.o $(XLIBS) $(LTLINK) -o $@ slapd-modrdn.o $(LIBS) +slapd-modify: slapd-modify.o $(XLIBS) + $(LTLINK) -o $@ slapd-modify.o $(LIBS) diff --git a/tests/progs/slapd-modify.c b/tests/progs/slapd-modify.c new file mode 100644 index 0000000000..449d1fc19e --- /dev/null +++ b/tests/progs/slapd-modify.c @@ -0,0 +1,196 @@ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 1999-2004 The OpenLDAP Foundation. + * 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 + * . + */ + +#include "portable.h" + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#define LDAP_DEPRECATED 1 +#include + +#define LOOPS 100 + +static void +do_modify( char *uri, char *host, int port, char *manager, char *passwd, char *entry, + char *attr, char *value, int maxloop ); + + +static void +usage( char *name ) +{ + fprintf( stderr, "usage: %s [-h ] -p port -D -w -e [-l ]\n", + name ); + exit( EXIT_FAILURE ); +} + +int +main( int argc, char **argv ) +{ + int i; + char *uri = NULL; + char *host = "localhost"; + int port = -1; + char *manager = NULL; + char *passwd = NULL; + char *entry = NULL; + char *ava = NULL; + char *value = NULL; + int loops = LOOPS; + + while ( (i = getopt( argc, argv, "H:h:p:D:w:e:a:l:" )) != EOF ) { + switch( i ) { + case 'H': /* the server uri */ + uri = strdup( optarg ); + break; + case 'h': /* the servers host */ + host = strdup( optarg ); + break; + + case 'p': /* the servers port */ + port = atoi( optarg ); + break; + case 'D': /* the servers manager */ + manager = strdup( optarg ); + break; + + case 'w': /* the server managers password */ + passwd = strdup( optarg ); + break; + case 'e': /* entry to modify */ + entry = strdup( optarg ); + break; + case 'a': + ava = strdup( optarg ); + break; + case 'l': /* the number of loops */ + loops = atoi( optarg ); + break; + + default: + usage( argv[0] ); + break; + } + } + + if (( entry == NULL ) || ( ava == NULL ) || ( port == -1 && uri == NULL )) + usage( argv[0] ); + + if ( *entry == '\0' ) { + + fprintf( stderr, "%s: invalid EMPTY entry DN.\n", + argv[0] ); + exit( EXIT_FAILURE ); + + } + if ( *ava == '\0' ) { + fprintf( stderr, "%s: invalid EMPTY AVA.\n", + argv[0] ); + exit( EXIT_FAILURE ); + } + + if ( !( value = strchr( ava, ':' ))) { + fprintf( stderr, "%s: invalid AVA.\n", + argv[0] ); + exit( EXIT_FAILURE ); + } + *value++ = '\0'; + while ( *value && isspace( (unsigned char) *value )) + value++; + + do_modify( uri, host, port, manager, passwd, entry, ava, value, loops ); + exit( EXIT_SUCCESS ); +} + + +static void +do_modify( char *uri, char *host, int port, char *manager, + char *passwd, char *entry, char* attr, char* value, int maxloop ) +{ + LDAP *ld = NULL; + int i; + pid_t pid; + + pid = getpid(); + + struct ldapmod mod; + struct ldapmod *mods[2]; + char *values[2] = { value, NULL }; + + mod.mod_op = LDAP_MOD_ADD; + mod.mod_type = attr; + mod.mod_values = values; + mods[0] = &mod; + mods[1] = NULL; + + + if ( uri ) { + ldap_initialize( &ld, uri ); + } else { + ld = ldap_init( host, port ); + } + if ( ld == NULL ) { + perror( "ldap_init" ); + exit( EXIT_FAILURE ); + } + + { + int version = LDAP_VERSION3; + (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, + &version ); + } + + if ( ldap_bind_s( ld, manager, passwd, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) { + ldap_perror( ld, "ldap_bind" ); + exit( EXIT_FAILURE ); + } + + + fprintf( stderr, "PID=%ld - Modify(%d): entry=\"%s\".\n", + (long) pid, maxloop, entry ); + + for ( i = 0; i < maxloop; i++ ) { + int rc; + + mod.mod_op = LDAP_MOD_ADD; + if (( rc = ldap_modify_s( ld, entry, mods )) != LDAP_SUCCESS ) { + ldap_perror( ld, "ldap_modify" ); + if ( rc != LDAP_NO_SUCH_OBJECT ) break; + continue; + } + + mod.mod_op = LDAP_MOD_DELETE; + if (( rc = ldap_modify_s( ld, entry, mods )) != LDAP_SUCCESS ) { + ldap_perror( ld, "ldap_modify" ); + if ( rc != LDAP_NO_SUCH_OBJECT ) break; + continue; + } + + } + + fprintf( stderr, " PID=%ld - Modify done.\n", (long) pid ); + + ldap_unbind( ld ); +} + + diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index e372f49df1..f3be95eaab 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -39,6 +39,7 @@ #define READCMD "slapd-read" #define ADDCMD "slapd-addel" #define MODRDNCMD "slapd-modrdn" +#define MODIFYCMD "slapd-modify" #define MAXARGS 100 #define MAXREQS 20 #define LOOPS "100" @@ -47,6 +48,7 @@ #define TREADFILE "do_read.0" #define TADDFILE "do_add." #define TMODRDNFILE "do_modrdn.0" +#define TMODIFYFILE "do_modify.0" static char *get_file_name( char *dirname, char *filename ); static int get_search_filters( char *filename, char *filters[], char *bases[] ); @@ -110,6 +112,13 @@ main( int argc, char **argv ) char *margs[MAXARGS]; int manum; char mcmd[MAXPATHLEN]; + char *modargs[MAXARGS]; + int modanum; + char modcmd[MAXPATHLEN]; + char *modfile = NULL; + char *modreqs[MAXREQS]; + char *moddn[MAXREQS]; + int modnum = 0; while ( (i = getopt( argc, argv, "H:h:p:D:w:b:d:j:l:P:" )) != EOF ) { switch( i ) { @@ -183,6 +192,9 @@ main( int argc, char **argv ) } else if ( !strcasecmp( file->d_name, TMODRDNFILE )) { mfile = get_file_name( dirname, file->d_name ); continue; + } else if ( !strcasecmp( file->d_name, TMODIFYFILE )) { + modfile = get_file_name( dirname, file->d_name ); + continue; } else if ( !strncasecmp( file->d_name, TADDFILE, strlen( TADDFILE )) && ( anum < MAXREQS )) { afiles[anum++] = get_file_name( dirname, file->d_name ); @@ -206,6 +218,10 @@ 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 ); + } /* * generate the search clients @@ -281,6 +297,35 @@ main( int argc, char **argv ) margs[manum++] = "-e"; margs[manum++] = NULL; /* will hold the modrdn entry */ margs[manum++] = NULL; + + /* + * generate the modify clients + */ + + modanum = 0; + snprintf( modcmd, sizeof modcmd, "%s" LDAP_DIRSEP MODIFYCMD, + progdir ); + modargs[modanum++] = modcmd; + if ( uri ) { + modargs[modanum++] = "-H"; + modargs[modanum++] = uri; + } else { + modargs[modanum++] = "-h"; + modargs[modanum++] = host; + modargs[modanum++] = "-p"; + modargs[modanum++] = port; + } + modargs[modanum++] = "-D"; + modargs[modanum++] = manager; + modargs[modanum++] = "-w"; + modargs[modanum++] = passwd; + modargs[modanum++] = "-l"; + modargs[modanum++] = loops; + modargs[modanum++] = "-e"; + modargs[modanum++] = NULL; /* will hold the modify entry */ + modargs[modanum++] = "-a";; + modargs[modanum++] = NULL; /* will hold the ava */ + modargs[modanum++] = NULL; /* * generate the add/delete clients @@ -331,6 +376,13 @@ main( int argc, char **argv ) margs[manum - 2] = mreqs[j]; fork_child( mcmd, margs ); + } + if ( j < modnum ) { + + modargs[modanum - 4] = moddn[j]; + modargs[modanum - 2] = modreqs[j]; + fork_child( modcmd, modargs ); + } if ( j < anum ) { diff --git a/tests/scripts/test008-concurrency b/tests/scripts/test008-concurrency index d55fb67ad7..2f9b4f4f6f 100755 --- a/tests/scripts/test008-concurrency +++ b/tests/scripts/test008-concurrency @@ -20,7 +20,7 @@ mkdir -p $TESTDIR $DBDIR1 echo "Running slapadd to build slapd database..." . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1 -$SLAPADD -f $CONF1 -l $LDIFORDERED +$SLAPADD -f $CONF1 -l $LDIFORDERED -d -1 2> /tmp/slapadd.log RC=$? if test $RC != 0 ; then echo "slapadd failed ($RC)!" -- 2.39.5