added new test slapd-modify (based on slapd-modrdn). Adds a single attribute to an entry and removes it again.

This commit is contained in:
Ralf Haferkamp 2004-08-27 17:07:18 +00:00
parent 78d08a8271
commit 0185c75c2f
5 changed files with 262 additions and 3 deletions

8
tests/data/do_modify.0 Normal file
View file

@ -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

View file

@ -13,10 +13,11 @@
## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>.
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)

196
tests/progs/slapd-modify.c Normal file
View file

@ -0,0 +1,196 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* 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
* <http://www.OpenLDAP.org/license.html>.
*/
#include "portable.h"
#include <stdio.h>
#include <ac/stdlib.h>
#include <ac/ctype.h>
#include <ac/param.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/unistd.h>
#include <ac/wait.h>
#define LDAP_DEPRECATED 1
#include <ldap.h>
#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 <host>] -p port -D <managerDN> -w <passwd> -e <entry> [-l <loops>]\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 );
}

View file

@ -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 ) {

View file

@ -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)!"