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;
34 * anonymous or no regex-based limits?
36 if ( be->be_limits == NULL || ndn == NULL || ndn[0] == '\0' ) {
40 for ( lm = be->be_limits; lm[0] != NULL; lm++ ) {
41 switch ( lm[0]->lm_type) {
42 case SLAP_LIMITS_EXACT:
43 if ( strcmp( lm[0]->lm_dn_pat, ndn ) == 0 ) {
44 *limit = &lm[0]->lm_limits;
49 case SLAP_LIMITS_REGEX:
50 if ( regexec( &lm[0]->lm_dn_regex, ndn, 0, NULL, 0) == 0 ) {
51 *limit = &lm[0]->lm_limits;
57 assert( 0 ); /* unreachable */
70 struct slap_limits_set *limit
74 struct slap_limits *lm;
80 lm = ( struct slap_limits * )ch_calloc( sizeof( struct slap_limits ), 1 );
83 case SLAP_LIMITS_EXACT:
84 lm->lm_type = SLAP_LIMITS_EXACT;
85 lm->lm_dn_pat = ch_strdup( pattern );
86 if ( dn_normalize( lm->lm_dn_pat ) == NULL ) {
87 ch_free( lm->lm_dn_pat );
93 case SLAP_LIMITS_REGEX:
94 case SLAP_LIMITS_UNDEFINED:
95 lm->lm_type = SLAP_LIMITS_REGEX;
96 lm->lm_dn_pat = ch_strdup( pattern );
97 if ( regcomp( &lm->lm_dn_regex, lm->lm_dn_pat, REG_EXTENDED | REG_ICASE ) ) {
98 ch_free( lm->lm_dn_pat );
105 lm->lm_limits = *limit;
108 if ( be->be_limits != NULL ) {
109 for ( ; be->be_limits[i]; i++ );
112 be->be_limits = ( struct slap_limits ** )ch_realloc( be->be_limits,
113 sizeof( struct slap_limits * ) * ( i + 2 ) );
114 be->be_limits[i] = lm;
115 be->be_limits[i+1] = NULL;
129 int type = SLAP_LIMITS_UNDEFINED;
131 struct slap_limits_set limit;
138 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
139 "%s : line %d: missing arg(s) in "
140 "\"limits <pattern> <limits>\" line.\n",
143 Debug( LDAP_DEBUG_ANY,
144 "%s : line %d: missing arg(s) in "
145 "\"limits <pattern> <limits>\" line.\n%s",
151 limit = be->be_def_limit;
156 * "limits" <pattern> <limit> [ ... ]
161 * [ "dn" [ "." { "exact" | "regex" } ] "=" ] <dn pattern>
166 * "time" [ "." { "soft" | "hard" } ] "=" <integer>
168 * "size" [ "." { "soft" | "hard" | "unchecked" } ] "=" <integer>
172 if ( strncasecmp( pattern, "dn", 2 ) == 0 ) {
174 if ( pattern[0] == '.' ) {
176 if ( strncasecmp( pattern, "exact", 5 ) == 0 ) {
177 type = SLAP_LIMITS_EXACT;
179 } else if ( strncasecmp( pattern, "regex", 5 ) == 0 ) {
180 type = SLAP_LIMITS_REGEX;
185 if ( pattern[0] != '=' ) {
187 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
188 "%s : line %d: missing '=' in "
189 "\"dn[.{exact|regex}]=<pattern>\" in "
190 "\"limits <pattern> <limits>\" line.\n",
193 Debug( LDAP_DEBUG_ANY,
194 "%s : line %d: missing '=' in "
195 "\"dn[.{exact|regex}]=<pattern>\" in "
196 "\"limits <pattern> <limits>\" line.\n%s",
202 /* skip '=' (required) */
206 for ( i = 2; i < argc; i++ ) {
207 if ( parse_limit( argv[i], &limit ) ) {
210 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
211 "%s : line %d: unknown limit type \"%s\" in "
212 "\"limits <pattern> <limits>\" line.\n",
213 fname, lineno, argv[i] ));
215 Debug( LDAP_DEBUG_ANY,
216 "%s : line %d: unknown limit type \"%s\" in "
217 "\"limits <pattern> <limits>\" line.\n",
218 fname, lineno, argv[i] );
228 if ( limit.lms_t_hard > 0 && limit.lms_t_hard < limit.lms_t_soft ) {
229 limit.lms_t_hard = limit.lms_t_soft;
232 if ( limit.lms_s_hard > 0 && limit.lms_s_hard < limit.lms_s_soft ) {
233 limit.lms_s_hard = limit.lms_s_soft;
236 return( add_limits( be, type, pattern, &limit ) );
242 struct slap_limits_set *limit
248 if ( strncasecmp( arg, "time", 4 ) == 0 ) {
251 if ( arg[0] == '.' ) {
253 if ( strncasecmp( arg, "soft", 4 ) == 0 ) {
255 if ( arg[0] != '=' ) {
259 limit->lms_t_soft = atoi( arg );
261 } else if ( strncasecmp( arg, "hard", 4 ) == 0 ) {
263 if ( arg[0] != '=' ) {
267 limit->lms_t_hard = atoi( arg );
273 } else if ( arg[0] == '=' ) {
274 limit->lms_t_soft = atoi( arg );
275 limit->lms_t_hard = 0;
281 } else if ( strncasecmp( arg, "size", 4 ) == 0 ) {
284 if ( arg[0] == '.' ) {
286 if ( strncasecmp( arg, "soft", 4 ) == 0 ) {
288 if ( arg[0] != '=' ) {
292 limit->lms_s_soft = atoi( arg );
294 } else if ( strncasecmp( arg, "hard", 4 ) == 0 ) {
296 if ( arg[0] != '=' ) {
300 limit->lms_s_hard = atoi( arg );
302 } else if ( strncasecmp( arg, "unchecked", 9 ) == 0 ) {
304 if ( arg[0] != '=' ) {
308 limit->lms_s_unchecked = atoi( arg );
314 } else if ( arg[0] == '=' ) {
315 limit->lms_s_soft = atoi( arg );
316 limit->lms_s_hard = 0;