2004-08-28 01:07:18 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2019-01-15 02:46:16 +08:00
|
|
|
* Copyright 1999-2019 The OpenLDAP Foundation.
|
2004-08-28 01:07:18 +08:00
|
|
|
* 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>
|
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
#include "ac/stdlib.h"
|
2004-08-28 01:07:18 +08:00
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
#include "ac/ctype.h"
|
|
|
|
#include "ac/param.h"
|
|
|
|
#include "ac/socket.h"
|
|
|
|
#include "ac/string.h"
|
|
|
|
#include "ac/unistd.h"
|
|
|
|
#include "ac/wait.h"
|
2004-08-28 01:07:18 +08:00
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
#include "ldap.h"
|
|
|
|
#include "lutil.h"
|
2004-08-28 01:07:18 +08:00
|
|
|
|
2006-01-12 21:01:38 +08:00
|
|
|
#include "slapd-common.h"
|
|
|
|
|
2004-08-28 01:07:18 +08:00
|
|
|
#define LOOPS 100
|
|
|
|
|
|
|
|
static void
|
2018-01-16 23:28:50 +08:00
|
|
|
do_modify( struct tester_conn_args *config, char *entry,
|
|
|
|
char *attr, char *value, int friendly );
|
2004-08-28 01:07:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2018-01-16 23:28:50 +08:00
|
|
|
usage( char *name, int opt )
|
2004-08-28 01:07:18 +08:00
|
|
|
{
|
2018-01-16 23:28:50 +08:00
|
|
|
if ( opt ) {
|
|
|
|
fprintf( stderr, "%s: unable to handle option \'%c\'\n\n",
|
|
|
|
name, opt );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( stderr, "usage: %s " TESTER_COMMON_HELP
|
|
|
|
"-a <attr:val> "
|
2005-08-19 15:27:32 +08:00
|
|
|
"-e <entry> "
|
2018-01-16 23:28:50 +08:00
|
|
|
"[-F]\n",
|
|
|
|
name );
|
2004-08-28 01:07:18 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *entry = NULL;
|
|
|
|
char *ava = NULL;
|
|
|
|
char *value = NULL;
|
2005-11-05 00:17:32 +08:00
|
|
|
int friendly = 0;
|
2018-01-16 23:28:50 +08:00
|
|
|
struct tester_conn_args *config;
|
2004-08-28 01:07:18 +08:00
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
config = tester_init( "slapd-modify", TESTER_MODIFY );
|
2006-01-12 21:01:38 +08:00
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
while ( ( i = getopt( argc, argv, TESTER_COMMON_OPTS "a:e:F" ) ) != EOF )
|
2006-12-04 05:34:24 +08:00
|
|
|
{
|
2006-03-25 18:13:30 +08:00
|
|
|
switch ( i ) {
|
2005-11-05 00:17:32 +08:00
|
|
|
case 'F':
|
|
|
|
friendly++;
|
|
|
|
break;
|
|
|
|
|
2006-06-09 17:30:36 +08:00
|
|
|
case 'i':
|
|
|
|
/* ignored (!) by now */
|
|
|
|
break;
|
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
case 'e': /* entry to modify */
|
|
|
|
entry = strdup( optarg );
|
2004-08-28 01:07:18 +08:00
|
|
|
break;
|
2005-04-21 00:16:39 +08:00
|
|
|
|
|
|
|
case 'a':
|
|
|
|
ava = strdup( optarg );
|
2004-08-28 01:07:18 +08:00
|
|
|
break;
|
2005-04-21 00:16:39 +08:00
|
|
|
|
|
|
|
default:
|
2018-01-16 23:28:50 +08:00
|
|
|
if ( tester_config_opt( config, i, optarg ) == LDAP_SUCCESS ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
usage( argv[0], i );
|
2004-08-28 01:07:18 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
if (( entry == NULL ) || ( ava == NULL ))
|
|
|
|
usage( argv[0], 0 );
|
2004-08-28 01:07:18 +08:00
|
|
|
|
|
|
|
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++;
|
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
tester_config_finish( config );
|
2006-01-12 21:01:38 +08:00
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
for ( i = 0; i < config->outerloops; i++ ) {
|
|
|
|
do_modify( config, entry, ava, value, friendly );
|
2006-03-04 00:02:34 +08:00
|
|
|
}
|
|
|
|
|
2004-08-28 01:07:18 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2018-01-16 23:28:50 +08:00
|
|
|
do_modify( struct tester_conn_args *config,
|
|
|
|
char *entry, char* attr, char* value, int friendly )
|
2004-08-28 01:07:18 +08:00
|
|
|
{
|
|
|
|
LDAP *ld = NULL;
|
2018-01-16 23:28:50 +08:00
|
|
|
int i = 0, do_retry = config->retries;
|
2004-09-05 02:31:43 +08:00
|
|
|
int rc = LDAP_SUCCESS;
|
2004-08-28 01:07:18 +08:00
|
|
|
|
|
|
|
struct ldapmod mod;
|
|
|
|
struct ldapmod *mods[2];
|
2005-07-06 16:06:47 +08:00
|
|
|
char *values[2];
|
2004-08-28 01:07:18 +08:00
|
|
|
|
2005-07-06 16:06:47 +08:00
|
|
|
values[0] = value;
|
|
|
|
values[1] = NULL;
|
2004-08-28 01:07:18 +08:00
|
|
|
mod.mod_op = LDAP_MOD_ADD;
|
|
|
|
mod.mod_type = attr;
|
|
|
|
mod.mod_values = values;
|
|
|
|
mods[0] = &mod;
|
|
|
|
mods[1] = NULL;
|
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
retry:;
|
2019-03-27 18:26:44 +08:00
|
|
|
if ( ld == NULL ) {
|
|
|
|
tester_init_ld( &ld, config, 0 );
|
|
|
|
}
|
2004-08-28 01:07:18 +08:00
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
if ( do_retry == config->retries ) {
|
2005-04-21 00:16:39 +08:00
|
|
|
fprintf( stderr, "PID=%ld - Modify(%d): entry=\"%s\".\n",
|
2018-01-16 23:28:50 +08:00
|
|
|
(long) pid, config->loops, entry );
|
2005-04-21 00:16:39 +08:00
|
|
|
}
|
2004-08-28 01:07:18 +08:00
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
for ( ; i < config->loops; i++ ) {
|
2004-08-28 01:07:18 +08:00
|
|
|
mod.mod_op = LDAP_MOD_ADD;
|
2006-01-12 21:01:38 +08:00
|
|
|
rc = ldap_modify_ext_s( ld, entry, mods, NULL, NULL );
|
2005-04-21 00:16:39 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_ldap_error( ld, "ldap_modify_ext_s", NULL );
|
2005-11-04 23:51:19 +08:00
|
|
|
switch ( rc ) {
|
|
|
|
case LDAP_TYPE_OR_VALUE_EXISTS:
|
|
|
|
/* NOTE: this likely means
|
|
|
|
* the second modify failed
|
|
|
|
* during the previous round... */
|
2005-11-05 00:17:32 +08:00
|
|
|
if ( !friendly ) {
|
|
|
|
goto done;
|
|
|
|
}
|
2005-11-04 23:51:19 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_BUSY:
|
|
|
|
case LDAP_UNAVAILABLE:
|
|
|
|
if ( do_retry > 0 ) {
|
|
|
|
do_retry--;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
/* fall thru */
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto done;
|
2005-04-21 00:16:39 +08:00
|
|
|
}
|
2004-08-28 01:07:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mod.mod_op = LDAP_MOD_DELETE;
|
2006-01-12 21:01:38 +08:00
|
|
|
rc = ldap_modify_ext_s( ld, entry, mods, NULL, NULL );
|
2005-04-21 00:16:39 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_ldap_error( ld, "ldap_modify_ext_s", NULL );
|
2005-11-04 22:49:59 +08:00
|
|
|
switch ( rc ) {
|
2005-11-04 23:51:19 +08:00
|
|
|
case LDAP_NO_SUCH_ATTRIBUTE:
|
|
|
|
/* NOTE: this likely means
|
|
|
|
* the first modify failed
|
|
|
|
* during the previous round... */
|
2005-11-05 00:17:32 +08:00
|
|
|
if ( !friendly ) {
|
|
|
|
goto done;
|
|
|
|
}
|
2005-11-04 22:49:59 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_BUSY:
|
|
|
|
case LDAP_UNAVAILABLE:
|
|
|
|
if ( do_retry > 0 ) {
|
|
|
|
do_retry--;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
/* fall thru */
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto done;
|
2005-04-21 00:16:39 +08:00
|
|
|
}
|
2004-08-28 01:07:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-11-04 22:49:59 +08:00
|
|
|
done:;
|
2008-07-19 19:54:54 +08:00
|
|
|
fprintf( stderr, " PID=%ld - Modify done (%d).\n", (long) pid, rc );
|
2004-08-28 01:07:18 +08:00
|
|
|
|
2006-01-12 21:01:38 +08:00
|
|
|
ldap_unbind_ext( ld, NULL, NULL );
|
2004-08-28 01:07:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|