]> git.sur5r.net Git - openldap/commitdiff
Fix slapi_filter_join() behavioural bug.
authorLuke Howard <lukeh@openldap.org>
Sat, 3 May 2003 04:15:35 +0000 (04:15 +0000)
committerLuke Howard <lukeh@openldap.org>
Sat, 3 May 2003 04:15:35 +0000 (04:15 +0000)
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
servers/slapd/slapi/slapi_utils.c

index 1dc0c5b3a8a2f9ce5c7d40476eb91e6ff05514db..cef405e9fa3ad50e0fe7aa77f7f70017333285a4 100644 (file)
@@ -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 );
index d6684ebdc231f1095c8012897bffa412897c9493..135b744a4fd3b495346b2fed6da6b3c79fdffbb1 100644 (file)
@@ -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 )