xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test040-subtree-rename (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1#! /bin/sh
2# $OpenLDAP: pkg/ldap/tests/scripts/test040-subtree-rename,v 1.4.2.3 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.
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
19case $BACKEND in
20hdb)
21	;;
22*)
23	echo "subtree rename not supported by back-$BACKEND"
24	exit 0
25esac
26
27mkdir -p $TESTDIR $DBDIR1
28
29echo "Starting slapd on TCP/IP port $PORT1..."
30. $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
31$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $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 searching..."
42for i in 0 1 2 3 4 5; do
43	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
44		'(objectclass=*)' > /dev/null 2>&1
45	RC=$?
46	if test $RC = 0 ; then
47		break
48	fi
49	echo "Waiting 5 seconds for slapd to start..."
50	sleep 5
51done
52
53if test $RC != 0 ; then
54	echo "ldapsearch failed ($RC)!"
55	test $KILLSERVERS != no && kill -HUP $KILLPIDS
56	exit $RC
57fi
58
59cat /dev/null > $TESTOUT
60cat /dev/null > $SEARCHOUT
61
62# Add
63echo "Populating the database..."
64echo "# Populating the database..." >> $TESTOUT
65$LDAPADD -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
66	>> $TESTOUT 2>&1 << EOMODS0
67dn: dc=example,dc=com
68objectClass: organization
69objectClass: dcObject
70o: Example, Inc.
71dc: example
72
73dn: ou=Parent,dc=example,dc=com
74objectClass: organizationalUnit
75ou: Parent
76
77dn: ou=Another parent,dc=example,dc=com
78objectClass: organizationalUnit
79ou: Another parent
80
81dn: ou=Child,ou=Parent,dc=example,dc=com
82objectClass: organizationalUnit
83ou: Child
84
85dn: ou=Grandchild,ou=Child,ou=Parent,dc=example,dc=com
86objectClass: organizationalUnit
87ou: Grandchild
88EOMODS0
89RC=$?
90if test $RC != 0 ; then
91	echo "ldapadd failed ($RC)!"
92	test $KILLSERVERS != no && kill -HUP $KILLPIDS
93	exit $RC
94fi
95
96echo "Searching all database..."
97echo "# Searching all database (after add)..." >> $SEARCHOUT
98$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
99	'(objectClass=*)' >> $SEARCHOUT 2>&1
100RC=$?
101if test $RC != 0 ; then
102	echo "ldapsearch failed ($RC)!"
103	test $KILLSERVERS != no && kill -HUP $KILLPIDS
104	exit $RC
105fi
106
107# Rename (PASS1)
108echo "Renaming (PASS1)..."
109echo "# Renaming (PASS1)..." >> $TESTOUT
110$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
111	>> $TESTOUT 2>&1 << EOMODS1
112dn: ou=Child,ou=Parent,dc=example,dc=com
113changetype: modrdn
114newrdn: ou=Renamed child
115deleteoldrdn: 0
116EOMODS1
117RC=$?
118if test $RC != 0 ; then
119	echo "ldapadd failed ($RC)!"
120	test $KILLSERVERS != no && kill -HUP $KILLPIDS
121	exit $RC
122fi
123
124echo "Searching all database..."
125echo "# Searching all database (after PASS1)..." >> $SEARCHOUT
126$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
127	'(objectClass=*)' >> $SEARCHOUT 2>&1
128RC=$?
129if test $RC != 0 ; then
130	echo "ldapsearch failed ($RC)!"
131	test $KILLSERVERS != no && kill -HUP $KILLPIDS
132	exit $RC
133fi
134
135# Rename (PASS2)
136echo "Renaming (PASS2)..."
137echo "# Renaming (PASS2)..." >> $TESTOUT
138$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
139	>> $TESTOUT 2>&1 << EOMODS2
140dn: ou=Parent,dc=example,dc=com
141changetype: modrdn
142newrdn: ou=Renamed parent
143deleteoldrdn: 0
144EOMODS2
145RC=$?
146if test $RC != 0 ; then
147	echo "ldapadd failed ($RC)!"
148	test $KILLSERVERS != no && kill -HUP $KILLPIDS
149	exit $RC
150fi
151
152echo "Searching all database..."
153echo "# Searching all database (after PASS2)..." >> $SEARCHOUT
154$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
155	'(objectClass=*)' >> $SEARCHOUT 2>&1
156RC=$?
157if test $RC != 0 ; then
158	echo "ldapsearch failed ($RC)!"
159	test $KILLSERVERS != no && kill -HUP $KILLPIDS
160	exit $RC
161fi
162
163# Rename (PASS3)
164echo "Renaming (PASS3)..."
165echo "# Renaming (PASS3)..." >> $TESTOUT
166$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
167	>> $TESTOUT 2>&1 << EOMODS3
168dn: ou=Renamed child,ou=Renamed parent,dc=example,dc=com
169changetype: modrdn
170newrdn: ou=Renamed child
171deleteoldrdn: 0
172newsuperior: ou=Another parent,dc=example,dc=com
173EOMODS3
174RC=$?
175if test $RC != 0 ; then
176	echo "ldapadd failed ($RC)!"
177	test $KILLSERVERS != no && kill -HUP $KILLPIDS
178	exit $RC
179fi
180
181echo "Searching all database..."
182echo "# Searching all database (after PASS3)..." >> $SEARCHOUT
183$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
184	'(objectClass=*)' >> $SEARCHOUT 2>&1
185RC=$?
186if test $RC != 0 ; then
187	echo "ldapsearch failed ($RC)!"
188	test $KILLSERVERS != no && kill -HUP $KILLPIDS
189	exit $RC
190fi
191
192test $KILLSERVERS != no && kill -HUP $KILLPIDS
193
194LDIF=$SUBTREERENAMEOUT
195
196echo "Filtering ldapsearch results..."
197. $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
198echo "Filtering original ldif used to create database..."
199. $LDIFFILTER < $LDIF > $LDIFFLT
200echo "Comparing filter output..."
201$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
202
203if test $? != 0 ; then
204	echo "Comparison failed"
205	exit 1
206fi
207
208echo ">>>>> Test succeeded"
209
210test $KILLSERVERS != no && wait
211
212exit 0
213