1 /* limits.c - routines to handle regex-based size and time limits */
3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
20 struct slap_limits_set **limit
23 struct slap_limits **lm;
31 *limit = &be->be_def_limit;
33 if ( be->be_limits == NULL ) {
37 for ( lm = be->be_limits; lm[0] != NULL; lm++ ) {
38 switch ( lm[0]->lm_type) {
39 case SLAP_LIMITS_EXACT:
40 if ( ndn == NULL || ndn[0] == '\0' ) {
43 if ( strcmp( lm[0]->lm_dn_pat, ndn ) == 0 ) {
44 *limit = &lm[0]->lm_limits;
49 case SLAP_LIMITS_REGEX:
50 if ( ndn == NULL || ndn[0] == '\0' ) {
53 if ( regexec( &lm[0]->lm_dn_regex, ndn, 0, NULL, 0 ) == 0 ) {
54 *limit = &lm[0]->lm_limits;
58 case SLAP_LIMITS_ANONYMOUS:
59 if ( ndn == NULL || ndn[0] == '\0' ) {
60 *limit = &lm[0]->lm_limits;
65 assert( 0 ); /* unreachable */
78 struct slap_limits_set *limit
82 struct slap_limits *lm;
87 lm = ( struct slap_limits * )ch_calloc( sizeof( struct slap_limits ), 1 );
90 case SLAP_LIMITS_EXACT:
91 lm->lm_type = SLAP_LIMITS_EXACT;
92 lm->lm_dn_pat = ch_strdup( pattern );
93 if ( dn_normalize( lm->lm_dn_pat ) == NULL ) {
94 ch_free( lm->lm_dn_pat );
100 case SLAP_LIMITS_REGEX:
101 case SLAP_LIMITS_UNDEFINED:
102 lm->lm_type = SLAP_LIMITS_REGEX;
103 lm->lm_dn_pat = ch_strdup( pattern );
104 if ( regcomp( &lm->lm_dn_regex, lm->lm_dn_pat, REG_EXTENDED | REG_ICASE ) ) {
105 ch_free( lm->lm_dn_pat );
110 case SLAP_LIMITS_ANONYMOUS:
111 lm->lm_type = SLAP_LIMITS_ANONYMOUS;
112 lm->lm_dn_pat = NULL;
116 lm->lm_limits = *limit;
119 if ( be->be_limits != NULL ) {
120 for ( ; be->be_limits[i]; i++ );
123 be->be_limits = ( struct slap_limits ** )ch_realloc( be->be_limits,
124 sizeof( struct slap_limits * ) * ( i + 2 ) );
125 be->be_limits[i] = lm;
126 be->be_limits[i+1] = NULL;
140 int type = SLAP_LIMITS_UNDEFINED;
142 struct slap_limits_set limit;
149 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
150 "%s : line %d: missing arg(s) in "
151 "\"limits <pattern> <limits>\" line.\n",
154 Debug( LDAP_DEBUG_ANY,
155 "%s : line %d: missing arg(s) in "
156 "\"limits <pattern> <limits>\" line.\n%s",
162 limit = be->be_def_limit;
167 * "limits" <pattern> <limit> [ ... ]
172 * [ "dn" [ "." { "exact" | "regex" | "anonymous" } ] "=" ] <dn pattern>
177 * "time" [ "." { "soft" | "hard" } ] "=" <integer>
179 * "size" [ "." { "soft" | "hard" | "unchecked" } ] "=" <integer>
183 if ( strncasecmp( pattern, "dn", 2 ) == 0 ) {
185 if ( pattern[0] == '.' ) {
187 if ( strncasecmp( pattern, "exact", 5 ) == 0 ) {
188 type = SLAP_LIMITS_EXACT;
190 } else if ( strncasecmp( pattern, "regex", 5 ) == 0 ) {
191 type = SLAP_LIMITS_REGEX;
193 } else if ( strncasecmp( pattern, "anonymous", 9 ) == 0 ) {
194 type = SLAP_LIMITS_ANONYMOUS;
199 if (( type != SLAP_LIMITS_ANONYMOUS ) && ( pattern[0] != '=' )) {
201 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
202 "%s : line %d: missing '=' in "
203 "\"dn[.{exact|regex|anonymous}]=<pattern>\" in "
204 "\"limits <pattern> <limits>\" line.\n",
207 Debug( LDAP_DEBUG_ANY,
208 "%s : line %d: missing '=' in "
209 "\"dn[.{exact|regex|anonymous}]=<pattern>\" in "
210 "\"limits <pattern> <limits>\" line.\n%s",
216 /* skip '=' (required) */
220 for ( i = 2; i < argc; i++ ) {
221 if ( parse_limit( argv[i], &limit ) ) {
224 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
225 "%s : line %d: unknown limit type \"%s\" in "
226 "\"limits <pattern> <limits>\" line.\n",
227 fname, lineno, argv[i] ));
229 Debug( LDAP_DEBUG_ANY,
230 "%s : line %d: unknown limit type \"%s\" in "
231 "\"limits <pattern> <limits>\" line.\n",
232 fname, lineno, argv[i] );
242 if ( limit.lms_t_hard > 0 && limit.lms_t_hard < limit.lms_t_soft ) {
243 limit.lms_t_hard = limit.lms_t_soft;
246 if ( limit.lms_s_hard > 0 && limit.lms_s_hard < limit.lms_s_soft ) {
247 limit.lms_s_hard = limit.lms_s_soft;
250 return( add_limits( be, type, pattern, &limit ) );
256 struct slap_limits_set *limit
262 if ( strncasecmp( arg, "time", 4 ) == 0 ) {
265 if ( arg[0] == '.' ) {
267 if ( strncasecmp( arg, "soft", 4 ) == 0 ) {
269 if ( arg[0] != '=' ) {
273 limit->lms_t_soft = atoi( arg );
275 } else if ( strncasecmp( arg, "hard", 4 ) == 0 ) {
277 if ( arg[0] != '=' ) {
281 if ( strcasecmp( arg, "soft" ) == 0 ) {
282 limit->lms_t_hard = 0;
283 } else if ( strcasecmp( arg, "none" ) == 0 ) {
284 limit->lms_t_hard = -1;
286 limit->lms_t_hard = atoi( arg );
293 } else if ( arg[0] == '=' ) {
294 limit->lms_t_soft = atoi( arg );
295 limit->lms_t_hard = 0;
301 } else if ( strncasecmp( arg, "size", 4 ) == 0 ) {
304 if ( arg[0] == '.' ) {
306 if ( strncasecmp( arg, "soft", 4 ) == 0 ) {
308 if ( arg[0] != '=' ) {
312 limit->lms_s_soft = atoi( arg );
314 } else if ( strncasecmp( arg, "hard", 4 ) == 0 ) {
316 if ( arg[0] != '=' ) {
320 if ( strcasecmp( arg, "soft" ) == 0 ) {
321 limit->lms_s_hard = 0;
322 } else if ( strcasecmp( arg, "none" ) == 0 ) {
323 limit->lms_s_hard = -1;
325 limit->lms_s_hard = atoi( arg );
328 } else if ( strncasecmp( arg, "unchecked", 9 ) == 0 ) {
330 if ( arg[0] != '=' ) {
334 if ( strcasecmp( arg, "none" ) == 0 ) {
335 limit->lms_s_unchecked = -1;
337 limit->lms_s_unchecked = atoi( arg );
344 } else if ( arg[0] == '=' ) {
345 limit->lms_s_soft = atoi( arg );
346 limit->lms_s_hard = 0;