2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2006 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"
38 do_modify( char *uri, char *manager, struct berval *passwd,
39 char *entry, char *attr, char *value, int maxloop,
40 int maxretries, int delay, int friendly, int chaserefs );
48 "-H <uri> | ([-h <host>] -p <port>) "
63 main( int argc, char **argv )
67 char *host = "localhost";
70 struct berval passwd = { 0, NULL };
76 int retries = RETRIES;
81 tester_init( "slapd-modify" );
83 while ( (i = getopt( argc, argv, "CFH:h:p:D:w:e:a:l:L:r:t:" )) != EOF ) {
93 case 'H': /* the server uri */
94 uri = strdup( optarg );
97 case 'h': /* the servers host */
98 host = strdup( optarg );
101 case 'p': /* the servers port */
102 if ( lutil_atoi( &port, optarg ) != 0 ) {
107 case 'D': /* the servers manager */
108 manager = strdup( optarg );
111 case 'w': /* the server managers password */
112 passwd.bv_val = strdup( optarg );
113 passwd.bv_len = strlen( optarg );
116 case 'e': /* entry to modify */
117 entry = strdup( optarg );
121 ava = strdup( optarg );
124 case 'l': /* the number of loops */
125 if ( lutil_atoi( &loops, optarg ) != 0 ) {
130 case 'L': /* the number of outerloops */
131 if ( lutil_atoi( &outerloops, optarg ) != 0 ) {
136 case 'r': /* number of retries */
137 if ( lutil_atoi( &retries, optarg ) != 0 ) {
142 case 't': /* delay in seconds */
143 if ( lutil_atoi( &delay, optarg ) != 0 ) {
154 if (( entry == NULL ) || ( ava == NULL ) || ( port == -1 && uri == NULL ))
157 if ( *entry == '\0' ) {
159 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
161 exit( EXIT_FAILURE );
164 if ( *ava == '\0' ) {
165 fprintf( stderr, "%s: invalid EMPTY AVA.\n",
167 exit( EXIT_FAILURE );
170 if ( !( value = strchr( ava, ':' ))) {
171 fprintf( stderr, "%s: invalid AVA.\n",
173 exit( EXIT_FAILURE );
176 while ( *value && isspace( (unsigned char) *value ))
179 uri = tester_uri( uri, host, port );
181 for ( i = 0; i < outerloops; i++ ) {
182 do_modify( uri, manager, &passwd, entry, ava, value,
183 loops, retries, delay, friendly, chaserefs );
186 exit( EXIT_SUCCESS );
191 do_modify( char *uri, char *manager,
192 struct berval *passwd, char *entry, char* attr, char* value,
193 int maxloop, int maxretries, int delay, int friendly, int chaserefs )
196 int i = 0, do_retry = maxretries;
198 int rc = LDAP_SUCCESS;
201 struct ldapmod *mods[2];
203 int version = LDAP_VERSION3;
209 mod.mod_op = LDAP_MOD_ADD;
211 mod.mod_values = values;
216 ldap_initialize( &ld, uri );
218 tester_perror( "ldap_initialize", NULL );
219 exit( EXIT_FAILURE );
222 (void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
223 (void) ldap_set_option( ld, LDAP_OPT_REFERRALS,
224 chaserefs ? LDAP_OPT_ON : LDAP_OPT_OFF );
226 if ( do_retry == maxretries ) {
227 fprintf( stderr, "PID=%ld - Modify(%d): entry=\"%s\".\n",
228 (long) pid, maxloop, entry );
231 rc = ldap_sasl_bind_s( ld, manager, LDAP_SASL_SIMPLE, passwd, NULL, NULL, NULL );
232 if ( rc != LDAP_SUCCESS ) {
233 tester_ldap_error( ld, "ldap_sasl_bind_s", NULL );
236 case LDAP_UNAVAILABLE:
237 if ( do_retry > 0 ) {
248 exit( EXIT_FAILURE );
251 for ( ; i < maxloop; i++ ) {
252 mod.mod_op = LDAP_MOD_ADD;
253 rc = ldap_modify_ext_s( ld, entry, mods, NULL, NULL );
254 if ( rc != LDAP_SUCCESS ) {
255 tester_ldap_error( ld, "ldap_modify_ext_s", NULL );
257 case LDAP_TYPE_OR_VALUE_EXISTS:
258 /* NOTE: this likely means
259 * the second modify failed
260 * during the previous round... */
267 case LDAP_UNAVAILABLE:
268 if ( do_retry > 0 ) {
279 mod.mod_op = LDAP_MOD_DELETE;
280 rc = ldap_modify_ext_s( ld, entry, mods, NULL, NULL );
281 if ( rc != LDAP_SUCCESS ) {
282 tester_ldap_error( ld, "ldap_modify_ext_s", NULL );
284 case LDAP_NO_SUCH_ATTRIBUTE:
285 /* NOTE: this likely means
286 * the first modify failed
287 * during the previous round... */
294 case LDAP_UNAVAILABLE:
295 if ( do_retry > 0 ) {
309 fprintf( stderr, " PID=%ld - Modify done (%d).\n", (long) pid, rc );
311 ldap_unbind_ext( ld, NULL, NULL );