if ( balance ) s++;
}
- return( *s ? s : NULL );
+ return *s ? s : NULL;
}
static int hex2value( int c )
return NULL;
/* allow RFC 1960 escapes */
- case '\\':
case '*':
case '(':
case ')':
+ case '\\':
s++;
}
}
*/
/* put explicit tag */
- if ( ber_printf( ber, "t{" /*"}"*/, tag ) == -1 )
- return( NULL );
+ if ( ber_printf( ber, "t{" /*"}"*/, tag ) == -1 ) {
+ return NULL;
+ }
str++;
- if ( (next = find_right_paren( str )) == NULL )
- return( NULL );
+ if ( (next = find_right_paren( str )) == NULL ) {
+ return NULL;
+ }
*next = '\0';
- if ( put_filter_list( ber, str, tag ) == -1 )
- return( NULL );
+ if ( put_filter_list( ber, str, tag ) == -1 ) {
+ return NULL;
+ }
/* close the '(' */
*next++ = ')';
/* flush explicit tagged thang */
- if ( ber_printf( ber, /*"{"*/ "N}" ) == -1 )
- return( NULL );
+ if ( ber_printf( ber, /*"{"*/ "N}" ) == -1 ) {
+ return NULL;
+ }
- return( next );
+ return next;
}
int
-ldap_int_put_filter( BerElement *ber, char *str )
+ldap_int_put_filter( BerElement *ber, const char *str_in )
{
+ int rc;
+ char *freeme;
+ char *str;
char *next;
int parens, balance, escape;
* Note: tags in a choice are always explicit
*/
- Debug( LDAP_DEBUG_TRACE, "put_filter: \"%s\"\n", str, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "put_filter: \"%s\"\n", str_in, 0, 0 );
+
+ freeme = LDAP_STRDUP( str_in );
+ if( freeme == NULL ) return LDAP_NO_MEMORY;
+ str = freeme;
parens = 0;
while ( *str ) {
str = put_complex_filter( ber, str,
LDAP_FILTER_AND, 0 );
- if( str == NULL ) return( -1 );
+ if( str == NULL ) {
+ rc = -1;
+ goto done;
+ }
parens--;
break;
str = put_complex_filter( ber, str,
LDAP_FILTER_OR, 0 );
- if( str == NULL ) return( -1 );
+ if( str == NULL ) {
+ rc = -1;
+ goto done;
+ }
parens--;
break;
str = put_complex_filter( ber, str,
LDAP_FILTER_NOT, 0 );
- if( str == NULL ) return( -1 );
+ if( str == NULL ) {
+ rc = -1;
+ goto done;
+ }
parens--;
break;
balance = 1;
escape = 0;
next = str;
+
while ( *next && balance ) {
if ( escape == 0 ) {
- if ( *next == '(' )
+ if ( *next == '(' ) {
balance++;
- else if ( *next == ')' )
+ } else if ( *next == ')' ) {
balance--;
+ }
}
- if ( *next == '\\' && ! escape )
+
+ if ( *next == '\\' && ! escape ) {
escape = 1;
- else
+ } else {
escape = 0;
- if ( balance )
- next++;
+ }
+
+ if ( balance ) next++;
+ }
+
+ if ( balance != 0 ) {
+ rc = -1;
+ goto done;
}
- if ( balance != 0 )
- return( -1 );
*next = '\0';
+
if ( put_simple_filter( ber, str ) == -1 ) {
- return( -1 );
+ rc = -1;
+ goto done;
}
- *next++ = ')';
+
+ *next++ = /*'('*/ ')';
+
str = next;
parens--;
break;
case /*'('*/ ')':
Debug( LDAP_DEBUG_TRACE, "put_filter: end\n",
0, 0, 0 );
- if ( ber_printf( ber, /*"["*/ "]" ) == -1 )
- return( -1 );
+ if ( ber_printf( ber, /*"["*/ "]" ) == -1 ) {
+ rc = -1;
+ goto done;
+ }
str++;
parens--;
break;
0, 0, 0 );
next = strchr( str, '\0' );
if ( put_simple_filter( ber, str ) == -1 ) {
- return( -1 );
+ rc = -1;
+ goto done;
}
str = next;
break;
}
}
- return( parens ? -1 : 0 );
+ rc = parens ? -1 : 0;
+
+done:
+ free( freeme );
+ return rc;
}
/*
if ( *str == '\0' ) break;
if ( (next = find_right_paren( str + 1 )) == NULL ) {
- return( -1 );
+ return -1;
}
save = *++next;
if( rc != -1 && rule && *rule != '\0' ) {
rc = ber_printf( ber, "ts", LDAP_FILTER_EXT_OID, rule );
}
+
if( rc != -1 && *str != '\0' ) {
rc = ber_printf( ber, "ts", LDAP_FILTER_EXT_TYPE, str );
}
+
if( rc != -1 ) {
ber_slen_t len = ldap_pvt_filter_value_unescape( value );
rc = -1;
}
}
+
if( rc != -1 && dn ) {
rc = ber_printf( ber, "tb",
LDAP_FILTER_EXT_DNATTRS, (ber_int_t) 1 );
}
+
if( rc != -1 ) {
rc = ber_printf( ber, /*"{"*/ "N}" );
}
goto done;
default:
- {
+ if( !ldap_is_desc( str ) ) {
+ goto done;
+
+ } else {
char *nextstar = ldap_pvt_find_wildcard( value );
+
if ( nextstar == NULL ) {
goto done;
+
} else if ( *nextstar == '\0' ) {
ftype = LDAP_FILTER_EQUALITY;
+
} else if ( strcmp( value, "*" ) == 0 ) {
ftype = LDAP_FILTER_PRESENT;
+
} else {
rc = put_substring_filter( ber, str, value );
goto done;
Debug( LDAP_DEBUG_TRACE, "put_substring_filter \"%s=%s\"\n",
type, val, 0 );
- if ( ber_printf( ber, "t{s{" /*"}}"*/, ftype, type ) == -1 )
- return( -1 );
+ if ( ber_printf( ber, "t{s{" /*"}}"*/, ftype, type ) == -1 ) {
+ return -1;
+ }
for( ; *val; val=nextstar ) {
nextstar = ldap_pvt_find_wildcard( val );
}
}
- if ( ber_printf( ber, /*"{{"*/ "N}N}" ) == -1 )
+ if ( ber_printf( ber, /*"{{"*/ "N}N}" ) == -1 ) {
return -1;
+ }
return 0;
}