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>
27 limits2str( unsigned i )
30 case SLAP_LIMITS_UNDEFINED:
33 case SLAP_LIMITS_EXACT:
39 case SLAP_LIMITS_SUBTREE:
42 case SLAP_LIMITS_CHILDREN:
45 case SLAP_LIMITS_REGEX:
48 case SLAP_LIMITS_ANONYMOUS:
51 case SLAP_LIMITS_USERS:
66 struct slap_limits_set **limit
69 struct slap_limits **lm;
75 LDAP_LOG( SLAPD, DETAIL1, "==> limits_get: conn=%lu op=%lu dn=\"%s\"\n",
76 op->o_connid, op->o_opid,
77 BER_BVISNULL( ndn ) ? "[anonymous]" : ndn->bv_val );
80 Debug( LDAP_DEBUG_TRACE, "==> limits_get: conn=%lu op=%lu dn=\"%s\"\n",
81 op->o_connid, op->o_opid,
82 BER_BVISNULL( ndn ) ? "[anonymous]" : ndn->bv_val );
87 *limit = &op->o_bd->be_def_limit;
89 if ( op->o_bd->be_limits == NULL ) {
93 for ( lm = op->o_bd->be_limits; lm[0] != NULL; lm++ ) {
94 unsigned style = lm[0]->lm_flags & SLAP_LIMITS_MASK;
95 unsigned type = lm[0]->lm_flags & SLAP_LIMITS_TYPE_MASK;
98 case SLAP_LIMITS_EXACT:
99 if ( ndn->bv_len == 0 ) {
103 if ( type == SLAP_LIMITS_TYPE_GROUP ) {
106 rc = backend_group( op, NULL,
109 lm[0]->lm_group_ad );
111 *limit = &lm[0]->lm_limits;
113 LDAP_LOG( SLAPD, DETAIL1, "<== limits_get: type=GROUP match=EXACT "
114 "dn=\"%s\" oc=\"%s\" ad=\"%s\"\n",
115 lm[0]->lm_pat.bv_val,
116 lm[0]->lm_group_oc->soc_cname.bv_val,
117 lm[0]->lm_group_ad->ad_cname.bv_val );
119 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=GROUP match=EXACT "
120 "dn=\"%s\" oc=\"%s\" ad=\"%s\"\n",
121 lm[0]->lm_pat.bv_val,
122 lm[0]->lm_group_oc->soc_cname.bv_val,
123 lm[0]->lm_group_ad->ad_cname.bv_val );
130 if ( dn_match( &lm[0]->lm_pat, ndn ) ) {
131 *limit = &lm[0]->lm_limits;
133 LDAP_LOG( SLAPD, DETAIL1, "<== limits_get: type=DN match=EXACT dn=\"%s\"\n",
134 lm[0]->lm_pat.bv_val, 0, 0 );
136 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=DN match=EXACT dn=\"%s\"\n",
137 lm[0]->lm_pat.bv_val, 0, 0 );
144 case SLAP_LIMITS_ONE:
145 case SLAP_LIMITS_SUBTREE:
146 case SLAP_LIMITS_CHILDREN: {
149 if ( ndn->bv_len == 0 ) {
153 /* ndn shorter than dn_pat */
154 if ( ndn->bv_len < lm[0]->lm_pat.bv_len ) {
157 d = ndn->bv_len - lm[0]->lm_pat.bv_len;
159 /* allow exact match for SUBTREE only */
161 if ( style != SLAP_LIMITS_SUBTREE ) {
165 /* check for unescaped rdn separator */
166 if ( !DN_SEPARATOR( ndn->bv_val[d-1] ) ) {
171 /* in case of (sub)match ... */
172 if ( lm[0]->lm_pat.bv_len == ( ndn->bv_len - d )
173 && strcmp( lm[0]->lm_pat.bv_val,
174 &ndn->bv_val[d] ) == 0 )
176 /* check for exactly one rdn in case of ONE */
177 if ( style == SLAP_LIMITS_ONE ) {
179 * if ndn is more that one rdn
180 * below dn_pat, continue
182 if ( (size_t) dn_rdnlen( NULL, ndn )
189 *limit = &lm[0]->lm_limits;
191 LDAP_LOG( SLAPD, DETAIL1, "<== limits_get: type=DN match=%s dn=\"%s\"\n",
192 limits2str( style ), lm[0]->lm_pat.bv_val, 0 );
194 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=DN match=%s dn=\"%s\"\n",
195 limits2str( style ), lm[0]->lm_pat.bv_val, 0 );
203 case SLAP_LIMITS_REGEX:
204 if ( ndn->bv_len == 0 ) {
207 if ( regexec( &lm[0]->lm_regex, ndn->bv_val,
210 *limit = &lm[0]->lm_limits;
212 LDAP_LOG( SLAPD, DETAIL1, "<== limits_get: type=DN match=%s dn=\"%s\"\n",
213 limits2str( style ), lm[0]->lm_pat.bv_val, 0 );
215 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=DN match=%s dn=\"%s\"\n",
216 limits2str( style ), lm[0]->lm_pat.bv_val, 0 );
222 case SLAP_LIMITS_ANONYMOUS:
223 if ( ndn->bv_len == 0 ) {
225 LDAP_LOG( SLAPD, DETAIL1, "<== limits_get: type=DN match=%s\n",
226 limits2str( style ), 0, 0 );
228 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=DN match=%s\n",
229 limits2str( style ), 0, 0 );
231 *limit = &lm[0]->lm_limits;
236 case SLAP_LIMITS_USERS:
237 if ( ndn->bv_len != 0 ) {
238 *limit = &lm[0]->lm_limits;
240 LDAP_LOG( SLAPD, DETAIL1, "<== limits_get: type=DN match=%s\n",
241 limits2str( style ), 0, 0 );
243 Debug( LDAP_DEBUG_TRACE, "<== limits_get: type=DN match=%s\n",
244 limits2str( style ), 0, 0 );
250 case SLAP_LIMITS_ANY:
251 *limit = &lm[0]->lm_limits;
255 assert( 0 ); /* unreachable */
268 ObjectClass *group_oc,
269 AttributeDescription *group_ad,
270 struct slap_limits_set *limit
274 struct slap_limits *lm;
275 unsigned type, style;
280 type = flags & SLAP_LIMITS_TYPE_MASK;
281 style = flags & SLAP_LIMITS_MASK;
284 case SLAP_LIMITS_ANONYMOUS:
285 case SLAP_LIMITS_USERS:
286 case SLAP_LIMITS_ANY:
287 for ( i = 0; be->be_limits && be->be_limits[ i ]; i++ ) {
288 if ( be->be_limits[ i ]->lm_flags == style ) {
296 lm = ( struct slap_limits * )ch_calloc( sizeof( struct slap_limits ), 1 );
299 case SLAP_LIMITS_UNDEFINED:
300 style = SLAP_LIMITS_EXACT;
301 /* continue to next cases */
302 case SLAP_LIMITS_EXACT:
303 case SLAP_LIMITS_ONE:
304 case SLAP_LIMITS_SUBTREE:
305 case SLAP_LIMITS_CHILDREN:
306 lm->lm_flags = style | type;
310 bv.bv_val = (char *) pattern;
311 bv.bv_len = strlen( pattern );
313 rc = dnNormalize( 0, NULL, NULL, &bv, &lm->lm_pat, NULL );
314 if ( rc != LDAP_SUCCESS ) {
321 case SLAP_LIMITS_REGEX:
322 lm->lm_flags = style | type;
323 ber_str2bv( pattern, 0, 1, &lm->lm_pat );
324 if ( regcomp( &lm->lm_regex, lm->lm_pat.bv_val,
325 REG_EXTENDED | REG_ICASE ) ) {
326 free( lm->lm_pat.bv_val );
332 case SLAP_LIMITS_ANONYMOUS:
333 case SLAP_LIMITS_USERS:
334 case SLAP_LIMITS_ANY:
335 lm->lm_flags = style | type;
336 lm->lm_pat.bv_val = NULL;
337 lm->lm_pat.bv_len = 0;
342 case SLAP_LIMITS_TYPE_GROUP:
345 lm->lm_group_oc = group_oc;
346 lm->lm_group_ad = group_ad;
350 lm->lm_limits = *limit;
353 if ( be->be_limits != NULL ) {
354 for ( ; be->be_limits[i]; i++ );
357 be->be_limits = ( struct slap_limits ** )ch_realloc( be->be_limits,
358 sizeof( struct slap_limits * ) * ( i + 2 ) );
359 be->be_limits[i] = lm;
360 be->be_limits[i+1] = NULL;
374 int flags = SLAP_LIMITS_UNDEFINED;
376 struct slap_limits_set limit;
378 ObjectClass *group_oc = NULL;
379 AttributeDescription *group_ad = NULL;
385 LDAP_LOG( CONFIG, CRIT,
386 "%s : line %d: missing arg(s) in "
387 "\"limits <pattern> <limits>\" line.\n", fname, lineno, 0 );
389 Debug( LDAP_DEBUG_ANY,
390 "%s : line %d: missing arg(s) in "
391 "\"limits <pattern> <limits>\" line.\n%s",
397 limit = be->be_def_limit;
402 * "limits" <pattern> <limit> [ ... ]
409 * [ "dn" [ "." { "exact" | "base" | "onelevel" | "subtree" | children"
410 * | "regex" | "anonymous" } ] "=" ] <dn pattern>
413 * "exact" and "base" are the same (exact match);
414 * "onelevel" means exactly one rdn below, NOT including pattern
415 * "subtree" means any rdn below, including pattern
416 * "children" means any rdn below, NOT including pattern
418 * "anonymous" may be deprecated in favour
419 * of the pattern = "anonymous" form
421 * "group[/objectClass[/attributeType]]" "=" "<dn pattern>"
425 * "time" [ "." { "soft" | "hard" } ] "=" <integer>
427 * "size" [ "." { "soft" | "hard" | "unchecked" } ] "=" <integer>
431 if ( strcmp( pattern, "*" ) == 0) {
432 flags = SLAP_LIMITS_ANY;
434 } else if ( strcasecmp( pattern, "anonymous" ) == 0 ) {
435 flags = SLAP_LIMITS_ANONYMOUS;
437 } else if ( strcasecmp( pattern, "users" ) == 0 ) {
438 flags = SLAP_LIMITS_USERS;
440 } else if ( strncasecmp( pattern, "dn", STRLENOF( "dn" ) ) == 0 ) {
441 pattern += STRLENOF( "dn" );
442 if ( pattern[0] == '.' ) {
444 if ( strncasecmp( pattern, "exact", STRLENOF( "exact" )) == 0 ) {
445 flags = SLAP_LIMITS_EXACT;
446 pattern += STRLENOF( "exact" );
448 } else if ( strncasecmp( pattern, "base", STRLENOF( "base" ) ) == 0 ) {
449 flags = SLAP_LIMITS_BASE;
450 pattern += STRLENOF( "base" );
452 } else if ( strncasecmp( pattern, "one", STRLENOF( "one" ) ) == 0 ) {
453 flags = SLAP_LIMITS_ONE;
454 pattern += STRLENOF( "one" );
455 if ( strncasecmp( pattern, "level", STRLENOF( "level" ) ) == 0 ) {
456 pattern += STRLENOF( "level" );
460 LDAP_LOG( CONFIG, WARNING ,
461 "%s : line %d: deprecated \"one\" style "
462 "\"limits <pattern> <limits>\" line; "
463 "use \"onelevel\" instead.\n", fname, lineno, 0 );
465 Debug( LDAP_DEBUG_ANY,
466 "%s : line %d: deprecated \"one\" style "
467 "\"limits <pattern> <limits>\" line; "
468 "use \"onelevel\" instead.\n", fname, lineno, 0 );
472 } else if ( strncasecmp( pattern, "sub", STRLENOF( "sub" ) ) == 0 ) {
473 flags = SLAP_LIMITS_SUBTREE;
474 pattern += STRLENOF( "sub" );
475 if ( strncasecmp( pattern, "tree", STRLENOF( "tree" ) ) == 0 ) {
476 pattern += STRLENOF( "tree" );
480 LDAP_LOG( CONFIG, WARNING ,
481 "%s : line %d: deprecated \"sub\" style "
482 "\"limits <pattern> <limits>\" line; "
483 "use \"subtree\" instead.\n", fname, lineno, 0 );
485 Debug( LDAP_DEBUG_ANY,
486 "%s : line %d: deprecated \"sub\" style "
487 "\"limits <pattern> <limits>\" line; "
488 "use \"subtree\" instead.\n", fname, lineno, 0 );
492 } else if ( strncasecmp( pattern, "children", STRLENOF( "children" ) ) == 0 ) {
493 flags = SLAP_LIMITS_CHILDREN;
494 pattern += STRLENOF( "children" );
496 } else if ( strncasecmp( pattern, "regex", STRLENOF( "regex" ) ) == 0 ) {
497 flags = SLAP_LIMITS_REGEX;
498 pattern += STRLENOF( "regex" );
501 * this could be deprecated in favour
502 * of the pattern = "anonymous" form
504 } else if ( strncasecmp( pattern, "anonymous", STRLENOF( "anonymous" ) ) == 0 ) {
505 flags = SLAP_LIMITS_ANONYMOUS;
510 /* pre-check the data */
512 case SLAP_LIMITS_ANONYMOUS:
513 case SLAP_LIMITS_USERS:
515 /* no need for pattern */
520 if ( pattern[0] != '=' ) {
522 LDAP_LOG( CONFIG, CRIT,
523 "%s : line %d: missing '=' in "
524 "\"dn[.{exact|base|onelevel|subtree"
525 "|children|regex|anonymous}]" "=<pattern>\" in "
526 "\"limits <pattern> <limits>\" line.\n", fname, lineno, 0 );
528 Debug( LDAP_DEBUG_ANY,
529 "%s : line %d: missing '=' in "
530 "\"dn[.{exact|base|onelevel|subtree"
531 "|children|regex|anonymous}]"
533 "\"limits <pattern> <limits>\" "
540 /* skip '=' (required) */
543 /* trim obvious cases */
544 if ( strcmp( pattern, "*" ) == 0 ) {
545 flags = SLAP_LIMITS_ANY;
548 } else if ( flags == SLAP_LIMITS_REGEX
549 && strcmp( pattern, ".*" ) == 0 ) {
550 flags = SLAP_LIMITS_ANY;
555 } else if (strncasecmp( pattern, "group", STRLENOF( "group" ) ) == 0 ) {
556 pattern += STRLENOF( "group" );
558 if ( pattern[0] == '/' ) {
559 struct berval oc, ad;
561 oc.bv_val = pattern + 1;
563 ad.bv_val = strchr(pattern, '/');
564 if ( ad.bv_val != NULL ) {
565 const char *text = NULL;
568 oc.bv_len = ad.bv_val - oc.bv_val;
571 ad.bv_len = strlen( ad.bv_val );
572 rc = slap_bv2ad( &ad, &group_ad, &text );
573 if ( rc != LDAP_SUCCESS ) {
577 pattern = ad.bv_val + ad.bv_len;
580 oc.bv_len = strlen( oc.bv_val );
582 pattern = oc.bv_val + oc.bv_len;
585 group_oc = oc_bvfind( &oc );
586 if ( group_oc == NULL ) {
591 if ( group_oc == NULL ) {
592 group_oc = oc_find( SLAPD_GROUP_CLASS );
593 if ( group_oc == NULL ) {
599 if ( group_ad == NULL ) {
600 const char *text = NULL;
603 rc = slap_str2ad( SLAPD_GROUP_ATTR, &group_ad, &text );
605 if ( rc != LDAP_SUCCESS ) {
611 flags = SLAP_LIMITS_TYPE_GROUP | SLAP_LIMITS_EXACT;
613 if ( pattern[0] != '=' ) {
615 LDAP_LOG( CONFIG, CRIT,
616 "%s : line %d: missing '=' in "
617 "\"group[/objectClass[/attributeType]]"
619 "\"limits <pattern> <limits>\" line.\n",
622 Debug( LDAP_DEBUG_ANY,
623 "%s : line %d: missing '=' in "
624 "\"group[/objectClass[/attributeType]]"
626 "\"limits <pattern> <limits>\" line.\n",
632 /* skip '=' (required) */
637 for ( i = 2; i < argc; i++ ) {
638 if ( limits_parse_one( argv[i], &limit ) ) {
641 LDAP_LOG( CONFIG, CRIT,
642 "%s : line %d: unknown limit values \"%s\" in "
643 "\"limits <pattern> <limits>\" line.\n",
644 fname, lineno, argv[i] );
646 Debug( LDAP_DEBUG_ANY,
647 "%s : line %d: unknown limit values \"%s\" in "
648 "\"limits <pattern> <limits>\" line.\n",
649 fname, lineno, argv[i] );
659 * FIXME: add warnings?
661 if ( limit.lms_t_hard > 0 &&
662 ( limit.lms_t_hard < limit.lms_t_soft
663 || limit.lms_t_soft == -1 ) ) {
664 limit.lms_t_hard = limit.lms_t_soft;
667 if ( limit.lms_s_hard > 0 &&
668 ( limit.lms_s_hard < limit.lms_s_soft
669 || limit.lms_s_soft == -1 ) ) {
670 limit.lms_s_hard = limit.lms_s_soft;
679 * > 0 => limit (in seconds)
684 * > 0 => limit (in entries)
687 * -2 => disable the control
690 * > 0 => limit (in entries)
695 * > 0 => limit size (in entries)
697 if ( limit.lms_s_pr_total > 0 &&
698 limit.lms_s_pr > limit.lms_s_pr_total ) {
699 limit.lms_s_pr = limit.lms_s_pr_total;
702 rc = limits_add( be, flags, pattern, group_oc, group_ad, &limit );
706 LDAP_LOG( CONFIG, CRIT,
707 "%s : line %d: unable to add limit in "
708 "\"limits <pattern> <limits>\" line.\n",
711 Debug( LDAP_DEBUG_ANY,
712 "%s : line %d: unable to add limit in "
713 "\"limits <pattern> <limits>\" line.\n",
724 struct slap_limits_set *limit
730 if ( strncasecmp( arg, "time", STRLENOF( "time" ) ) == 0 ) {
731 arg += STRLENOF( "time" );
733 if ( arg[0] == '.' ) {
735 if ( strncasecmp( arg, "soft=", STRLENOF( "soft=" ) ) == 0 ) {
736 arg += STRLENOF( "soft=" );
737 if ( strcasecmp( arg, "none" ) == 0 ) {
738 limit->lms_t_soft = -1;
742 int soft = strtol( arg, &next, 10 );
744 if ( next == arg || next[ 0 ] != '\0' ) {
753 /* FIXME: use "none" instead */
756 limit->lms_t_soft = soft;
759 } else if ( strncasecmp( arg, "hard=", STRLENOF( "hard=" ) ) == 0 ) {
760 arg += STRLENOF( "hard=" );
761 if ( strcasecmp( arg, "soft" ) == 0 ) {
762 limit->lms_t_hard = 0;
764 } else if ( strcasecmp( arg, "none" ) == 0 ) {
765 limit->lms_t_hard = -1;
769 int hard = strtol( arg, &next, 10 );
771 if ( next == arg || next[ 0 ] != '\0' ) {
780 /* FIXME: use "none" instead */
784 /* FIXME: use "soft" instead */
787 limit->lms_t_hard = hard;
794 } else if ( arg[0] == '=' ) {
796 if ( strcasecmp( arg, "none" ) == 0 ) {
797 limit->lms_t_soft = -1;
802 limit->lms_t_soft = strtol( arg, &next, 10 );
803 if ( next == arg || limit->lms_t_soft < -1 ) {
807 limit->lms_t_hard = 0;
813 } else if ( strncasecmp( arg, "size", STRLENOF( "size" ) ) == 0 ) {
814 arg += STRLENOF( "size" );
816 if ( arg[0] == '.' ) {
818 if ( strncasecmp( arg, "soft=", STRLENOF( "soft=" ) ) == 0 ) {
819 arg += STRLENOF( "soft=" );
820 if ( strcasecmp( arg, "none" ) == 0 ) {
821 limit->lms_s_soft = -1;
825 int soft = strtol( arg, &next, 10 );
827 if ( next == arg || next[ 0 ] != '\0' ) {
836 /* FIXME: use "none" instead */
839 limit->lms_s_soft = soft;
842 } else if ( strncasecmp( arg, "hard=", STRLENOF( "hard=" ) ) == 0 ) {
843 arg += STRLENOF( "hard=" );
844 if ( strcasecmp( arg, "soft" ) == 0 ) {
845 limit->lms_s_hard = 0;
847 } else if ( strcasecmp( arg, "none" ) == 0 ) {
848 limit->lms_s_hard = -1;
852 int hard = strtol( arg, &next, 10 );
854 if ( next == arg || next[ 0 ] != '\0' ) {
863 /* FIXME: use "none" instead */
867 /* FIXME: use "soft" instead */
870 limit->lms_s_hard = hard;
873 } else if ( strncasecmp( arg, "unchecked=", STRLENOF( "unchecked=" ) ) == 0 ) {
874 arg += STRLENOF( "unchecked=" );
875 if ( strcasecmp( arg, "none" ) == 0 ) {
876 limit->lms_s_unchecked = -1;
878 } else if ( strcasecmp( arg, "disabled" ) == 0 ) {
879 limit->lms_s_unchecked = 0;
883 int unchecked = strtol( arg, &next, 10 );
885 if ( next == arg || next[ 0 ] != '\0' ) {
889 if ( unchecked < -1 ) {
893 if ( unchecked == -1 ) {
894 /* FIXME: use "none" instead */
897 limit->lms_s_unchecked = unchecked;
900 } else if ( strncasecmp( arg, "pr=", STRLENOF( "pr=" ) ) == 0 ) {
901 arg += STRLENOF( "pr=" );
902 if ( strcasecmp( arg, "noEstimate" ) == 0 ) {
903 limit->lms_s_pr_hide = 1;
905 } else if ( strcasecmp( arg, "none" ) == 0 ) {
906 limit->lms_s_pr = -1;
910 int pr = strtol( arg, &next, 10 );
912 if ( next == arg || next[ 0 ] != '\0' ) {
921 /* FIXME: use "none" instead */
924 limit->lms_s_pr = pr;
927 } else if ( strncasecmp( arg, "prtotal=", STRLENOF( "prtotal=" ) ) == 0 ) {
928 arg += STRLENOF( "prtotal=" );
930 if ( strcasecmp( arg, "none" ) == 0 ) {
931 limit->lms_s_pr_total = -1;
933 } else if ( strcasecmp( arg, "disabled" ) == 0 ) {
934 limit->lms_s_pr_total = -2;
936 } else if ( strcasecmp( arg, "hard" ) == 0 ) {
937 limit->lms_s_pr_total = 0;
943 total = strtol( arg, &next, 10 );
944 if ( next == arg || next[ 0 ] != '\0' ) {
953 /* FIXME: use "none" instead */
957 /* FIXME: use "pr=disable" instead */
960 limit->lms_s_pr_total = total;
967 } else if ( arg[0] == '=' ) {
969 if ( strcasecmp( arg, "none" ) == 0 ) {
970 limit->lms_s_soft = -1;
975 limit->lms_s_soft = strtol( arg, &next, 10 );
976 if ( next == arg || limit->lms_s_soft < -1 ) {
980 limit->lms_s_hard = 0;
992 limits_check( Operation *op, SlapReply *rs )
996 /* FIXME: should this be always true? */
997 assert( op->o_tag == LDAP_REQ_SEARCH);
999 /* protocol only allows 0..maxInt; internal searches
1000 * may use SLAP_NO_LIMIT ( = -1 ) to indicate no limits... */
1001 if ( op->ors_tlimit == SLAP_NO_LIMIT && op->ors_slimit == SLAP_NO_LIMIT ) {
1005 /* fail when at least one is set to a negative value... */
1006 assert( op->ors_tlimit >= 0 );
1007 assert( op->ors_slimit >= 0 );
1009 /* allow root to set no limit */
1010 if ( be_isroot( op ) ) {
1011 op->ors_limit = NULL;
1013 if ( op->ors_tlimit == 0 ) {
1014 op->ors_tlimit = SLAP_NO_LIMIT;
1017 if ( op->ors_slimit == 0 ) {
1018 op->ors_slimit = SLAP_NO_LIMIT;
1021 /* if not root, get appropriate limits */
1023 ( void ) limits_get( op, &op->o_ndn, &op->ors_limit );
1025 assert( op->ors_limit != NULL );
1027 /* if no limit is required, use soft limit */
1028 if ( op->ors_tlimit == 0 ) {
1029 op->ors_tlimit = op->ors_limit->lms_t_soft;
1031 /* limit required: check if legal */
1033 if ( op->ors_limit->lms_t_hard == 0 ) {
1034 if ( op->ors_limit->lms_t_soft > 0
1035 && ( op->ors_tlimit > op->ors_limit->lms_t_soft ) ) {
1036 op->ors_tlimit = op->ors_limit->lms_t_soft;
1039 } else if ( op->ors_limit->lms_t_hard > 0 ) {
1040 if ( op->ors_tlimit == SLAP_MAX_LIMIT ) {
1041 op->ors_tlimit = op->ors_limit->lms_t_hard;
1043 } else if ( op->ors_tlimit > op->ors_limit->lms_t_hard ) {
1044 /* error if exceeding hard limit */
1045 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1046 send_ldap_result( op, rs );
1047 rs->sr_err = LDAP_SUCCESS;
1053 /* else leave as is */
1055 /* don't even get to backend if candidate check is disabled */
1056 if ( op->ors_limit->lms_s_unchecked == 0 ) {
1057 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1058 send_ldap_result( op, rs );
1059 rs->sr_err = LDAP_SUCCESS;
1063 /* if paged results is requested */
1064 if ( get_pagedresults( op ) > SLAP_NO_CONTROL ) {
1068 /* paged results is not allowed */
1069 if ( op->ors_limit->lms_s_pr_total == -2 ) {
1070 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1071 rs->sr_text = "pagedResults control not allowed";
1072 send_ldap_result( op, rs );
1073 rs->sr_err = LDAP_SUCCESS;
1078 if ( op->ors_limit->lms_s_pr > 0 && op->o_pagedresults_size > op->ors_limit->lms_s_pr ) {
1079 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1080 rs->sr_text = "illegal pagedResults page size";
1081 send_ldap_result( op, rs );
1082 rs->sr_err = LDAP_SUCCESS;
1087 if ( op->ors_limit->lms_s_pr_total == 0 ) {
1088 if ( op->ors_limit->lms_s_hard == 0 ) {
1089 pr_total = op->ors_limit->lms_s_soft;
1091 pr_total = op->ors_limit->lms_s_hard;
1094 pr_total = op->ors_limit->lms_s_pr_total;
1097 if ( pr_total == -1 ) {
1100 } else if ( pr_total > 0 && op->ors_slimit != SLAP_MAX_LIMIT
1101 && ( op->ors_slimit == SLAP_NO_LIMIT || op->ors_slimit > pr_total ) )
1103 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1104 send_ldap_result( op, rs );
1105 rs->sr_err = LDAP_SUCCESS;
1109 /* if no limit is required, use soft limit */
1113 /* first round of pagedResults: set count to any appropriate limit */
1115 /* if the limit is set, check that it does not violate any server-side limit */
1116 if ( op->ors_slimit == SLAP_MAX_LIMIT ) {
1117 slimit2 = op->ors_slimit = pr_total;
1119 } else if ( op->ors_slimit == 0 ) {
1123 slimit2 = op->ors_slimit;
1126 total = slimit2 - op->o_pagedresults_state.ps_count;
1129 if ( op->ors_limit->lms_s_pr > 0 ) {
1130 /* use the smallest limit set by total/per page */
1131 if ( total < op->ors_limit->lms_s_pr ) {
1135 /* use the perpage limit if any
1136 * NOTE: + 1 because the given value must be legal */
1137 slimit = op->ors_limit->lms_s_pr + 1;
1141 /* use the total limit if any */
1145 } else if ( op->ors_limit->lms_s_pr > 0 ) {
1146 /* use the perpage limit if any
1147 * NOTE: + 1 because the given value must be legal */
1148 slimit = op->ors_limit->lms_s_pr + 1;
1151 /* use the standard hard/soft limit if any */
1152 slimit = op->ors_limit->lms_s_hard;
1156 /* if got any limit, use it */
1157 if ( slimit != -2 ) {
1158 if ( op->ors_slimit == 0 ) {
1159 op->ors_slimit = slimit;
1161 } else if ( slimit > 0 ) {
1162 if ( op->ors_slimit - op->o_pagedresults_state.ps_count > slimit ) {
1163 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1164 send_ldap_result( op, rs );
1165 rs->sr_err = LDAP_SUCCESS;
1168 op->ors_slimit = slimit;
1172 /* use the standard hard/soft limit if any */
1173 op->ors_slimit = pr_total;
1176 /* no limit requested: use soft, whatever it is */
1177 } else if ( op->ors_slimit == 0 ) {
1178 op->ors_slimit = op->ors_limit->lms_s_soft;
1180 /* limit requested: check if legal */
1182 /* hard limit as soft (traditional behavior) */
1183 if ( op->ors_limit->lms_s_hard == 0 ) {
1184 if ( op->ors_limit->lms_s_soft > 0
1185 && op->ors_slimit > op->ors_limit->lms_s_soft ) {
1186 op->ors_slimit = op->ors_limit->lms_s_soft;
1189 /* explicit hard limit: error if violated */
1190 } else if ( op->ors_limit->lms_s_hard > 0 ) {
1191 if ( op->ors_slimit == SLAP_MAX_LIMIT ) {
1192 op->ors_slimit = op->ors_limit->lms_s_hard;
1194 } else if ( op->ors_slimit > op->ors_limit->lms_s_hard ) {
1195 /* if limit exceeds hard, error */
1196 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
1197 send_ldap_result( op, rs );
1198 rs->sr_err = LDAP_SUCCESS;
1204 /* else leave as is */