From 83cb1037a4beb65393bc00615fc1c9357cb854aa Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Sat, 3 May 2003 04:15:35 +0000 Subject: [PATCH] Fix slapi_filter_join() behavioural bug. Fix slapi_filter_dup() crasher. Add slapi_x_filter_append(), as a replacement for slapi_filter_join() that can create compound filters containing multiple filters. Will propose API to Sun DS team; until then it should likely be marked LDAP_DEVEL (if SLAPI is not entirely marked as such already). --- servers/slapd/slapi/proto-slapi.h | 2 ++ servers/slapd/slapi/slapi_utils.c | 39 ++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/servers/slapd/slapi/proto-slapi.h b/servers/slapd/slapi/proto-slapi.h index 1dc0c5b3a8..cef405e9fa 100644 --- a/servers/slapd/slapi/proto-slapi.h +++ b/servers/slapd/slapi/proto-slapi.h @@ -187,6 +187,8 @@ extern int slapi_filter_get_attribute_type( Slapi_Filter *f, char **type ); extern int slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial, char ***any, char **final ); extern Slapi_Filter *slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2); +extern int slapi_x_filter_append( int choice, Slapi_Filter **pContainingFilter, + Slapi_Filter **pNextFilter, Slapi_Filter *filterToAppend ); extern int slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f, int verify_access ); extern int slapi_filter_apply( Slapi_Filter *f, FILTER_APPLY_FN fn, void *arg, int *error_code ); diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index d6684ebdc2..135b744a4f 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -1520,6 +1520,7 @@ slapi_filter_dup( Slapi_Filter *filter ) int i; f->f_sub = (SubstringsAssertion *)slapi_ch_malloc( sizeof(SubstringsAssertion) ); + f->f_sub->sa_desc = filter->f_sub->sa_desc; ber_dupbv( &f->f_sub_initial, &filter->f_sub_initial ); if ( filter->f_sub_any != NULL ) { for ( i = 0; filter->f_sub_any[i].bv_val != NULL; i++ ) @@ -1619,7 +1620,7 @@ slapi_filter_list_first( Slapi_Filter *f ) if ( ftype == LDAP_FILTER_AND || ftype == LDAP_FILTER_OR || ftype == LDAP_FILTER_NOT ) { - return (Slapi_Filter *)f->f_and; + return (Slapi_Filter *)f->f_list; } else { return NULL; } @@ -1725,7 +1726,7 @@ slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial, } Slapi_Filter * -slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2) +slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2 ) { #ifdef LDAP_SLAPI Slapi_Filter *f = NULL; @@ -1737,7 +1738,8 @@ slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2) f = (Slapi_Filter *)slapi_ch_malloc( sizeof(*f) ); f->f_choice = ftype; f->f_list = f1; - f->f_next = f2; + f->f_list->f_next = f2; + f->f_next = NULL; } return f; @@ -1746,6 +1748,37 @@ slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2) #endif /* LDAP_SLAPI */ } +int +slapi_x_filter_append( int ftype, + Slapi_Filter **pContainingFilter, /* NULL on first call */ + Slapi_Filter **pNextFilter, + Slapi_Filter *filterToAppend ) +{ +#ifdef LDAP_SLAPI + if ( ftype == LDAP_FILTER_AND || + ftype == LDAP_FILTER_OR || + ftype == LDAP_FILTER_NOT ) + { + if ( *pContainingFilter == NULL ) { + *pContainingFilter = (Slapi_Filter *)slapi_ch_malloc( sizeof(Slapi_Filter) ); + (*pContainingFilter)->f_choice = ftype; + (*pContainingFilter)->f_list = filterToAppend; + (*pContainingFilter)->f_next = NULL; + } else { + if ( (*pContainingFilter)->f_choice != ftype ) { + /* Sanity check */ + return -1; + } + (*pNextFilter)->f_next = filterToAppend; + } + *pNextFilter = filterToAppend; + + return 0; + } +#endif /* LDAP_SLAPI */ + return -1; +} + int slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f, int verify_access ) -- 2.39.5