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>
24 struct slap_limits **lm;
29 *timelimit = be->be_timelimit;
30 *sizelimit = be->be_sizelimit;
33 * anonymous or no regex-based limits?
35 if ( be->be_limits == NULL || ndn == NULL || ndn[0] == '\0' ) {
39 for ( lm = be->be_limits; lm[0] != NULL; lm++ ) {
40 switch ( lm[0]->lm_type) {
41 case SLAP_LIMITS_EXACT:
42 if ( strcmp( lm[0]->lm_dn_pat, ndn ) == 0 ) {
43 *timelimit = lm[0]->lm_timelimit;
44 *sizelimit = lm[0]->lm_sizelimit;
49 case SLAP_LIMITS_REGEX:
50 if ( regexec( &lm[0]->lm_dn_regex, ndn, 0, NULL, 0) == 0 ) {
51 *timelimit = lm[0]->lm_timelimit;
52 *sizelimit = lm[0]->lm_sizelimit;
58 assert( 0 ); /* unreachable */
76 struct slap_limits *lm;
81 lm = ( struct slap_limits * )ch_calloc( sizeof( struct slap_limits ), 1 );
84 case SLAP_LIMITS_EXACT:
85 lm->lm_type = SLAP_LIMITS_EXACT;
86 lm->lm_dn_pat = ch_strdup( pattern );
87 if ( dn_normalize( lm->lm_dn_pat ) == NULL ) {
88 ch_free( lm->lm_dn_pat );
94 case SLAP_LIMITS_REGEX:
95 case SLAP_LIMITS_UNDEFINED:
96 lm->lm_type = SLAP_LIMITS_REGEX;
97 lm->lm_dn_pat = ch_strdup( pattern );
98 if ( regcomp( &lm->lm_dn_regex, lm->lm_dn_pat, REG_EXTENDED | REG_ICASE ) ) {
99 ch_free( lm->lm_dn_pat );
106 lm->lm_timelimit = timelimit;
107 lm->lm_sizelimit = sizelimit;
109 if ( be->be_limits == NULL ) {
111 be->be_limits = ( struct slap_limits ** )ch_calloc( sizeof( struct slap_limits * ), 2 );
113 for ( i = 0; be->be_limits[i]; i++ );
115 be->be_limits = ( struct slap_limits ** )ch_realloc( be->be_limits,
116 sizeof( struct slap_limits * ) * ( i + 1 ) );
118 be->be_limits[i] = lm;
132 int type = SLAP_LIMITS_UNDEFINED;
142 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
143 "%s : line %d: missing arg(s) in "
144 "\"limits <pattern> <limits>\" line.\n",
147 Debug( LDAP_DEBUG_ANY,
148 "%s : line %d: missing arg(s) in "
149 "\"limits <pattern> <limits>\" line.\n%s",
155 timelimit = be->be_timelimit;
156 sizelimit = be->be_sizelimit;
161 * "limits" <pattern> <limit> [ <limit> [ ... ] ]
166 * [ "dn" [ "." { "exact" | "regex" } ] "=" ] <dn pattern>
171 * { "time" | "size" } "=" <value>
175 if ( strncasecmp( pattern, "dn", 2 ) == 0 ) {
177 if ( pattern[0] == '.' ) {
179 if ( strncasecmp( pattern, "exact", 5 ) == 0 ) {
180 type = SLAP_LIMITS_EXACT;
182 } else if ( strncasecmp( pattern, "regex", 5 ) == 0 ) {
183 type = SLAP_LIMITS_REGEX;
188 if ( pattern[0] != '=' ) {
190 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
191 "%s : line %d: missing '=' in "
192 "\"dn[.{exact|regex}]=<pattern>\" in "
193 "\"limits <pattern> <limits>\" line.\n",
196 Debug( LDAP_DEBUG_ANY,
197 "%s : line %d: missing '=' in "
198 "\"dn[.{exact|regex}]=<pattern>\" in "
199 "\"limits <pattern> <limits>\" line.\n%s",
205 /* skip '=' (required) */
209 for ( i = 2; i < argc; i++ ) {
210 if ( strncasecmp( argv[i], "time=", 5) == 0 ) {
211 timelimit = atoi( argv[i]+5 );
212 } else if ( strncasecmp( argv[i], "size=", 5) == 0 ) {
213 sizelimit = atoi( argv[i]+5 );
216 LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
217 "%s : line %d: unknown limit type \"%s\" in "
218 "\"limits <pattern> <limits>\" line "
220 fname, lineno, argv[i] ));
222 Debug( LDAP_DEBUG_ANY,
223 "%s : line %d: unknown limit type \"%s\" in "
224 "\"limits <pattern> <limits>\" line "
226 fname, lineno, argv[i] );
231 return( add_limits( be, type, pattern, timelimit, sizelimit ) );