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>.
16 * This work was initially developed by Howard Chu, based in part
17 * on other OpenLDAP test tools, for inclusion in OpenLDAP Software.
24 #include "ac/stdlib.h"
28 #include "ac/socket.h"
29 #include "ac/string.h"
30 #include "ac/unistd.h"
36 #include "slapd-common.h"
42 do_modrdn( struct tester_conn_args *config,
43 char *entry, int friendly );
46 usage( char *name, char opt )
49 fprintf( stderr, "%s: unable to handle option \'%c\'\n\n",
53 fprintf( stderr, "usage: %s " TESTER_COMMON_HELP
61 main( int argc, char **argv )
66 struct tester_conn_args *config;
68 config = tester_init( "slapd-modrdn", TESTER_MODRDN );
70 while ( ( i = getopt( argc, argv, TESTER_COMMON_OPTS "e:F" ) ) != EOF )
78 /* ignored (!) by now */
81 case 'e': /* entry to rename */
82 entry = strdup( optarg );
86 if ( tester_config_opt( config, i, optarg ) == LDAP_SUCCESS ) {
97 if ( *entry == '\0' ) {
99 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
101 exit( EXIT_FAILURE );
105 tester_config_finish( config );
107 for ( i = 0; i < config->outerloops; i++ ) {
108 do_modrdn( config, entry, friendly );
111 exit( EXIT_SUCCESS );
116 do_modrdn( struct tester_conn_args *config,
117 char *entry, int friendly )
120 int i, do_retry = config->retries;
123 int rc = LDAP_SUCCESS;
127 DNs[1] = strdup( entry );
129 /* reverse the RDN, make new DN */
130 p1 = strchr( entry, '=' ) + 1;
131 p2 = strchr( p1, ',' );
134 rdns[1] = strdup( entry );
137 for (i = p1 - entry;p2 >= p1;)
141 rdns[0] = strdup( DNs[1] );
147 tester_init_ld( &ld, config, 0 );
149 if ( do_retry == config->retries ) {
150 fprintf( stderr, "PID=%ld - Modrdn(%d): entry=\"%s\".\n",
151 (long) pid, config->loops, entry );
154 for ( ; i < config->loops; i++ ) {
155 rc = ldap_rename_s( ld, DNs[0], rdns[0], NULL, 0, NULL, NULL );
156 if ( rc != LDAP_SUCCESS ) {
157 tester_ldap_error( ld, "ldap_rename_s", NULL );
159 case LDAP_NO_SUCH_OBJECT:
160 /* NOTE: this likely means
161 * the second modrdn failed
162 * during the previous round... */
169 case LDAP_UNAVAILABLE:
170 if ( do_retry > 0 ) {
180 rc = ldap_rename_s( ld, DNs[1], rdns[1], NULL, 1, NULL, NULL );
181 if ( rc != LDAP_SUCCESS ) {
182 tester_ldap_error( ld, "ldap_rename_s", NULL );
184 case LDAP_NO_SUCH_OBJECT:
185 /* NOTE: this likely means
186 * the first modrdn failed
187 * during the previous round... */
194 case LDAP_UNAVAILABLE:
195 if ( do_retry > 0 ) {
208 fprintf( stderr, " PID=%ld - Modrdn done (%d).\n", (long) pid, rc );
210 ldap_unbind_ext( ld, NULL, NULL );