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