1 /* limits.c - routines to handle regex-based size and time limits */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
22 #include <ac/string.h>
26 /* define to get an error if requesting limit higher than hard */
27 #undef ABOVE_HARD_LIMIT_IS_ERROR
30 limits2str( unsigned i )
33 case SLAP_LIMITS_UNDEFINED:
36 case SLAP_LIMITS_EXACT:
42 case SLAP_LIMITS_SUBTREE:
45 case SLAP_LIMITS_CHILDREN:
48 case SLAP_LIMITS_REGEX:
51 case SLAP_LIMITS_ANONYMOUS:
54 case SLAP_LIMITS_USERS:
69 struct slap_limits_set **limit
72 struct slap_limits **lm;
77 Debug( LDAP_DEBUG_TRACE, "==> limits_get: conn=%lu op=%lu dn=\"%s\"\n",
78 op->o_connid, op->o_opid,
79 BER_BVISNULL( ndn ) ? "[anonymous]" : ndn->bv_val );
83 *limit = &op->o_bd->be_def_limit;
85 if ( op->o_bd->be_limits == NULL ) {
89 for ( lm = op->o_bd->be_limits; lm[0] != NULL; lm++ ) {
90 unsigned style = lm[0]->lm_flags & SLAP_LIMITS_MASK;
91 unsigned type = lm[0]->lm_flags & SLAP_LIMITS_TYPE_MASK;
94 case SLAP_LIMITS_EXACT:
95 if ( ndn->bv_len == 0 ) {
99 if ( type == SLAP_LIMITS_TYPE_GROUP ) {
102 rc = backend_group( op, NULL,
105 lm[0]->lm_group_ad );
107 *limit = &lm[0]->lm_limits;
108 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=GROUP match=EXACT "
109 "dn=\"%s\" oc=\"%s\" ad=\"%s\"\n",
110 lm[0]->lm_pat.bv_val,
111 lm[0]->lm_group_oc->soc_cname.bv_val,
112 lm[0]->lm_group_ad->ad_cname.bv_val );
118 if ( dn_match( &lm[0]->lm_pat, ndn ) ) {
119 *limit = &lm[0]->lm_limits;
120 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=DN match=EXACT dn=\"%s\"\n",
121 lm[0]->lm_pat.bv_val, 0, 0 );
127 case SLAP_LIMITS_ONE:
128 case SLAP_LIMITS_SUBTREE:
129 case SLAP_LIMITS_CHILDREN: {
132 if ( ndn->bv_len == 0 ) {
136 /* ndn shorter than dn_pat */
137 if ( ndn->bv_len < lm[0]->lm_pat.bv_len ) {
140 d = ndn->bv_len - lm[0]->lm_pat.bv_len;
142 /* allow exact match for SUBTREE only */
144 if ( style != SLAP_LIMITS_SUBTREE ) {
148 /* check for unescaped rdn separator */
149 if ( !DN_SEPARATOR( ndn->bv_val[d-1] ) ) {
154 /* in case of (sub)match ... */
155 if ( lm[0]->lm_pat.bv_len == ( ndn->bv_len - d )
156 && strcmp( lm[0]->lm_pat.bv_val,
157 &ndn->bv_val[d] ) == 0 )
159 /* check for exactly one rdn in case of ONE */
160 if ( style == SLAP_LIMITS_ONE ) {
162 * if ndn is more that one rdn
163 * below dn_pat, continue
165 if ( (size_t) dn_rdnlen( NULL, ndn )
172 *limit = &lm[0]->lm_limits;
173 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=DN match=%s dn=\"%s\"\n",
174 limits2str( style ), lm[0]->lm_pat.bv_val, 0 );
181 case SLAP_LIMITS_REGEX:
182 if ( ndn->bv_len == 0 ) {
185 if ( regexec( &lm[0]->lm_regex, ndn->bv_val,
188 *limit = &lm[0]->lm_limits;
189 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=DN match=%s dn=\"%s\"\n",
190 limits2str( style ), lm[0]->lm_pat.bv_val, 0 );
195 case SLAP_LIMITS_ANONYMOUS:
196 if ( ndn->bv_len == 0 ) {
197 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=DN match=%s\n",
198 limits2str( style ), 0, 0 );
199 *limit = &lm[0]->lm_limits;
204 case SLAP_LIMITS_USERS:
205 if ( ndn->bv_len != 0 ) {
206 *limit = &lm[0]->lm_limits;
207 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=DN match=%s\n",
208 limits2str( style ), 0, 0 );
213 case SLAP_LIMITS_ANY:
214 *limit = &lm[0]->lm_limits;
218 assert( 0 ); /* unreachable */
231 ObjectClass *group_oc,
232 AttributeDescription *group_ad,
233 struct slap_limits_set *limit
237 struct slap_limits *lm;
238 unsigned type, style;
243 type = flags & SLAP_LIMITS_TYPE_MASK;
244 style = flags & SLAP_LIMITS_MASK;
247 case SLAP_LIMITS_ANONYMOUS:
248 case SLAP_LIMITS_USERS:
249 case SLAP_LIMITS_ANY:
250 for ( i = 0; be->be_limits && be->be_limits[ i ]; i++ ) {
251 if ( be->be_limits[ i ]->lm_flags == style ) {
259 lm = ( struct slap_limits * )ch_calloc( sizeof( struct slap_limits ), 1 );
262 case SLAP_LIMITS_UNDEFINED:
263 style = SLAP_LIMITS_EXACT;
264 /* continue to next cases */
265 case SLAP_LIMITS_EXACT:
266 case SLAP_LIMITS_ONE:
267 case SLAP_LIMITS_SUBTREE:
268 case SLAP_LIMITS_CHILDREN:
269 lm->lm_flags = style | type;
273 bv.bv_val = (char *) pattern;
274 bv.bv_len = strlen( pattern );
276 rc = dnNormalize( 0, NULL, NULL, &bv, &lm->lm_pat, NULL );
277 if ( rc != LDAP_SUCCESS ) {
284 case SLAP_LIMITS_REGEX:
285 lm->lm_flags = style | type;
286 ber_str2bv( pattern, 0, 1, &lm->lm_pat );
287 if ( regcomp( &lm->lm_regex, lm->lm_pat.bv_val,
288 REG_EXTENDED | REG_ICASE ) ) {
289 free( lm->lm_pat.bv_val );
295 case SLAP_LIMITS_ANONYMOUS:
296 case SLAP_LIMITS_USERS:
297 case SLAP_LIMITS_ANY:
298 lm->lm_flags = style | type;
299 lm->lm_pat.bv_val = NULL;
300 lm->lm_pat.bv_len = 0;
305 case SLAP_LIMITS_TYPE_GROUP:
308 lm->lm_group_oc = group_oc;
309 lm->lm_group_ad = group_ad;
313 lm->lm_limits = *limit;
316 if ( be->be_limits != NULL ) {
317 for ( ; be->be_limits[i]; i++ );
320 be->be_limits = ( struct slap_limits ** )ch_realloc( be->be_limits,
321 sizeof( struct slap_limits * ) * ( i + 2 ) );
322 be->be_limits[i] = lm;
323 be->be_limits[i+1] = NULL;
337 int flags = SLAP_LIMITS_UNDEFINED;
339 struct slap_limits_set limit;
341 ObjectClass *group_oc = NULL;
342 AttributeDescription *group_ad = NULL;
347 Debug( LDAP_DEBUG_ANY,
348 "%s : line %d: missing arg(s) in "
349 "\"limits <pattern> <limits>\" line.\n%s",
354 limit = be->be_def_limit;
359 * "limits" <pattern> <limit> [ ... ]
366 * [ "dn" [ "." { "exact" | "base" | "onelevel" | "subtree" | children"
367 * | "regex" | "anonymous" } ] "=" ] <dn pattern>
370 * "exact" and "base" are the same (exact match);
371 * "onelevel" means exactly one rdn below, NOT including pattern
372 * "subtree" means any rdn below, including pattern
373 * "children" means any rdn below, NOT including pattern
375 * "anonymous" may be deprecated in favour
376 * of the pattern = "anonymous" form
378 * "group[/objectClass[/attributeType]]" "=" "<dn pattern>"
382 * "time" [ "." { "soft" | "hard" } ] "=" <integer>
384 * "size" [ "." { "soft" | "hard" | "unchecked" } ] "=" <integer>
388 if ( strcmp( pattern, "*" ) == 0) {
389 flags = SLAP_LIMITS_ANY;
391 } else if ( strcasecmp( pattern, "anonymous" ) == 0 ) {
392 flags = SLAP_LIMITS_ANONYMOUS;
394 } else if ( strcasecmp( pattern, "users" ) == 0 ) {
395 flags = SLAP_LIMITS_USERS;
397 } else if ( strncasecmp( pattern, "dn", STRLENOF( "dn" ) ) == 0 ) {
398 pattern += STRLENOF( "dn" );
399 if ( pattern[0] == '.' ) {
401 if ( strncasecmp( pattern, "exact", STRLENOF( "exact" )) == 0 ) {
402 flags = SLAP_LIMITS_EXACT;
403 pattern += STRLENOF( "exact" );
405 } else if ( strncasecmp( pattern, "base", STRLENOF( "base" ) ) == 0 ) {
406 flags = SLAP_LIMITS_BASE;
407 pattern += STRLENOF( "base" );
409 } else if ( strncasecmp( pattern, "one", STRLENOF( "one" ) ) == 0 ) {
410 flags = SLAP_LIMITS_ONE;
411 pattern += STRLENOF( "one" );
412 if ( strncasecmp( pattern, "level", STRLENOF( "level" ) ) == 0 ) {
413 pattern += STRLENOF( "level" );
416 Debug( LDAP_DEBUG_ANY,
417 "%s : line %d: deprecated \"one\" style "
418 "\"limits <pattern> <limits>\" line; "
419 "use \"onelevel\" instead.\n", fname, lineno, 0 );
422 } else if ( strncasecmp( pattern, "sub", STRLENOF( "sub" ) ) == 0 ) {
423 flags = SLAP_LIMITS_SUBTREE;
424 pattern += STRLENOF( "sub" );
425 if ( strncasecmp( pattern, "tree", STRLENOF( "tree" ) ) == 0 ) {
426 pattern += STRLENOF( "tree" );
429 Debug( LDAP_DEBUG_ANY,
430 "%s : line %d: deprecated \"sub\" style "
431 "\"limits <pattern> <limits>\" line; "
432 "use \"subtree\" instead.\n", fname, lineno, 0 );
435 } else if ( strncasecmp( pattern, "children", STRLENOF( "children" ) ) == 0 ) {
436 flags = SLAP_LIMITS_CHILDREN;
437 pattern += STRLENOF( "children" );
439 } else if ( strncasecmp( pattern, "regex", STRLENOF( "regex" ) ) == 0 ) {
440 flags = SLAP_LIMITS_REGEX;
441 pattern += STRLENOF( "regex" );
444 * this could be deprecated in favour
445 * of the pattern = "anonymous" form
447 } else if ( strncasecmp( pattern, "anonymous", STRLENOF( "anonymous" ) ) == 0 ) {
448 flags = SLAP_LIMITS_ANONYMOUS;
453 /* pre-check the data */
455 case SLAP_LIMITS_ANONYMOUS:
456 case SLAP_LIMITS_USERS:
458 /* no need for pattern */
463 if ( pattern[0] != '=' ) {
464 Debug( LDAP_DEBUG_ANY,
465 "%s : line %d: missing '=' in "
466 "\"dn[.{exact|base|onelevel|subtree"
467 "|children|regex|anonymous}]"
469 "\"limits <pattern> <limits>\" "
475 /* skip '=' (required) */
478 /* trim obvious cases */
479 if ( strcmp( pattern, "*" ) == 0 ) {
480 flags = SLAP_LIMITS_ANY;
483 } else if ( flags == SLAP_LIMITS_REGEX
484 && strcmp( pattern, ".*" ) == 0 ) {
485 flags = SLAP_LIMITS_ANY;
490 } else if (strncasecmp( pattern, "group", STRLENOF( "group" ) ) == 0 ) {
491 pattern += STRLENOF( "group" );
493 if ( pattern[0] == '/' ) {
494 struct berval oc, ad;
496 oc.bv_val = pattern + 1;
498 ad.bv_val = strchr(pattern, '/');
499 if ( ad.bv_val != NULL ) {
500 const char *text = NULL;
503 oc.bv_len = ad.bv_val - oc.bv_val;
506 ad.bv_len = strlen( ad.bv_val );
507 rc = slap_bv2ad( &ad, &group_ad, &text );
508 if ( rc != LDAP_SUCCESS ) {
512 pattern = ad.bv_val + ad.bv_len;
515 oc.bv_len = strlen( oc.bv_val );
517 pattern = oc.bv_val + oc.bv_len;
520 group_oc = oc_bvfind( &oc );
521 if ( group_oc == NULL ) {
526 if ( group_oc == NULL ) {
527 group_oc = oc_find( SLAPD_GROUP_CLASS );
528 if ( group_oc == NULL ) {
534 if ( group_ad == NULL ) {
535 const char *text = NULL;
538 rc = slap_str2ad( SLAPD_GROUP_ATTR, &group_ad, &text );
540 if ( rc != LDAP_SUCCESS ) {
546 flags = SLAP_LIMITS_TYPE_GROUP | SLAP_LIMITS_EXACT;
548 if ( pattern[0] != '=' ) {
549 Debug( LDAP_DEBUG_ANY,
550 "%s : line %d: missing '=' in "
551 "\"group[/objectClass[/attributeType]]"
553 "\"limits <pattern> <limits>\" line.\n",
558 /* skip '=' (required) */
563 for ( i = 2; i < argc; i++ ) {
564 if ( limits_parse_one( argv[i], &limit ) ) {
566 Debug( LDAP_DEBUG_ANY,
567 "%s : line %d: unknown limit values \"%s\" in "
568 "\"limits <pattern> <limits>\" line.\n",
569 fname, lineno, argv[i] );
578 * FIXME: add warnings?
580 if ( limit.lms_t_hard > 0 &&
581 ( limit.lms_t_hard < limit.lms_t_soft
582 || limit.lms_t_soft == -1 ) ) {
583 limit.lms_t_hard = limit.lms_t_soft;
586 if ( limit.lms_s_hard > 0 &&
587 ( limit.lms_s_hard < limit.lms_s_soft
588 || limit.lms_s_soft == -1 ) ) {
589 limit.lms_s_hard = limit.lms_s_soft;
598 * > 0 => limit (in seconds)
603 * > 0 => limit (in entries)
606 * -2 => disable the control
609 * > 0 => limit (in entries)
614 * > 0 => limit size (in entries)
616 if ( limit.lms_s_pr_total > 0 &&
617 limit.lms_s_pr > limit.lms_s_pr_total ) {
618 limit.lms_s_pr = limit.lms_s_pr_total;
621 rc = limits_add( be, flags, pattern, group_oc, group_ad, &limit );
624 Debug( LDAP_DEBUG_ANY,
625 "%s : line %d: unable to add limit in "
626 "\"limits <pattern> <limits>\" line.\n",
636 struct slap_limits_set *limit
642 if ( strncasecmp( arg, "time", STRLENOF( "time" ) ) == 0 ) {
643 arg += STRLENOF( "time" );
645 if ( arg[0] == '.' ) {
647 if ( strncasecmp( arg, "soft=", STRLENOF( "soft=" ) ) == 0 ) {
648 arg += STRLENOF( "soft=" );
649 if ( strcasecmp( arg, "unlimited" ) == 0 || strcasecmp( arg, "none" ) == 0 ) {
650 limit->lms_t_soft = -1;
654 int soft = strtol( arg, &next, 10 );
656 if ( next == arg || next[ 0 ] != '\0' ) {
665 /* FIXME: use "unlimited" instead; issue warning? */
668 limit->lms_t_soft = soft;
671 } else if ( strncasecmp( arg, "hard=", STRLENOF( "hard=" ) ) == 0 ) {
672 arg += STRLENOF( "hard=" );
673 if ( strcasecmp( arg, "soft" ) == 0 ) {
674 limit->lms_t_hard = 0;
676 } else if ( strcasecmp( arg, "unlimited" ) == 0 || strcasecmp( arg, "none" ) == 0 ) {
677 limit->lms_t_hard = -1;
681 int hard = strtol( arg, &next, 10 );
683 if ( next == arg || next[ 0 ] != '\0' ) {
692 /* FIXME: use "unlimited" instead */
696 /* FIXME: use "soft" instead */
699 limit->lms_t_hard = hard;
706 } else if ( arg[0] == '=' ) {
708 if ( strcasecmp( arg, "unlimited" ) == 0 || strcasecmp( arg, "none" ) == 0 ) {
709 limit->lms_t_soft = -1;
714 limit->lms_t_soft = strtol( arg, &next, 10 );
715 if ( next == arg || limit->lms_t_soft < -1 ) {
719 limit->lms_t_hard = 0;
725 } else if ( strncasecmp( arg, "size", STRLENOF( "size" ) ) == 0 ) {
726 arg += STRLENOF( "size" );
728 if ( arg[0] == '.' ) {
730 if ( strncasecmp( arg, "soft=", STRLENOF( "soft=" ) ) == 0 ) {
731 arg += STRLENOF( "soft=" );
732 if ( strcasecmp( arg, "unlimited" ) == 0 || strcasecmp( arg, "none" ) == 0 ) {
733 limit->lms_s_soft = -1;
737 int soft = strtol( arg, &next, 10 );
739 if ( next == arg || next[ 0 ] != '\0' ) {
748 /* FIXME: use "unlimited" instead */
751 limit->lms_s_soft = soft;
754 } else if ( strncasecmp( arg, "hard=", STRLENOF( "hard=" ) ) == 0 ) {
755 arg += STRLENOF( "hard=" );
756 if ( strcasecmp( arg, "soft" ) == 0 ) {
757 limit->lms_s_hard = 0;
759 } else if ( strcasecmp( arg, "unlimited" ) == 0 || strcasecmp( arg, "none" ) == 0 ) {
760 limit->lms_s_hard = -1;
764 int hard = strtol( arg, &next, 10 );
766 if ( next == arg || next[ 0 ] != '\0' ) {
775 /* FIXME: use "unlimited" instead */
779 /* FIXME: use "soft" instead */
782 limit->lms_s_hard = hard;
785 } else if ( strncasecmp( arg, "unchecked=", STRLENOF( "unchecked=" ) ) == 0 ) {
786 arg += STRLENOF( "unchecked=" );
787 if ( strcasecmp( arg, "unlimited" ) == 0 || strcasecmp( arg, "none" ) == 0 ) {
788 limit->lms_s_unchecked = -1;
790 } else if ( strcasecmp( arg, "disabled" ) == 0 ) {
791 limit->lms_s_unchecked = 0;
795 int unchecked = strtol( arg, &next, 10 );
797 if ( next == arg || next[ 0 ] != '\0' ) {
801 if ( unchecked < -1 ) {
805 if ( unchecked == -1 ) {
806 /* FIXME: use "unlimited" instead */
809 limit->lms_s_unchecked = unchecked;
812 } else if ( strncasecmp( arg, "pr=", STRLENOF( "pr=" ) ) == 0 ) {
813 arg += STRLENOF( "pr=" );
814 if ( strcasecmp( arg, "noEstimate" ) == 0 ) {
815 limit->lms_s_pr_hide = 1;
817 } else if ( strcasecmp( arg, "unlimited" ) == 0 || strcasecmp( arg, "none" ) == 0 ) {
818 limit->lms_s_pr = -1;
822 int pr = strtol( arg, &next, 10 );
824 if ( next == arg || next[ 0 ] != '\0' ) {
833 /* FIXME: use "unlimited" instead */
836 limit->lms_s_pr = pr;
839 } else if ( strncasecmp( arg, "prtotal=", STRLENOF( "prtotal=" ) ) == 0 ) {
840 arg += STRLENOF( "prtotal=" );
842 if ( strcasecmp( arg, "unlimited" ) == 0 || strcasecmp( arg, "none" ) == 0 ) {
843 limit->lms_s_pr_total = -1;
845 } else if ( strcasecmp( arg, "disabled" ) == 0 ) {
846 limit->lms_s_pr_total = -2;
848 } else if ( strcasecmp( arg, "hard" ) == 0 ) {
849 limit->lms_s_pr_total = 0;
855 total = strtol( arg, &next, 10 );
856 if ( next == arg || next[ 0 ] != '\0' ) {
865 /* FIXME: use "unlimited" instead */
869 /* FIXME: use "pr=disable" instead */
872 limit->lms_s_pr_total = total;
879 } else if ( arg[0] == '=' ) {
881 if ( strcasecmp( arg, "unlimited" ) == 0 || strcasecmp( arg, "none" ) == 0 ) {
882 limit->lms_s_soft = -1;
887 limit->lms_s_soft = strtol( arg, &next, 10 );
888 if ( next == arg || limit->lms_s_soft < -1 ) {
892 limit->lms_s_hard = 0;
904 limits_check( Operation *op, SlapReply *rs )
908 /* FIXME: should this be always true? */
909 assert( op->o_tag == LDAP_REQ_SEARCH);
911 /* protocol only allows 0..maxInt;
914 * - may use SLAP_NO_LIMIT ( = -1 ) to indicate no limits;
915 * - should use slimit = N and tlimit = SLAP_NO_LIMIT to
916 * indicate searches that should return exactly N matches,
917 * and handle errors thru a callback (see for instance
918 * slap_sasl_match() and slap_sasl2dn())
920 if ( op->ors_tlimit == SLAP_NO_LIMIT && op->ors_slimit == SLAP_NO_LIMIT ) {
924 /* allow root to set no limit */
925 if ( be_isroot( op ) ) {
926 op->ors_limit = NULL;
928 if ( op->ors_tlimit == 0 ) {
929 op->ors_tlimit = SLAP_NO_LIMIT;
932 if ( op->ors_slimit == 0 ) {
933 op->ors_slimit = SLAP_NO_LIMIT;
936 /* if not root, get appropriate limits */
938 ( void ) limits_get( op, &op->o_ndn, &op->ors_limit );
940 assert( op->ors_limit != NULL );
942 /* if no limit is required, use soft limit */
943 if ( op->ors_tlimit == 0 ) {
944 op->ors_tlimit = op->ors_limit->lms_t_soft;
946 /* limit required: check if legal */
948 if ( op->ors_limit->lms_t_hard == 0 ) {
949 if ( op->ors_limit->lms_t_soft > 0
950 && ( op->ors_tlimit > op->ors_limit->lms_t_soft ) ) {
951 op->ors_tlimit = op->ors_limit->lms_t_soft;
954 } else if ( op->ors_limit->lms_t_hard > 0 ) {
955 #ifdef ABOVE_HARD_LIMIT_IS_ERROR
956 if ( op->ors_tlimit == SLAP_MAX_LIMIT ) {
957 op->ors_tlimit = op->ors_limit->lms_t_hard;
959 } else if ( op->ors_tlimit > op->ors_limit->lms_t_hard ) {
960 /* error if exceeding hard limit */
961 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
962 send_ldap_result( op, rs );
963 rs->sr_err = LDAP_SUCCESS;
966 #else /* ! ABOVE_HARD_LIMIT_IS_ERROR */
967 if ( op->ors_tlimit > op->ors_limit->lms_t_hard ) {
968 op->ors_tlimit = op->ors_limit->lms_t_hard;
970 #endif /* ! ABOVE_HARD_LIMIT_IS_ERROR */
974 /* else leave as is */
976 /* don't even get to backend if candidate check is disabled */
977 if ( op->ors_limit->lms_s_unchecked == 0 ) {
978 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
979 send_ldap_result( op, rs );
980 rs->sr_err = LDAP_SUCCESS;
984 /* if paged results is requested */
985 if ( get_pagedresults( op ) > SLAP_NO_CONTROL ) {
989 /* paged results is not allowed */
990 if ( op->ors_limit->lms_s_pr_total == -2 ) {
991 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
992 rs->sr_text = "pagedResults control not allowed";
993 send_ldap_result( op, rs );
994 rs->sr_err = LDAP_SUCCESS;
999 if ( op->ors_limit->lms_s_pr > 0 && op->o_pagedresults_size > op->ors_limit->lms_s_pr ) {
1000 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1001 rs->sr_text = "illegal pagedResults page size";
1002 send_ldap_result( op, rs );
1003 rs->sr_err = LDAP_SUCCESS;
1008 if ( op->ors_limit->lms_s_pr_total == 0 ) {
1009 if ( op->ors_limit->lms_s_hard == 0 ) {
1010 pr_total = op->ors_limit->lms_s_soft;
1012 pr_total = op->ors_limit->lms_s_hard;
1015 pr_total = op->ors_limit->lms_s_pr_total;
1018 if ( pr_total == -1 ) {
1019 if ( op->ors_slimit == 0 || op->ors_slimit == SLAP_MAX_LIMIT ) {
1023 slimit = op->ors_slimit - op->o_pagedresults_state.ps_count;
1026 #ifdef ABOVE_HARD_LIMIT_IS_ERROR
1027 } else if ( pr_total > 0 && op->ors_slimit != SLAP_MAX_LIMIT
1028 && ( op->ors_slimit == SLAP_NO_LIMIT || op->ors_slimit > pr_total ) )
1030 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1031 send_ldap_result( op, rs );
1032 rs->sr_err = LDAP_SUCCESS;
1034 #endif /* ! ABOVE_HARD_LIMIT_IS_ERROR */
1037 /* if no limit is required, use soft limit */
1041 /* first round of pagedResults: set count to any appropriate limit */
1043 /* if the limit is set, check that it does not violate any server-side limit */
1044 #ifdef ABOVE_HARD_LIMIT_IS_ERROR
1045 if ( op->ors_slimit == SLAP_MAX_LIMIT ) {
1046 slimit2 = op->ors_slimit = pr_total;
1047 #else /* ! ABOVE_HARD_LIMIT_IS_ERROR */
1048 if ( op->ors_slimit == SLAP_MAX_LIMIT || op->ors_slimit > pr_total ) {
1049 slimit2 = op->ors_slimit = pr_total;
1050 #endif /* ! ABOVE_HARD_LIMIT_IS_ERROR */
1052 } else if ( op->ors_slimit == 0 ) {
1056 slimit2 = op->ors_slimit;
1059 total = slimit2 - op->o_pagedresults_state.ps_count;
1062 if ( op->ors_limit->lms_s_pr > 0 ) {
1063 /* use the smallest limit set by total/per page */
1064 if ( total < op->ors_limit->lms_s_pr ) {
1068 /* use the perpage limit if any
1069 * NOTE: + 1 because the given value must be legal */
1070 slimit = op->ors_limit->lms_s_pr + 1;
1074 /* use the total limit if any */
1078 } else if ( op->ors_limit->lms_s_pr > 0 ) {
1079 /* use the perpage limit if any
1080 * NOTE: + 1 because the given value must be legal */
1081 slimit = op->ors_limit->lms_s_pr + 1;
1084 /* use the standard hard/soft limit if any */
1085 slimit = op->ors_limit->lms_s_hard;
1089 /* if got any limit, use it */
1090 if ( slimit != -2 ) {
1091 if ( op->ors_slimit == 0 ) {
1092 op->ors_slimit = slimit;
1094 } else if ( slimit > 0 ) {
1095 if ( op->ors_slimit - op->o_pagedresults_state.ps_count > slimit ) {
1096 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1097 send_ldap_result( op, rs );
1098 rs->sr_err = LDAP_SUCCESS;
1101 op->ors_slimit = slimit;
1105 /* use the standard hard/soft limit if any */
1106 op->ors_slimit = pr_total;
1109 /* no limit requested: use soft, whatever it is */
1110 } else if ( op->ors_slimit == 0 ) {
1111 op->ors_slimit = op->ors_limit->lms_s_soft;
1113 /* limit requested: check if legal */
1115 /* hard limit as soft (traditional behavior) */
1116 if ( op->ors_limit->lms_s_hard == 0 ) {
1117 if ( op->ors_limit->lms_s_soft > 0
1118 && op->ors_slimit > op->ors_limit->lms_s_soft ) {
1119 op->ors_slimit = op->ors_limit->lms_s_soft;
1122 /* explicit hard limit: error if violated */
1123 } else if ( op->ors_limit->lms_s_hard > 0 ) {
1124 #ifdef ABOVE_HARD_LIMIT_IS_ERROR
1125 if ( op->ors_slimit == SLAP_MAX_LIMIT ) {
1126 op->ors_slimit = op->ors_limit->lms_s_hard;
1128 } else if ( op->ors_slimit > op->ors_limit->lms_s_hard ) {
1129 /* if limit exceeds hard, error */
1130 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1131 send_ldap_result( op, rs );
1132 rs->sr_err = LDAP_SUCCESS;
1135 #else /* ! ABOVE_HARD_LIMIT_IS_ERROR */
1136 if ( op->ors_slimit > op->ors_limit->lms_s_hard ) {
1137 op->ors_slimit = op->ors_limit->lms_s_hard;
1139 #endif /* ! ABOVE_HARD_LIMIT_IS_ERROR */
1143 /* else leave as is */