From 7e833d90a7e2bf588c90061e2e1ec946ae1669fe Mon Sep 17 00:00:00 2001
From: Pierangelo Masarati <ando@openldap.org>
Date: Sat, 19 Jun 2004 10:02:27 +0000
Subject: [PATCH] implement server side of "max" limit

---
 servers/slapd/limits.c | 21 ++++++++++++++++-----
 servers/slapd/slap.h   |  1 +
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/servers/slapd/limits.c b/servers/slapd/limits.c
index b32ea0be77..0f43faf548 100644
--- a/servers/slapd/limits.c
+++ b/servers/slapd/limits.c
@@ -1027,7 +1027,10 @@ limits_check( Operation *op, SlapReply *rs )
 				}
 
 			} else if ( op->ors_limit->lms_t_hard > 0 ) {
-				if ( op->ors_tlimit < 0 || op->ors_tlimit > op->ors_limit->lms_t_hard ) {
+				if ( op->ors_tlimit == SLAP_MAX_LIMIT ) {
+					op->ors_tlimit = op->ors_limit->lms_t_hard;
+
+				} else if ( op->ors_tlimit < 0 || op->ors_tlimit > op->ors_limit->lms_t_hard ) {
 					/* error if exceeding hard limit */
 					rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
 					send_ldap_result( op, rs );
@@ -1084,7 +1087,9 @@ limits_check( Operation *op, SlapReply *rs )
 			if ( pr_total == -1 ) {
 				slimit = -1;
 
-			} else if ( pr_total > 0 && ( op->ors_slimit == SLAP_NO_LIMIT || op->ors_slimit > pr_total ) ) {
+			} else if ( pr_total > 0 && op->ors_slimit != SLAP_MAX_LIMIT
+					&& ( op->ors_slimit == SLAP_NO_LIMIT || op->ors_slimit > pr_total ) )
+			{
 				rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
 				send_ldap_result( op, rs );
 				rs->sr_err = LDAP_SUCCESS;
@@ -1097,8 +1102,11 @@ limits_check( Operation *op, SlapReply *rs )
 
 				/* first round of pagedResults: set count to any appropriate limit */
 
-				/* if the limit is set, check that it does not violate any limit */
-				if ( op->ors_slimit > 0 ) {
+				/* if the limit is set, check that it does not violate any server-side limit */
+				if ( op->ors_slimit == SLAP_MAX_LIMIT ) {
+					slimit2 = op->ors_slimit = pr_total;
+
+				} else if ( op->ors_slimit > 0 ) {
 					slimit2 = op->ors_slimit;
 
 				} else if ( op->ors_slimit == 0 ) {
@@ -1173,7 +1181,10 @@ limits_check( Operation *op, SlapReply *rs )
 
 			/* explicit hard limit: error if violated */
 			} else if ( op->ors_limit->lms_s_hard > 0 ) {
-				if ( op->ors_slimit > op->ors_limit->lms_s_hard ) {
+				if ( op->ors_slimit == SLAP_MAX_LIMIT ) {
+					op->ors_slimit = op->ors_limit->lms_s_hard;
+
+				} else if ( op->ors_slimit > op->ors_limit->lms_s_hard ) {
 					/* if limit exceeds hard, error */
 					rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
 					send_ldap_result( op, rs );
diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h
index e0330c07bb..f1853ee04f 100644
--- a/servers/slapd/slap.h
+++ b/servers/slapd/slap.h
@@ -1314,6 +1314,7 @@ struct slap_limits_set {
 
 /* Note: this is different from LDAP_NO_LIMIT (0); slapd internal use only */
 #define SLAP_NO_LIMIT			-1
+#define SLAP_MAX_LIMIT			2147483647
 
 struct slap_limits {
 	unsigned		lm_flags;	/* type of pattern */
-- 
GitLab