]> git.sur5r.net Git - openldap/blob - tests/scripts/test035-meta
Fix typo "failed $(RC)" -> "failed ($RC)"
[openldap] / tests / scripts / test035-meta
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2005 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
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 echo ""
20
21 if test $BACKMETA = metano ; then 
22         echo "meta backend not available, test skipped"
23         exit 0
24 fi
25
26 rm -rf $TESTDIR
27
28 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
29
30 echo "Starting slapd on TCP/IP port $PORT1..."
31 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
32 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
33 PID=$!
34 if test $WAIT != 0 ; then
35     echo PID $PID
36     read foo
37 fi
38 KILLPIDS="$PID"
39
40 echo "Using ldapsearch to check that slapd is running..."
41 for i in 0 1 2 3 4 5; do
42         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
43                 'objectclass=*' > /dev/null 2>&1
44         RC=$?
45         if test $RC = 0 ; then
46                 break
47         fi
48         echo "Waiting 5 seconds for slapd to start..."
49         sleep 5
50 done
51 if test $RC != 0 ; then
52         echo "ldapsearch failed ($RC)!"
53         test $KILLSERVERS != no && kill -HUP $KILLPIDS
54         exit $RC
55 fi
56
57 echo "Using ldapadd to populate the database..."
58 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
59         $LDIFORDERED > $TESTOUT 2>&1
60 RC=$?
61 if test $RC != 0 ; then
62         echo "ldapadd failed ($RC)!"
63         test $KILLSERVERS != no && kill -HUP $KILLPIDS
64         exit $RC
65 fi
66
67 echo "Starting slapd on TCP/IP port $PORT2..."
68 . $CONFFILTER $BACKEND $MONITORDB < $METACONF2 > $CONF2
69 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
70 PID=$!
71 if test $WAIT != 0 ; then
72     echo PID $PID
73     read foo
74 fi
75 KILLPIDS="$KILLPIDS $PID"
76
77 echo "Using ldapsearch to check that slapd is running..."
78 for i in 0 1 2 3 4 5; do
79         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
80                 'objectclass=*' > /dev/null 2>&1
81         RC=$?
82         if test $RC = 0 ; then
83                 break
84         fi
85         echo "Waiting 5 seconds for slapd to start..."
86         sleep 5
87 done
88 if test $RC != 0 ; then
89         echo "ldapsearch failed ($RC)!"
90         test $KILLSERVERS != no && kill -HUP $KILLPIDS
91         exit $RC
92 fi
93
94 echo "Using ldapadd to populate the database..."
95 $LDAPADD -D "$METAMANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD < \
96         $LDIFMETA >> $TESTOUT 2>&1
97 RC=$?
98 if test $RC != 0 ; then
99         echo "ldapadd failed ($RC)!"
100         test $KILLSERVERS != no && kill -HUP $KILLPIDS
101         exit $RC
102 fi
103
104 echo "Starting slapd on TCP/IP port $PORT3..."
105 . $CONFFILTER $BACKEND $MONITORDB < $METACONF > $CONF3
106 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
107 PID=$!
108 if test $WAIT != 0 ; then
109     echo PID $PID
110     read foo
111 fi
112 KILLPIDS="$KILLPIDS $PID"
113
114 echo "Using ldapsearch to check that slapd is running..."
115 for i in 0 1 2 3 4 5; do
116         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
117                 'objectclass=*' > /dev/null 2>&1
118         RC=$?
119         if test $RC = 0 ; then
120                 break
121         fi
122         echo "Waiting 5 seconds for slapd to start..."
123         sleep 5
124 done
125 if test $RC != 0 ; then
126         echo "ldapsearch failed ($RC)!"
127         test $KILLSERVERS != no && kill -HUP $KILLPIDS
128         exit $RC
129 fi
130
131 cat /dev/null > $SEARCHOUT
132
133 BASEDN="o=Example,c=US"
134 echo "Searching base=\"$BASEDN\"..."
135 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
136 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" >> $SEARCHOUT 2>&1
137 RC=$?
138 #if test $RC != 0 ; then
139 #       echo "Search failed ($RC)!"
140 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
141 #       exit $RC
142 #fi
143 case $RC in 
144         0)
145         ;;
146         51)
147                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
148                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
149                 exit 0
150         ;;
151         *)
152                 echo "Search failed ($RC)!"
153                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
154                 exit $RC
155         ;;
156 esac
157
158 #
159 # Do some modifications
160 #
161
162 BASEDN="o=Example,c=US"
163 echo "Modifying database \"$BASEDN\"..."
164 $LDAPMODIFY -v -D "cn=Manager,$BASEDN" -h $LOCALHOST -p $PORT3 -w $PASSWD \
165         -M >> $TESTOUT 2>&1 << EOMODS
166 # These operations (updates with objectClass mapping) triggered ITS#3499
167 dn: cn=Added Group,ou=Groups,$BASEDN
168 changetype: add
169 objectClass: groupOfNames
170 objectClass: uidObject
171 cn: Added Group
172 member: cn=Added Group,ou=Groups,$BASEDN
173 uid: added
174
175 dn: cn=Another Added Group,ou=Groups,$BASEDN
176 changetype: add
177 objectClass: groupOfNames
178 cn: Another Added Group
179 member: cn=Added Group,ou=Groups,$BASEDN
180 member: cn=Another Added Group,ou=Groups,$BASEDN
181
182 dn: cn=Another Added Group,ou=Groups,$BASEDN
183 changetype: modify
184 add: objectClass
185 objectClass: uidObject
186 -
187 add: uid
188 uid: added
189 -
190
191 dn: cn=Added Group,ou=Groups,$BASEDN
192 changetype: modify
193 delete: objectClass
194 objectClass: uidObject
195 -
196 delete: uid
197 -
198
199 dn: ou=Meta,$BASEDN
200 changetype: modify
201 add: description
202 description: added to "ou=Meta,$BASEDN"
203 -
204
205 dn: ou=Who's going to handle this?,$BASEDN
206 changetype: add
207 objectClass: organizationalUnit
208 ou: Who's going to handle this?
209 description: added
210 description: will be deleted
211
212 dn: ou=Same as above,$BASEDN
213 changetype: add
214 objectClass: organizationalUnit
215 ou: Same as above
216 description: added right after "Who's going to handle this?"
217 description: will be preserved
218
219 dn: ou=Who's going to handle this?,$BASEDN
220 changetype: delete
221
222 dn: ou=Who's going to handle this?,ou=Meta,$BASEDN
223 changetype: add
224 objectClass: organizationalUnit
225 ou: Who's going to handle this?
226 description: added
227 description: will be deleted
228
229 dn: ou=Same as above,ou=Meta,$BASEDN
230 changetype: add
231 objectClass: organizationalUnit
232 ou: Same as above
233 description: added right after "Who's going to handle this?"
234 description: will be preserved
235
236 dn: cn=Added User,ou=Same as above,ou=Meta,$BASEDN
237 changetype: add
238 objectClass: inetOrgPerson
239 cn: Added User
240 sn: User
241 userPassword: secret
242
243 dn: ou=Who's going to handle this?,ou=Meta,$BASEDN
244 changetype: delete
245 EOMODS
246
247 RC=$?
248 #if test $RC != 0 ; then
249 #       echo "Modify failed ($RC)!"
250 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
251 #       exit $RC
252 #fi
253 case $RC in 
254         0)
255         ;;
256         51)
257                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
258                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
259                 exit 0
260         ;;
261         *)
262                 echo "Compare failed ($RC)!"
263                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
264                 exit $RC
265         ;;
266 esac
267
268 echo "Searching base=\"$BASEDN\"..."
269 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
270 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" >> $SEARCHOUT 2>&1
271 RC=$?
272 #if test $RC != 0 ; then
273 #       echo "Search failed ($RC)!"
274 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
275 #       exit $RC
276 #fi
277 case $RC in 
278         0)
279         ;;
280         51)
281                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
282                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
283                 exit 0
284         ;;
285         *)
286                 echo "Search failed ($RC)!"
287                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
288                 exit $RC
289         ;;
290 esac
291
292 BASEDN="o=Example,c=US"
293 echo "  base=\"$BASEDN\"..."
294 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
295 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" -M "$FILTER" '*' ref \
296         >> $SEARCHOUT 2>&1
297 RC=$?
298 #if test $RC != 0 ; then
299 #       echo "Search failed ($RC)!"
300 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
301 #       exit $RC
302 #fi
303 case $RC in 
304         0)
305         ;;
306         51)
307                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
308                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
309                 exit 0
310         ;;
311         *)
312                 echo "Search failed ($RC)!"
313                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
314                 exit $RC
315         ;;
316 esac
317
318 BASEDN="o=Example,c=US"
319 FILTER="(seeAlso=cn=all staff,ou=Groups,$BASEDN)"
320 echo "Searching filter=\"$FILTER\""
321 echo "  attrs=\"seeAlso\""
322 echo "  base=\"$BASEDN\"..."
323 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
324 echo "#         attrs=\"seeAlso\"" >> $SEARCHOUT
325 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
326 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" "$FILTER" seeAlso \
327         >> $SEARCHOUT 2>&1
328 RC=$?
329 #if test $RC != 0 ; then
330 #       echo "Search failed ($RC)!"
331 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
332 #       exit $RC
333 #fi
334 case $RC in 
335         0)
336         ;;
337         51)
338                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
339                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
340                 exit 0
341         ;;
342         *)
343                 echo "Search failed ($RC)!"
344                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
345                 exit $RC
346         ;;
347 esac
348
349 FILTER="(uid=example)"
350 echo "Searching filter=\"$FILTER\""
351 echo "  attrs=\"uid\""
352 echo "  base=\"$BASEDN\"..."
353 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
354 echo "#         attrs=\"uid\"" >> $SEARCHOUT
355 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
356 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" "$FILTER" uid \
357         >> $SEARCHOUT 2>&1
358 RC=$?
359 #if test $RC != 0 ; then
360 #       echo "Search failed ($RC)!"
361 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
362 #       exit $RC
363 #fi
364 case $RC in 
365         0)
366         ;;
367         51)
368                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
369                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
370                 exit 0
371         ;;
372         *)
373                 echo "Search failed ($RC)!"
374                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
375                 exit $RC
376         ;;
377 esac
378
379 FILTER="(member=cn=Another Added Group,ou=Groups,$BASEDN)"
380 echo "Searching filter=\"$FILTER\""
381 echo "  attrs=\"member\""
382 echo "  base=\"$BASEDN\"..."
383 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
384 echo "#         attrs=\"member\"" >> $SEARCHOUT
385 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
386 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" "$FILTER" member \
387         >> $SEARCHOUT 2>&1
388 RC=$?
389 #if test $RC != 0 ; then
390 #       echo "Search failed ($RC)!"
391 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
392 #       exit $RC
393 #fi
394 case $RC in 
395         0)
396         ;;
397         51)
398                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
399                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
400                 exit 0
401         ;;
402         *)
403                 echo "Search failed ($RC)!"
404                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
405                 exit $RC
406         ;;
407 esac
408
409 echo "Filtering ldapsearch results..."
410 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
411 echo "Filtering original ldif used to create database..."
412 . $LDIFFILTER < $METAOUT > $LDIFFLT
413 echo "Comparing filter output..."
414 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
415         
416 if test $? != 0 ; then
417         echo "comparison failed - meta search/modification didn't succeed"
418         test $KILLSERVERS != no && kill -HUP $KILLPIDS
419         exit 1
420 fi
421
422 BASEDN="o=Example,c=US"
423 echo "Changing password to database \"$BASEDN\"..."
424 $LDAPPASSWD -h $LOCALHOST -p $PORT3 -D "cn=Manager,$BASEDN" -w $PASSWD \
425         -s $PASSWD "cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN" \
426         >> $TESTOUT 2>&1
427 RC=$?
428 #if test $RC != 0 ; then
429 #       echo "Passwd ExOp failed ($RC)!"
430 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
431 #       exit $RC
432 #fi
433 case $RC in 
434         0)
435         ;;
436         51)
437                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
438                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
439                 exit 0
440         ;;
441         *)
442                 echo "Passwd ExOp failed ($RC)!"
443                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
444                 exit $RC
445         ;;
446 esac
447
448 echo "Binding with newly changed password to database \"$BASEDN\"..."
449 $LDAPWHOAMI -h $LOCALHOST -p $PORT3 \
450         -D "cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN" \
451         -w $PASSWD >> $TESTOUT 2>&1
452 RC=$?
453 #if test $RC != 0 ; then
454 #       echo "WhoAmI failed ($RC)!"
455 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
456 #       exit $RC
457 #fi
458 case $RC in 
459         0)
460         ;;
461         51)
462                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
463         ;;
464         *)
465                 echo "WhoAmI failed ($RC)!"
466                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
467                 exit $RC
468         ;;
469 esac
470
471 echo "Binding as newly added user to database \"$BASEDN\"..."
472 $LDAPWHOAMI -h $LOCALHOST -p $PORT3 \
473         -D "cn=Added User,ou=Same as above,ou=Meta,$BASEDN" \
474         -w $PASSWD >> $TESTOUT 2>&1
475 RC=$?
476 #if test $RC != 0 ; then
477 #       echo "WhoAmI failed ($RC)!"
478 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
479 #       exit $RC
480 #fi
481 case $RC in 
482         0)
483         ;;
484         51)
485                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
486         ;;
487         *)
488                 echo "Compare failed ($RC)!"
489                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
490                 exit $RC
491         ;;
492 esac
493
494 echo "Changing password to database \"$BASEDN\"..."
495 $LDAPPASSWD -h $LOCALHOST -p $PORT3 -D "cn=Manager,$BASEDN" -w $PASSWD \
496         -s meta "cn=Added User,ou=Same as above,ou=Meta,$BASEDN" \
497         >> $TESTOUT 2>&1
498 RC=$?
499 #if test $RC != 0 ; then
500 #       echo "Passwd ExOp failed ($RC)!"
501 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
502 #       exit $RC
503 #fi
504 case $RC in 
505         0)
506         ;;
507         51)
508                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
509                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
510                 exit 0
511         ;;
512         *)
513                 echo "Passwd ExOp failed ($RC)!"
514                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
515                 exit $RC
516         ;;
517 esac
518
519 echo "Binding with newly changed password to database \"$BASEDN\"..."
520 $LDAPWHOAMI -h $LOCALHOST -p $PORT3 \
521         -D "cn=Added User,ou=Same as above,ou=Meta,$BASEDN" \
522         -w meta >> $TESTOUT 2>&1
523 RC=$?
524 #if test $RC != 0 ; then
525 #       echo "WhoAmI failed ($RC)!"
526 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
527 #       exit $RC
528 #fi
529 case $RC in 
530         0)
531         ;;
532         51)
533                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
534         ;;
535         *)
536                 echo "WhoAmI failed ($RC)!"
537                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
538                 exit $RC
539         ;;
540 esac
541
542 echo "Comparing to database \"$BASEDN\"..."
543 $LDAPCOMPARE -h $LOCALHOST -p $PORT3 \
544         "cn=Another Added Group,ou=Groups,$BASEDN" \
545         "member:cn=Added Group,ou=Groups,$BASEDN" >> $TESTOUT 2>&1
546 RC=$?
547 #if test $RC != 6 ; then
548 #       echo "Compare failed ($RC)!"
549 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
550 #       exit $RC
551 #fi
552 case $RC in 
553         6)
554         ;;
555         51)
556                 echo "### Hit LDAP_BUSY problem; you may want to re-run the test"
557         ;;
558         *)
559                 echo "Compare failed ($RC)!"
560                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
561                 exit $RC
562         ;;
563 esac
564
565 test $KILLSERVERS != no && kill -HUP $KILLPIDS
566
567 echo ">>>>> Test succeeded"
568 exit 0
569