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