]> git.sur5r.net Git - openldap/blob - tests/scripts/test025-limits
Add missing revision string
[openldap] / tests / scripts / test025-limits
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-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
16 ## FIXME: need to exclude legal but wrong results...
17
18 echo "running defines.sh"
19 . $SRCDIR/scripts/defines.sh
20
21 mkdir -p $TESTDIR $DBDIR1
22
23 echo "Running slapadd to build slapd database..."
24 . $CONFFILTER $BACKEND $MONITORDB < $LIMITSCONF > $ADDCONF
25 $SLAPADD -f $ADDCONF -l $LDIFLIMITS
26 RC=$?
27 if test $RC != 0 ; then
28         echo "slapadd failed ($RC)!"
29         exit $RC
30 fi
31
32 echo "Running slapindex to index slapd database..."
33 . $CONFFILTER $BACKEND $MONITORDB < $LIMITSCONF > $CONF1
34 $SLAPINDEX -f $CONF1
35 RC=$?
36 if test $RC != 0 ; then
37         echo "warning: slapindex failed ($RC)"
38         echo "  assuming no indexing support"
39 fi
40
41 echo "Starting slapd on TCP/IP port $PORT1..."
42 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
43 PID=$!
44 if test $WAIT != 0 ; then
45     echo PID $PID
46     read foo
47 fi
48 KILLPIDS="$PID"
49
50 sleep 1
51
52 echo "Testing slapd searching..."
53 for i in 0 1 2 3 4 5; do
54         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
55                 '(objectclass=*)' > /dev/null 2>&1
56         RC=$?
57         if test $RC = 0 ; then
58                 break
59         fi
60         echo "Waiting 5 seconds for slapd to start..."
61         sleep 5
62 done
63
64 if test $RC != 0 ; then
65         echo "ldapsearch failed ($RC)!"
66         test $KILLSERVERS != no && kill -HUP $KILLPIDS
67         exit $RC
68 fi
69
70 cat /dev/null > $SEARCHOUT
71
72 echo ""
73 echo "Testing regular search limits"
74 echo ""
75
76 echo "Testing no limits requested for unlimited ID..."
77 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
78         -D 'cn=Unlimited User,ou=People,dc=example,dc=com' \
79         '(objectClass=*)' >$SEARCHOUT 2>&1
80 RC=$?
81 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
82 case $RC in
83         0)
84                 if test x"$COUNT" != x ; then
85                         echo "...success (got $COUNT entries)"
86                 else
87                         echo "...error: did not expect ldapsearch success ($RC)!"
88                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
89                         exit 1
90                 fi
91         ;;
92         *)
93                 echo "ldapsearch failed ($RC)!"
94                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
95                 exit $RC
96         ;;
97 esac
98
99 echo "Testing no limits requested for rootdn=$MANAGERDN..."
100 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
101         -D "$MANAGERDN" \
102         '(objectClass=*)' >$SEARCHOUT 2>&1
103 RC=$?
104 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
105 case $RC in
106         0)
107                 if test x"$COUNT" != x ; then
108                         echo "...success (got $COUNT entries)"
109                 else
110                         echo "...error: did not expect ldapsearch success ($RC)!"
111                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
112                         exit 1
113                 fi
114         ;;
115         *)
116                 echo "ldapsearch failed ($RC)!"
117                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
118                 exit $RC
119         ;;
120 esac
121
122 SIZELIMIT=4
123 echo "Testing limit requested for rootdn=$MANAGERDN..."
124 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
125         -D "$MANAGERDN" \
126         '(objectClass=*)' >$SEARCHOUT 2>&1
127 RC=$?
128 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
129 case $RC in
130         0)
131                 if test x"$COUNT" != x ; then
132                         if test "$COUNT" -gt "$SIZELIMIT" ; then
133                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
134                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
135                                 exit 1
136                         fi
137                         echo "...didn't bump into the requested size limit ($SIZELIMIT; got $COUNT entries)"
138                 else
139                         echo "...error: did not expect ldapsearch success ($RC)!"
140                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
141                         exit 1
142                 fi
143         ;;
144         4)
145                 if test x"$COUNT" != x ; then
146                         if test "$COUNT" = "$SIZELIMIT" ; then
147                                 echo "...bumped into requested size limit ($SIZELIMIT)"
148                         else
149                                 echo "...error: got $COUNT entries with a requested sizelimit of $SIZELIMIT"
150                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
151                                 exit $RC
152                         fi
153                 else
154                         echo "...error: bumped into server-side size limit, but got no entries!"
155                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
156                         exit $RC
157                 fi
158         ;;
159         *)
160                 echo "ldapsearch failed ($RC)!"
161                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
162                 exit $RC
163         ;;
164 esac
165
166 SIZELIMIT=2
167 echo "Testing size limit request ($SIZELIMIT) for unlimited ID..."
168 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
169         -D 'cn=Unlimited User,ou=People,dc=example,dc=com' \
170         '(objectClass=*)' > $SEARCHOUT 2>&1
171 RC=$?
172 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
173 case $RC in
174         0)
175                 if test x"$COUNT" != x ; then
176                         if test "$COUNT" -gt "$SIZELIMIT" ; then
177                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
178                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
179                                 exit 1
180                         fi
181                         echo "...didn't bump into the requested size limit ($SIZELIMIT; got $COUNT entries)"
182                 else
183                         echo "...error: did not expect ldapsearch success ($RC)!"
184                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
185                         exit 1
186                 fi
187         ;;
188         4)
189                 if test x"$COUNT" != x ; then
190                         if test "$COUNT" = "$SIZELIMIT" ; then
191                                 echo "...bumped into requested size limit ($SIZELIMIT)"
192                         else
193                                 echo "...error: got $COUNT entries with a requested sizelimit of $SIZELIMIT"
194                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
195                                 exit $RC
196                         fi
197                 else
198                         echo "...error: bumped into server-side size limit, but got no entries!"
199                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
200                         exit $RC
201                 fi
202         ;;
203         *)
204                 echo "ldapsearch failed ($RC)!"
205                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
206                 exit $RC
207         ;;
208 esac
209
210 TIMELIMIT=10
211 echo "Testing time limit request ($TIMELIMIT s) for unlimited ID..."
212 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -l $TIMELIMIT \
213         -D 'cn=Unlimited User,ou=People,dc=example,dc=com' \
214         '(objectClass=*)' > $SEARCHOUT 2>&1
215 RC=$?
216 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
217 case $RC in
218         0)
219                 if test x"$COUNT" != x ; then
220                         echo "...didn't bump into the requested time limit ($TIMELIMIT s; got $COUNT entries)"
221                 else
222                         echo "...error: did not expect ldapsearch success ($RC)!"
223                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
224                         exit 1
225                 fi
226         ;;
227         3)
228                 if test x"$COUNT" != x ; then
229                         COUNT=0
230                 fi
231                 echo "...bumped into requested time limit ($TIMELIMIT s; got $COUNT entries)"
232         ;;
233         *)
234                 echo "ldapsearch failed ($RC)!"
235                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
236                 exit $RC
237         ;;
238 esac
239
240 echo "Testing no limits requested for soft limited ID..."
241 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
242         -D 'cn=Soft Limited User,ou=People,dc=example,dc=com' \
243         '(objectClass=*)' > $SEARCHOUT 2>&1
244 RC=$?
245 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
246 case $RC in
247         0)
248                 if test x"$COUNT" != x ; then
249                         echo "...didn't bump into server-side size limit (got $COUNT entries)"
250                 else
251                         echo "...error: did not expect ldapsearch success ($RC)!"
252                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
253                         exit 1
254                 fi
255         ;;
256         4)
257                 if test x"$COUNT" != x ; then
258                         echo "...bumped into server-side size limit (got $COUNT entries)"
259                 else
260                         echo "...error: bumped into server-side size limit, but got no entries!"
261                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
262                         exit $RC
263                 fi
264         ;;
265         *)
266                 echo "ldapsearch failed ($RC)!"
267                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
268                 exit $RC
269         ;;
270 esac
271
272 SIZELIMIT=2
273 echo "Testing lower than soft limit request ($SIZELIMIT) for soft limited ID..."
274 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
275         -D 'cn=Soft Limited User,ou=People,dc=example,dc=com' \
276         '(objectClass=*)' > $SEARCHOUT 2>&1
277 RC=$?
278 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
279 case $RC in
280         0)
281                 if test x"$COUNT" != x ; then
282                         if test "$COUNT" -gt "$SIZELIMIT" ; then
283                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
284                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
285                                 exit 1
286                         fi
287                         echo "...didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
288                 else
289                         echo "...error: did not expect ldapsearch success ($RC)!"
290                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
291                         exit 1
292                 fi
293         ;;
294         4)
295                 if test "x$COUNT" != "x" ; then
296                         if test "x$SIZELIMIT" = "x$COUNT" ; then
297                                 echo "...bumped into requested ($SIZELIMIT) size limit"
298                         else
299                                 echo "...bumped into server-side size limit ($COUNT)"
300                         fi
301                 else
302                         echo "...error: bumped into server-side size limit, but got no entries!"
303                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
304                         exit $RC
305                 fi
306         ;;
307         *)
308                 echo "ldapsearch failed ($RC)!"
309                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
310                 exit $RC
311         ;;
312 esac
313
314 SIZELIMIT=100
315 echo "Testing higher than soft limit request ($SIZELIMIT) for soft limited ID..."
316 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
317         -D 'cn=Soft Limited User,ou=People,dc=example,dc=com' \
318         '(objectClass=*)' > $SEARCHOUT 2>&1
319 RC=$?
320 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
321 case $RC in
322         0)
323                 if test x"$COUNT" != x ; then
324                         if test "$COUNT" -gt "$SIZELIMIT" ; then
325                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
326                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
327                                 exit 1
328                         fi
329                         echo "...didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
330                 else
331                         echo "...error: did not expect ldapsearch success ($RC)!"
332                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
333                         exit 1
334                 fi
335         ;;
336         4)
337                 if test "x$COUNT" != "x" ; then
338                         if test "x$SIZELIMIT" = "x$COUNT" ; then
339                                 echo "...bumped into requested ($SIZELIMIT) size limit"
340                         else
341                                 echo "...bumped into server-side size limit ($COUNT)"
342                         fi
343                 else
344                         echo "...error: bumped into server-side size limit, but got no entries!"
345                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
346                         exit $RC
347                 fi
348         ;;
349         *)
350                 echo "ldapsearch failed ($RC)!"
351                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
352                 exit $RC
353         ;;
354 esac
355
356 SIZELIMIT=2
357 echo "Testing lower than hard limit request ($SIZELIMIT) for hard limited ID..."
358 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
359         -D 'cn=Hard Limited User,ou=People,dc=example,dc=com' \
360         '(objectClass=*)' > $SEARCHOUT 2>&1
361 RC=$?
362 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
363 case $RC in
364         0)
365                 if test x"$COUNT" != x ; then
366                         if test "$COUNT" -gt "$SIZELIMIT" ; then
367                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
368                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
369                                 exit 1
370                         fi
371                         echo "...didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
372                 else
373                         echo "...error: did not expect ldapsearch success ($RC)!"
374                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
375                         exit 1
376                 fi
377         ;;
378         4)
379                 echo "...bumped into requested ($SIZELIMIT) size limit"
380         ;;
381         *)
382                 echo "ldapsearch failed ($RC)!"
383                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
384                 exit $RC
385         ;;
386 esac
387
388 SIZELIMIT=100
389 echo "Testing higher than hard limit request ($SIZELIMIT) for hard limited ID..."
390 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
391         -D 'cn=Hard Limited User,ou=People,dc=example,dc=com' \
392         '(objectClass=*)' > $SEARCHOUT 2>&1
393 RC=$?
394 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
395 case $RC in
396         0)
397                 if test x"$COUNT" != x ; then
398                         if test "$COUNT" -gt "$SIZELIMIT" ; then
399                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
400                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
401                                 exit 1
402                         fi
403                         echo "...didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
404                 else
405                         echo "...error: did not expect ldapsearch success ($RC)!"
406                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
407                         exit 1
408                 fi
409         ;;
410         4)
411                 if test x"$COUNT" != x ; then
412                         if test "$COUNT" = "$SIZELIMIT" ; then
413                                 echo "...error: bumped into requested ($SIZELIMIT) size limit"
414                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
415                                 exit $RC
416                         else
417                                 echo "...got size limit $COUNT instead of requested $SIZELIMIT entries"
418                         fi
419                 else
420                         echo "...error: bumped into server-side size limit, but got no entries!"
421                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
422                         exit $RC
423                 fi
424         ;;
425 #       11)
426 #               echo "...bumped into server-side hard size administrative limit"
427 #       ;;
428         *)
429                 echo "ldapsearch failed ($RC)!"
430                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
431                 exit $RC
432         ;;
433 esac
434
435 SIZELIMIT=max
436 echo "Testing max limit request ($SIZELIMIT) for hard limited ID..."
437 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
438         -D 'cn=Hard Limited User,ou=People,dc=example,dc=com' \
439         '(objectClass=*)' > $SEARCHOUT 2>&1
440 RC=$?
441 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
442 case $RC in
443         0)
444                 if test x"$COUNT" != x ; then
445                         echo "...didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
446                 else
447                         echo "...error: did not expect ldapsearch success ($RC)!"
448                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
449                         exit 1
450                 fi
451         ;;
452         4)
453                 if test x"$COUNT" != x ; then
454                         echo "...bumped into requested ($SIZELIMIT=$COUNT) size limit"
455                 else
456                         echo "...error: bumped into server-side size limit, but got no entries!"
457                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
458                         exit $RC
459                 fi
460         ;;
461 #       11)
462 #               echo "...bumped into server-side hard size administrative limit"
463 #       ;;
464         *)
465                 echo "ldapsearch failed ($RC)!"
466                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
467                 exit $RC
468         ;;
469 esac
470
471 echo "Testing lower than unchecked limit request for unchecked limited ID..."
472 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
473         -D 'cn=Unchecked Limited User,ou=People,dc=example,dc=com' \
474         '(uid=uncheckedlimited)' > $SEARCHOUT 2>&1
475 RC=$?
476 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
477 case $RC in
478         0)
479                 if test x"$COUNT" != x ; then
480                         echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
481                 else
482                         echo "...error: did not expect ldapsearch success ($RC)!"
483                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
484                         exit 1
485                 fi
486         ;;
487         11)
488                 echo "...error: bumped into unchecked administrative limit"
489                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
490                 exit $RC
491         ;;
492         *)
493                 echo "ldapsearch failed ($RC)!"
494                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
495                 exit $RC
496         ;;
497 esac
498
499 case $BACKEND in bdb | hdb)
500
501 echo "Testing higher than unchecked limit requested for unchecked limited ID..."
502 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
503         -D 'cn=Unchecked Limited User,ou=People,dc=example,dc=com' \
504         '(objectClass=*)' > $SEARCHOUT 2>&1
505 RC=$?
506 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
507 case $RC in
508         0)
509                 if test x"$COUNT" != x ; then
510                         echo "...error: didn't bump into server-side unchecked limit (got $COUNT entries)"
511                 else
512                         echo "...error: did not expect ldapsearch success ($RC)!"
513                 fi
514                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
515                 exit 1
516         ;;
517         11)
518                 echo "...bumped into unchecked administrative limit"
519         ;;
520         *)
521                 echo "ldapsearch failed ($RC)!"
522                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
523                 exit $RC
524         ;;
525 esac
526
527 echo "Testing no limits requested for unchecked limited group..."
528 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
529         -D 'cn=Unchecked Limited User 2,ou=People,dc=example,dc=com' \
530         '(objectClass=*)' > $SEARCHOUT 2>&1
531 RC=$?
532 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
533 case $RC in
534         0)
535                 if test x"$COUNT" != x ; then
536                         echo "...error: didn't bump into server-side unchecked limit (got $COUNT entries)"
537                 else
538                         echo "...error: did not expect ldapsearch success ($RC)!"
539                 fi
540                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
541                 exit 1
542         ;;
543         11)
544                 echo "...bumped into unchecked administrative limit"
545         ;;
546         *)
547                 echo "ldapsearch failed ($RC)!"
548                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
549                 exit $RC
550         ;;
551 esac
552 ;;
553 *)      echo "Skipping test for unchecked limit with $BACKEND backend." ;;
554 esac
555
556 echo "Testing no limits requested for limited regex..."
557 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
558         -D 'cn=Foo User,ou=People,dc=example,dc=com' \
559         '(objectClass=*)' > $SEARCHOUT 2>&1
560 RC=$?
561 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
562 case $RC in
563         0)
564                 if test x"$COUNT" != x ; then
565                         echo "...didn't bump into server-side size limit (got $COUNT entries)"
566                 else
567                         echo "...error: did not expect ldapsearch success ($RC)!"
568                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
569                         exit 1
570                 fi
571         ;;
572         4)
573                 if test "x$COUNT" != "x" ; then
574                         echo "...bumped into server-side size limit ($COUNT)"
575                 else
576                         echo "...error: bumped into server-side size limit, but got no entries!"
577                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
578                         exit $RC
579                 fi
580         ;;
581         *)
582                 echo "ldapsearch failed ($RC)!"
583                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
584                 exit $RC
585         ;;
586 esac
587
588 echo "Testing no limits requested for limited onelevel..."
589 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
590         -D 'cn=Bar User,ou=People,dc=example,dc=com' \
591         '(objectClass=*)' > $SEARCHOUT 2>&1
592 RC=$?
593 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
594 case $RC in
595         0)
596                 if test x"$COUNT" != x ; then
597                         echo "...didn't bump into server-side size limit (got $COUNT entries)"
598                 else
599                         echo "...error: did not expect ldapsearch success ($RC)!"
600                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
601                         exit 1
602                 fi
603         ;;
604         4)
605                 if test "x$COUNT" != "x" ; then
606                         echo "...bumped into server-side size limit ($COUNT)"
607                 else
608                         echo "...error: bumped into server-side size limit, but got no entries!"
609                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
610                         exit $RC
611                 fi
612         ;;
613         *)
614                 echo "ldapsearch failed ($RC)!"
615                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
616                 exit $RC
617         ;;
618 esac
619
620 echo "Testing no limit requested for limited children..."
621 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
622         -D 'cn=Unchecked Limited Users,ou=Groups,dc=example,dc=com' \
623         '(objectClass=*)' > $SEARCHOUT 2>&1
624 RC=$?
625 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
626 case $RC in
627         0)
628                 if test x"$COUNT" != x ; then
629                         echo "...didn't bump into server-side size limit (got $COUNT entries)"
630                 else
631                         echo "...error: did not expect ldapsearch success ($RC)!"
632                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
633                         exit 1
634                 fi
635         ;;
636         4)
637                 if test "x$COUNT" != "x" ; then
638                         echo "...bumped into server-side size limit ($COUNT)"
639                 else
640                         echo "...error: bumped into server-side size limit, but got no entries!"
641                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
642                         exit $RC
643                 fi
644         ;;
645         *)
646                 echo "ldapsearch failed ($RC)!"
647                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
648                 exit $RC
649         ;;
650 esac
651
652 echo "Testing no limit requested for limited subtree..."
653 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
654         -D 'cn=Unchecked Limited User 3,ou=Admin,dc=example,dc=com' \
655         '(objectClass=*)' > $SEARCHOUT 2>&1
656 RC=$?
657 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
658 case $RC in
659         0)
660                 if test x"$COUNT" != x ; then
661                         echo "...didn't bump into server-side size limit (got $COUNT entries)"
662                 else
663                         echo "...error: did not expect ldapsearch success ($RC)!"
664                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
665                         exit 1
666                 fi
667         ;;
668         4)
669                 if test "x$COUNT" != "x" ; then
670                         echo "...bumped into server-side size limit ($COUNT)"
671                 else
672                         echo "...error: bumped into server-side size limit, but got no entries!"
673                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
674                         exit $RC
675                 fi
676         ;;
677         *)
678                 echo "ldapsearch failed ($RC)!"
679                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
680                 exit $RC
681         ;;
682 esac
683
684 echo "Testing no limit requested for limited users..."
685 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
686         -D 'cn=Special User,dc=example,dc=com' \
687         '(objectClass=*)' > $SEARCHOUT 2>&1
688 RC=$?
689 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
690 case $RC in
691         0)
692                 if test x"$COUNT" != x ; then
693                         echo "...didn't bump into server-side size limit (got $COUNT entries)"
694                 else
695                         echo "...error: did not expect ldapsearch success ($RC)!"
696                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
697                         exit 1
698                 fi
699         ;;
700         4)
701                 if test "x$COUNT" != "x" ; then
702                         echo "...bumped into server-side size limit ($COUNT)"
703                 else
704                         echo "...error: bumped into server-side size limit, but got no entries!"
705                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
706                         exit $RC
707                 fi
708         ;;
709         *)
710                 echo "ldapsearch failed ($RC)!"
711                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
712                 exit $RC
713         ;;
714 esac
715
716 echo "Testing no limit requested for limited anonymous..."
717 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
718         '(objectClass=*)' > $SEARCHOUT 2>&1
719 RC=$?
720 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
721 case $RC in
722         0)
723                 if test x"$COUNT" != x ; then
724                         echo "...didn't bump into server-side size limit (got $COUNT entries)"
725                 else
726                         echo "...error: did not expect ldapsearch success ($RC)!"
727                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
728                         exit 1
729                 fi
730         ;;
731         4)
732                 if test "x$COUNT" != "x" ; then
733                         echo "...bumped into server-side size limit ($COUNT)"
734                 else
735                         echo "...error: bumped into server-side size limit, but got no entries!"
736                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
737                         exit $RC
738                 fi
739         ;;
740         *)
741                 echo "ldapsearch failed ($RC)!"
742                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
743                 exit $RC
744         ;;
745 esac
746
747 case $BACKEND in
748         bdb | hdb)
749                 # only bdb|hdb currently supports pagedResults control
750                 ;;
751         *)
752                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
753
754                 echo ">>>>> Test succeeded"
755                 exit 0
756         ;;
757 esac
758
759 if test x"$SLAPD_PAGE_SIZE" != x ; then
760         PAGESIZE="$SLAPD_PAGE_SIZE"
761         if test "$PAGESIZE" -le 0 ; then
762                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
763
764                 echo ""
765                 echo "Testing with pagedResults control disabled"
766                 echo ""
767                 echo ">>>>> Test succeeded"
768                 exit 0
769         fi
770 else
771         PAGESIZE=5
772 fi
773
774 echo ""
775 echo "Testing regular search limits with pagedResults control (page size $PAGESIZE)"
776 echo ""
777
778 echo "Testing no limits requested for unlimited ID..."
779 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
780         -D 'cn=Unlimited User,ou=People,dc=example,dc=com' \
781         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' >$SEARCHOUT 2>&1
782 RC=$?
783 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
784 case $RC in
785         0)
786                 if test x"$COUNT" != x ; then
787                         echo "...success (got $COUNT entries)"
788                 else
789                         echo "...error: did not expect ldapsearch success ($RC)!"
790                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
791                         exit 1
792                 fi
793         ;;
794         *)
795                 echo "ldapsearch failed ($RC)!"
796                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
797                 exit $RC
798         ;;
799 esac
800
801 SIZELIMIT=2
802 echo "Testing size limit request ($SIZELIMIT) for unlimited ID..."
803 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
804         -D 'cn=Unlimited User,ou=People,dc=example,dc=com' \
805         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
806 RC=$?
807 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
808 case $RC in
809         0)
810                 if test x"$COUNT" != x ; then
811                         if test "$COUNT" -gt "$SIZELIMIT" ; then
812                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
813                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
814                                 exit 1
815                         fi
816                         echo "...didn't bump into the requested size limit ($SIZELIMIT; got $COUNT entries)"
817                 else
818                         echo "...error: did not expect ldapsearch success ($RC)!"
819                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
820                         exit 1
821                 fi
822         ;;
823         4)
824                 if test x"$COUNT" != x ; then
825                         if test $COUNT = $SIZELIMIT ; then
826                                 echo "...bumped into requested size limit ($SIZELIMIT)"
827                         else
828                                 echo "...error: got $COUNT entries while requesting $SIZELIMIT..."
829                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
830                                 exit $RC
831                         fi
832                 else
833                         echo "...error: bumped into server-side size limit, but got no entries!"
834                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
835                         exit $RC
836                 fi
837         ;;
838         *)
839                 echo "ldapsearch failed ($RC)!"
840                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
841                 exit $RC
842         ;;
843 esac
844
845 TIMELIMIT=10
846 echo "Testing time limit request ($TIMELIMIT s) for unlimited ID..."
847 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -l $TIMELIMIT \
848         -D 'cn=Unlimited User,ou=People,dc=example,dc=com' \
849         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
850 RC=$?
851 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
852 case $RC in
853         0)
854                 if test x"$COUNT" != x ; then
855                         echo "...didn't bump into the requested time limit ($TIMELIMIT s; got $COUNT entries)"
856                 else
857                         echo "...error: did not expect ldapsearch success ($RC)!"
858                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
859                         exit 1
860                 fi
861         ;;
862         3)
863                 if test x"$COUNT" = x ; then
864                         COUNT=0
865                 fi
866                 echo "...bumped into requested time limit ($TIMELIMIT s; got $COUNT entries)"
867         ;;
868         *)
869                 echo "ldapsearch failed ($RC)!"
870                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
871                 exit $RC
872         ;;
873 esac
874
875 echo "Testing no limits requested for soft limited ID..."
876 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
877         -D 'cn=Soft Limited User,ou=People,dc=example,dc=com' \
878         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
879 RC=$?
880 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
881 case $RC in
882         0)
883                 if test x"$COUNT" != x ; then
884                         echo "...didn't bump into server-side size limit (got $COUNT entries)"
885                 else
886                         echo "...error: did not expect ldapsearch success ($RC)!"
887                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
888                         exit 1
889                 fi
890         ;;
891         4)
892                 if test x"$COUNT" != x ; then
893                         echo "...bumped into server-side size limit (got $COUNT entries)"
894                 else
895                         echo "...error: bumped into server-side size limit, but got no entries!"
896                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
897                         exit $RC
898                 fi
899         ;;
900         *)
901                 echo "ldapsearch failed ($RC)!"
902                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
903                 exit $RC
904         ;;
905 esac
906
907 SIZELIMIT=2
908 echo "Testing lower than soft limit request ($SIZELIMIT) for soft limited ID..."
909 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
910         -D 'cn=Soft Limited User,ou=People,dc=example,dc=com' \
911         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
912 RC=$?
913 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
914 case $RC in
915         0)
916                 if test x"$COUNT" != x ; then
917                         if test "$COUNT" -gt "$SIZELIMIT" ; then
918                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
919                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
920                                 exit 1
921                         fi
922                         echo "...didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
923                 else
924                         echo "...error: did not expect ldapsearch success ($RC)!"
925                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
926                         exit 1
927                 fi
928         ;;
929         4)
930                 if test "x$COUNT" != "x" ; then
931                         if test "x$SIZELIMIT" = "x$COUNT" ; then
932                                 echo "...bumped into requested ($SIZELIMIT) size limit"
933                         else
934                                 echo "...bumped into server-side size limit ($COUNT)"
935                         fi
936                 else
937                         echo "...bumped into either requested ($SIZELIMIT) or server-side size limit"
938                 fi
939         ;;
940         *)
941                 echo "ldapsearch failed ($RC)!"
942                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
943                 exit $RC
944         ;;
945 esac
946
947 SIZELIMIT=100
948 echo "Testing higher than soft limit request ($SIZELIMIT) for soft limited ID..."
949 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
950         -D 'cn=Soft Limited User,ou=People,dc=example,dc=com' \
951         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
952 RC=$?
953 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
954 case $RC in
955         0)
956                 if test x"$COUNT" != x ; then
957                         if test "$COUNT" -gt "$SIZELIMIT" ; then
958                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
959                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
960                                 exit 1
961                         fi
962                         echo "...didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
963                 else
964                         echo "...error: did not expect ldapsearch success ($RC)!"
965                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
966                         exit 1
967                 fi
968         ;;
969         4)
970                 if test "x$COUNT" != "x" ; then
971                         if test "x$SIZELIMIT" = "x$COUNT" ; then
972                                 echo "...bumped into requested ($SIZELIMIT) size limit"
973                         else
974                                 echo "...bumped into server-side size limit ($COUNT)"
975                         fi
976                 else
977                         echo "...bumped into either requested ($SIZELIMIT) or server-side size limit"
978                 fi
979         ;;
980         *)
981                 echo "ldapsearch failed ($RC)!"
982                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
983                 exit $RC
984         ;;
985 esac
986
987 SIZELIMIT=2
988 echo "Testing lower than hard limit request ($SIZELIMIT) for hard limited ID..."
989 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
990         -D 'cn=Hard Limited User,ou=People,dc=example,dc=com' \
991         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
992 RC=$?
993 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
994 case $RC in
995         0)
996                 if test x"$COUNT" != x ; then
997                         if test "$COUNT" -gt "$SIZELIMIT" ; then
998                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
999                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1000                                 exit 1
1001                         fi
1002                         echo "...didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
1003                 else
1004                         echo "...error: did not expect ldapsearch success ($RC)!"
1005                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1006                         exit 1
1007                 fi
1008         ;;
1009         4)
1010                 if test x"$COUNT" != x ; then
1011                         if test "$COUNT" = "$SIZELIMIT" ; then
1012                                 echo "...bumped into requested ($SIZELIMIT) size limit"
1013                         else
1014                                 echo "...error: got size limit $SIZELIMIT but $COUNT entries"
1015                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1016                                 exit $RC
1017                         fi
1018                 else
1019                         echo "...error: bumped into server-side size limit, but got no entries!"
1020                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1021                         exit $RC
1022                 fi
1023         ;;
1024         *)
1025                 echo "ldapsearch failed ($RC)!"
1026                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1027                 exit $RC
1028         ;;
1029 esac
1030
1031 SIZELIMIT=100
1032 echo "Testing higher than hard limit request ($SIZELIMIT) for hard limited ID..."
1033 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
1034         -D 'cn=Hard Limited User,ou=People,dc=example,dc=com' \
1035         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1036 RC=$?
1037 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1038 case $RC in
1039         0)
1040                 if test x"$COUNT" != x ; then
1041                         if test "$COUNT" -gt "$SIZELIMIT" ; then
1042                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
1043                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1044                                 exit 1
1045                         fi
1046                         echo "...didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
1047                 else
1048                         echo "...error: did not expect ldapsearch success ($RC)!"
1049                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1050                         exit 1
1051                 fi
1052         ;;
1053         4)
1054                 if test x"$COUNT" != x ; then
1055                         if test "$COUNT" = "$SIZELIMIT" ; then
1056                                 echo "...error: bumped into requested ($SIZELIMIT) size limit"
1057                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1058                                 exit $RC
1059                         else
1060                                 echo "...got size limit $COUNT instead of requested $SIZELIMIT entries"
1061                         fi
1062                 else
1063                         echo "...error: bumped into server-side size limit, but got no entries!"
1064                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1065                         exit $RC
1066                 fi
1067         ;;
1068 #       11)
1069 #               echo "...bumped into hard size administrative limit"
1070 #       ;;
1071         *)
1072                 echo "ldapsearch failed ($RC)!"
1073                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1074                 exit $RC
1075         ;;
1076 esac
1077
1078 SIZELIMIT=max
1079 echo "Testing max limit request ($SIZELIMIT) for hard limited ID..."
1080 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
1081         -D 'cn=Hard Limited User,ou=People,dc=example,dc=com' \
1082         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1083 RC=$?
1084 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1085 case $RC in
1086         0)
1087                 if test x"$COUNT" != x ; then
1088                         echo "...didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
1089                 else
1090                         echo "...error: did not expect ldapsearch success ($RC)!"
1091                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1092                         exit 1
1093                 fi
1094         ;;
1095         4)
1096                 if test x"$COUNT" != x ; then
1097                         echo "...bumped into requested ($SIZELIMIT=$COUNT) size limit"
1098                 else
1099                         echo "...error: bumped into size limit but got no entries!"
1100                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1101                         exit $RC
1102                 fi
1103         ;;
1104 #       11)
1105 #               echo "...bumped into hard size administrative limit"
1106 #       ;;
1107         *)
1108                 echo "ldapsearch failed ($RC)!"
1109                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1110                 exit $RC
1111         ;;
1112 esac
1113
1114 echo "Testing lower than unchecked limit request for unchecked limited ID..."
1115 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
1116         -D 'cn=Unchecked Limited User,ou=People,dc=example,dc=com' \
1117         -E '!pr='$PAGESIZE'/noprompt' '(uid=uncheckedlimited)' > $SEARCHOUT 2>&1
1118 RC=$?
1119 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1120 case $RC in
1121         0)
1122                 if test x"$COUNT" != x ; then
1123                         echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
1124                 else
1125                         echo "...error: did not expect ldapsearch success ($RC)!"
1126                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1127                         exit 1
1128                 fi
1129         ;;
1130 #       11)
1131 #               echo "...bumped into unchecked administrative limit"
1132 #       ;;
1133         *)
1134                 echo "ldapsearch failed ($RC)!"
1135                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1136                 exit $RC
1137         ;;
1138 esac
1139
1140 echo "Testing higher than unchecked limit requested for unchecked limited ID..."
1141 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
1142         -D 'cn=Unchecked Limited User,ou=People,dc=example,dc=com' \
1143         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1144 RC=$?
1145 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1146 case $RC in
1147         0)
1148                 if test x"$COUNT" != x ; then
1149                         echo "...error: didn't bump into server-side unchecked limit (got $COUNT entries)"
1150                 else
1151                         echo "...error: did not expect ldapsearch success ($RC)!"
1152                 fi
1153                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1154                 exit 1
1155         ;;
1156         11)
1157                 echo "...bumped into unchecked administrative limit"
1158         ;;
1159         *)
1160                 echo "ldapsearch failed ($RC)!"
1161                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1162                 exit $RC
1163         ;;
1164 esac
1165
1166 echo ""
1167 echo "Testing specific search limits with pagedResults control"
1168 echo ""
1169
1170 echo "Testing no limit requested for unlimited page size ID..."
1171 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
1172         -D 'cn=Unlimited User,ou=Paged Results Users,dc=example,dc=com' \
1173         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1174 RC=$?
1175 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1176 case $RC in
1177         0)
1178                 if test x"$COUNT" != x ; then
1179                         echo "...success; didn't bump into server-side size limit (got $COUNT entries)"
1180                 else
1181                         echo "...error: did not expect ldapsearch success ($RC)!"
1182                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1183                         exit 1
1184                 fi
1185         ;;
1186         4)
1187                 if test x"$COUNT" != x ; then
1188                         echo "...bumped into server-side size limit (got $COUNT entries)"
1189                 else
1190                         echo "...error: bumped into server-side size limit, but got no entries!"
1191                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1192                         exit $RC
1193                 fi
1194         ;;
1195         *)
1196                 echo "ldapsearch failed ($RC)!"
1197                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1198                 exit $RC
1199         ;;
1200 esac
1201
1202 echo "Testing no limit requested for limited page size ID..."
1203 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
1204         -D 'cn=Page Size Limited User,ou=Paged Results Users,dc=example,dc=com' \
1205         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1206 RC=$?
1207 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1208 case $RC in
1209         0)
1210                 echo "...success; didn't bump into server-side page size limit (got $COUNT entries)"
1211         ;;
1212         4)
1213                 echo "...bumped into page size limit ($COUNT)"
1214         ;;
1215         11)
1216                 echo "...bumped into page size administrative limit"
1217         ;;
1218         *)
1219                 echo "ldapsearch failed ($RC)!"
1220                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1221                 exit $RC
1222         ;;
1223 esac
1224
1225 echo "Testing no limit requested for pagedResults disabled ID..."
1226 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
1227         -D 'cn=Paged Results Disabled User,ou=Paged Results Users,dc=example,dc=com' \
1228         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1229 RC=$?
1230 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1231 case $RC in
1232         0)
1233                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
1234         ;;
1235         4)
1236                 echo "...bumped into server-side size limit ($COUNT)"
1237         ;;
1238         11)
1239                 echo "...bumped into pagedResults disabled administrative limit"
1240         ;;
1241         *)
1242                 echo "ldapsearch failed ($RC)!"
1243                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1244                 exit $RC
1245         ;;
1246 esac
1247
1248 echo "Testing no limit requested for pagedResults total count limited ID..."
1249 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
1250         -D 'cn=Paged Results Limited User,ou=Paged Results Users,dc=example,dc=com' \
1251         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1252 RC=$?
1253 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1254 case $RC in
1255         0)
1256                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
1257         ;;
1258         4)
1259                 echo "...bumped into server-side size limit ($COUNT)"
1260         ;;
1261         11)
1262                 echo "...bumped into pagedResults total count administrative limit"
1263         ;;
1264         *)
1265                 echo "ldapsearch failed ($RC)!"
1266                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1267                 exit $RC
1268         ;;
1269 esac
1270
1271 SIZELIMIT=8
1272 echo "Testing higher than hard but lower then total count limit requested for pagedResults total count limited ID..."
1273 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
1274         -D 'cn=Paged Results Limited User,ou=Paged Results Users,dc=example,dc=com' \
1275         -z $SIZELIMIT -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1276 RC=$?
1277 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1278 case $RC in
1279         0)
1280                 echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side unchecked limit (got $COUNT entries)"
1281         ;;
1282         4)
1283                 if test "x$COUNT" != "x" ; then
1284                         if test "x$SIZELIMIT" = "x$COUNT" ; then
1285                                 echo "...bumped into requested ($SIZELIMIT) size limit"
1286                         else
1287                                 echo "...bumped into server-side size limit ($COUNT)"
1288                         fi
1289                 else
1290                         echo "...bumped into either requested ($SIZELIMIT) or server-side size limit"
1291                 fi
1292         ;;
1293         11)
1294                 echo "...bumped into either hard size or pagedResults total count administrative limit"
1295         ;;
1296         *)
1297                 echo "ldapsearch failed ($RC)!"
1298                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1299                 exit $RC
1300         ;;
1301 esac
1302
1303 SIZELIMIT=15
1304 echo "Testing higher than total count limit requested for pagedResults total count limited ID..."
1305 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
1306         -D 'cn=Paged Results Limited User,ou=Paged Results Users,dc=example,dc=com' \
1307         -z $SIZELIMIT -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1308 RC=$?
1309 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1310 case $RC in
1311         0)
1312                 echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side unchecked limit (got $COUNT entries)"
1313         ;;
1314         4)
1315                 if test "x$COUNT" != "x" ; then
1316                         if test "x$SIZELIMIT" = "x$COUNT" ; then
1317                                 echo "...bumped into requested ($SIZELIMIT) size limit"
1318                         else
1319                                 echo "...bumped into server-side size limit ($COUNT)"
1320                         fi
1321                 else
1322                         echo "...bumped into either requested ($SIZELIMIT) or server-side size limit"
1323                 fi
1324         ;;
1325         11)
1326                 echo "...bumped into pagedResults total count administrative limit"
1327         ;;
1328         *)
1329                 echo "ldapsearch failed ($RC)!"
1330                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1331                 exit $RC
1332         ;;
1333 esac
1334
1335 SIZELIMIT=max
1336 echo "Testing max limit requested for pagedResults total count limited ID..."
1337 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
1338         -D 'cn=Paged Results Limited User,ou=Paged Results Users,dc=example,dc=com' \
1339         -z $SIZELIMIT -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1340 RC=$?
1341 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1342 case $RC in
1343         0)
1344                 echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side unchecked limit (got $COUNT entries)"
1345         ;;
1346         4)
1347                 if test "x$COUNT" != "x" ; then
1348                         if test "x$SIZELIMIT" = "x$COUNT" ; then
1349                                 echo "...bumped into requested ($SIZELIMIT) size limit"
1350                         else
1351                                 echo "...bumped into server-side size limit ($COUNT)"
1352                         fi
1353                 else
1354                         echo "...bumped into either requested ($SIZELIMIT) or server-side size limit"
1355                 fi
1356         ;;
1357         11)
1358                 echo "...bumped into pagedResults total count administrative limit"
1359         ;;
1360         *)
1361                 echo "ldapsearch failed ($RC)!"
1362                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1363                 exit $RC
1364         ;;
1365 esac
1366
1367 # ITS#4479
1368 PAGESIZE=1
1369 SIZELIMIT=2
1370 echo "Testing size limit request ($SIZELIMIT) for unlimited ID and pagesize=$PAGESIZE..."
1371 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
1372         -D 'cn=Unlimited User,ou=People,dc=example,dc=com' \
1373         -E '!pr='$PAGESIZE'/noprompt' '(objectClass=*)' > $SEARCHOUT 2>&1
1374 RC=$?
1375 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHOUT`
1376 case $RC in
1377         0)
1378                 if test x"$COUNT" != x ; then
1379                         if test "$COUNT" -gt "$SIZELIMIT" ; then
1380                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
1381                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1382                                 exit 1
1383                         fi
1384                         echo "...didn't bump into the requested size limit ($SIZELIMIT; got $COUNT entries)"
1385                 else
1386                         echo "...error: did not expect ldapsearch success ($RC)!"
1387                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1388                         exit 1
1389                 fi
1390         ;;
1391         4)
1392                 if test x"$COUNT" != x ; then
1393                         if test $COUNT = $SIZELIMIT ; then
1394                                 echo "...bumped into requested size limit ($SIZELIMIT)"
1395                         else
1396                                 echo "...error: got $COUNT entries while requesting $SIZELIMIT..."
1397                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1398                                 exit $RC
1399                         fi
1400                 else
1401                         echo "...error: bumped into server-side size limit, but got no entries!"
1402                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1403                         exit $RC
1404                 fi
1405         ;;
1406         *)
1407                 echo "ldapsearch failed ($RC)!"
1408                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1409                 exit $RC
1410         ;;
1411 esac
1412
1413 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1414
1415 echo ">>>>> Test succeeded"
1416
1417 test $KILLSERVERS != no && wait
1418
1419 exit 0