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