Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / test044-dynlist
blobe0bb527409e2f8923625cae15621a32725f9fd3b
1 #! /bin/sh
2 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 ##
4 ## Copyright 1998-2008 The OpenLDAP Foundation.
5 ## All rights reserved.
6 ##
7 ## Redistribution and use in source and binary forms, with or without
8 ## modification, are permitted only as authorized by the OpenLDAP
9 ## Public License.
11 ## A copy of this license is available in the file LICENSE in the
12 ## top-level directory of the distribution or, alternatively, at
13 ## <http://www.OpenLDAP.org/license.html>.
15 echo "running defines.sh"
16 . $SRCDIR/scripts/defines.sh
18 if test $DYNLIST = "dynlistno" ; then
19 echo "dynlist overlay not available, test skipped"
20 exit 0
21 fi
23 mkdir -p $TESTDIR $DBDIR1
25 $SLAPPASSWD -g -n >$CONFIGPWF
26 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
28 echo "Running slapadd to build slapd database..."
29 . $CONFFILTER $BACKEND $MONITORDB < $MCONF > $ADDCONF
30 $SLAPADD -f $ADDCONF -l $LDIFORDERED
31 RC=$?
32 if test $RC != 0 ; then
33 echo "slapadd failed ($RC)!"
34 exit $RC
37 . $CONFFILTER $BACKEND $MONITORDB < $DYNLISTCONF > $CONF1
39 echo "Starting slapd on TCP/IP port $PORT1..."
40 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
41 PID=$!
42 if test $WAIT != 0 ; then
43 echo PID $PID
44 read foo
46 KILLPIDS="$PID"
48 sleep 1
50 echo "Testing slapd searching..."
51 for i in 0 1 2 3 4 5; do
52 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
53 '(objectclass=*)' > /dev/null 2>&1
54 RC=$?
55 if test $RC = 0 ; then
56 break
58 echo "Waiting 5 seconds for slapd to start..."
59 sleep 5
60 done
62 if test $RC != 0 ; then
63 echo "ldapsearch failed ($RC)!"
64 test $KILLSERVERS != no && kill -HUP $KILLPIDS
65 exit $RC
68 cat /dev/null > $SEARCHOUT
70 LISTDN="ou=Dynamic Lists,$BASEDN"
71 echo "Adding a dynamic list..."
72 $LDAPADD -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
73 > $TESTOUT 2>&1 << EOMODS
74 dn: $LISTDN
75 objectClass: organizationalUnit
76 ou: Dynamic Lists
78 dn: cn=Dynamic List,$LISTDN
79 objectClass: groupOfURLs
80 cn: Dynamic List
81 memberURL: ldap:///ou=People,${BASEDN}?cn,mail?sub?(objectClass=person)
82 EOMODS
84 echo "Testing list search of all attrs..."
85 echo "# Testing list search of all attrs..." >> $SEARCHOUT
86 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 \
87 '(cn=Dynamic List)' '*' \
88 >> $SEARCHOUT 2>&1
89 RC=$?
90 if test $RC != 0 ; then
91 echo "ldapsearch failed ($RC)!"
92 test $KILLSERVERS != no && kill -HUP $KILLPIDS
93 exit $RC
96 echo "Testing list search of a listed attr..."
97 echo "# Testing list search of a listed attr..." >> $SEARCHOUT
98 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 \
99 '(cn=Dynamic List)' mail \
100 >> $SEARCHOUT 2>&1
101 RC=$?
102 if test $RC != 0 ; then
103 echo "ldapsearch failed ($RC)!"
104 test $KILLSERVERS != no && kill -HUP $KILLPIDS
105 exit $RC
108 echo "Testing list search of a non-listed attr..."
109 echo "# Testing list search of a non-listed attr..." >> $SEARCHOUT
110 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 \
111 '(cn=Dynamic List)' objectClass \
112 >> $SEARCHOUT 2>&1
113 RC=$?
114 if test $RC != 0 ; then
115 echo "ldapsearch failed ($RC)!"
116 test $KILLSERVERS != no && kill -HUP $KILLPIDS
117 exit $RC
120 echo "Testing list search with (critical) manageDSAit..."
121 echo "# Testing list search with (critical) manageDSAit..." >> $SEARCHOUT
122 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 -MM \
123 '(cn=Dynamic List)' '*' \
124 >> $SEARCHOUT 2>&1
125 RC=$?
126 if test $RC != 0 ; then
127 echo "ldapsearch failed ($RC)!"
128 test $KILLSERVERS != no && kill -HUP $KILLPIDS
129 exit $RC
132 echo "Testing list compare..."
133 echo "# Testing list compare..." >> $SEARCHOUT
134 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
135 "cn=Dynamic List,$LISTDN" "cn:Bjorn Jensen" \
136 >> $SEARCHOUT 2>&1
137 RC=$?
138 case $RC in
140 echo "ldapcompare returned FALSE ($RC)!"
141 test $KILLSERVERS != no && kill -HUP $KILLPIDS
142 exit $RC
145 echo "ldapcompare returned TRUE ($RC)"
148 echo "ldapcompare returned success ($RC)!"
149 test $KILLSERVERS != no && kill -HUP $KILLPIDS
150 exit -1
153 echo "ldapcompare failed ($RC)!"
154 test $KILLSERVERS != no && kill -HUP $KILLPIDS
155 exit $RC
157 esac
158 echo "" >> $SEARCHOUT
160 echo "Testing list compare (should return FALSE)..."
161 echo "# Testing list compare (should return FALSE)..." >> $SEARCHOUT
162 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
163 "cn=Dynamic List,$LISTDN" "cn:FALSE" \
164 >> $SEARCHOUT 2>&1
165 RC=$?
166 case $RC in
168 echo "ldapcompare returned FALSE ($RC)"
171 echo "ldapcompare returned TRUE ($RC)!"
172 test $KILLSERVERS != no && kill -HUP $KILLPIDS
173 exit $RC
176 echo "ldapcompare returned success ($RC)!"
177 test $KILLSERVERS != no && kill -HUP $KILLPIDS
178 exit -1
181 echo "ldapcompare failed ($RC)!"
182 test $KILLSERVERS != no && kill -HUP $KILLPIDS
183 exit $RC
185 esac
186 echo "" >> $SEARCHOUT
188 echo "Testing list compare (should return UNDEFINED)..."
189 echo "# Testing list compare (should return UNDEFINED)..." >> $SEARCHOUT
190 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
191 "cn=Dynamic List,$LISTDN" "dc:UNDEFINED" \
192 >> $SEARCHOUT 2>&1
193 RC=$?
194 case $RC in
196 echo "ldapcompare returned FALSE ($RC)!"
197 test $KILLSERVERS != no && kill -HUP $KILLPIDS
198 exit $RC
201 echo "ldapcompare returned TRUE ($RC)!"
202 test $KILLSERVERS != no && kill -HUP $KILLPIDS
203 exit $RC
205 16|32)
206 echo "ldapcompare returned UNDEFINED ($RC)"
209 echo "ldapcompare returned success ($RC)!"
210 test $KILLSERVERS != no && kill -HUP $KILLPIDS
211 exit -1
214 echo "ldapcompare failed ($RC)"
216 esac
217 echo "" >> $SEARCHOUT
219 echo "Testing list compare with manageDSAit..."
220 echo "# Testing list compare with manageDSAit..." >> $SEARCHOUT
221 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 -MM \
222 "cn=Dynamic List,$LISTDN" "cn:Bjorn Jensen" \
223 >> $SEARCHOUT 2>&1
224 RC=$?
225 case $RC in
227 echo "ldapcompare returned FALSE ($RC)"
230 echo "ldapcompare returned TRUE ($RC)!"
231 test $KILLSERVERS != no && kill -HUP $KILLPIDS
232 exit $RC
235 echo "ldapcompare returned success ($RC)!"
236 test $KILLSERVERS != no && kill -HUP $KILLPIDS
237 exit -1
240 echo "ldapcompare failed ($RC)!"
241 test $KILLSERVERS != no && kill -HUP $KILLPIDS
242 exit $RC
244 esac
245 echo "" >> $SEARCHOUT
247 echo "Reconfiguring slapd..."
248 $LDAPMODIFY -x -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF > \
249 $TESTOUT 2>&1 << EOMODS
250 version: 1
251 dn: olcOverlay={0}dynlist,olcDatabase={2}$BACKEND,cn=config
252 changetype: modify
253 delete: olcDLattrSet
254 olcDLattrSet: {0}
256 add: olcDLattrSet
257 olcDLattrSet: groupOfURLs memberURL member
258 EOMODS
260 echo "==========================================================" >> $LOG1
262 echo "Adding a dynamic list..."
263 $LDAPADD -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
264 > $TESTOUT 2>&1 << EOMODS
265 dn: cn=Dynamic List of Members,$LISTDN
266 objectClass: groupOfURLs
267 cn: Dynamic List of Members
268 memberURL: ldap:///ou=People,${BASEDN}??sub?(objectClass=person)
269 EOMODS
271 echo "Testing list search of all attrs..."
272 echo "# Testing list search of all attrs..." >> $SEARCHOUT
273 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 \
274 '(cn=Dynamic List of Members)' '*' \
275 >> $SEARCHOUT 2>&1
276 RC=$?
277 if test $RC != 0 ; then
278 echo "ldapsearch failed ($RC)!"
279 test $KILLSERVERS != no && kill -HUP $KILLPIDS
280 exit $RC
283 echo "Testing list search of a listed attr..."
284 echo "# Testing list search of a listed attr..." >> $SEARCHOUT
285 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 \
286 '(cn=Dynamic List of Members)' member \
287 >> $SEARCHOUT 2>&1
288 RC=$?
289 if test $RC != 0 ; then
290 echo "ldapsearch failed ($RC)!"
291 test $KILLSERVERS != no && kill -HUP $KILLPIDS
292 exit $RC
295 echo "Testing list search of a non-listed attr..."
296 echo "# Testing list search of a non-listed attr..." >> $SEARCHOUT
297 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 \
298 '(cn=Dynamic List of Members)' objectClass \
299 >> $SEARCHOUT 2>&1
300 RC=$?
301 if test $RC != 0 ; then
302 echo "ldapsearch failed ($RC)!"
303 test $KILLSERVERS != no && kill -HUP $KILLPIDS
304 exit $RC
307 echo "Testing list search with (critical) manageDSAit..."
308 echo "# Testing list search with (critical) manageDSAit..." >> $SEARCHOUT
309 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 -MM \
310 '(&(cn=Dynamic List of Members)(objectClass=groupOfURLs))' '*' \
311 >> $SEARCHOUT 2>&1
312 RC=$?
313 if test $RC != 0 ; then
314 echo "ldapsearch failed ($RC)!"
315 test $KILLSERVERS != no && kill -HUP $KILLPIDS
316 exit $RC
319 CMPDN="$BJORNSDN"
320 echo "Testing list compare..."
321 echo "# Testing list compare..." >> $SEARCHOUT
322 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
323 "cn=Dynamic List of Members,$LISTDN" "member:$CMPDN" \
324 >> $SEARCHOUT 2>&1
325 RC=$?
326 case $RC in
328 echo "ldapcompare returned FALSE ($RC)!"
329 test $KILLSERVERS != no && kill -HUP $KILLPIDS
330 exit $RC
333 echo "ldapcompare returned TRUE ($RC)"
336 echo "ldapcompare returned success ($RC)!"
337 test $KILLSERVERS != no && kill -HUP $KILLPIDS
338 exit -1
341 echo "ldapcompare failed ($RC)!"
342 test $KILLSERVERS != no && kill -HUP $KILLPIDS
343 exit $RC
345 esac
346 echo "" >> $SEARCHOUT
348 echo "Testing list compare (should return FALSE)..."
349 echo "# Testing list compare (should return FALSE)..." >> $SEARCHOUT
350 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
351 "cn=Dynamic List of Members,$LISTDN" "member:cn=Foo Bar" \
352 >> $SEARCHOUT 2>&1
353 RC=$?
354 case $RC in
356 echo "ldapcompare returned FALSE ($RC)"
359 echo "ldapcompare returned TRUE ($RC)!"
360 test $KILLSERVERS != no && kill -HUP $KILLPIDS
361 exit $RC
364 echo "ldapcompare returned success ($RC)!"
365 test $KILLSERVERS != no && kill -HUP $KILLPIDS
366 exit -1
369 echo "ldapcompare failed ($RC)!"
370 test $KILLSERVERS != no && kill -HUP $KILLPIDS
371 exit $RC
373 esac
374 echo "" >> $SEARCHOUT
376 echo "Testing list compare with manageDSAit..."
377 echo "# Testing list compare with manageDSAit..." >> $SEARCHOUT
378 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 -MM \
379 "cn=Dynamic List,$LISTDN" "member:$CMPDN" \
380 >> $SEARCHOUT 2>&1
381 RC=$?
382 case $RC in
384 echo "ldapcompare returned FALSE ($RC)"
387 echo "ldapcompare returned TRUE ($RC)!"
388 test $KILLSERVERS != no && kill -HUP $KILLPIDS
389 exit $RC
392 echo "ldapcompare returned success ($RC)!"
393 test $KILLSERVERS != no && kill -HUP $KILLPIDS
394 exit -1
397 echo "ldapcompare failed ($RC)!"
398 test $KILLSERVERS != no && kill -HUP $KILLPIDS
399 exit $RC
401 esac
402 echo "" >> $SEARCHOUT
404 echo "==========================================================" >> $LOG1
406 echo "Testing dgIdentity..."
408 # Set ACL, require authentication to get list contents
409 $LDAPMODIFY -x -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF > \
410 $TESTOUT 2>&1 << EOMODS
411 version: 1
412 dn: olcDatabase={2}$BACKEND,cn=config
413 changetype: modify
414 add: olcAccess
415 olcAccess: to dn.base="cn=Dynamic List of Members,$LISTDN" by * read
416 olcAccess: to * by users read by * search
417 EOMODS
419 echo "Testing list search without dgIdentity..."
420 echo "# Testing list search without dgIdentity..." >> $SEARCHOUT
421 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 \
422 '(cn=Dynamic List of Members)' '*' \
423 >> $SEARCHOUT 2>&1
424 RC=$?
425 if test $RC != 0 ; then
426 echo "ldapsearch failed ($RC)!"
427 test $KILLSERVERS != no && kill -HUP $KILLPIDS
428 exit $RC
431 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
432 > $TESTOUT 2>&1 << EOMODS
433 dn: cn=Dynamic List of Members,$LISTDN
434 changetype: modify
435 add: objectClass
436 objectClass: dgIdentityAux
438 add: dgIdentity
439 dgIdentity: $CMPDN
440 EOMODS
442 echo "Testing list search with dgIdentity..."
443 echo "# Testing list search with dgIdentity..." >> $SEARCHOUT
444 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 \
445 '(cn=Dynamic List of Members)' '*' \
446 >> $SEARCHOUT 2>&1
447 RC=$?
448 if test $RC != 0 ; then
449 echo "ldapsearch failed ($RC)!"
450 test $KILLSERVERS != no && kill -HUP $KILLPIDS
451 exit $RC
454 echo "Testing dgAuthz..."
456 CMPDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,$BASEDN"
457 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
458 > $TESTOUT 2>&1 << EOMODS
459 dn: cn=Dynamic List of Members,$LISTDN
460 changetype: modify
461 add: dgAuthz
462 dgAuthz: dn:$BABSDN
463 EOMODS
465 echo "Testing list search with dgIdentity and dgAuthz anonymously..."
466 echo "# Testing list search with dgIdentity and dgAuthz anonymously..." >> $SEARCHOUT
467 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 \
468 '(cn=Dynamic List of Members)' '*' \
469 >> $SEARCHOUT 2>&1
470 RC=$?
471 if test $RC != 0 ; then
472 echo "ldapsearch failed ($RC)!"
473 test $KILLSERVERS != no && kill -HUP $KILLPIDS
474 exit $RC
477 echo "Testing list search with dgIdentity and dgAuthz as the authorized identity..."
478 echo "# Testing list search with dgIdentity and dgAuthz as the authorized identity..." >> $SEARCHOUT
479 $LDAPSEARCH -S "" -b "$LISTDN" -h $LOCALHOST -p $PORT1 \
480 -D "$BABSDN" -w bjensen \
481 '(cn=Dynamic List of Members)' '*' \
482 >> $SEARCHOUT 2>&1
483 RC=$?
484 if test $RC != 0 ; then
485 echo "ldapsearch failed ($RC)!"
486 test $KILLSERVERS != no && kill -HUP $KILLPIDS
487 exit $RC
490 test $KILLSERVERS != no && kill -HUP $KILLPIDS
492 LDIF=$DYNLISTOUT
494 echo "Filtering ldapsearch results..."
495 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
496 echo "Filtering original ldif used to create database..."
497 . $LDIFFILTER < $LDIF > $LDIFFLT
498 echo "Comparing filter output..."
499 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
501 if test $? != 0 ; then
502 echo "Comparison failed"
503 exit 1
506 echo ">>>>> Test succeeded"
508 test $KILLSERVERS != no && wait
510 exit 0