diff --git a/tests/scripts/test025-limits b/tests/scripts/test025-limits
index 7e9c771c85ca2ef50e2e3236c1f2aabd709d5204..abfdd2bac60f1b6de0eb90fbb95a8ea8dd4842a8 100755
--- a/tests/scripts/test025-limits
+++ b/tests/scripts/test025-limits
@@ -65,12 +65,16 @@ fi
 
 cat /dev/null > $SEARCHOUT
 
+echo ""
+echo "Testing regular search limits"
+echo ""
+
 echo "Testing no limits requested for unlimited ID..."
 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
 	-D 'cn=Unlimited User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' >$SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success (got $COUNT entries)"
@@ -88,7 +92,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT
 	-D 'cn=Unlimited User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success (got $COUNT entries)"
@@ -109,7 +113,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -l $TIMELIMIT
 	-D 'cn=Unlimited User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success (got $COUNT entries)"
@@ -129,7 +133,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
 	-D 'cn=Soft Limited User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into server-side size limit (got $COUNT entries)"
@@ -150,7 +154,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT
 	-D 'cn=Soft Limited User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
@@ -179,7 +183,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT
 	-D 'cn=Soft Limited User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
@@ -208,7 +212,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT
 	-D 'cn=Hard Limited User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
@@ -229,7 +233,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT
 	-D 'cn=Hard Limited User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
@@ -252,7 +256,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
 	-D 'cn=Unchecked Limited User,ou=People,o=University of Michigan,c=US' \
 	'(uid=uncheckedlimited)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
@@ -272,7 +276,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
 	-D 'cn=Unchecked Limited User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
@@ -292,7 +296,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
 	-D 'cn=Unchecked Limited User 2,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
@@ -312,7 +316,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
 	-D 'cn=Foo User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
@@ -340,7 +344,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
 	-D 'cn=Bar User,ou=People,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
@@ -368,7 +372,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
 	-D 'cn=Unchecked Limited Users,ou=Groups,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
@@ -396,7 +400,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
 	-D 'cn=Unchecked Limited User 3,ou=Admin,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
@@ -424,7 +428,7 @@ $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
 	-D 'cn=Special User,o=University of Michigan,c=US' \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
@@ -451,7 +455,132 @@ echo "Testing higher than unchecked limit requested for unchecked limited anonym
 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
 	'(objectClass=*)' > $SEARCHOUT 2>&1
 RC=$?
-COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
+case $RC in
+	0)
+		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
+	;;
+	4)
+		if test "x$COUNT" != "x" ; then
+			if test $SIZELIMIT = $COUNT ; then
+				echo "...bumped into requested ($SIZELIMIT) size limit"
+			else
+				echo "...bumped into server-side size limit ($COUNT)"
+			fi
+		else
+			echo "...bumped into either requested ($SIZELIMIT) or server-side size limit"
+		fi
+	;;
+	*)
+		echo "ldapsearch failed ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	;;
+esac
+
+case $BACKEND in
+	bdb | hdb)
+		# only bdb|hdb currently supports pagedResults control
+		;;
+	*)
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+
+		echo ">>>>> Test succeeded"
+		exit 0
+	;;
+esac
+
+echo ""
+echo "Testing regular search limits with pagedResults control"
+echo ""
+
+PAGESIZE=5
+echo "Testing no limits requested for unlimited ID..."
+$LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
+	-D 'cn=Unlimited User,ou=People,o=University of Michigan,c=US' \
+	-E '!pr='$PAGESIZE '(objectClass=*)' </dev/null >$SEARCHOUT 2>&1
+RC=$?
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
+case $RC in
+	0)
+		echo "...success (got $COUNT entries)"
+	;;
+	*)
+		echo "ldapsearch failed ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	;;
+esac
+
+SIZELIMIT=2
+echo "Testing size limit request ($SIZELIMIT) for unlimited ID..."
+$LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
+	-D 'cn=Unlimited User,ou=People,o=University of Michigan,c=US' \
+	-E '!pr='$PAGESIZE '(objectClass=*)' </dev/null > $SEARCHOUT 2>&1
+RC=$?
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
+case $RC in
+	0)
+		echo "...success (got $COUNT entries)"
+	;;
+	4)
+		echo "...bumped into requested size limit ($SIZELIMIT)"
+	;;
+	*)
+		echo "ldapsearch failed ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	;;
+esac
+
+TIMELIMIT=10
+echo "Testing time limit request ($TIMELIMIT s) for unlimited ID..."
+$LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -l $TIMELIMIT \
+	-D 'cn=Unlimited User,ou=People,o=University of Michigan,c=US' \
+	-E '!pr='$PAGESIZE '(objectClass=*)' </dev/null > $SEARCHOUT 2>&1
+RC=$?
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
+case $RC in
+	0)
+		echo "...success (got $COUNT entries)"
+	;;
+	3)
+		echo "...bumped into requested time limit ($TIMELIMIT s; $COUNT entries)"
+	;;
+	*)
+		echo "ldapsearch failed ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	;;
+esac
+
+echo "Testing no limits requested for soft limited ID..."
+$LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
+	-D 'cn=Soft Limited User,ou=People,o=University of Michigan,c=US' \
+	-E '!pr='$PAGESIZE '(objectClass=*)' </dev/null > $SEARCHOUT 2>&1
+RC=$?
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
+case $RC in
+	0)
+		echo "...success; didn't bump into server-side size limit (got $COUNT entries)"
+	;;
+	4)
+		echo "...bumped into server-side size limit ($COUNT)"
+	;;
+	*)
+		echo "ldapsearch failed ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	;;
+esac
+
+SIZELIMIT=2
+echo "Testing lower than soft limit request ($SIZELIMIT) for soft limited ID..."
+$LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
+	-D 'cn=Soft Limited User,ou=People,o=University of Michigan,c=US' \
+	-E '!pr='$PAGESIZE '(objectClass=*)' </dev/null > $SEARCHOUT 2>&1
+RC=$?
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
 case $RC in
 	0)
 		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
