1999-09-02 16:40:22 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 23:24:38 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2020-01-10 00:50:21 +08:00
|
|
|
* Copyright 1999-2020 The OpenLDAP Foundation.
|
2003-11-26 23:24:38 +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>.
|
1999-09-02 08:56:32 +08:00
|
|
|
*/
|
2003-11-26 23:24:38 +08:00
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Kurt Spanier for inclusion
|
|
|
|
* in OpenLDAP Software.
|
|
|
|
*/
|
|
|
|
|
1999-02-15 18:49:20 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
#include "ac/stdlib.h"
|
1999-02-15 18:49:20 +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"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2007-08-14 00:20:24 +08:00
|
|
|
#include "ldap.h"
|
|
|
|
#include "lutil.h"
|
2018-11-01 02:12:04 +08:00
|
|
|
#include "ldif.h"
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2006-01-12 21:01:38 +08:00
|
|
|
#include "slapd-common.h"
|
|
|
|
|
2018-11-01 02:12:04 +08:00
|
|
|
static LDIFRecord *
|
|
|
|
get_add_entry( char *filename );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
static void
|
2018-01-16 23:28:50 +08:00
|
|
|
do_addel( struct tester_conn_args *config,
|
2018-11-01 02:12:04 +08:00
|
|
|
LDIFRecord *record, int friendly );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
static void
|
2018-01-16 23:28:50 +08:00
|
|
|
usage( char *name, char opt )
|
1999-02-15 18:49:20 +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
|
2005-08-19 15:27:32 +08:00
|
|
|
"-f <addfile> "
|
2018-01-16 23:28:50 +08:00
|
|
|
"[-F]\n",
|
|
|
|
name );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
|
|
|
{
|
1999-03-06 14:33:34 +08:00
|
|
|
int i;
|
2018-11-01 02:12:04 +08:00
|
|
|
char *filename = NULL, *buf = NULL;
|
2005-11-05 00:17:32 +08:00
|
|
|
int friendly = 0;
|
2018-11-01 02:12:04 +08:00
|
|
|
struct LDIFFP *fp;
|
|
|
|
LDIFRecord record = {};
|
2018-01-16 23:28:50 +08:00
|
|
|
struct tester_conn_args *config;
|
2018-11-01 02:12:04 +08:00
|
|
|
struct berval bv = {};
|
|
|
|
unsigned long lineno = 0;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
config = tester_init( "slapd-addel", TESTER_ADDEL );
|
2006-01-12 21:01:38 +08:00
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
while ( ( i = getopt( argc, argv, TESTER_COMMON_OPTS "Ff:" ) ) != EOF )
|
2006-12-04 05:34:24 +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 'f': /* file with entry search request */
|
|
|
|
filename = strdup( optarg );
|
|
|
|
break;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
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 );
|
2005-04-21 00:16:39 +08:00
|
|
|
break;
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
if ( filename == NULL )
|
|
|
|
usage( argv[0], 0 );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2018-11-01 02:12:04 +08:00
|
|
|
if ( (fp = ldif_open( filename, "r" )) == NULL ) {
|
|
|
|
tester_perror( filename, "while reading ldif file" );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2018-11-01 02:12:04 +08:00
|
|
|
i = 0;
|
|
|
|
if ( ldif_read_record( fp, &lineno, &buf, &i ) < 0 ) {
|
|
|
|
tester_error( "ldif_read_record failed" );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
2018-11-01 02:12:04 +08:00
|
|
|
}
|
|
|
|
bv.bv_val = buf;
|
|
|
|
bv.bv_len = i;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2018-11-01 02:12:04 +08:00
|
|
|
if ( ldap_parse_ldif_record( &bv, lineno, &record, "slapd-addel",
|
|
|
|
LDIF_DEFAULT_ADD | LDIF_ENTRIES_ONLY ) ) {
|
|
|
|
tester_error( "ldif_read_record failed" );
|
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
2018-11-01 02:12:04 +08:00
|
|
|
ldif_close( fp );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2018-11-01 02:12:04 +08:00
|
|
|
if ( ( record.lr_op != LDAP_REQ_ADD ) || ( !record.lrop_mods ) ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2018-11-01 02:12:04 +08:00
|
|
|
fprintf( stderr, "%s: invalid entry DN in file \"%s\".\n",
|
1999-02-15 18:49:20 +08:00
|
|
|
argv[0], filename );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
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++ ) {
|
2018-11-01 02:12:04 +08:00
|
|
|
do_addel( config, &record, friendly );
|
2006-03-04 00:02:34 +08:00
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2018-11-01 02:12:04 +08:00
|
|
|
free( buf );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen )
|
|
|
|
{
|
|
|
|
LDAPMod **pmods;
|
|
|
|
int i, j;
|
|
|
|
struct berval *bvp;
|
|
|
|
|
|
|
|
pmods = *pmodsp;
|
|
|
|
modop |= LDAP_MOD_BVALUES;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
if ( pmods != NULL ) {
|
|
|
|
for ( ; pmods[ i ] != NULL; ++i ) {
|
|
|
|
if ( strcasecmp( pmods[ i ]->mod_type, attr ) == 0 &&
|
|
|
|
pmods[ i ]->mod_op == modop ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pmods == NULL || pmods[ i ] == NULL ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
if (( pmods = (LDAPMod **)realloc( pmods, (i + 2) *
|
1999-02-15 18:49:20 +08:00
|
|
|
sizeof( LDAPMod * ))) == NULL ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "realloc", NULL );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
*pmodsp = pmods;
|
|
|
|
pmods[ i + 1 ] = NULL;
|
|
|
|
if (( pmods[ i ] = (LDAPMod *)calloc( 1, sizeof( LDAPMod )))
|
|
|
|
== NULL ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "calloc", NULL );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
pmods[ i ]->mod_op = modop;
|
|
|
|
if (( pmods[ i ]->mod_type = strdup( attr )) == NULL ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "strdup", NULL );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( value != NULL ) {
|
|
|
|
j = 0;
|
|
|
|
if ( pmods[ i ]->mod_bvalues != NULL ) {
|
|
|
|
for ( ; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (( pmods[ i ]->mod_bvalues =
|
1999-05-29 09:26:12 +08:00
|
|
|
(struct berval **)ber_memrealloc( pmods[ i ]->mod_bvalues,
|
1999-02-15 18:49:20 +08:00
|
|
|
(j + 2) * sizeof( struct berval * ))) == NULL ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "ber_memrealloc", NULL );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
pmods[ i ]->mod_bvalues[ j + 1 ] = NULL;
|
1999-05-29 09:26:12 +08:00
|
|
|
if (( bvp = (struct berval *)ber_memalloc( sizeof( struct berval )))
|
1999-02-15 18:49:20 +08:00
|
|
|
== NULL ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "ber_memalloc", NULL );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
pmods[ i ]->mod_bvalues[ j ] = bvp;
|
|
|
|
|
|
|
|
bvp->bv_len = vlen;
|
|
|
|
if (( bvp->bv_val = (char *)malloc( vlen + 1 )) == NULL ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "malloc", NULL );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
2000-07-28 09:07:07 +08:00
|
|
|
AC_MEMCPY( bvp->bv_val, value, vlen );
|
1999-02-15 18:49:20 +08:00
|
|
|
bvp->bv_val[ vlen ] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_addel(
|
2018-01-16 23:28:50 +08:00
|
|
|
struct tester_conn_args *config,
|
2018-11-01 02:12:04 +08:00
|
|
|
LDIFRecord *record,
|
2018-01-16 23:28:50 +08:00
|
|
|
int friendly )
|
1999-02-15 18:49:20 +08:00
|
|
|
{
|
2003-02-13 16:02:40 +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;
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2005-04-21 00:16:39 +08:00
|
|
|
retry:;
|
2003-02-13 16:02:40 +08:00
|
|
|
if ( ld == NULL ) {
|
2018-01-16 23:28:50 +08:00
|
|
|
tester_init_ld( &ld, config, 0 );
|
1999-02-15 18:49:20 +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 - Add/Delete(%d): entry=\"%s\".\n",
|
2018-11-01 02:12:04 +08:00
|
|
|
(long) pid, config->loops, record->lr_dn.bv_val );
|
2005-04-21 00:16:39 +08:00
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2018-01-16 23:28:50 +08:00
|
|
|
for ( ; i < config->loops; i++ ) {
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
/* add the entry */
|
2018-11-01 02:12:04 +08:00
|
|
|
rc = ldap_add_ext_s( ld, record->lr_dn.bv_val, record->lrop_mods, NULL, NULL );
|
2004-09-05 02:31:43 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_ldap_error( ld, "ldap_add_ext_s", NULL );
|
2005-11-04 22:49:59 +08:00
|
|
|
switch ( rc ) {
|
2005-11-04 23:51:19 +08:00
|
|
|
case LDAP_ALREADY_EXISTS:
|
|
|
|
/* NOTE: this likely means
|
|
|
|
* the delete 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;
|
|
|
|
|
2005-11-04 22:49:59 +08:00
|
|
|
case LDAP_BUSY:
|
|
|
|
case LDAP_UNAVAILABLE:
|
|
|
|
if ( do_retry > 0 ) {
|
|
|
|
do_retry--;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
/* fall thru */
|
1999-02-15 18:49:20 +08:00
|
|
|
|
2005-11-04 22:49:59 +08:00
|
|
|
default:
|
|
|
|
goto done;
|
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
2003-12-24 22:03:43 +08:00
|
|
|
#if 0
|
1999-02-15 18:49:20 +08:00
|
|
|
/* wait a second for the add to really complete */
|
2003-12-24 22:03:43 +08:00
|
|
|
/* This masks some race conditions though. */
|
2003-02-22 20:55:05 +08:00
|
|
|
sleep( 1 );
|
2003-12-24 22:03:43 +08:00
|
|
|
#endif
|
1999-02-15 18:49:20 +08:00
|
|
|
|
|
|
|
/* now delete the entry again */
|
2018-11-01 02:12:04 +08:00
|
|
|
rc = ldap_delete_ext_s( ld, record->lr_dn.bv_val, NULL, NULL );
|
2004-09-05 02:31:43 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_ldap_error( ld, "ldap_delete_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_OBJECT:
|
|
|
|
/* NOTE: this likely means
|
|
|
|
* the add 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;
|
|
|
|
|
2005-11-04 22:49:59 +08:00
|
|
|
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
|
|
|
}
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-04 22:49:59 +08:00
|
|
|
done:;
|
2008-07-19 19:54:54 +08:00
|
|
|
fprintf( stderr, " PID=%ld - Add/Delete done (%d).\n", (long) pid, rc );
|
1999-02-17 19:13:22 +08:00
|
|
|
|
2006-01-12 21:01:38 +08:00
|
|
|
ldap_unbind_ext( ld, NULL, NULL );
|
1999-02-15 18:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|