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