Skip to content
Snippets Groups Projects
Commit 6632e41e authored by Hallvard Furuseth's avatar Hallvard Furuseth
Browse files

Export ldap_pvt_<find_wildcard,filter_value_unescape>() from libldap.

Use them in slapd/str2filter.c.
parent 10bbb7c9
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define _LDAP_PVT_H 1 #define _LDAP_PVT_H 1
#include <ldap_cdefs.h> #include <ldap_cdefs.h>
#include <lber.h> /* get ber_slen_t */
LDAP_BEGIN_DECL LDAP_BEGIN_DECL
...@@ -98,6 +99,13 @@ int ldap_pvt_unhex( int c ); ...@@ -98,6 +99,13 @@ int ldap_pvt_unhex( int c );
#define LDAP_NEEDSESCAPE(c) ((c) == '\\' || (c) == '"') #define LDAP_NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
/* search.c */
LDAP_F( char * )
ldap_pvt_find_wildcard LDAP_P(( char *s ));
LDAP_F( ber_slen_t )
ldap_pvt_filter_value_unescape LDAP_P(( char *filter ));
/* string.c */ /* string.c */
LDAP_F( char * ) LDAP_F( char * )
ldap_pvt_str2upper LDAP_P(( char *str )); ldap_pvt_str2upper LDAP_P(( char *str ));
......
...@@ -31,15 +31,9 @@ static int ldap_is_attr_desc LDAP_P(( ...@@ -31,15 +31,9 @@ static int ldap_is_attr_desc LDAP_P((
static int hex2value LDAP_P(( static int hex2value LDAP_P((
int c )); int c ));
static ber_slen_t filter_value_unescape LDAP_P((
char *filter ));
static char *find_right_paren LDAP_P(( static char *find_right_paren LDAP_P((
char *s )); char *s ));
static char *find_wildcard LDAP_P((
char *s ));
static char *put_complex_filter LDAP_P(( static char *put_complex_filter LDAP_P((
BerElement *ber, BerElement *ber,
char *str, char *str,
...@@ -416,8 +410,8 @@ static int hex2value( int c ) ...@@ -416,8 +410,8 @@ static int hex2value( int c )
return -1; return -1;
} }
static char * char *
find_wildcard( char *s ) ldap_pvt_find_wildcard( char *s )
{ {
for( ; *s != '\0' ; s++ ) { for( ; *s != '\0' ; s++ ) {
switch( *s ) { switch( *s ) {
...@@ -428,10 +422,6 @@ find_wildcard( char *s ) ...@@ -428,10 +422,6 @@ find_wildcard( char *s )
s++; /* skip over escape */ s++; /* skip over escape */
if ( *s == '\0' ) if ( *s == '\0' )
return NULL; /* escape at end of string */ return NULL; /* escape at end of string */
if( hex2value( s[0] ) >= 0 && hex2value( s[1] ) >= 0 ) {
/* skip over lead digit of two hex digit code */
s++;
}
} }
} }
...@@ -441,8 +431,8 @@ find_wildcard( char *s ) ...@@ -441,8 +431,8 @@ find_wildcard( char *s )
/* unescape filter value */ /* unescape filter value */
/* support both LDAP v2 and v3 escapes */ /* support both LDAP v2 and v3 escapes */
/* output can include nul characters */ /* output can include nul characters */
static ber_slen_t ber_slen_t
filter_value_unescape( char *fval ) ldap_pvt_filter_value_unescape( char *fval )
{ {
ber_slen_t r, v; ber_slen_t r, v;
int v1, v2; int v1, v2;
...@@ -805,7 +795,7 @@ put_simple_filter( ...@@ -805,7 +795,7 @@ put_simple_filter(
} }
if( rc != -1 ) { if( rc != -1 ) {
ber_slen_t len = filter_value_unescape( value ); ber_slen_t len = ldap_pvt_filter_value_unescape( value );
if( len >= 0 ) { if( len >= 0 ) {
rc = ber_printf( ber, "totb}", rc = ber_printf( ber, "totb}",
...@@ -819,7 +809,7 @@ put_simple_filter( ...@@ -819,7 +809,7 @@ put_simple_filter(
break; break;
default: default:
if ( find_wildcard( value ) == NULL ) { if ( ldap_pvt_find_wildcard( value ) == NULL ) {
ftype = LDAP_FILTER_EQUALITY; ftype = LDAP_FILTER_EQUALITY;
} else if ( strcmp( value, "*" ) == 0 ) { } else if ( strcmp( value, "*" ) == 0 ) {
ftype = LDAP_FILTER_PRESENT; ftype = LDAP_FILTER_PRESENT;
...@@ -834,7 +824,7 @@ put_simple_filter( ...@@ -834,7 +824,7 @@ put_simple_filter(
rc = ber_printf( ber, "ts", ftype, str ); rc = ber_printf( ber, "ts", ftype, str );
} else { } else {
ber_slen_t len = filter_value_unescape( value ); ber_slen_t len = ldap_pvt_filter_value_unescape( value );
if( len >= 0 ) { if( len >= 0 ) {
rc = ber_printf( ber, "t{so}", rc = ber_printf( ber, "t{so}",
...@@ -862,7 +852,7 @@ put_substring_filter( BerElement *ber, char *type, char *val ) ...@@ -862,7 +852,7 @@ put_substring_filter( BerElement *ber, char *type, char *val )
return( -1 ); return( -1 );
for( ; val != NULL; val=nextstar ) { for( ; val != NULL; val=nextstar ) {
if ( (nextstar = find_wildcard( val )) != NULL ) if ( (nextstar = ldap_pvt_find_wildcard( val )) != NULL )
*nextstar++ = '\0'; *nextstar++ = '\0';
if ( gotstar == 0 ) { if ( gotstar == 0 ) {
...@@ -874,7 +864,7 @@ put_substring_filter( BerElement *ber, char *type, char *val ) ...@@ -874,7 +864,7 @@ put_substring_filter( BerElement *ber, char *type, char *val )
} }
if ( *val != '\0' ) { if ( *val != '\0' ) {
ber_slen_t len = filter_value_unescape( val ); ber_slen_t len = ldap_pvt_filter_value_unescape( val );
if ( len < 0 ) { if ( len < 0 ) {
return -1; return -1;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <ac/socket.h> #include <ac/socket.h>
#include "slap.h" #include "slap.h"
#include <ldap_pvt.h>
static char *find_matching_paren(char *s); static char *find_matching_paren(char *s);
static Filter *str2list(char *str, long unsigned int ftype); static Filter *str2list(char *str, long unsigned int ftype);
...@@ -23,7 +24,7 @@ Filter * ...@@ -23,7 +24,7 @@ Filter *
str2filter( char *str ) str2filter( char *str )
{ {
Filter *f = NULL; Filter *f = NULL;
char *end; char *end, *freeme;
Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 ); Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
...@@ -31,10 +32,13 @@ str2filter( char *str ) ...@@ -31,10 +32,13 @@ str2filter( char *str )
return( NULL ); return( NULL );
} }
str = freeme = ch_strdup( str );
switch ( *str ) { switch ( *str ) {
case '(': case '(':
if ( (end = find_matching_paren( str )) == NULL ) { if ( (end = find_matching_paren( str )) == NULL ) {
filter_free( f ); filter_free( f );
free( freeme );
return( NULL ); return( NULL );
} }
*end = '\0'; *end = '\0';
...@@ -83,6 +87,7 @@ str2filter( char *str ) ...@@ -83,6 +87,7 @@ str2filter( char *str )
break; break;
} }
free( freeme );
return( f ); return( f );
} }
...@@ -165,7 +170,7 @@ str2simple( char *str ) ...@@ -165,7 +170,7 @@ str2simple( char *str )
*s = '\0'; *s = '\0';
break; break;
default: default:
if ( strchr( value, '*' ) == NULL ) { if ( ldap_pvt_find_wildcard( value ) == NULL ) {
f->f_choice = LDAP_FILTER_EQUALITY; f->f_choice = LDAP_FILTER_EQUALITY;
} else if ( strcmp( value, "*" ) == 0 ) { } else if ( strcmp( value, "*" ) == 0 ) {
f->f_choice = LDAP_FILTER_PRESENT; f->f_choice = LDAP_FILTER_PRESENT;
...@@ -188,6 +193,7 @@ str2simple( char *str ) ...@@ -188,6 +193,7 @@ str2simple( char *str )
} else { } else {
f->f_avtype = ch_strdup( str ); f->f_avtype = ch_strdup( str );
f->f_avvalue.bv_val = ch_strdup( value ); f->f_avvalue.bv_val = ch_strdup( value );
ldap_pvt_filter_value_unescape( f->f_avvalue.bv_val );
f->f_avvalue.bv_len = strlen( value ); f->f_avvalue.bv_len = strlen( value );
} }
...@@ -199,30 +205,31 @@ str2simple( char *str ) ...@@ -199,30 +205,31 @@ str2simple( char *str )
static int static int
str2subvals( char *val, Filter *f ) str2subvals( char *val, Filter *f )
{ {
char *nextstar; char *nextstar, *freeme;
int gotstar; int gotstar;
Debug( LDAP_DEBUG_FILTER, "str2subvals \"%s\"\n", val, 0, 0 ); Debug( LDAP_DEBUG_FILTER, "str2subvals \"%s\"\n", val, 0, 0 );
val = freeme = ch_strdup( val );
gotstar = 0; gotstar = 0;
while ( val != NULL && *val ) { while ( val != NULL && *val ) {
if ( (nextstar = strchr( val, '*' )) != NULL ) if ( (nextstar = ldap_pvt_find_wildcard( val )) != NULL )
*nextstar++ = '\0'; *nextstar++ = '\0';
ldap_pvt_filter_value_unescape( val );
if ( gotstar == 0 ) { if ( gotstar == 0 ) {
f->f_sub_initial = ch_strdup( val ); f->f_sub_initial = ch_strdup( val );
} else if ( nextstar == NULL ) { } else if ( nextstar == NULL ) {
f->f_sub_final = ch_strdup( val ); f->f_sub_final = ch_strdup( val );
} else { } else {
charray_add( &f->f_sub_any, ch_strdup( val ) ); charray_add( &f->f_sub_any, val );
} }
gotstar = 1; gotstar = 1;
if ( nextstar != NULL )
*(nextstar-1) = '*';
val = nextstar; val = nextstar;
} }
free( freeme );
return( 0 ); return( 0 );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment