From: Kurt Zeilenga Date: Wed, 2 Jan 2002 17:06:56 +0000 (+0000) Subject: Rework filter code X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~356 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=763c0de59b423f88b8a0f2aa362fe6c37b4007b6;p=openldap Rework filter code Misc cleanup / lint removal --- diff --git a/build/main.dsw b/build/main.dsw index 13475f4a66..3b8c2ce998 100644 --- a/build/main.dsw +++ b/build/main.dsw @@ -149,6 +149,33 @@ Package=<4> Begin Project Dependency Project_Dep_Name ucgendat End Project Dependency + Begin Project Dependency + Project_Dep_Name dntest + End Project Dependency + Begin Project Dependency + Project_Dep_Name ftest + End Project Dependency +}}} + +############################################################################### + +Project: "dntest"=..\libraries\libldap\dntest.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name liblber + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldap + End Project Dependency + Begin Project Dependency + Project_Dep_Name liblutil + End Project Dependency }}} ############################################################################### @@ -183,6 +210,27 @@ Package=<4> ############################################################################### +Project: "ftest"=..\libraries\libldap\ftest.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name liblber + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldap + End Project Dependency + Begin Project Dependency + Project_Dep_Name liblutil + End Project Dependency +}}} + +############################################################################### + Project: "ldapdelete"=..\clients\tools\ldapdelete.dsp - Package Owner=<4> Package=<5> diff --git a/include/ldap_pvt.h b/include/ldap_pvt.h index 82ab24d258..c6af0fb819 100644 --- a/include/ldap_pvt.h +++ b/include/ldap_pvt.h @@ -17,7 +17,6 @@ #ifndef _LDAP_PVT_H #define _LDAP_PVT_H 1 -#include #include /* get ber_slen_t */ LDAP_BEGIN_DECL @@ -107,6 +106,7 @@ LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s )); * these macros assume 'x' is an ASCII x * and assume the "C" locale */ +#define LDAP_ASCII(c) ((c) < 0x80) #define LDAP_SPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n') #define LDAP_DIGIT(c) ((c) >= '0' && (c) <= '9') #define LDAP_LOWER(c) ((c) >= 'a' && (c) <= 'z') @@ -114,6 +114,12 @@ LDAP_F (void) ldap_pvt_hex_unescape LDAP_P(( char *s )); #define LDAP_ALPHA(c) (LDAP_LOWER(c) || LDAP_UPPER(c)) #define LDAP_ALNUM(c) (LDAP_ALPHA(c) || LDAP_DIGIT(c)) +#define LDAP_LDH(c) (LDAP_ALNUM(c) || (c) == '-') + +#define LDAP_HEXLOWER(c) ((c) >= 'a' && (c) <= 'f') +#define LDAP_HEXUPPER(c) ((c) >= 'A' && (c) <= 'F') +#define LDAP_HEX(c) (LDAP_DIGIT(c) || \ + LDAP_HEXLOWER(c) || LDAP_HEXUPPER(c)) #ifdef HAVE_CYRUS_SASL /* cyrus.c */ diff --git a/include/ldap_pvt_uc.h b/include/ldap_pvt_uc.h index 6c1b3cfe6f..c5d7458258 100644 --- a/include/ldap_pvt_uc.h +++ b/include/ldap_pvt_uc.h @@ -18,7 +18,6 @@ #ifndef _LDAP_PVT_UC_H #define _LDAP_PVT_UC_H 1 -#include #include /* get ber_slen_t */ #ifdef _MSC_VER @@ -79,13 +78,12 @@ LDAP_F (char*) ldap_utf8_strtok( char* sp, const char* sep, char **last); LDAP_V (const char) ldap_utf8_lentab[128]; #define LDAP_UTF8_ISASCII(p) ( *(unsigned char *)(p) ^ 0x80 ) -#define LDAP_UTF8_ISSPACE(p) ( *(p) == ' ' || (*(p) >= '\t' && *(p) <= '\r') ) #define LDAP_UTF8_CHARLEN(p) ( LDAP_UTF8_ISASCII(p) \ ? 1 : ldap_utf8_lentab[*(unsigned char *)(p) ^ 0x80] ) #define LDAP_UTF8_OFFSET(p) ( LDAP_UTF8_ISASCII(p) \ ? 1 : ldap_utf8_offset((p)) ) -#define LDAP_UTF8_COPY(d,s) ( LDAP_UTF8_ISASCII(s) \ +#define LDAP_UTF8_COPY(d,s) ( LDAP_UTF8_ISASCII(s) \ ? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) ) #define LDAP_UTF8_NEXT(p) ( LDAP_UTF8_ISASCII(p) \ @@ -123,17 +121,17 @@ LDAP_LUNICODE_F(void) ucstr2upper( ldap_unicode_t *, ber_len_t ); -#define UTF8_CASEFOLD 1 -#define UTF8_NOCASEFOLD 0 +#define LDAP_UTF8_CASEFOLD 0x1U +#define LDAP_UTF8_NOCASEFOLD 0x0U LDAP_LUNICODE_F(char *) UTF8normalize( struct berval *, - char ); + unsigned ); LDAP_LUNICODE_F(int) UTF8normcmp( const char *, const char *, - char ); + unsigned ); LDAP_END_DECL diff --git a/libraries/liblber/decode.c b/libraries/liblber/decode.c index 305e766a76..488318db96 100644 --- a/libraries/liblber/decode.c +++ b/libraries/liblber/decode.c @@ -704,9 +704,7 @@ ber_scanf ( BerElement *ber, } } -breakout: va_end( ap ); - if ( rc == LBER_DEFAULT ) { /* * Error. Reclaim malloced memory that was given to the caller. diff --git a/libraries/liblber/liblber.dsp b/libraries/liblber/liblber.dsp index e414c67d3e..e02e1f3f76 100644 --- a/libraries/liblber/liblber.dsp +++ b/libraries/liblber/liblber.dsp @@ -219,10 +219,6 @@ SOURCE=.\options.c # End Source File # Begin Source File -SOURCE="..\..\include\queue-compat.h" -# End Source File -# Begin Source File - SOURCE=.\sockbuf.c # End Source File # End Target diff --git a/libraries/libldap/compare.c b/libraries/libldap/compare.c index 2b890b1fe9..1a4fed1b35 100644 --- a/libraries/libldap/compare.c +++ b/libraries/libldap/compare.c @@ -36,7 +36,7 @@ * attr and value) are supplied. The msgid of the response is returned. * * Example: - * struct berval bvalue = { "secret", strlen("secret") }; + * struct berval bvalue = { "secret", sizeof("secret")-1 }; * rc = ldap_compare( ld, "c=us@cn=bob", * "userPassword", &bvalue, * sctrl, cctrl, &msgid ) diff --git a/libraries/libldap/cyrus.c b/libraries/libldap/cyrus.c index 390ae47400..8f3c5282da 100644 --- a/libraries/libldap/cyrus.c +++ b/libraries/libldap/cyrus.c @@ -161,7 +161,7 @@ sb_sasl_drop_packet ( Sockbuf_Buf *sec_buf_in, int debuglevel ) len = sec_buf_in->buf_ptr - sec_buf_in->buf_end; if ( len > 0 ) - memmove( sec_buf_in->buf_base, sec_buf_in->buf_base + + AC_MEMCPY( sec_buf_in->buf_base, sec_buf_in->buf_base + sec_buf_in->buf_end, len ); if ( len >= 4 ) { diff --git a/libraries/libldap/getdn.c b/libraries/libldap/getdn.c index 41db8756bd..76bc499463 100644 --- a/libraries/libldap/getdn.c +++ b/libraries/libldap/getdn.c @@ -354,25 +354,21 @@ ldap_dn_normalize( const char *dnin, unsigned fin, char **dnout, unsigned fout ) */ #define LDAP_DN_ASCII_SPACE(c) \ ( (c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' ) -#define LDAP_DN_ASCII_LOWER(c) ( (c) >= 'a' && (c) <= 'z' ) -#define LDAP_DN_ASCII_UPPER(c) ( (c) >= 'A' && (c) <= 'Z' ) -#define LDAP_DN_ASCII_ALPHA(c) \ - ( LDAP_DN_ASCII_LOWER(c) || LDAP_DN_ASCII_UPPER(c) ) -#define LDAP_DN_ASCII_DIGIT(c) ( (c) >= '0' && (c) <= '9' ) -#define LDAP_DN_ASCII_LCASE_HEXALPHA(c) ( (c) >= 'a' && (c) <= 'f' ) -#define LDAP_DN_ASCII_UCASE_HEXALPHA(c) ( (c) >= 'A' && (c) <= 'F' ) -#define LDAP_DN_ASCII_HEXDIGIT(c) \ - ( LDAP_DN_ASCII_DIGIT(c) \ - || LDAP_DN_ASCII_LCASE_HEXALPHA(c) \ - || LDAP_DN_ASCII_UCASE_HEXALPHA(c) ) -#define LDAP_DN_ASCII_ALNUM(c) \ - ( LDAP_DN_ASCII_ALPHA(c) || LDAP_DN_ASCII_DIGIT(c) ) +#define LDAP_DN_ASCII_LOWER(c) LDAP_LOWER(c) +#define LDAP_DN_ASCII_UPPER(c) LDAP_UPPER(c) +#define LDAP_DN_ASCII_ALPHA(c) LDAP_ALPHA(c) + +#define LDAP_DN_ASCII_DIGIT(c) LDAP_DIGIT(c) +#define LDAP_DN_ASCII_LCASE_HEXALPHA(c) LDAP_HEXLOWER(c) +#define LDAP_DN_ASCII_UCASE_HEXALPHA(c) LDAP_HEXUPPER(c) +#define LDAP_DN_ASCII_HEXDIGIT(c) LDAP_HEX(c) +#define LDAP_DN_ASCII_ALNUM(c) LDAP_ALNUM(c) #define LDAP_DN_ASCII_PRINTABLE(c) ( (c) >= ' ' && (c) <= '~' ) /* attribute type */ -#define LDAP_DN_OID_LEADCHAR(c) ( LDAP_DN_ASCII_DIGIT(c) ) -#define LDAP_DN_DESC_LEADCHAR(c) ( LDAP_DN_ASCII_ALPHA(c) ) -#define LDAP_DN_DESC_CHAR(c) ( LDAP_DN_ASCII_ALNUM(c) || (c) == '-' ) +#define LDAP_DN_OID_LEADCHAR(c) LDAP_DIGIT(c) +#define LDAP_DN_DESC_LEADCHAR(c) LDAP_ALPHA(c) +#define LDAP_DN_DESC_CHAR(c) LDAP_LDH(c) #define LDAP_DN_LANG_SEP(c) ( (c) == ';' ) #define LDAP_DN_ATTRDESC_CHAR(c) \ ( LDAP_DN_DESC_CHAR(c) || LDAP_DN_LANG_SEP(c) ) @@ -655,7 +651,6 @@ ldap_str2dn( const char *str, LDAPDN **dn, unsigned flags ) } for ( ; p[ 0 ]; p++ ) { - LDAPDN *dn; int err; err = ldap_str2rdn( p, &newRDN, &p, flags ); @@ -3060,7 +3055,8 @@ got_funcs: } - Debug( LDAP_DEBUG_TRACE, "<= ldap_dn2bv(%s,%u)=%d\n", bv->bv_val, flags, rc ); + Debug( LDAP_DEBUG_TRACE, "<= ldap_dn2bv(%s,%u)=%d\n", + bv->bv_val, flags, rc ); return_results:; return( rc ); } diff --git a/libraries/libldap/libldap.dsp b/libraries/libldap/libldap.dsp index b143f709d9..5548eff5ce 100644 --- a/libraries/libldap/libldap.dsp +++ b/libraries/libldap/libldap.dsp @@ -183,6 +183,10 @@ SOURCE=.\extended.c # End Source File # Begin Source File +SOURCE=.\filter.c +# End Source File +# Begin Source File + SOURCE=.\free.c # End Source File # Begin Source File diff --git a/libraries/libldap/search.c b/libraries/libldap/search.c index c4a223dfe3..818f90e43c 100644 --- a/libraries/libldap/search.c +++ b/libraries/libldap/search.c @@ -22,43 +22,6 @@ #include "ldap-int.h" -static int ldap_is_attr_oid LDAP_P(( - const char *attr )); - -static int ldap_is_attr_desc LDAP_P(( - const char *attr )); - -static int hex2value LDAP_P(( - int c )); - -static char *find_right_paren LDAP_P(( - char *s )); - -static char *put_complex_filter LDAP_P(( - BerElement *ber, - char *str, - ber_tag_t tag, - int not )); - -int ldap_int_put_filter LDAP_P(( - BerElement *ber, - char *str )); - -#define put_filter(b,s) ldap_int_put_filter((b),(s)) - -static int put_simple_filter LDAP_P(( - BerElement *ber, - char *str )); - -static int put_substring_filter LDAP_P(( - BerElement *ber, - char *type, - char *str )); - -static int put_filter_list LDAP_P(( - BerElement *ber, - char *str, - ber_tag_t tag )); /* * ldap_search_ext - initiate an ldap search operation. @@ -334,7 +297,7 @@ ldap_build_search_req( } else { filter = LDAP_STRDUP( "(objectclass=*)" ); } - err = put_filter( ber, filter ); + err = ldap_int_put_filter( ber, filter ); LDAP_FREE( filter ); if ( err == -1 ) { @@ -364,583 +327,6 @@ ldap_build_search_req( return( ber ); } -static int ldap_is_attr_oid ( const char *attr ) -{ - int i, c, digit=0; - - for( i = 0; (c = attr[i]) != 0; i++ ) { - if( c >= '0' && c <= '9' ) { - digit=1; - - } else if ( c != '.' ) { - /* not digit nor '.' */ - return 0; - - } else if ( !digit ) { - /* '.' but prev not digit */ - return 0; - - } else { - /* '.' */ - digit = 0; - } - } - - return digit; -} - -static int ldap_is_attr_desc ( const char *attr ) -{ - /* cheap attribute description check */ - int i, c; - - for( i = 0; (c = attr[i]) != 0; i++ ) { - if (( c >= '0' && c <= '9' ) - || ( c >= 'A' && c <= 'Z' ) - || ( c >= 'a' && c <= 'z' ) - || ( c == '.' || c == '-' ) - || ( c == ';' )) continue; - - return 0; - } - - return i > 0; -} - -static char * -find_right_paren( char *s ) -{ - int balance, escape; - - balance = 1; - escape = 0; - while ( *s && balance ) { - if ( escape == 0 ) { - if ( *s == '(' ) - balance++; - else if ( *s == ')' ) - balance--; - } - if ( *s == '\\' && ! escape ) - escape = 1; - else - escape = 0; - if ( balance ) - s++; - } - - return( *s ? s : NULL ); -} - -static int hex2value( int c ) -{ - if( c >= '0' && c <= '9' ) { - return c - '0'; - } - - if( c >= 'A' && c <= 'F' ) { - return c + (10 - (int) 'A'); - } - - if( c >= 'a' && c <= 'f' ) { - return c + (10 - (int) 'a'); - } - - return -1; -} - -char * -ldap_pvt_find_wildcard( const char *s ) -{ - for( ; *s != '\0' ; s++ ) { - switch( *s ) { - case '*': /* found wildcard */ - return (char *) s; - - case '\\': - s++; /* skip over escape */ - if ( *s == '\0' ) - return NULL; /* escape at end of string */ - } - } - - return NULL; -} - -/* unescape filter value */ -/* support both LDAP v2 and v3 escapes */ -/* output can include nul characters! */ -ber_slen_t -ldap_pvt_filter_value_unescape( char *fval ) -{ - ber_slen_t r, v; - int v1, v2; - - for( r=v=0; fval[v] != '\0'; v++ ) { - switch( fval[v] ) { - case '\\': - /* escape */ - v++; - - if ( fval[v] == '\0' ) { - /* escape at end of string */ - return -1; - - } - - if (( v1 = hex2value( fval[v] )) >= 0 ) { - /* LDAPv3 escape */ - if (( v2 = hex2value( fval[v+1] )) < 0 ) { - /* must be two digit code */ - return -1; - } - - fval[r++] = v1 * 16 + v2; - v++; - - } else { - /* LDAPv2 escape */ - switch( fval[v] ) { - case '(': - case ')': - case '*': - case '\\': - fval[r++] = fval[v]; - break; - default: - /* illegal escape */ - return -1; - } - } - break; - - default: - fval[r++] = fval[v]; - } - } - - fval[r] = '\0'; - return r; -} - -static char * -put_complex_filter( BerElement *ber, char *str, ber_tag_t tag, int not ) -{ - char *next; - - /* - * We have (x(filter)...) with str sitting on - * the x. We have to find the paren matching - * the one before the x and put the intervening - * filters by calling put_filter_list(). - */ - - /* put explicit tag */ - if ( ber_printf( ber, "t{" /*}*/, tag ) == -1 ) - return( NULL ); - - str++; - if ( (next = find_right_paren( str )) == NULL ) - return( NULL ); - - *next = '\0'; - if ( put_filter_list( ber, str, tag ) == -1 ) - return( NULL ); - *next++ = ')'; - - /* flush explicit tagged thang */ - if ( ber_printf( ber, /*{*/ "N}" ) == -1 ) - return( NULL ); - - return( next ); -} - -int -ldap_int_put_filter( BerElement *ber, char *str ) -{ - char *next; - int parens, balance, escape; - - /* - * A Filter looks like this: - * Filter ::= CHOICE { - * and [0] SET OF Filter, - * or [1] SET OF Filter, - * not [2] Filter, - * equalityMatch [3] AttributeValueAssertion, - * substrings [4] SubstringFilter, - * greaterOrEqual [5] AttributeValueAssertion, - * lessOrEqual [6] AttributeValueAssertion, - * present [7] AttributeType, - * approxMatch [8] AttributeValueAssertion, - * extensibleMatch [9] MatchingRuleAssertion -- LDAPv3 - * } - * - * SubstringFilter ::= SEQUENCE { - * type AttributeType, - * SEQUENCE OF CHOICE { - * initial [0] IA5String, - * any [1] IA5String, - * final [2] IA5String - * } - * } - * - * MatchingRuleAssertion ::= SEQUENCE { -- LDAPv3 - * matchingRule [1] MatchingRuleId OPTIONAL, - * type [2] AttributeDescription OPTIONAL, - * matchValue [3] AssertionValue, - * dnAttributes [4] BOOLEAN DEFAULT FALSE } - * - * Note: tags in a choice are always explicit - */ - - Debug( LDAP_DEBUG_TRACE, "put_filter \"%s\"\n", str, 0, 0 ); - - parens = 0; - while ( *str ) { - switch ( *str ) { - case '(': - str++; - parens++; - - /* skip spaces */ - while( LDAP_SPACE( *str ) ) str++; - - switch ( *str ) { - case '&': - Debug( LDAP_DEBUG_TRACE, "put_filter: AND\n", - 0, 0, 0 ); - - if ( (str = put_complex_filter( ber, str, - LDAP_FILTER_AND, 0 )) == NULL ) - return( -1 ); - - parens--; - break; - - case '|': - Debug( LDAP_DEBUG_TRACE, "put_filter: OR\n", - 0, 0, 0 ); - - if ( (str = put_complex_filter( ber, str, - LDAP_FILTER_OR, 0 )) == NULL ) - return( -1 ); - - parens--; - break; - - case '!': - Debug( LDAP_DEBUG_TRACE, "put_filter: NOT\n", - 0, 0, 0 ); - - if ( (str = put_complex_filter( ber, str, - LDAP_FILTER_NOT, 1 )) == NULL ) - return( -1 ); - - parens--; - break; - - default: - Debug( LDAP_DEBUG_TRACE, "put_filter: simple\n", - 0, 0, 0 ); - - balance = 1; - escape = 0; - next = str; - while ( *next && balance ) { - if ( escape == 0 ) { - if ( *next == '(' ) - balance++; - else if ( *next == ')' ) - balance--; - } - if ( *next == '\\' && ! escape ) - escape = 1; - else - escape = 0; - if ( balance ) - next++; - } - if ( balance != 0 ) - return( -1 ); - - *next = '\0'; - if ( put_simple_filter( ber, str ) == -1 ) { - return( -1 ); - } - *next++ = ')'; - str = next; - parens--; - break; - } - break; - - case ')': - Debug( LDAP_DEBUG_TRACE, "put_filter: end\n", 0, 0, - 0 ); - if ( ber_printf( ber, /*[*/ "]" ) == -1 ) - return( -1 ); - str++; - parens--; - break; - - case ' ': - str++; - break; - - default: /* assume it's a simple type=value filter */ - Debug( LDAP_DEBUG_TRACE, "put_filter: default\n", 0, 0, - 0 ); - next = strchr( str, '\0' ); - if ( put_simple_filter( ber, str ) == -1 ) { - return( -1 ); - } - str = next; - break; - } - } - - return( parens ? -1 : 0 ); -} - -/* - * Put a list of filters like this "(filter1)(filter2)..." - */ - -static int -put_filter_list( BerElement *ber, char *str, ber_tag_t tag ) -{ - char *next = NULL; - char save; - - Debug( LDAP_DEBUG_TRACE, "put_filter_list \"%s\"\n", str, 0, 0 ); - - while ( *str ) { - while ( *str && LDAP_SPACE( (unsigned char) *str ) ) { - str++; - } - if ( *str == '\0' ) break; - - if ( (next = find_right_paren( str + 1 )) == NULL ) { - return( -1 ); - } - save = *++next; - - /* now we have "(filter)" with str pointing to it */ - *next = '\0'; - if ( put_filter( ber, str ) == -1 ) return -1; - *next = save; - str = next; - - if( tag == LDAP_FILTER_NOT ) break; - } - - if( tag == LDAP_FILTER_NOT && ( next == NULL || *str )) { - return -1; - } - - return 0; -} - -static int -put_simple_filter( - BerElement *ber, - char *str ) -{ - char *s; - char *value; - ber_tag_t ftype; - int rc = -1; - - Debug( LDAP_DEBUG_TRACE, "put_simple_filter \"%s\"\n", str, 0, 0 ); - - str = LDAP_STRDUP( str ); - if( str == NULL ) return -1; - - if ( (s = strchr( str, '=' )) == NULL ) { - goto done; - } - - value = s + 1; - *s-- = '\0'; - - switch ( *s ) { - case '<': - ftype = LDAP_FILTER_LE; - *s = '\0'; - if(! ldap_is_attr_desc( str ) ) goto done; - break; - - case '>': - ftype = LDAP_FILTER_GE; - *s = '\0'; - if(! ldap_is_attr_desc( str ) ) goto done; - break; - - case '~': - ftype = LDAP_FILTER_APPROX; - *s = '\0'; - if(! ldap_is_attr_desc( str ) ) goto done; - break; - - case ':': - /* RFC2254 extensible filters are off the form: - * type [:dn] [:rule] := value - * or [:dn]:rule := value - */ - ftype = LDAP_FILTER_EXT; - *s = '\0'; - - { - char *dn = strchr( str, ':' ); - char *rule = NULL; - - if( dn == NULL ) { - if(! ldap_is_attr_desc( str ) ) goto done; - } else { - - *dn++ = '\0'; - rule = strchr( dn, ':' ); - - if( rule == NULL ) { - /* one colon */ - if ( strcmp(dn, "dn") == 0 ) { - /* must have attribute */ - if( !ldap_is_attr_desc( str ) ) { - goto done; - } - - rule = ""; - - } else { - rule = dn; - dn = NULL; - } - - } else { - /* two colons */ - *rule++ = '\0'; - - if ( strcmp(dn, "dn") != 0 ) { - /* must have "dn" */ - goto done; - } - } - - } - - if ( *str == '\0' && ( !rule || *rule == '\0' ) ) { - /* must have either type or rule */ - goto done; - } - - if ( *str != '\0' && !ldap_is_attr_desc( str ) ) { - goto done; - } - - if ( rule && *rule != '\0' && !ldap_is_attr_oid( rule ) ) { - goto done; - } - - rc = ber_printf( ber, "t{" /*}*/, ftype ); - - 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 ); - - if( len >= 0 ) { - rc = ber_printf( ber, "totbN}", - LDAP_FILTER_EXT_VALUE, value, len, - LDAP_FILTER_EXT_DNATTRS, dn != NULL); - } else { - rc = -1; - } - } - } - goto done; - - default: - if ( ldap_pvt_find_wildcard( value ) == NULL ) { - ftype = LDAP_FILTER_EQUALITY; - } else if ( strcmp( value, "*" ) == 0 ) { - ftype = LDAP_FILTER_PRESENT; - } else { - rc = put_substring_filter( ber, str, value ); - goto done; - } - break; - } - - if ( ftype == LDAP_FILTER_PRESENT ) { - rc = ber_printf( ber, "ts", ftype, str ); - - } else { - ber_slen_t len = ldap_pvt_filter_value_unescape( value ); - - if( len >= 0 ) { - rc = ber_printf( ber, "t{soN}", - ftype, str, value, len ); - } - } - - if( rc != -1 ) rc = 0; - -done: - LDAP_FREE( str ); - return rc; -} - -static int -put_substring_filter( BerElement *ber, char *type, char *val ) -{ - char *nextstar, gotstar = 0; - ber_tag_t ftype = LDAP_FILTER_SUBSTRINGS; - - Debug( LDAP_DEBUG_TRACE, "put_substring_filter \"%s=%s\"\n", type, - val, 0 ); - - if ( ber_printf( ber, "t{s{", ftype, type ) == -1 ) - return( -1 ); - - for( ; val != NULL; val=nextstar ) { - if ( (nextstar = ldap_pvt_find_wildcard( val )) != NULL ) - *nextstar++ = '\0'; - - if ( gotstar == 0 ) { - ftype = LDAP_SUBSTRING_INITIAL; - } else if ( nextstar == NULL ) { - ftype = LDAP_SUBSTRING_FINAL; - } else { - ftype = LDAP_SUBSTRING_ANY; - } - - if ( *val != '\0' ) { - ber_slen_t len = ldap_pvt_filter_value_unescape( val ); - - if ( len < 0 ) { - return -1; - } - - if ( ber_printf( ber, "to", ftype, val, len ) == -1 ) { - return( -1 ); - } - } - - gotstar = 1; - } - - if ( ber_printf( ber, /* {{ */ "N}N}" ) == -1 ) - return( -1 ); - - return( 0 ); -} - int ldap_search_st( LDAP *ld, LDAP_CONST char *base, int scope, diff --git a/libraries/libldap/utf-8.c b/libraries/libldap/utf-8.c index 6a97a4fc45..a5bcc029e6 100644 --- a/libraries/libldap/utf-8.c +++ b/libraries/libldap/utf-8.c @@ -30,9 +30,6 @@ #include "ldap-int.h" #include "ldap_defaults.h" -#undef LDAP_IS_ASCII -#define LDAP_IS_ASCII(uc) ((uc) < 0x80) - /* * Basic UTF-8 routines */ @@ -250,6 +247,7 @@ int ldap_utf8_copy( char* dst, const char *src ) return i; } +#ifndef UTF8_ALPHA_CTYPE /* * UTF-8 ctype routines * Only deals with characters < 0x80 (ie: US-ASCII) @@ -258,34 +256,32 @@ int ldap_utf8_copy( char* dst, const char *src ) int ldap_utf8_isascii( const char * p ) { unsigned c = * (const unsigned char *) p; - return LDAP_IS_ASCII(c); + return LDAP_ASCII(c); } int ldap_utf8_isdigit( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!LDAP_IS_ASCII(c)) return 0; + if(!LDAP_ASCII(c)) return 0; - return c >= '0' && c <= '9'; + return LDAP_DIGIT( c ); } int ldap_utf8_isxdigit( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!LDAP_IS_ASCII(c)) return 0; + if(!LDAP_ASCII(c)) return 0; - return ( c >= '0' && c <= '9' ) - || ( c >= 'A' && c <= 'F' ) - || ( c >= 'a' && c <= 'f' ); + return LDAP_HEX(c); } int ldap_utf8_isspace( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!LDAP_IS_ASCII(c)) return 0; + if(!LDAP_ASCII(c)) return 0; switch(c) { case ' ': @@ -300,7 +296,6 @@ int ldap_utf8_isspace( const char * p ) return 0; } -#ifndef UTF8_ALPHA_CTYPE /* * These are not needed by the C SDK and are * not "good enough" for general use. @@ -309,39 +304,36 @@ int ldap_utf8_isalpha( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!LDAP_IS_ASCII(c)) return 0; + if(!LDAP_ASCII(c)) return 0; - return ( c >= 'A' && c <= 'Z' ) - || ( c >= 'a' && c <= 'z' ); + return LDAP_ALPHA(c); } int ldap_utf8_isalnum( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!LDAP_IS_ASCII(c)) return 0; + if(!LDAP_ASCII(c)) return 0; - return ( c >= '0' && c <= '9' ) - || ( c >= 'A' && c <= 'Z' ) - || ( c >= 'a' && c <= 'z' ); + return LDAP_ALNUM(c); } int ldap_utf8_islower( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!LDAP_IS_ASCII(c)) return 0; + if(!LDAP_ASCII(c)) return 0; - return ( c >= 'a' && c <= 'z' ); + return LDAP_LOWER(c); } int ldap_utf8_isupper( const char * p ) { unsigned c = * (const unsigned char *) p; - if(!LDAP_IS_ASCII(c)) return 0; + if(!LDAP_ASCII(c)) return 0; - return ( c >= 'A' && c <= 'Z' ); + return LDAP_UPPER(c); } #endif diff --git a/libraries/libldap/util-int.c b/libraries/libldap/util-int.c index ffd2214081..2473817aac 100644 --- a/libraries/libldap/util-int.c +++ b/libraries/libldap/util-int.c @@ -92,8 +92,8 @@ char *ldap_pvt_ctime( const time_t *tp, char *buf ) #endif } -#define BUFSTART 1024 -#define BUFMAX (32*1024) +#define BUFSTART (1024-32 +#define BUFMAX (32*1024-32) static char *safe_realloc( char **buf, int len ); diff --git a/libraries/libldap_r/libldap_r.dsp b/libraries/libldap_r/libldap_r.dsp index b8d32ff47a..46a235863a 100644 --- a/libraries/libldap_r/libldap_r.dsp +++ b/libraries/libldap_r/libldap_r.dsp @@ -184,6 +184,10 @@ SOURCE=..\libldap\extended.c # End Source File # Begin Source File +SOURCE=..\libldap\filter.c +# End Source File +# Begin Source File + SOURCE=..\libldap\free.c # End Source File # Begin Source File @@ -228,10 +232,22 @@ SOURCE=..\..\include\ldap_cdefs.h # End Source File # Begin Source File +SOURCE=..\..\include\ldap_config.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\ldap_defaults.h +# End Source File +# Begin Source File + SOURCE=..\..\include\ldap_features.h # End Source File # Begin Source File +SOURCE=..\..\include\ldap_int_thread.h +# End Source File +# Begin Source File + SOURCE=..\..\include\ldap_log.h # End Source File # Begin Source File @@ -244,6 +260,18 @@ SOURCE=..\..\include\ldap_pvt_thread.h # End Source File # Begin Source File +SOURCE=..\..\include\ldap_pvt_uc.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\ldap_schema.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\ldap_utf8.h +# End Source File +# Begin Source File + SOURCE=..\libldap\modify.c # End Source File # Begin Source File diff --git a/libraries/libldap_r/tpool.c b/libraries/libldap_r/tpool.c index f0ea8db9bc..b1b32957da 100644 --- a/libraries/libldap_r/tpool.c +++ b/libraries/libldap_r/tpool.c @@ -17,10 +17,11 @@ #include #include #include +#include #include "ldap-int.h" #include "ldap_pvt_thread.h" -#include "queue-compat.h" + #ifndef LDAP_THREAD_HAVE_TPOOL @@ -72,7 +73,6 @@ ldap_int_thread_pool_startup ( void ) int ldap_int_thread_pool_shutdown ( void ) { - ldap_int_thread_ctx_t *ctx; struct ldap_int_thread_pool_s *pool; while ((pool = STAILQ_FIRST(&ldap_int_thread_pool_list)) != NULL) { diff --git a/libraries/liblunicode/ucdata/ucdata.c b/libraries/liblunicode/ucdata/ucdata.c index 172fbea326..1c48a1d730 100644 --- a/libraries/liblunicode/ucdata/ucdata.c +++ b/libraries/liblunicode/ucdata/ucdata.c @@ -816,7 +816,7 @@ uccanondecomp(const unsigned long *in, int inlen, for (l = i; l > 0; l--) if (class >= uccombining_class((*out)[l-1])) break; - memmove(*out + l + 1, *out + l, (i - l) * sizeof(**out)); + AC_MEMCPY(*out + l + 1, *out + l, (i - l) * sizeof(**out)); (*out)[l] = decomp[k]; } i++; @@ -846,7 +846,7 @@ uccanondecomp(const unsigned long *in, int inlen, for (l = i; l > 0; l--) if (class >= uccombining_class((*out)[l-1])) break; - memmove(*out + l + 1, *out + l, (i - l) * sizeof(**out)); + AC_MEMCPY(*out + l + 1, *out + l, (i - l) * sizeof(**out)); (*out)[l] = in[j]; } i++; diff --git a/libraries/liblunicode/ucdata/ucgendat.c b/libraries/liblunicode/ucdata/ucgendat.c index e7a9a563e7..4bab6d9880 100644 --- a/libraries/liblunicode/ucdata/ucgendat.c +++ b/libraries/liblunicode/ucdata/ucgendat.c @@ -30,6 +30,7 @@ #include #include +#undef ishdigit #define ishdigit(cc) (((cc) >= '0' && (cc) <= '9') ||\ ((cc) >= 'A' && (cc) <= 'F') ||\ ((cc) >= 'a' && (cc) <= 'f')) diff --git a/libraries/liblunicode/ucstr.c b/libraries/liblunicode/ucstr.c index d970aa5a75..43ab99ddf7 100644 --- a/libraries/liblunicode/ucstr.c +++ b/libraries/liblunicode/ucstr.c @@ -83,7 +83,7 @@ void ucstr2upper( char * UTF8normalize( struct berval *bv, - char casefold ) + unsigned casefold ) { int i, j, len, clen, outpos, ucsoutlen, outsize, last; char *out, *s; @@ -219,7 +219,7 @@ char * UTF8normalize( int UTF8normcmp( const char *s1, const char *s2, - char casefold ) + unsigned casefold ) { int i, l1, l2, len, ulen, res; unsigned long *ucs, *ucsout1, *ucsout2; diff --git a/libraries/liblutil/liblutil.dsp b/libraries/liblutil/liblutil.dsp index 613c9995f2..a17939d6f3 100644 --- a/libraries/liblutil/liblutil.dsp +++ b/libraries/liblutil/liblutil.dsp @@ -180,6 +180,10 @@ SOURCE=..\..\include\lutil.h # End Source File # Begin Source File +SOURCE=..\..\include\lutil_hash.h +# End Source File +# Begin Source File + SOURCE=..\..\include\lutil_ldap.h # End Source File # Begin Source File diff --git a/libraries/librewrite/map.c b/libraries/librewrite/map.c index 9fbf330c3c..816a27edf7 100644 --- a/libraries/librewrite/map.c +++ b/libraries/librewrite/map.c @@ -187,7 +187,7 @@ rewrite_xmap_parse( */ p = strchr( url, '%' ); if ( p != NULL ) { - memmove( p + 3, p + 1, strlen( p + 1 ) + 1 ); + AC_MEMCPY( p + 3, p + 1, strlen( p + 1 ) + 1 ); p[ 1 ] = '2'; p[ 2 ] = '5'; } diff --git a/libraries/librewrite/subst.c b/libraries/librewrite/subst.c index b85a7560bd..f84ed44c25 100644 --- a/libraries/librewrite/subst.c +++ b/libraries/librewrite/subst.c @@ -59,7 +59,7 @@ rewrite_subst_compile( continue; } if ( p[ 1 ] == REWRITE_SUBMATCH_ESCAPE ) { - memmove((char *)p, p + 1, strlen( p ) ); + AC_MEMCPY((char *)p, p + 1, strlen( p ) ); continue; } diff --git a/servers/slapd/acl.c b/servers/slapd/acl.c index 44e4129583..839bac7de6 100644 --- a/servers/slapd/acl.c +++ b/servers/slapd/acl.c @@ -1208,7 +1208,6 @@ aci_set_gather (void *cookie, char *name, struct berval *attr) AciSetCookie *cp = cookie; BVarray bvals = NULL; struct berval bv, ndn; - int i; /* this routine needs to return the bervals instead of * plain strings, since syntax is not known. It should @@ -1299,7 +1298,8 @@ aci_match_set ( cookie.e = e; cookie.conn = conn; cookie.op = op; - rc = (set_filter(aci_set_gather, &cookie, &set, op->o_ndn.bv_val, e->e_ndn, NULL) > 0); + rc = (slap_set_filter(aci_set_gather, &cookie, &set, + op->o_ndn.bv_val, e->e_ndn, NULL) > 0); ch_free(set.bv_val); } return(rc); diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index 0dfb081817..54a4a61e8a 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -277,7 +277,7 @@ LDAPDN_rewrite( LDAPDN *dn, unsigned flags ) char *s = bv.bv_val; ber_str2bv( UTF8normalize( bv.bv_val ? &bv - : &ava->la_value, UTF8_CASEFOLD ), + : &ava->la_value, LDAP_UTF8_CASEFOLD ), 0, 0, &bv ); free( s ); } diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index 7b07619693..6ae8ba512b 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -511,17 +511,17 @@ int entry_encode(Entry *e, struct berval *bv) ptr = (unsigned char *)bv->bv_val; entry_putlen(&ptr, siz); entry_putlen(&ptr, dnlen); - memcpy(ptr, e->e_dn, dnlen); + AC_MEMCPY(ptr, e->e_dn, dnlen); ptr += dnlen; *ptr++ = '\0'; entry_putlen(&ptr, ndnlen); - memcpy(ptr, e->e_ndn, ndnlen); + AC_MEMCPY(ptr, e->e_ndn, ndnlen); ptr += ndnlen; *ptr++ = '\0'; for (a=e->e_attrs; a; a=a->a_next) { entry_putlen(&ptr, a->a_desc->ad_cname.bv_len); - memcpy(ptr, a->a_desc->ad_cname.bv_val, + AC_MEMCPY(ptr, a->a_desc->ad_cname.bv_val, a->a_desc->ad_cname.bv_len); ptr += a->a_desc->ad_cname.bv_len; *ptr++ = '\0'; diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index d452ae5020..8f781d3338 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -303,12 +303,12 @@ nameUIDNormalize( if( uidlen ) { struct berval b2; b2.bv_val = ch_malloc(dnlen + uidlen + 1); - SAFEMEMCPY( b2.bv_val, normalized->bv_val, dnlen ); + AC_MEMCPY( b2.bv_val, normalized->bv_val, dnlen ); /* restore the separator */ *uid = '#'; /* shift the UID */ - SAFEMEMCPY( normalized->bv_val+dnlen, uid, uidlen ); + AC_MEMCPY( normalized->bv_val+dnlen, uid, uidlen ); b2.bv_len = dnlen + uidlen; normalized->bv_val[dnlen+uidlen] = '\0'; free(normalized->bv_val); @@ -567,7 +567,7 @@ UTF8StringNormalize( static SubstringsAssertion * UTF8SubstringsassertionNormalize( SubstringsAssertion *sa, - char casefold ) + unsigned casefold ) { SubstringsAssertion *nsa; int i; @@ -634,7 +634,7 @@ strip8bitChars( while( *++q & 0x80 ) { /* empty */ } - p = memmove(p, q, strlen(q) + 1); + p = AC_MEMCPY(p, q, strlen(q) + 1); } else { p++; } @@ -666,7 +666,7 @@ approxMatch( size_t avlen; /* Yes, this is necessary */ - nval = UTF8normalize( value, UTF8_NOCASEFOLD ); + nval = UTF8normalize( value, LDAP_UTF8_NOCASEFOLD ); if( nval == NULL ) { *matchp = 1; return LDAP_SUCCESS; @@ -675,7 +675,7 @@ approxMatch( /* Yes, this is necessary */ assertv = UTF8normalize( ((struct berval *)assertedValue), - UTF8_NOCASEFOLD ); + LDAP_UTF8_NOCASEFOLD ); if( assertv == NULL ) { ch_free( nval ); *matchp = 1; @@ -781,7 +781,7 @@ approxIndexer( for( j=0; values[j].bv_val != NULL; j++ ) { /* Yes, this is necessary */ - val = UTF8normalize( &values[j], UTF8_NOCASEFOLD ); + val = UTF8normalize( &values[j], LDAP_UTF8_NOCASEFOLD ); strip8bitChars( val ); /* Isolate how many words there are. There will be a key for each */ @@ -796,7 +796,7 @@ approxIndexer( /* Allocate/increase storage to account for new keys */ newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1) * sizeof(struct berval) ); - memcpy( newkeys, keys, keycount * sizeof(struct berval) ); + AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) ); if( keys ) ch_free( keys ); keys = newkeys; @@ -833,7 +833,7 @@ approxFilter( /* Yes, this is necessary */ val = UTF8normalize( ((struct berval *)assertValue), - UTF8_NOCASEFOLD ); + LDAP_UTF8_NOCASEFOLD ); if( val == NULL ) { keys = (struct berval *)ch_malloc( sizeof(struct berval) ); keys[0].bv_val = NULL; @@ -999,7 +999,7 @@ caseExactMatch( { *matchp = UTF8normcmp( value->bv_val, ((struct berval *) assertedValue)->bv_val, - UTF8_NOCASEFOLD ); + LDAP_UTF8_NOCASEFOLD ); return LDAP_SUCCESS; } @@ -1017,10 +1017,11 @@ caseExactIgnoreSubstringsMatch( struct berval left; int i; ber_len_t inlen=0; - char *nav, casefold; + char *nav; + unsigned casefold; casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID ) - ? UTF8_CASEFOLD : UTF8_NOCASEFOLD; + ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD; nav = UTF8normalize( value, casefold ); if( nav == NULL ) { @@ -1172,7 +1173,7 @@ static int caseExactIgnoreIndexer( BVarray *keysp ) { int i; - char casefold; + unsigned casefold; size_t slen, mlen; BVarray keys; HASH_CONTEXT HASHcontext; @@ -1194,7 +1195,7 @@ static int caseExactIgnoreIndexer( mlen = mr->smr_oidlen; casefold = strcmp( mr->smr_oid, caseExactMatchOID ) - ? UTF8_CASEFOLD : UTF8_NOCASEFOLD; + ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD; for( i=0; values[i].bv_val != NULL; i++ ) { struct berval value; @@ -1234,7 +1235,7 @@ static int caseExactIgnoreFilter( void * assertValue, BVarray *keysp ) { - char casefold; + unsigned casefold; size_t slen, mlen; BVarray keys; HASH_CONTEXT HASHcontext; @@ -1248,7 +1249,7 @@ static int caseExactIgnoreFilter( mlen = mr->smr_oidlen; casefold = strcmp( mr->smr_oid, caseExactMatchOID ) - ? UTF8_CASEFOLD : UTF8_NOCASEFOLD; + ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD; ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ), 0, 0, &value ); @@ -1293,7 +1294,7 @@ static int caseExactIgnoreSubstringsIndexer( BVarray values, BVarray *keysp ) { - char casefold; + unsigned casefold; ber_len_t i, nkeys; size_t slen, mlen; BVarray keys; @@ -1315,7 +1316,7 @@ static int caseExactIgnoreSubstringsIndexer( assert( i > 0 ); casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID ) - ? UTF8_CASEFOLD : UTF8_NOCASEFOLD; + ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD; nvalues = ch_malloc( sizeof( struct berval ) * (i+1) ); for( i=0; values[i].bv_val != NULL; i++ ) { @@ -1475,7 +1476,8 @@ static int caseExactIgnoreSubstringsFilter( BVarray *keysp ) { SubstringsAssertion *sa; - char pre, casefold; + char pre; + unsigned casefold; ber_len_t nkeys = 0; size_t slen, mlen, klen; BVarray keys; @@ -1485,7 +1487,7 @@ static int caseExactIgnoreSubstringsFilter( struct berval digest; casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID ) - ? UTF8_CASEFOLD : UTF8_NOCASEFOLD; + ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD; sa = UTF8SubstringsassertionNormalize( assertValue, casefold ); if( sa == NULL ) { @@ -1651,7 +1653,7 @@ caseIgnoreMatch( { *matchp = UTF8normcmp( value->bv_val, ((struct berval *) assertedValue)->bv_val, - UTF8_CASEFOLD ); + LDAP_UTF8_CASEFOLD ); return LDAP_SUCCESS; } @@ -1855,7 +1857,7 @@ integerNormalize( if( negative ) { normalized->bv_val[0] = '-'; } - memcpy( normalized->bv_val + negative, p, len ); + AC_MEMCPY( normalized->bv_val + negative, p, len ); } return LDAP_SUCCESS; @@ -3531,12 +3533,12 @@ certificateExactConvert( X509_free(xcert); - out->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1; + out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ "); out->bv_val = ch_malloc(out->bv_len); p = out->bv_val; AC_MEMCPY(p, serial->bv_val, serial->bv_len); p += serial->bv_len; - AC_MEMCPY(p, " $ ", 3); + AC_MEMCPY(p, " $ ", sizeof(" $ ")-1); p += 3; AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len); p += issuer_dn->bv_len; @@ -4041,7 +4043,7 @@ nisNetgroupTripleValidate( return LDAP_INVALID_SYNTAX; } - for ( p++; ( p < e ) && ( *p != ')' ); p++ ) { + for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) { if ( *p == ',' ) { commas++; if ( commas > 2 ) { diff --git a/servers/slapd/schema_prep.c b/servers/slapd/schema_prep.c index c4a5fcc8ad..ae42f8c1b8 100644 --- a/servers/slapd/schema_prep.c +++ b/servers/slapd/schema_prep.c @@ -21,9 +21,6 @@ int schema_init_done = 0; struct slap_internal_schema slap_schema; -#define objectClassIndexer NULL -#define objectClassFilter NULL - static int objectClassMatch( int *matchp, @@ -68,15 +65,11 @@ objectClassMatch( Debug( LDAP_DEBUG_TRACE, "objectClassMatch(%s,%s) = %d\n", value->bv_val, a->bv_val, *matchp ); #endif - #endif return LDAP_SUCCESS; } -#define structuralObjectClassIndexer NULL -#define structuralObjectClassFilter NULL - static int structuralObjectClassMatch( int *matchp, @@ -144,11 +137,10 @@ static struct slap_schema_ad_map { size_t ssam_offset; } ad_map[] = { { "objectClass", - objectClassMatch, objectClassIndexer, objectClassFilter, + objectClassMatch, NULL, NULL, offsetof(struct slap_internal_schema, si_ad_objectClass) }, { "structuralObjectClass", - structuralObjectClassMatch, - structuralObjectClassIndexer, structuralObjectClassFilter, + structuralObjectClassMatch, NULL, NULL, offsetof(struct slap_internal_schema, si_ad_structuralObjectClass) }, /* user entry operational attributes */ @@ -225,7 +217,7 @@ static AttributeType slap_at_undefined = { { "1.1.1", NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 1, 3 }, /* LDAPAttributeType */ - { sizeof( "UNDEFINED" ) - 1, "UNDEFINED" }, /* cname */ + { sizeof("UNDEFINED")-1, "UNDEFINED" }, /* cname */ NULL, /* sup */ NULL, /* subtypes */ NULL, NULL, NULL, NULL, /* matching rules */ diff --git a/servers/slapd/schemaparse.c b/servers/slapd/schemaparse.c index d9f6b6c106..5959b003cd 100644 --- a/servers/slapd/schemaparse.c +++ b/servers/slapd/schemaparse.c @@ -116,16 +116,15 @@ find_oidm(char *oid) if( pos ) { int suflen = strlen(oid + pos); - char *new = ch_malloc( om->som_oid.bv_len + char *tmp = ch_malloc( om->som_oid.bv_len + suflen + 1); - strcpy(new, om->som_oid.bv_val); - + strcpy(tmp, om->som_oid.bv_val); if( suflen ) { suflen = om->som_oid.bv_len; - new[suflen++] = '.'; - strcpy(new+suflen, oid+pos+1); + tmp[suflen++] = '.'; + strcpy(tmp+suflen, oid+pos+1); } - return new; + return tmp; } } } diff --git a/servers/slapd/search.c b/servers/slapd/search.c index 86ecc786db..435417b071 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -30,7 +30,6 @@ do_search( Connection *conn, /* where to send results */ Operation *op /* info about the op to which we're responding */ ) { - int i; ber_int_t scope, deref, attrsonly; ber_int_t sizelimit, timelimit; struct berval base = { 0, NULL }; @@ -129,9 +128,10 @@ do_search( "do_search \"%s\" %d %d %d %d %d\n", base.bv_val, scope, deref, sizelimit, timelimit, attrsonly )); #else - Debug( LDAP_DEBUG_ARGS, "SRCH \"%s\" %d %d", base.bv_val, scope, deref ); - Debug( LDAP_DEBUG_ARGS, " %d %d %d\n", sizelimit, timelimit, - attrsonly); + Debug( LDAP_DEBUG_ARGS, "SRCH \"%s\" %d %d", + base.bv_val, scope, deref ); + Debug( LDAP_DEBUG_ARGS, " %d %d %d\n", + sizelimit, timelimit, attrsonly); #endif /* filter - returns a "normalized" version */ diff --git a/servers/slapd/sets.c b/servers/slapd/sets.c index 5effb4b134..4f2f617d34 100644 --- a/servers/slapd/sets.c +++ b/servers/slapd/sets.c @@ -13,12 +13,12 @@ #include "sets.h" static BVarray set_join (BVarray lset, int op, BVarray rset); -static BVarray set_chase (SET_GATHER gatherer, +static BVarray set_chase (SLAP_SET_GATHER gatherer, void *cookie, BVarray set, struct berval *attr, int closure); static int set_samedn (char *dn1, char *dn2); long -set_size (BVarray set) +slap_set_size (BVarray set) { int i; @@ -31,7 +31,7 @@ set_size (BVarray set) } void -set_dispose (BVarray set) +slap_set_dispose (BVarray set) { bvarray_free(set); } @@ -50,15 +50,15 @@ set_join (BVarray lset, int op, BVarray rset) return(ch_calloc(1, sizeof(struct berval))); return(lset); } - set_dispose(lset); + slap_set_dispose(lset); return(rset); } if (rset == NULL || rset->bv_val == NULL) { - set_dispose(rset); + slap_set_dispose(rset); return(lset); } - i = set_size(lset) + set_size(rset) + 1; + i = slap_set_size(lset) + slap_set_size(rset) + 1; set = ch_calloc(i, sizeof(struct berval)); if (set != NULL) { /* set_chase() depends on this routine to @@ -91,7 +91,7 @@ set_join (BVarray lset, int op, BVarray rset) } else { set = lset; lset = NULL; - last = set_size(set) - 1; + last = slap_set_size(set) - 1; for (i = 0; set[i].bv_val; i++) { for (j = 0; rset[j].bv_val; j++) { if (set_samedn(set[i].bv_val, rset[j].bv_val)) @@ -108,13 +108,13 @@ set_join (BVarray lset, int op, BVarray rset) } } - set_dispose(lset); - set_dispose(rset); + slap_set_dispose(lset); + slap_set_dispose(rset); return(set); } static BVarray -set_chase (SET_GATHER gatherer, +set_chase (SLAP_SET_GATHER gatherer, void *cookie, BVarray set, struct berval *attr, int closure) { BVarray vals, nset; @@ -129,7 +129,7 @@ set_chase (SET_GATHER gatherer, return(set); if (attr->bv_len > (sizeof(attrstr) - 1)) { - set_dispose(set); + slap_set_dispose(set); return(NULL); } AC_MEMCPY(attrstr, attr->bv_val, attr->bv_len); @@ -137,7 +137,7 @@ set_chase (SET_GATHER gatherer, nset = ch_calloc(1, sizeof(struct berval)); if (nset == NULL) { - set_dispose(set); + slap_set_dispose(set); return(NULL); } for (i = 0; set[i].bv_val; i++) { @@ -145,7 +145,7 @@ set_chase (SET_GATHER gatherer, if (vals != NULL) nset = set_join(nset, '|', vals); } - set_dispose(set); + slap_set_dispose(set); if (closure) { for (i = 0; nset[i].bv_val; i++) { @@ -192,8 +192,9 @@ set_samedn (char *dn1, char *dn2) } int -set_filter (SET_GATHER gatherer, - void *cookie, struct berval *fbv, char *user, char *this, BVarray *results) +slap_set_filter (SLAP_SET_GATHER gatherer, + void *cookie, struct berval *fbv, + char *user, char *this, BVarray *results) { #define IS_SET(x) ( (long)(x) >= 256 ) #define IS_OP(x) ( (long)(x) < 256 ) @@ -347,8 +348,8 @@ set_filter (SET_GATHER gatherer, } else if (SF_TOP() != (void *)'/') { SF_ERROR(syntax); } else { - SF_POP(); struct berval fb2; + SF_POP(); fb2.bv_val = filter; fb2.bv_len = len; set = set_chase(gatherer, @@ -380,7 +381,7 @@ set_filter (SET_GATHER gatherer, SF_ERROR(syntax); } - rc = set_size(set); + rc = slap_set_size(set); if (results) { *results = set; set = NULL; @@ -388,10 +389,10 @@ set_filter (SET_GATHER gatherer, _error: if (IS_SET(set)) - set_dispose(set); + slap_set_dispose(set); while ((set = SF_POP())) { if (IS_SET(set)) - set_dispose(set); + slap_set_dispose(set); } return(rc); } diff --git a/servers/slapd/sets.h b/servers/slapd/sets.h index eb9cc5dc88..0f2129afb7 100644 --- a/servers/slapd/sets.h +++ b/servers/slapd/sets.h @@ -9,12 +9,14 @@ * also return the syntax or some "comparison cookie" * that is used by set_filter. */ -typedef BVarray (SET_GATHER) (void *cookie, char *name, struct berval *attr); +typedef BVarray (SLAP_SET_GATHER)( + void *cookie, char *name, struct berval *attr); -LDAP_SLAPD_F (long) set_size (BVarray set); -LDAP_SLAPD_F (void) set_dispose (BVarray set); +LDAP_SLAPD_F (long) slap_set_size (BVarray set); +LDAP_SLAPD_F (void) slap_set_dispose (BVarray set); LDAP_SLAPD_F (int) -set_filter (SET_GATHER gatherer, void *cookie, struct berval *filter, - char *user, char *this, BVarray *results); +slap_set_filter (SLAP_SET_GATHER gatherer, + void *cookie, struct berval *filter, + char *user, char *this, BVarray *results); diff --git a/servers/slapd/str2filter.c b/servers/slapd/str2filter.c index d0cd38f1e9..2f68609441 100644 --- a/servers/slapd/str2filter.c +++ b/servers/slapd/str2filter.c @@ -227,29 +227,34 @@ str2simple( const char *str ) return NULL; break; - default: - 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 = ch_calloc( 1, sizeof( SubstringsAssertion ) ); - rc = slap_str2ad( str, &f->f_sub_desc, &text ); - if( rc != LDAP_SUCCESS ) { + default: { + char *nextstar = ldap_pvt_find_wildcard( value ); + if ( nextstar == NULL ) { filter_free( f ); *(value-1) = '='; return NULL; - } - if ( str2subvals( value, f ) != 0 ) { - filter_free( f ); + } else if ( nextstar == '\0' ) { + 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 = ch_calloc( 1, sizeof( SubstringsAssertion ) ); + rc = slap_str2ad( str, &f->f_sub_desc, &text ); + if( rc != LDAP_SUCCESS ) { + filter_free( f ); + *(value-1) = '='; + return NULL; + } + if ( str2subvals( value, f ) != 0 ) { + filter_free( f ); + *(value-1) = '='; + return( NULL ); + } *(value-1) = '='; - return( NULL ); + return( f ); } - *(value-1) = '='; - return( f ); - } - break; + } break; } if ( f->f_choice == LDAP_FILTER_PRESENT ) { @@ -287,6 +292,7 @@ str2subvals( const char *in, Filter *f ) { char *nextstar, *val, *freeme; int gotstar; + int final; #ifdef NEW_LOGGING LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY, @@ -299,26 +305,36 @@ str2subvals( const char *in, Filter *f ) if( in == NULL ) return 0; val = freeme = ch_strdup( in ); - gotstar = 0; + gotstar = final = 0; while ( *val ) { - if ( (nextstar = ldap_pvt_find_wildcard( val )) != NULL ) - *nextstar++ = '\0'; + nextstar = ldap_pvt_find_wildcard( val ); - ldap_pvt_filter_value_unescape( val ); + if ( nextstar == NULL ) { + free( freeme ); + return -1; + } - if ( gotstar == 0 ) { - ber_str2bv( val, 0, 1, &f->f_sub_initial ); + if( *nextstar == '\0' ) { + final = 1; + } else { + gotstar++; + *nextstar = '\0'; + } - } else if ( nextstar == NULL ) { + ldap_pvt_filter_value_unescape( val ); + + if ( final ) { ber_str2bv( val, 0, 1, &f->f_sub_final ); + } else if ( gotstar <= 1 ) { + ber_str2bv( val, 0, 1, &f->f_sub_initial ); + } else { charray_add( (char ***) &f->f_sub_any, (char *) ber_bvstrdup( val ) ); } - gotstar = 1; - val = nextstar; + val = nextstar+1; } free( freeme );