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