xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test046-dds (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test046-dds,v 1.4.2.6 2009/08/13 00:47:41 quanah Exp
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 2005-2009 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
19if test $BACKEND = "ldif" ; then
20        echo "LDIF backend does not support acls, test skipped"
21        exit 0
22fi
23
24if test $DDS = ddsno; then
25	echo "Dynamic Directory Services overlay not available, test skipped"
26	exit 0
27fi
28
29mkdir -p $TESTDIR $DBDIR1
30
31echo "Running slapadd to build slapd database..."
32. $CONFFILTER $BACKEND $MONITORDB < $MCONF > $ADDCONF
33$SLAPADD -f $ADDCONF -l $LDIFORDERED
34RC=$?
35if test $RC != 0 ; then
36	echo "slapadd failed ($RC)!"
37	exit $RC
38fi
39
40echo "Running slapindex to index slapd database..."
41. $CONFFILTER $BACKEND $MONITORDB < $DDSCONF > $CONF1
42$SLAPINDEX -f $CONF1
43RC=$?
44if test $RC != 0 ; then
45	echo "warning: slapindex failed ($RC)"
46	echo "  assuming no indexing support"
47fi
48
49echo "Starting slapd on TCP/IP port $PORT1..."
50$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
51PID=$!
52if test $WAIT != 0 ; then
53    echo PID $PID
54    read foo
55fi
56KILLPIDS="$PID"
57
58sleep 1
59
60echo "Testing slapd searching..."
61for i in 0 1 2 3 4 5; do
62	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
63		'(objectclass=*)' > /dev/null 2>&1
64	RC=$?
65	if test $RC = 0 ; then
66		break
67	fi
68	echo "Waiting 5 seconds for slapd to start..."
69	sleep 5
70done
71
72if test $RC != 0 ; then
73	echo "ldapsearch failed ($RC)!"
74	test $KILLSERVERS != no && kill -HUP $KILLPIDS
75	exit $RC
76fi
77
78cat /dev/null > $SEARCHOUT
79
80echo "Creating a dynamic entry..."
81$LDAPADD -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
82	>> $TESTOUT 2>&1 << EOMODS
83dn: cn=Dynamic Object,dc=example,dc=com
84objectClass: inetOrgPerson
85objectClass: dynamicObject
86cn: Dynamic Object
87sn: Object
88EOMODS
89RC=$?
90if test $RC != 0 ; then
91	echo "ldapadd failed ($RC)!"
92	test $KILLSERVERS != no && kill -HUP $KILLPIDS
93	exit $RC
94fi
95
96echo "Refreshing the newly created dynamic entry..."
97$LDAPEXOP -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
98	"refresh" "cn=Dynamic Object,dc=example,dc=com" "120" \
99	>> $TESTOUT 2>&1
100RC=$?
101if test $RC != 0 ; then
102	echo "ldapexop failed ($RC)!"
103	test $KILLSERVERS != no && kill -HUP $KILLPIDS
104	exit $RC
105fi
106
107echo "Modifying the newly created dynamic entry..."
108$LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
109	>> $TESTOUT 2>&1 << EOMODS
110dn: cn=Dynamic Object,dc=example,dc=com
111changetype: modify
112add: userPassword
113userPassword: dynamic
114EOMODS
115RC=$?
116if test $RC != 0 ; then
117	echo "ldapadd failed ($RC)!"
118	test $KILLSERVERS != no && kill -HUP $KILLPIDS
119	exit $RC
120fi
121
122echo "Binding as the newly created dynamic entry..."
123$LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
124	-D "cn=Dynamic Object,dc=example,dc=com" -w dynamic
125RC=$?
126if test $RC != 0 ; then
127	echo "ldapwhoami failed ($RC)!"
128	test $KILLSERVERS != no && kill -HUP $KILLPIDS
129	exit $RC
130fi
131
132echo "Creating a dynamic entry subordinate to another..."
133$LDAPADD -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
134	>> $TESTOUT 2>&1 << EOMODS
135dn: cn=Subordinate Dynamic Object,cn=Dynamic Object,dc=example,dc=com
136objectClass: inetOrgPerson
137objectClass: dynamicObject
138cn: Subordinate Dynamic Object
139sn: Object
140userPassword: dynamic
141EOMODS
142RC=$?
143if test $RC != 0 ; then
144	echo "ldapadd failed ($RC)!"
145	test $KILLSERVERS != no && kill -HUP $KILLPIDS
146	exit $RC
147fi
148
149SEARCH=0
150
151SEARCH=`expr $SEARCH + 1`
152echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
153$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
154	'(objectClass=dynamicObject)' '*' entryTtl \
155	>> $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
163echo "Creating a static entry subordinate to a dynamic one (should fail)..."
164$LDAPADD -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
165	>> $TESTOUT 2>&1 << EOMODS
166dn: cn=Subordinate Static Object,cn=Dynamic Object,dc=example,dc=com
167objectClass: inetOrgPerson
168cn: Subordinate Static Object
169sn: Object
170userPassword: static
171EOMODS
172RC=$?
173case $RC in
1740)
175	echo "ldapadd should have failed ($RC)!"
176	test $KILLSERVERS != no && kill -HUP $KILLPIDS
177	exit -1
178	;;
17919)
180	echo "ldapadd failed ($RC)"
181	;;
182*)
183	echo "ldapadd failed ($RC)!"
184	test $KILLSERVERS != no && kill -HUP $KILLPIDS
185	exit $RC
186	;;
187esac
188
189echo "Turning a static into a dynamic entry (should fail)..."
190$LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
191	>> $TESTOUT 2>&1 << EOMODS
192dn: ou=People,dc=example,dc=com
193changetype: modify
194add: objectClass
195objectClass: dynamicObject
196EOMODS
197RC=$?
198case $RC in
1990)
200	echo "ldapmodify should have failed ($RC)!"
201	test $KILLSERVERS != no && kill -HUP $KILLPIDS
202	exit -1
203	;;
20465)
205	echo "ldapmodify failed ($RC)"
206	;;
207*)
208	echo "ldapmodify failed ($RC)!"
209	test $KILLSERVERS != no && kill -HUP $KILLPIDS
210	exit $RC
211	;;
212esac
213
214echo "Turning a dynamic into a static entry (should fail)..."
215$LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
216	>> $TESTOUT 2>&1 << EOMODS
217dn: cn=Dynamic Object,dc=example,dc=com
218changetype: modify
219delete: objectClass
220objectClass: dynamicObject
221EOMODS
222RC=$?
223case $RC in
2240)
225	echo "ldapmodify should have failed ($RC)!"
226	test $KILLSERVERS != no && kill -HUP $KILLPIDS
227	exit -1
228	;;
22965)
230	echo "ldapmodify failed ($RC)"
231	;;
232*)
233	echo "ldapmodify failed ($RC)!"
234	test $KILLSERVERS != no && kill -HUP $KILLPIDS
235	exit $RC
236	;;
237esac
238
239echo "Renaming a dynamic entry..."
240$LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
241	>> $TESTOUT 2>&1 << EOMODS
242dn: cn=Subordinate Dynamic Object,cn=Dynamic Object,dc=example,dc=com
243changetype: modrdn
244newrdn: cn=Renamed Dynamic Object
245deleteoldrdn: 1
246EOMODS
247RC=$?
248if test $RC != 0 ; then
249	echo "ldapmodrdn failed ($RC)!"
250	test $KILLSERVERS != no && kill -HUP $KILLPIDS
251	exit $RC
252fi
253
254SEARCH=`expr $SEARCH + 1`
255echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
256$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
257	'(objectClass=dynamicObject)' '*' entryTtl \
258	>> $SEARCHOUT 2>&1
259RC=$?
260if test $RC != 0 ; then
261	echo "ldapsearch failed ($RC)!"
262	test $KILLSERVERS != no && kill -HUP $KILLPIDS
263	exit $RC
264fi
265
266echo "Refreshing the initial dynamic entry to make it expire earlier than the subordinate..."
267$LDAPEXOP -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
268	"refresh" "cn=Dynamic Object,dc=example,dc=com" "1" \
269	>> $TESTOUT 2>&1
270RC=$?
271if test $RC != 0 ; then
272	echo "ldapexop failed ($RC)!"
273	test $KILLSERVERS != no && kill -HUP $KILLPIDS
274	exit $RC
275fi
276
277SLEEP=10
278echo "Waiting $SLEEP seconds to force a subordinate/superior expiration conflict..."
279sleep $SLEEP
280
281echo "Re-vitalizing the initial dynamic entry..."
282$LDAPEXOP -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
283	"refresh" "cn=Dynamic Object,dc=example,dc=com" "120" \
284	>> $TESTOUT 2>&1
285RC=$?
286if test $RC != 0 ; then
287	echo "ldapexop failed ($RC)!"
288	test $KILLSERVERS != no && kill -HUP $KILLPIDS
289	exit $RC
290fi
291
292echo "Re-renaming the subordinate dynamic entry (new superior)..."
293$LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
294	>> $TESTOUT 2>&1 << EOMODS
295dn: cn=Renamed Dynamic Object,cn=Dynamic Object,dc=example,dc=com
296changetype: modrdn
297newrdn: cn=Renamed Dynamic Object
298deleteoldrdn: 1
299newsuperior: dc=example,dc=com
300EOMODS
301RC=$?
302if test $RC != 0 ; then
303	echo "ldapmodrdn failed ($RC)!"
304	test $KILLSERVERS != no && kill -HUP $KILLPIDS
305	exit $RC
306fi
307
308SEARCH=`expr $SEARCH + 1`
309echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
310$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
311	'(objectClass=dynamicObject)' '*' entryTtl \
312	>> $SEARCHOUT 2>&1
313RC=$?
314if test $RC != 0 ; then
315	echo "ldapsearch failed ($RC)!"
316	test $KILLSERVERS != no && kill -HUP $KILLPIDS
317	exit $RC
318fi
319
320echo "Deleting a dynamic entry..."
321$LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
322	>> $TESTOUT 2>&1 << EOMODS
323dn: cn=Dynamic Object,dc=example,dc=com
324changetype: delete
325EOMODS
326RC=$?
327if test $RC != 0 ; then
328	echo "ldapdelete failed ($RC)!"
329	test $KILLSERVERS != no && kill -HUP $KILLPIDS
330	exit $RC
331fi
332
333SEARCH=`expr $SEARCH + 1`
334echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
335$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
336	'(objectClass=dynamicObject)' '*' entryTtl \
337	>> $SEARCHOUT 2>&1
338RC=$?
339if test $RC != 0 ; then
340	echo "ldapsearch failed ($RC)!"
341	test $KILLSERVERS != no && kill -HUP $KILLPIDS
342	exit $RC
343fi
344
345echo "Refreshing the remaining dynamic entry..."
346$LDAPEXOP -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
347	"refresh" "cn=Renamed Dynamic Object,dc=example,dc=com" "1" \
348	>> $TESTOUT 2>&1
349RC=$?
350if test $RC != 0 ; then
351	echo "ldapexop failed ($RC)!"
352	test $KILLSERVERS != no && kill -HUP $KILLPIDS
353	exit $RC
354fi
355
356SEARCH=`expr $SEARCH + 1`
357echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
358$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
359	'(objectClass=dynamicObject)' '*' entryTtl \
360	>> $SEARCHOUT 2>&1
361RC=$?
362if test $RC != 0 ; then
363	echo "ldapsearch failed ($RC)!"
364	test $KILLSERVERS != no && kill -HUP $KILLPIDS
365	exit $RC
366fi
367
368SLEEP=15
369echo "Waiting $SLEEP seconds for remaining entry to expire..."
370sleep $SLEEP
371
372SEARCH=`expr $SEARCH + 1`
373echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
374$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
375	'(objectClass=dynamicObject)' '*' entryTtl \
376	>> $SEARCHOUT 2>&1
377RC=$?
378if test $RC != 0 ; then
379	echo "ldapsearch failed ($RC)!"
380	test $KILLSERVERS != no && kill -HUP $KILLPIDS
381	exit $RC
382fi
383
384# Meeting
385MEETINGDN="cn=Meeting,ou=Groups,dc=example,dc=com"
386echo "Creating a meeting as $BJORNSDN..."
387$LDAPMODIFY -D "$BJORNSDN" -w bjorn -h $LOCALHOST -p $PORT1 \
388	>> $TESTOUT 2>&1 << EOMODS
389dn: $MEETINGDN
390changetype: add
391objectClass: groupOfNames
392objectClass: dynamicObject
393cn: Meeting
394member: $BJORNSDN
395
396dn: $MEETINGDN
397changetype: modify
398add: member
399member: $JOHNDDN
400EOMODS
401RC=$?
402if test $RC != 0 ; then
403	echo "ldapmodify failed ($RC)!"
404	test $KILLSERVERS != no && kill -HUP $KILLPIDS
405	exit $RC
406fi
407
408echo "Refreshing the meeting as $BJORNSDN..."
409$LDAPEXOP -D "$BJORNSDN" -w bjorn -h $LOCALHOST -p $PORT1 \
410	"refresh" "$MEETINGDN" "120" \
411	>> $TESTOUT 2>&1
412RC=$?
413if test $RC != 0 ; then
414	echo "ldapexop failed ($RC)!"
415	test $KILLSERVERS != no && kill -HUP $KILLPIDS
416	exit $RC
417fi
418
419echo "Joining the meeting as $BABSDN..."
420$LDAPMODIFY -D "$BABSDN" -w bjensen -h $LOCALHOST -p $PORT1 \
421	>> $TESTOUT 2>&1 << EOMODS
422dn: $MEETINGDN
423changetype: modify
424add: member
425member: $BABSDN
426EOMODS
427RC=$?
428if test $RC != 0 ; then
429	echo "ldapmodify failed ($RC)!"
430	test $KILLSERVERS != no && kill -HUP $KILLPIDS
431	exit $RC
432fi
433
434echo "Trying to add a member as $BABSDN (should fail)..."
435$LDAPMODIFY -D "$BABSDN" -w bjensen -h $LOCALHOST -p $PORT1 \
436	>> $TESTOUT 2>&1 << EOMODS
437dn: $MEETINGDN
438changetype: modify
439add: member
440member: $MELLIOTDN
441EOMODS
442RC=$?
443case $RC in
4440)
445	echo "ldapmodify should have failed ($RC)!"
446	test $KILLSERVERS != no && kill -HUP $KILLPIDS
447	exit $RC
448	;;
44950)
450	echo "ldapmodify failed ($RC)"
451	;;
452*)
453	echo "ldapmodify failed ($RC)!"
454	test $KILLSERVERS != no && kill -HUP $KILLPIDS
455	exit $RC
456	;;
457esac
458
459echo "Refreshing the meeting as $BABSDN..."
460$LDAPEXOP -D "$BABSDN" -w bjensen -h $LOCALHOST -p $PORT1 \
461	"refresh" "$MEETINGDN" "180" \
462	>> $TESTOUT 2>&1
463RC=$?
464if test $RC != 0 ; then
465	echo "ldapexop failed ($RC)!"
466	test $KILLSERVERS != no && kill -HUP $KILLPIDS
467	exit $RC
468fi
469
470echo "Trying to refresh the meeting anonymously (should fail)..."
471$LDAPEXOP -h $LOCALHOST -p $PORT1 \
472	"refresh" "$MEETINGDN" "240" \
473	>> $TESTOUT 2>&1
474RC=$?
475if test $RC = 0 ; then
476	echo "ldapexop should have failed ($RC)!"
477	test $KILLSERVERS != no && kill -HUP $KILLPIDS
478	exit $RC
479fi
480
481echo "Trying to refresh the meeting as $JAJDN (should fail)..."
482$LDAPEXOP -D "$JAJDN" -w "jaj" -h $LOCALHOST -p $PORT1 \
483	"refresh" "$MEETINGDN" "240" \
484	>> $TESTOUT 2>&1
485RC=$?
486if test $RC = 0 ; then
487	echo "ldapexop should have failed ($RC)!"
488	test $KILLSERVERS != no && kill -HUP $KILLPIDS
489	exit $RC
490fi
491
492echo "Trying to delete the meeting as $BABSDN (should fail)..."
493$LDAPMODIFY -D "$BABSDN" -w bjensen -h $LOCALHOST -p $PORT1 \
494	>> $TESTOUT 2>&1 << EOMODS
495dn: $MEETINGDN
496changetype: delete
497EOMODS
498RC=$?
499case $RC in
5000)
501	echo "ldapdelete should have failed ($RC)!"
502	test $KILLSERVERS != no && kill -HUP $KILLPIDS
503	exit $RC
504	;;
50550)
506	echo "ldapdelete failed ($RC)"
507	;;
508*)
509	echo "ldapdelete failed ($RC)!"
510	test $KILLSERVERS != no && kill -HUP $KILLPIDS
511	exit $RC
512	;;
513esac
514
515echo "Deleting the meeting as $BJORNSDN..."
516$LDAPMODIFY -D "$BJORNSDN" -w bjorn -h $LOCALHOST -p $PORT1 \
517	>> $TESTOUT 2>&1 << EOMODS
518dn: $MEETINGDN
519changetype: delete
520EOMODS
521RC=$?
522if test $RC != 0 ; then
523	echo "ldapdelete failed ($RC)!"
524	test $KILLSERVERS != no && kill -HUP $KILLPIDS
525	exit $RC
526fi
527
528test $KILLSERVERS != no && kill -HUP $KILLPIDS
529
530LDIF=$DDSOUT
531
532echo "Filtering ldapsearch results..."
533. $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
534echo "Filtering original ldif used to create database..."
535. $LDIFFILTER < $LDIF > $LDIFFLT
536echo "Comparing filter output..."
537$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
538
539if test $? != 0 ; then
540	echo "Comparison failed"
541	exit 1
542fi
543
544echo ">>>>> Test succeeded"
545
546test $KILLSERVERS != no && wait
547
548exit 0
549