2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2018 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
20 #include "ac/stdlib.h"
24 #include "ac/socket.h"
25 #include "ac/string.h"
26 #include "ac/unistd.h"
32 #include "slapd-common.h"
37 do_modify( struct tester_conn_args *config, char *entry,
38 char *attr, char *value, int friendly );
42 usage( char *name, int opt )
45 fprintf( stderr, "%s: unable to handle option \'%c\'\n\n",
49 fprintf( stderr, "usage: %s " TESTER_COMMON_HELP
58 main( int argc, char **argv )
65 struct tester_conn_args *config;
67 config = tester_init( "slapd-modify", TESTER_MODIFY );
69 while ( ( i = getopt( argc, argv, TESTER_COMMON_OPTS "a:e:F" ) ) != EOF )
77 /* ignored (!) by now */
80 case 'e': /* entry to modify */
81 entry = strdup( optarg );
85 ava = strdup( optarg );
89 if ( tester_config_opt( config, i, optarg ) == LDAP_SUCCESS ) {
97 if (( entry == NULL ) || ( ava == NULL ))
100 if ( *entry == '\0' ) {
102 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
104 exit( EXIT_FAILURE );
107 if ( *ava == '\0' ) {
108 fprintf( stderr, "%s: invalid EMPTY AVA.\n",
110 exit( EXIT_FAILURE );
113 if ( !( value = strchr( ava, ':' ))) {
114 fprintf( stderr, "%s: invalid AVA.\n",
116 exit( EXIT_FAILURE );
119 while ( *value && isspace( (unsigned char) *value ))
122 tester_config_finish( config );
124 for ( i = 0; i < config->outerloops; i++ ) {
125 do_modify( config, entry, ava, value, friendly );
128 exit( EXIT_SUCCESS );
133 do_modify( struct tester_conn_args *config,
134 char *entry, char* attr, char* value, int friendly )
137 int i = 0, do_retry = config->retries;
138 int rc = LDAP_SUCCESS;
141 struct ldapmod *mods[2];
146 mod.mod_op = LDAP_MOD_ADD;
148 mod.mod_values = values;
153 tester_init_ld( &ld, config, 0 );
155 if ( do_retry == config->retries ) {
156 fprintf( stderr, "PID=%ld - Modify(%d): entry=\"%s\".\n",
157 (long) pid, config->loops, entry );
160 for ( ; i < config->loops; i++ ) {
161 mod.mod_op = LDAP_MOD_ADD;
162 rc = ldap_modify_ext_s( ld, entry, mods, NULL, NULL );
163 if ( rc != LDAP_SUCCESS ) {
164 tester_ldap_error( ld, "ldap_modify_ext_s", NULL );
166 case LDAP_TYPE_OR_VALUE_EXISTS:
167 /* NOTE: this likely means
168 * the second modify failed
169 * during the previous round... */
176 case LDAP_UNAVAILABLE:
177 if ( do_retry > 0 ) {
188 mod.mod_op = LDAP_MOD_DELETE;
189 rc = ldap_modify_ext_s( ld, entry, mods, NULL, NULL );
190 if ( rc != LDAP_SUCCESS ) {
191 tester_ldap_error( ld, "ldap_modify_ext_s", NULL );
193 case LDAP_NO_SUCH_ATTRIBUTE:
194 /* NOTE: this likely means
195 * the first modify failed
196 * during the previous round... */
203 case LDAP_UNAVAILABLE:
204 if ( do_retry > 0 ) {
218 fprintf( stderr, " PID=%ld - Modify done (%d).\n", (long) pid, rc );
220 ldap_unbind_ext( ld, NULL, NULL );