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