1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2021 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.
11##
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>.
15
16echo "running defines.sh"
17. $SRCDIR/scripts/defines.sh
18
19mkdir -p $TESTDIR $DBDIR1A $DBDIR1B
20
21echo "Running slapadd to build slapd database..."
22. $CONFFILTER $BACKEND < $CONF2DB > $CONF1
23$SLAPADD -f $CONF1 -b "$BASEDN" -l $LDIFORDERED
24RC=$?
25if test $RC != 0 ; then
26          echo "slapadd failed ($RC)!"
27          exit $RC
28fi
29
30echo "Starting slapd on TCP/IP port $PORT1..."
31$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
32PID=$!
33if test $WAIT != 0 ; then
34    echo PID $PID
35    read foo
36fi
37KILLPIDS="$PID"
38
39sleep 1
40
41echo "Testing slapd modrdn operations..."
42
43# Make sure we can search the database
44for i in 0 1 2 3 4 5; do
45          $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
46              'objectClass=*' > $INITOUT 2>&1
47          RC=$?
48          if test $RC = 0 ; then
49                    break
50          fi
51          echo "Waiting 5 seconds for slapd to start..."
52          sleep 5
53done
54
55if test $RC != 0 ; then
56          echo "ldapsearch failed ($RC)!"
57          test $KILLSERVERS != no && kill -HUP $KILLPIDS
58          exit $RC
59fi
60
61# -r used to do remove of old rdn
62
63echo "Testing modrdn(deleteoldrdn=0)..."
64$LDAPMODRDN -D "$MANAGERDN" -H $URI1 -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'
66
67RC=$?
68if test $RC != 0 ; then
69          echo "ldapmodrdn failed ($RC)!"
70          test $KILLSERVERS != no && kill -HUP $KILLPIDS
71          exit $RC
72fi
73
74echo "Testing modrdn(deleteoldrdn=1)..."
75$LDAPMODRDN -D "$MANAGERDN" -r -H $URI1 -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'
77
78RC=$?
79if test $RC != 0 ; then
80          echo "ldapmodrdn failed ($RC)!"
81          test $KILLSERVERS != no && kill -HUP $KILLPIDS
82          exit $RC
83fi
84
85# Ensure the new rdn's can be found
86
87echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones III)..."
88$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
89              'cn=James A Jones III' > $SEARCHOUT 2>&1
90RC=$?
91if test $RC != 0 ; then
92          echo "ldapsearch failed ($RC)!"
93          test $KILLSERVERS != no && kill -HUP $KILLPIDS
94          exit $RC
95fi
96
97
98LDIF=$MODRDNOUTPROVIDER1
99
100echo "Filtering ldapsearch results..."
101$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
102echo "Filtering original ldif used to create database..."
103$LDIFFILTER < $LDIF > $LDIFFLT
104echo "Comparing filter output..."
105$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
106
107if test $? != 0 ; then
108          echo "comparison failed - modrdn operations did not complete correctly"
109          test $KILLSERVERS != no && kill -HUP $KILLPIDS
110          exit -1
111fi
112
113
114echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones II)..."
115$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
116              'cn=James A Jones II' > $SEARCHOUT 2>&1
117RC=$?
118if test $RC != 0 ; then
119          echo "ldapsearch failed ($RC)!"
120          test $KILLSERVERS != no && kill -HUP $KILLPIDS
121          exit $RC
122fi
123
124
125LDIF=$MODRDNOUTPROVIDER2
126
127echo "Filtering ldapsearch results..."
128$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
129echo "Filtering original ldif used to create database..."
130$LDIFFILTER < $LDIF > $LDIFFLT
131echo "Comparing filter output..."
132$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
133
134if test $? != 0 ; then
135          echo "comparison failed - modrdn operations did not complete correctly"
136          test $KILLSERVERS != no && kill -HUP $KILLPIDS
137          exit -1
138fi
139
140# Ensure that you cannot find the entry for which the rdn was deleted as
141# an attribute.
142
143echo "Using ldapsearch to retrieve entries using removed rdn (cn=James A Jones 2)..."
144$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
145              'cn=James A Jones 2' > $SEARCHOUT 2>&1
146RC=$?
147if test $RC != 0 ; then
148          test $KILLSERVERS != no && kill -HUP $KILLPIDS
149          echo "ldapsearch failed ($RC)!"
150          exit $RC
151fi
152$CMP $SEARCHOUT - < /dev/null > $CMPOUT
153if test $? != 0 ; then
154          echo "failure: ldapsearch found attribute that was to be removed!"
155          test $KILLSERVERS != no && kill -HUP $KILLPIDS
156          exit -1
157fi
158
159echo "Using ldapsearch to retrieve all the entries..."
160$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
161              'objectClass=*' > $SEARCHOUT 2>&1
162RC=$?
163if test $RC != 0 ; then
164          test $KILLSERVERS != no && kill -HUP $KILLPIDS
165          echo "ldapsearch failed ($RC)!"
166          exit $RC
167fi
168
169LDIF=$MODRDNOUTPROVIDER0
170
171echo "Filtering ldapsearch results..."
172$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
173echo "Filtering original ldif used to create database..."
174$LDIFFILTER < $LDIF > $LDIFFLT
175echo "Comparing filter output..."
176$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
177
178if test $? != 0 ; then
179          echo "comparison failed - modrdn operations did not complete correctly"
180          test $KILLSERVERS != no && kill -HUP $KILLPIDS
181          exit -1
182fi
183
184# Test that you can use modrdn with an attribute value which was previously
185# present
186
187echo "Testing modrdn(deleteoldrdn=1), modrdn with new rdn already an att val..."
188$LDAPMODRDN -D "$MANAGERDN" -r -H $URI1 -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'
190
191RC=$?
192if test $RC != 0 ; then
193          echo "ldapmodrdn failed ($RC)!"
194          test $KILLSERVERS != no && kill -HUP $KILLPIDS
195          exit $RC
196fi
197
198echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones 1)..."
199$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
200              'cn=James A Jones 1' > $SEARCHOUT 2>&1
201RC=$?
202
203if test $RC != 0 ; then
204          echo "ldapsearch failed ($RC)!"
205          test $KILLSERVERS != no && kill -HUP $KILLPIDS
206          exit $RC
207fi
208
209LDIF=$MODRDNOUTPROVIDER3
210
211echo "Filtering ldapsearch results..."
212$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
213echo "Filtering original ldif used to create database..."
214$LDIFFILTER < $LDIF > $LDIFFLT
215echo "Comparing filter output..."
216$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
217
218if test $? != 0 ; then
219          echo "comparison failed - modrdn operations did not complete correctly"
220          test $KILLSERVERS != no && kill -HUP $KILLPIDS
221          exit -1
222fi
223
224echo "Testing modrdn to another database (should fail with affectsMultipleDSAs)"
225$LDAPMODRDN -D "$MANAGERDN" -H $URI1 -w $PASSWD > \
226          $TESTOUT 2>&1 'cn=All Staff,ou=Groups,dc=example,dc=com' 'cn=Everyone'
227RC=$?
228case $RC in
2290)
230          echo "ldapmodrdn succeeded, should have failed!"
231          test $KILLSERVERS != no && kill -HUP $KILLPIDS
232          exit -1
233          ;;
23471)
235          ;;
236*)
237          echo "ldapmodrdn failed ($RC)!"
238          test $KILLSERVERS != no && kill -HUP $KILLPIDS
239          exit $RC
240          ;;
241esac
242
243echo "Testing modrdn with newSuperior = target (should fail with unwillingToPerform)"
244$LDAPMODRDN -D "$MANAGERDN" -H $URI1 -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'
247
248RC=$?
249case $RC in
2500)
251          echo "ldapmodrdn succeeded, should have failed!"
252          test $KILLSERVERS != no && kill -HUP $KILLPIDS
253          exit -1
254          ;;
25553)
256          ;;
257*)
258          echo "ldapmodrdn failed ($RC)!"
259          test $KILLSERVERS != no && kill -HUP $KILLPIDS
260          exit $RC
261          ;;
262esac
263
264echo "Testing modrdn with newRdn exact same as target..."
265$LDAPMODRDN -D "$MANAGERDN" -H $URI1 -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'
267
268RC=$?
269case $RC in
2700)
271          ;;
272*)
273          echo "ldapmodrdn failed ($RC)!"
274          test $KILLSERVERS != no && kill -HUP $KILLPIDS
275          exit $RC
276          ;;
277esac
278
279echo "Testing modrdn with newRdn same as target, changed case..."
280$LDAPMODRDN -D "$MANAGERDN" -H $URI1 -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'
282
283RC=$?
284case $RC in
2850)
286          ;;
287*)
288          echo "ldapmodrdn failed ($RC)!"
289          test $KILLSERVERS != no && kill -HUP $KILLPIDS
290          exit $RC
291          ;;
292esac
293
294test $KILLSERVERS != no && kill -HUP $KILLPIDS
295
296echo ">>>>> Test succeeded"
297
298test $KILLSERVERS != no && wait
299
300exit 0
301