#include "ldap.h"
#include "lutil.h"
+#include "ldif.h"
#include "slapd-common.h"
-static char *
-get_add_entry( char *filename, LDAPMod ***mods );
+static LDIFRecord *
+get_add_entry( char *filename );
static void
do_addel( struct tester_conn_args *config,
- char *dn, LDAPMod **attrs, int friendly );
+ LDIFRecord *record, int friendly );
static void
usage( char *name, char opt )
main( int argc, char **argv )
{
int i;
- char *filename = NULL;
- char *entry = NULL;
+ char *filename = NULL, *buf = NULL;
int friendly = 0;
- LDAPMod **attrs = NULL;
+ struct LDIFFP *fp;
+ LDIFRecord record = {};
struct tester_conn_args *config;
+ struct berval bv = {};
+ unsigned long lineno = 0;
config = tester_init( "slapd-addel", TESTER_ADDEL );
if ( filename == NULL )
usage( argv[0], 0 );
- entry = get_add_entry( filename, &attrs );
- if (( entry == NULL ) || ( *entry == '\0' )) {
+ if ( (fp = ldif_open( filename, "r" )) == NULL ) {
+ tester_perror( filename, "while reading ldif file" );
+ exit( EXIT_FAILURE );
+ }
- fprintf( stderr, "%s: invalid entry DN in file \"%s\".\n",
- argv[0], filename );
+ i = 0;
+ if ( ldif_read_record( fp, &lineno, &buf, &i ) < 0 ) {
+ tester_error( "ldif_read_record failed" );
exit( EXIT_FAILURE );
+ }
+ bv.bv_val = buf;
+ bv.bv_len = i;
+ 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 );
}
+ ldif_close( fp );
- if (( attrs == NULL ) || ( *attrs == '\0' )) {
+ if ( ( record.lr_op != LDAP_REQ_ADD ) || ( !record.lrop_mods ) ) {
- fprintf( stderr, "%s: invalid attrs in file \"%s\".\n",
+ fprintf( stderr, "%s: invalid entry DN in file \"%s\".\n",
argv[0], filename );
exit( EXIT_FAILURE );
tester_config_finish( config );
for ( i = 0; i < config->outerloops; i++ ) {
- do_addel( config, entry, attrs, friendly );
+ do_addel( config, &record, friendly );
}
+ free( buf );
exit( EXIT_SUCCESS );
}
}
-static char *
-get_add_entry( char *filename, LDAPMod ***mods )
-{
- FILE *fp;
- char *entry = NULL;
-
- if ( (fp = fopen( filename, "r" )) != NULL ) {
- char line[BUFSIZ];
-
- if ( fgets( line, BUFSIZ, fp )) {
- char *nl;
-
- if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
- *nl = '\0';
- nl = line;
- if ( !strncasecmp( nl, "dn: ", 4 ))
- nl += 4;
- entry = strdup( nl );
-
- }
-
- while ( fgets( line, BUFSIZ, fp )) {
- char *nl;
- char *value;
-
- if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
- *nl = '\0';
-
- if ( *line == '\0' ) break;
- if ( !( value = strchr( line, ':' ))) break;
-
- *value++ = '\0';
- while ( *value && isspace( (unsigned char) *value ))
- value++;
-
- addmodifyop( mods, LDAP_MOD_ADD, line, value, strlen( value ));
-
- }
- fclose( fp );
- }
-
- return( entry );
-}
-
-
static void
do_addel(
struct tester_conn_args *config,
- char *entry,
- LDAPMod **attrs,
+ LDIFRecord *record,
int friendly )
{
LDAP *ld = NULL;
if ( do_retry == config->retries ) {
fprintf( stderr, "PID=%ld - Add/Delete(%d): entry=\"%s\".\n",
- (long) pid, config->loops, entry );
+ (long) pid, config->loops, record->lr_dn.bv_val );
}
for ( ; i < config->loops; i++ ) {
/* add the entry */
- rc = ldap_add_ext_s( ld, entry, attrs, NULL, NULL );
+ rc = ldap_add_ext_s( ld, record->lr_dn.bv_val, record->lrop_mods, NULL, NULL );
if ( rc != LDAP_SUCCESS ) {
tester_ldap_error( ld, "ldap_add_ext_s", NULL );
switch ( rc ) {
#endif
/* now delete the entry again */
- rc = ldap_delete_ext_s( ld, entry, NULL, NULL );
+ rc = ldap_delete_ext_s( ld, record->lr_dn.bv_val, NULL, NULL );
if ( rc != LDAP_SUCCESS ) {
tester_ldap_error( ld, "ldap_delete_ext_s", NULL );
switch ( rc ) {