]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/str2filter.c
Per ITS#419, don't require SLAPD_RLOOKUPS when HAVE_TCPD
[openldap] / servers / slapd / str2filter.c
index 5aea1d55b3b5bf248ab8d8e39077f0dbd110ffda..cc98593519548c68ed085d21eaa82616b8157f37 100644 (file)
@@ -1,24 +1,31 @@
 /* str2filter.c - parse an rfc 1588 string filter */
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 
 #include "portable.h"
 
 #include <stdio.h>
 
 #include <ac/string.h>
+#include <ac/ctype.h>
 #include <ac/socket.h>
 
 #include "slap.h"
+#include <ldap_pvt.h>
 
-static char    *find_matching_paren();
-static Filter  *str2list();
-static Filter  *str2simple();
-static int     str2subvals();
+static char    *find_matching_paren(char *s);
+static Filter  *str2list(char *str, long unsigned int ftype);
+static Filter  *str2simple(char *str);
+static int     str2subvals(char *val, Filter *f);
 
 Filter *
 str2filter( char *str )
 {
-       Filter  *f;
-       char    *end;
+       Filter  *f = NULL;
+       char    *end, *freeme;
 
        Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
 
@@ -26,10 +33,13 @@ str2filter( char *str )
                return( NULL );
        }
 
+       str = freeme = ch_strdup( str );
+
        switch ( *str ) {
        case '(':
                if ( (end = find_matching_paren( str )) == NULL ) {
                        filter_free( f );
+                       free( freeme );
                        return( NULL );
                }
                *end = '\0';
@@ -78,6 +88,7 @@ str2filter( char *str )
                break;
        }
 
+       free( freeme );
        return( f );
 }
 
@@ -100,7 +111,7 @@ str2list( char *str, unsigned long ftype )
        fp = &f->f_list;
 
        while ( *str ) {
-               while ( *str && isspace( *str ) )
+               while ( *str && isspace( (unsigned char) *str ) )
                        str++;
                if ( *str == '\0' )
                        break;
@@ -160,13 +171,13 @@ str2simple( char *str )
                *s = '\0';
                break;
        default:
-               if ( strchr( value, '*' ) == NULL ) {
+               if ( ldap_pvt_find_wildcard( value ) == NULL ) {
                        f->f_choice = LDAP_FILTER_EQUALITY;
                } else if ( strcmp( value, "*" ) == 0 ) {
                        f->f_choice = LDAP_FILTER_PRESENT;
                } else {
                        f->f_choice = LDAP_FILTER_SUBSTRINGS;
-                       f->f_sub_type = strdup( str );
+                       f->f_sub_type = ch_strdup( str );
                        if ( str2subvals( value, f ) != 0 ) {
                                filter_free( f );
                                *(value-1) = '=';
@@ -179,10 +190,11 @@ str2simple( char *str )
        }
 
        if ( f->f_choice == LDAP_FILTER_PRESENT ) {
-               f->f_type = strdup( str );
+               f->f_type = ch_strdup( str );
        } else {
-               f->f_avtype = strdup( str );
-               f->f_avvalue.bv_val = strdup( value );
+               f->f_avtype = ch_strdup( str );
+               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 );
        }
 
@@ -194,30 +206,31 @@ str2simple( char *str )
 static int
 str2subvals( char *val, Filter *f )
 {
-       char    *nextstar;
+       char    *nextstar, *freeme;
        int     gotstar;
 
        Debug( LDAP_DEBUG_FILTER, "str2subvals \"%s\"\n", val, 0, 0 );
 
+       val = freeme = ch_strdup( val );
        gotstar = 0;
        while ( val != NULL && *val ) {
-               if ( (nextstar = strchr( val, '*' )) != NULL )
+               if ( (nextstar = ldap_pvt_find_wildcard( val )) != NULL )
                        *nextstar++ = '\0';
 
+               ldap_pvt_filter_value_unescape( val );
                if ( gotstar == 0 ) {
-                       f->f_sub_initial = strdup( val );
+                       f->f_sub_initial = ch_strdup( val );
                } else if ( nextstar == NULL ) {
-                       f->f_sub_final = strdup( val );
+                       f->f_sub_final = ch_strdup( val );
                } else {
-                       charray_add( &f->f_sub_any, strdup( val ) );
+                       charray_add( &f->f_sub_any, val );
                }
 
                gotstar = 1;
-               if ( nextstar != NULL )
-                       *(nextstar-1) = '*';
                val = nextstar;
        }
 
+       free( freeme );
        return( 0 );
 }