- /*
- * construct a regular expression corresponding to the
- * filter and let regex do the work
- */
-
- pat[0] = '\0';
- p = pat;
- end = pat + sizeof(pat) - 2; /* leave room for null */
- if ( f->f_sub_initial != NULL ) {
- strcpy( p, "^" );
- p = strchr( p, '\0' );
- /* 2 * in case every char is special */
- if ( p + 2 * f->f_sub_initial->bv_len > end ) {
- Debug( LDAP_DEBUG_ANY, "not enough pattern space\n",
- 0, 0, 0 );
- return LDAP_OTHER;
- }
- strcpy_regex( p, f->f_sub_initial->bv_val );
- p = strchr( p, '\0' );
- }
- if ( f->f_sub_any != NULL ) {
- for ( i = 0; f->f_sub_any[i] != NULL; i++ ) {
- /* ".*" + value */
- if ( p + 2 * f->f_sub_any[i]->bv_len + 2 > end ) {
- Debug( LDAP_DEBUG_ANY,
- "not enough pattern space\n", 0, 0, 0 );
- return LDAP_OTHER;
- }
- strcpy( p, ".*" );
- p = strchr( p, '\0' );
- strcpy_regex( p, f->f_sub_any[i]->bv_val );
- p = strchr( p, '\0' );
- }
- }
- if ( f->f_sub_final != NULL ) {
- /* ".*" + value */
- if ( p + 2 * f->f_sub_final->bv_len + 2 > end ) {
- Debug( LDAP_DEBUG_ANY, "not enough pattern space\n",
- 0, 0, 0 );
- return( -1 );
- }
- strcpy( p, ".*" );
- p = strchr( p, '\0' );
- strcpy_regex( p, f->f_sub_final->bv_val );
- p = strchr( p, '\0' );
- strcpy( p, "$" );
- }
-
- /* compile the regex */
- Debug( LDAP_DEBUG_FILTER, "test_substring_filter: regcomp pat: %s\n",
- pat, 0, 0 );
- if ((rc = regcomp(&re, pat, REG_EXTENDED|REG_NOSUB))) {
- char error[512];
-
- regerror(rc, &re, error, sizeof(error));
- Debug( LDAP_DEBUG_ANY, "regcomp failed (%s) %s\n",
- p, error, 0 );
- return LDAP_OTHER;
- }
-
- /* for each value in the attribute see if regex matches */
- for ( i = 0; a->a_vals[i] != NULL; i++ ) {
- val = a->a_vals[i];
- tmp = NULL;
- if ( val->bv_len < sizeof(buf) ) {
- strcpy( buf, val->bv_val );
- realval = buf;
- } else {
- tmp = (char *) ch_malloc( val->bv_len + 1 );
- strcpy( tmp, val->bv_val );
- realval = tmp;
- }
-
- value_normalize( realval, a->a_syntax );
-
- rc = !regexec(&re, realval, 0, NULL, 0);
-
- if ( tmp != NULL ) {
- free( tmp );
- }
- if ( rc == 1 ) {
- regfree(&re);
- return LDAP_COMPARE_TRUE;
- }
- }
-
- regfree(&re);