Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / test005-modrdn
blob79661377c95b57d5a3ffd343e9677d5ad499117b
1 #! /bin/sh
2 # $OpenLDAP: pkg/ldap/tests/scripts/test005-modrdn,v 1.49.2.6 2008/02/11 23:26:51 kurt Exp $
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2008 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 mkdir -p $TESTDIR $DBDIR1A $DBDIR1B
21 echo "Running slapadd to build slapd database..."
22 . $CONFFILTER $BACKEND $MONITORDB < $CONF2DB > $CONF1
23 $SLAPADD -f $CONF1 -b "$BASEDN" -l $LDIFORDERED
24 RC=$?
25 if test $RC != 0 ; then
26 echo "slapadd failed ($RC)!"
27 exit $RC
30 echo "Starting slapd on TCP/IP port $PORT1..."
31 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
32 PID=$!
33 if test $WAIT != 0 ; then
34 echo PID $PID
35 read foo
37 KILLPIDS="$PID"
39 sleep 1
41 echo "Testing slapd modrdn operations..."
43 # Make sure we can search the database
44 for i in 0 1 2 3 4 5; do
45 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
46 'objectClass=*' > $INITOUT 2>&1
47 RC=$?
48 if test $RC = 0 ; then
49 break
51 echo "Waiting 5 seconds for slapd to start..."
52 sleep 5
53 done
55 if test $RC != 0 ; then
56 echo "ldapsearch failed ($RC)!"
57 test $KILLSERVERS != no && kill -HUP $KILLPIDS
58 exit $RC
61 # -r used to do remove of old rdn
63 echo "Testing modrdn(deleteoldrdn=0)..."
64 $LDAPMODRDN -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
65 $TESTOUT 2>&1 'cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com' 'cn=James A Jones III'
67 RC=$?
68 if test $RC != 0 ; then
69 echo "ldapmodrdn failed ($RC)!"
70 test $KILLSERVERS != no && kill -HUP $KILLPIDS
71 exit $RC
74 echo "Testing modrdn(deleteoldrdn=1)..."
75 $LDAPMODRDN -D "$MANAGERDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
76 $TESTOUT 2>&1 'cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example, dc=com' 'cn=James A Jones II'
78 RC=$?
79 if test $RC != 0 ; then
80 echo "ldapmodrdn failed ($RC)!"
81 test $KILLSERVERS != no && kill -HUP $KILLPIDS
82 exit $RC
85 # Ensure the new rdn's can be found
87 echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones III)..."
88 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
89 'cn=James A Jones III' > $SEARCHOUT 2>&1
90 RC=$?
91 if test $RC != 0 ; then
92 echo "ldapsearch failed ($RC)!"
93 test $KILLSERVERS != no && kill -HUP $KILLPIDS
94 exit $RC
98 LDIF=$MODRDNOUTMASTER1
100 echo "Filtering ldapsearch results..."
101 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
102 echo "Filtering original ldif used to create database..."
103 . $LDIFFILTER < $LDIF > $LDIFFLT
104 echo "Comparing filter output..."
105 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
107 if test $? != 0 ; then
108 echo "comparison failed - modrdn operations did not complete correctly"
109 test $KILLSERVERS != no && kill -HUP $KILLPIDS
110 exit -1
114 echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones II)..."
115 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
116 'cn=James A Jones II' > $SEARCHOUT 2>&1
117 RC=$?
118 if test $RC != 0 ; then
119 echo "ldapsearch failed ($RC)!"
120 test $KILLSERVERS != no && kill -HUP $KILLPIDS
121 exit $RC
125 LDIF=$MODRDNOUTMASTER2
127 echo "Filtering ldapsearch results..."
128 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
129 echo "Filtering original ldif used to create database..."
130 . $LDIFFILTER < $LDIF > $LDIFFLT
131 echo "Comparing filter output..."
132 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
134 if test $? != 0 ; then
135 echo "comparison failed - modrdn operations did not complete correctly"
136 test $KILLSERVERS != no && kill -HUP $KILLPIDS
137 exit -1
140 # Ensure that you cannot find the entry for which the rdn was deleted as
141 # an attribute.
143 echo "Using ldapsearch to retrieve entries using removed rdn (cn=James A Jones 2)..."
144 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
145 'cn=James A Jones 2' > $SEARCHOUT 2>&1
146 RC=$?
147 if test $RC != 0 ; then
148 test $KILLSERVERS != no && kill -HUP $KILLPIDS
149 echo "ldapsearch failed ($RC)!"
150 exit $RC
152 $CMP $SEARCHOUT - < /dev/null > $CMPOUT
153 if test $? != 0 ; then
154 echo "failure: ldapsearch found attribute that was to be removed!"
155 test $KILLSERVERS != no && kill -HUP $KILLPIDS
156 exit -1
159 echo "Using ldapsearch to retrieve all the entries..."
160 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
161 'objectClass=*' > $SEARCHOUT 2>&1
162 RC=$?
163 if test $RC != 0 ; then
164 test $KILLSERVERS != no && kill -HUP $KILLPIDS
165 echo "ldapsearch failed ($RC)!"
166 exit $RC
169 LDIF=$MODRDNOUTMASTER0
171 echo "Filtering ldapsearch results..."
172 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
173 echo "Filtering original ldif used to create database..."
174 . $LDIFFILTER < $LDIF > $LDIFFLT
175 echo "Comparing filter output..."
176 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
178 if test $? != 0 ; then
179 echo "comparison failed - modrdn operations did not complete correctly"
180 test $KILLSERVERS != no && kill -HUP $KILLPIDS
181 exit -1
184 # Test that you can use modrdn with an attribute value which was previously
185 # present
187 echo "Testing modrdn(deleteoldrdn=1), modrdn with new rdn already an att val..."
188 $LDAPMODRDN -D "$MANAGERDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD > \
189 /dev/null 2>&1 'cn=James A Jones III, ou=Alumni Association, ou=People, dc=example, dc=com' 'cn=James A Jones 1'
191 RC=$?
192 if test $RC != 0 ; then
193 echo "ldapmodrdn failed ($RC)!"
194 test $KILLSERVERS != no && kill -HUP $KILLPIDS
195 exit $RC
198 echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones 1)..."
199 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
200 'cn=James A Jones 1' > $SEARCHOUT 2>&1
201 RC=$?
203 if test $RC != 0 ; then
204 echo "ldapsearch failed ($RC)!"
205 test $KILLSERVERS != no && kill -HUP $KILLPIDS
206 exit $RC
209 LDIF=$MODRDNOUTMASTER3
211 echo "Filtering ldapsearch results..."
212 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
213 echo "Filtering original ldif used to create database..."
214 . $LDIFFILTER < $LDIF > $LDIFFLT
215 echo "Comparing filter output..."
216 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
218 if test $? != 0 ; then
219 echo "comparison failed - modrdn operations did not complete correctly"
220 test $KILLSERVERS != no && kill -HUP $KILLPIDS
221 exit -1
224 echo "Testing modrdn to another database (should fail with affectsMultipleDSAs)"
225 $LDAPMODRDN -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
226 $TESTOUT 2>&1 'cn=All Staff,ou=Groups,dc=example,dc=com' 'cn=Everyone'
227 RC=$?
228 case $RC in
230 echo "ldapmodrdn succeeded, should have failed!"
231 test $KILLSERVERS != no && kill -HUP $KILLPIDS
232 exit -1
237 echo "ldapmodrdn failed ($RC)!"
238 test $KILLSERVERS != no && kill -HUP $KILLPIDS
239 exit $RC
241 esac
243 echo "Testing modrdn with newSuperior = target (should fail with unwillingToPerform)"
244 $LDAPMODRDN -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
245 $TESTOUT 2>&1 -s 'cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com' \
246 'cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com' 'cn=James A Jones 1'
248 RC=$?
249 case $RC in
251 echo "ldapmodrdn succeeded, should have failed!"
252 test $KILLSERVERS != no && kill -HUP $KILLPIDS
253 exit -1
258 echo "ldapmodrdn failed ($RC)!"
259 test $KILLSERVERS != no && kill -HUP $KILLPIDS
260 exit $RC
262 esac
264 echo "Testing modrdn with newRdn exact same as target..."
265 $LDAPMODRDN -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
266 $TESTOUT 2>&1 'cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com' 'cn=James A Jones 1'
268 RC=$?
269 case $RC in
273 echo "ldapmodrdn failed ($RC)!"
274 test $KILLSERVERS != no && kill -HUP $KILLPIDS
275 exit $RC
277 esac
279 echo "Testing modrdn with newRdn same as target, changed case..."
280 $LDAPMODRDN -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
281 $TESTOUT 2>&1 'cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com' 'cn=James A JONES 1'
283 RC=$?
284 case $RC in
288 echo "ldapmodrdn failed ($RC)!"
289 test $KILLSERVERS != no && kill -HUP $KILLPIDS
290 exit $RC
292 esac
294 test $KILLSERVERS != no && kill -HUP $KILLPIDS
296 echo ">>>>> Test succeeded"
298 test $KILLSERVERS != no && wait
300 exit 0