@@ -474,6 +603,125 @@ case $RC in
 	;;
 esac
 
+SIZELIMIT=100
+echo "Testing higher than soft limit request ($SIZELIMIT) for soft limited ID..."
+$LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
+	-D 'cn=Soft Limited User,ou=People,o=University of Michigan,c=US' \
+	-E '!pr='$PAGESIZE '(objectClass=*)' </dev/null > $SEARCHOUT 2>&1
+RC=$?
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
+case $RC in
+	0)
+		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
+	;;
+	4)
+		if test "x$COUNT" != "x" ; then
+			if test $SIZELIMIT = $COUNT ; then
+				echo "...bumped into requested ($SIZELIMIT) size limit"
+			else
+				echo "...bumped into server-side size limit ($COUNT)"
+			fi
+		else
+			echo "...bumped into either requested ($SIZELIMIT) or server-side size limit"
+		fi
+	;;
+	*)
+		echo "ldapsearch failed ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	;;
+esac
+
+SIZELIMIT=2
+echo "Testing lower than hard limit request ($SIZELIMIT) for hard limited ID..."
+$LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
+	-D 'cn=Hard Limited User,ou=People,o=University of Michigan,c=US' \
+	-E '!pr='$PAGESIZE '(objectClass=*)' </dev/null > $SEARCHOUT 2>&1
+RC=$?
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
+case $RC in
+	0)
+		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
+	;;
+	4)
+		echo "...bumped into requested ($SIZELIMIT) size limit"
+	;;
+	*)
+		echo "ldapsearch failed ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	;;
+esac
+
+SIZELIMIT=100
+echo "Testing higher than hard limit request ($SIZELIMIT) for hard limited ID..."
+$LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
+	-D 'cn=Hard Limited User,ou=People,o=University of Michigan,c=US' \
+	-E '!pr='$PAGESIZE '(objectClass=*)' </dev/null > $SEARCHOUT 2>&1
+RC=$?
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
+case $RC in
+	0)
+		echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
+	;;
+	4)
+		echo "...bumped into requested ($SIZELIMIT) size limit"
+	;;
+	11)
+		echo "...bumped into server-side size limit"
+	;;
+	*)
+		echo "ldapsearch failed ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	;;
+esac
+
+echo "Testing lower than unchecked limit request for unchecked limited ID..."
+$LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
+	-D 'cn=Unchecked Limited User,ou=People,o=University of Michigan,c=US' \
+	-E '!pr='$PAGESIZE '(uid=uncheckedlimited)' </dev/null > $SEARCHOUT 2>&1
+RC=$?
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
+case $RC in
+	0)
+		echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
+	;;
+	11)
+		echo "...bumped into server-side unchecked limit"
+	;;
+	*)
+		echo "ldapsearch failed ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	;;
+esac
+
+echo "Testing higher than unchecked limit requested for unchecked limited ID..."
+$LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
+	-D 'cn=Unchecked Limited User,ou=People,o=University of Michigan,c=US' \
+	-E '!pr='$PAGESIZE '(objectClass=*)' </dev/null > $SEARCHOUT 2>&1
+RC=$?
+COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;[^0-9]\+\([0-9]\+\)$;\1;'`
+case $RC in
+	0)
+		echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
+	;;
+	11)
+		echo "...bumped into server-side unchecked limit"
+	;;
+	*)
+		echo "ldapsearch failed ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	;;
+esac
+
+# TODO
+#echo ""
+#echo "Testing specific search limits with pagedResults control"
+#echo ""
+
 test $KILLSERVERS != no && kill -HUP $KILLPIDS
 
 echo ">>>>> Test succeeded"