Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / test040-subtree-rename
blob43473570fa9ad27f233863b9ccb3812425686596
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.
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 case $BACKEND in
20 hdb)
23 echo "subtree rename not supported by back-$BACKEND"
24 exit 0
25 esac
27 mkdir -p $TESTDIR $DBDIR1
29 echo "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 &
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 searching..."
42 for 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
49 echo "Waiting 5 seconds for slapd to start..."
50 sleep 5
51 done
53 if test $RC != 0 ; then
54 echo "ldapsearch failed ($RC)!"
55 test $KILLSERVERS != no && kill -HUP $KILLPIDS
56 exit $RC
59 cat /dev/null > $TESTOUT
60 cat /dev/null > $SEARCHOUT
62 # Add
63 echo "Populating the database..."
64 echo "# Populating the database..." >> $TESTOUT
65 $LDAPADD -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
66 >> $TESTOUT 2>&1 << EOMODS0
67 dn: dc=example,dc=com
68 objectClass: organization
69 objectClass: dcObject
70 o: Example, Inc.
71 dc: example
73 dn: ou=Parent,dc=example,dc=com
74 objectClass: organizationalUnit
75 ou: Parent
77 dn: ou=Another parent,dc=example,dc=com
78 objectClass: organizationalUnit
79 ou: Another parent
81 dn: ou=Child,ou=Parent,dc=example,dc=com
82 objectClass: organizationalUnit
83 ou: Child
85 dn: ou=Grandchild,ou=Child,ou=Parent,dc=example,dc=com
86 objectClass: organizationalUnit
87 ou: Grandchild
88 EOMODS0
89 RC=$?
90 if test $RC != 0 ; then
91 echo "ldapadd failed ($RC)!"
92 test $KILLSERVERS != no && kill -HUP $KILLPIDS
93 exit $RC
96 echo "Searching all database..."
97 echo "# Searching all database (after add)..." >> $SEARCHOUT
98 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
99 '(objectClass=*)' >> $SEARCHOUT 2>&1
100 RC=$?
101 if test $RC != 0 ; then
102 echo "ldapsearch failed ($RC)!"
103 test $KILLSERVERS != no && kill -HUP $KILLPIDS
104 exit $RC
107 # Rename (PASS1)
108 echo "Renaming (PASS1)..."
109 echo "# Renaming (PASS1)..." >> $TESTOUT
110 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
111 >> $TESTOUT 2>&1 << EOMODS1
112 dn: ou=Child,ou=Parent,dc=example,dc=com
113 changetype: modrdn
114 newrdn: ou=Renamed child
115 deleteoldrdn: 0
116 EOMODS1
117 RC=$?
118 if test $RC != 0 ; then
119 echo "ldapadd failed ($RC)!"
120 test $KILLSERVERS != no && kill -HUP $KILLPIDS
121 exit $RC
124 echo "Searching all database..."
125 echo "# Searching all database (after PASS1)..." >> $SEARCHOUT
126 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
127 '(objectClass=*)' >> $SEARCHOUT 2>&1
128 RC=$?
129 if test $RC != 0 ; then
130 echo "ldapsearch failed ($RC)!"
131 test $KILLSERVERS != no && kill -HUP $KILLPIDS
132 exit $RC
135 # Rename (PASS2)
136 echo "Renaming (PASS2)..."
137 echo "# Renaming (PASS2)..." >> $TESTOUT
138 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
139 >> $TESTOUT 2>&1 << EOMODS2
140 dn: ou=Parent,dc=example,dc=com
141 changetype: modrdn
142 newrdn: ou=Renamed parent
143 deleteoldrdn: 0
144 EOMODS2
145 RC=$?
146 if test $RC != 0 ; then
147 echo "ldapadd failed ($RC)!"
148 test $KILLSERVERS != no && kill -HUP $KILLPIDS
149 exit $RC
152 echo "Searching all database..."
153 echo "# Searching all database (after PASS2)..." >> $SEARCHOUT
154 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
155 '(objectClass=*)' >> $SEARCHOUT 2>&1
156 RC=$?
157 if test $RC != 0 ; then
158 echo "ldapsearch failed ($RC)!"
159 test $KILLSERVERS != no && kill -HUP $KILLPIDS
160 exit $RC
163 # Rename (PASS3)
164 echo "Renaming (PASS3)..."
165 echo "# Renaming (PASS3)..." >> $TESTOUT
166 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
167 >> $TESTOUT 2>&1 << EOMODS3
168 dn: ou=Renamed child,ou=Renamed parent,dc=example,dc=com
169 changetype: modrdn
170 newrdn: ou=Renamed child
171 deleteoldrdn: 0
172 newsuperior: ou=Another parent,dc=example,dc=com
173 EOMODS3
174 RC=$?
175 if test $RC != 0 ; then
176 echo "ldapadd failed ($RC)!"
177 test $KILLSERVERS != no && kill -HUP $KILLPIDS
178 exit $RC
181 echo "Searching all database..."
182 echo "# Searching all database (after PASS3)..." >> $SEARCHOUT
183 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
184 '(objectClass=*)' >> $SEARCHOUT 2>&1
185 RC=$?
186 if test $RC != 0 ; then
187 echo "ldapsearch failed ($RC)!"
188 test $KILLSERVERS != no && kill -HUP $KILLPIDS
189 exit $RC
192 test $KILLSERVERS != no && kill -HUP $KILLPIDS
194 LDIF=$SUBTREERENAMEOUT
196 echo "Filtering ldapsearch results..."
197 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
198 echo "Filtering original ldif used to create database..."
199 . $LDIFFILTER < $LDIF > $LDIFFLT
200 echo "Comparing filter output..."
201 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
203 if test $? != 0 ; then
204 echo "Comparison failed"
205 exit 1
208 echo ">>>>> Test succeeded"
210 test $KILLSERVERS != no && wait
212 exit 0