]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_init.c
add Time subsystem
[openldap] / servers / slapd / schema_init.c
index cfd141b2fcba882a814eb77db8dc1ce76c30d46d..a6e68b5316721997755004752f622fd9712cbcb8 100644 (file)
 #define caseExactMatchOID                      "2.5.13.5"
 #define caseExactSubstringsMatchOID            "2.5.13.7"
 
-static char *strcasechr( const char *str, int c )
+static char *bvcasechr( struct berval *bv, int c, ber_len_t *len )
 {
-       char *lower = strchr( str, TOLOWER(c) );
-       char *upper = strchr( str, TOUPPER(c) );
+       ber_len_t i;
+       int lower = TOLOWER( c );
+       int upper = TOUPPER( c );
 
-       if( lower && upper ) {
-               return lower < upper ? lower : upper;
-       } else if ( lower ) {
-               return lower;
-       } else {
-               return upper;
+       if( c == 0 ) return NULL;
+       
+       for( i=0; i < bv->bv_len; i++ ) {
+               if( upper == bv->bv_val[i] || lower == bv->bv_val[i] ) {
+                       *len = i;
+                       return &bv->bv_val[i];
+               }
        }
+
+       return NULL;
 }
 
 static int
@@ -123,12 +127,12 @@ static int octetStringIndexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        int i;
        size_t slen, mlen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval digest;
@@ -179,10 +183,10 @@ static int octetStringFilter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
        size_t slen, mlen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval *value = (struct berval *) assertValue;
@@ -471,10 +475,36 @@ UTF8StringValidate(
 
        for( count = in->bv_len; count > 0; count-=len, u+=len ) {
                /* get the length indicated by the first byte */
-               len = LDAP_UTF8_CHARLEN( u );
+               len = LDAP_UTF8_CHARLEN2( u, len );
 
-               /* should not be zero */
-               if( len == 0 ) return LDAP_INVALID_SYNTAX;
+               /* very basic checks */
+               switch( len ) {
+                       case 6:
+                               if( (u[5] & 0xC0) != 0x80 ) {
+                                       return LDAP_INVALID_SYNTAX;
+                               }
+                       case 5:
+                               if( (u[4] & 0xC0) != 0x80 ) {
+                                       return LDAP_INVALID_SYNTAX;
+                               }
+                       case 4:
+                               if( (u[3] & 0xC0) != 0x80 ) {
+                                       return LDAP_INVALID_SYNTAX;
+                               }
+                       case 3:
+                               if( (u[2] & 0xC0 )!= 0x80 ) {
+                                       return LDAP_INVALID_SYNTAX;
+                               }
+                       case 2:
+                               if( (u[1] & 0xC0) != 0x80 ) {
+                                       return LDAP_INVALID_SYNTAX;
+                               }
+                       case 1:
+                               /* CHARLEN already validated it */
+                               break;
+                       default:
+                               return LDAP_INVALID_SYNTAX;
+               }
 
                /* make sure len corresponds with the offset
                        to the next character */
@@ -612,7 +642,7 @@ UTF8SubstringsassertionNormalize(
 
 err:
        if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
-       if ( nsa->sa_any )bvarray_free( nsa->sa_any );
+       if ( nsa->sa_any )ber_bvarray_free( nsa->sa_any );
        if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
        ch_free( nsa );
        return NULL;
@@ -771,13 +801,13 @@ approxIndexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        char *val, *c;
        int i,j, len, wordcount, keycount=0;
        struct berval *newkeys;
-       BVarray keys=NULL;
+       BerVarray keys=NULL;
 
        for( j=0; values[j].bv_val != NULL; j++ ) {
                /* Yes, this is necessary */
@@ -825,11 +855,11 @@ approxFilter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
        char *val, *c;
        int i, count, len;
-       BVarray keys;
+       BerVarray keys;
 
        /* Yes, this is necessary */
        val = UTF8normalize( ((struct berval *)assertValue),
@@ -923,11 +953,11 @@ approxIndexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        int i;
-       BVarray *keys;
+       BerVarray *keys;
        char *s;
 
        for( i=0; values[i].bv_val != NULL; i++ ) {
@@ -963,9 +993,9 @@ approxFilter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
-       BVarray keys;
+       BerVarray keys;
        char *s;
 
        keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
@@ -1110,7 +1140,6 @@ retry:
                        }
 
                        idx = p - left.bv_val;
-                       assert( idx < left.bv_len );
 
                        if( idx >= left.bv_len ) {
                                /* this shouldn't happen */
@@ -1118,7 +1147,7 @@ retry:
                                if ( sub->sa_final.bv_val )
                                        ch_free( sub->sa_final.bv_val );
                                if ( sub->sa_any )
-                                       bvarray_free( sub->sa_any );
+                                       ber_bvarray_free( sub->sa_any );
                                if ( sub->sa_initial.bv_val )
                                        ch_free( sub->sa_initial.bv_val );
                                ch_free( sub );
@@ -1154,7 +1183,7 @@ done:
        free( nav );
        if( sub != NULL ) {
                if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
-               if ( sub->sa_any ) bvarray_free( sub->sa_any );
+               if ( sub->sa_any ) ber_bvarray_free( sub->sa_any );
                if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
                ch_free( sub );
        }
@@ -1169,13 +1198,13 @@ static int caseExactIgnoreIndexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        int i;
        unsigned casefold;
        size_t slen, mlen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval digest;
@@ -1233,11 +1262,11 @@ static int caseExactIgnoreFilter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
        unsigned casefold;
        size_t slen, mlen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval value;
@@ -1291,14 +1320,14 @@ static int caseExactIgnoreSubstringsIndexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        unsigned casefold;
        ber_len_t i, nkeys;
        size_t slen, mlen;
-       BVarray keys;
-       BVarray nvalues;
+       BerVarray keys;
+       BerVarray nvalues;
 
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
@@ -1360,7 +1389,7 @@ static int caseExactIgnoreSubstringsIndexer(
        if( nkeys == 0 ) {
                /* no keys to generate */
                *keysp = NULL;
-               bvarray_free( nvalues );
+               ber_bvarray_free( nvalues );
                return LDAP_SUCCESS;
        }
 
@@ -1461,7 +1490,7 @@ static int caseExactIgnoreSubstringsIndexer(
                *keysp = NULL;
        }
 
-       bvarray_free( nvalues );
+       ber_bvarray_free( nvalues );
 
        return LDAP_SUCCESS;
 }
@@ -1473,14 +1502,14 @@ static int caseExactIgnoreSubstringsFilter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
        SubstringsAssertion *sa;
        char pre;
        unsigned casefold;
        ber_len_t nkeys = 0;
        size_t slen, mlen, klen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval *value;
@@ -1520,7 +1549,7 @@ static int caseExactIgnoreSubstringsFilter(
 
        if( nkeys == 0 ) {
                if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
-               if ( sa->sa_any ) bvarray_free( sa->sa_any );
+               if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
                if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
                ch_free( sa );
                *keysp = NULL;
@@ -1635,7 +1664,7 @@ static int caseExactIgnoreSubstringsFilter(
                *keysp = NULL;
        }
        if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
-       if ( sa->sa_any ) bvarray_free( sa->sa_any );
+       if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
        if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
        ch_free( sa );
 
@@ -1870,11 +1899,11 @@ static int integerIndexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        int i;
-       BVarray keys;
+       BerVarray keys;
 
        /* we should have at least one value at this point */
        assert( values != NULL && values[0].bv_val != NULL );
@@ -1902,9 +1931,9 @@ static int integerFilter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
-       BVarray keys;
+       BerVarray keys;
 
        keys = ch_malloc( sizeof( struct berval ) * 2 );
        integerNormalize( syntax, assertValue, &keys[0] );
@@ -2141,7 +2170,6 @@ retry:
                        }
 
                        idx = p - left.bv_val;
-                       assert( idx < left.bv_len );
 
                        if( idx >= left.bv_len ) {
                                /* this shouldn't happen */
@@ -2185,12 +2213,12 @@ static int caseExactIA5Indexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        int i;
        size_t slen, mlen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval digest;
@@ -2241,10 +2269,10 @@ static int caseExactIA5Filter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
        size_t slen, mlen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval *value;
@@ -2286,12 +2314,12 @@ static int caseExactIA5SubstringsIndexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        ber_len_t i, nkeys;
        size_t slen, mlen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval digest;
@@ -2447,13 +2475,13 @@ static int caseExactIA5SubstringsFilter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
        SubstringsAssertion *sa = assertValue;
        char pre;
        ber_len_t nkeys = 0;
        size_t slen, mlen, klen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval *value;
@@ -2698,16 +2726,14 @@ retry:
                                continue;
                        }
 
-                       p = strcasechr( left.bv_val, *sub->sa_any[i].bv_val );
+                       p = bvcasechr( &left, *sub->sa_any[i].bv_val, &idx );
 
                        if( p == NULL ) {
                                match = 1;
                                goto done;
                        }
 
-                       idx = p - left.bv_val;
                        assert( idx < left.bv_len );
-
                        if( idx >= left.bv_len ) {
                                /* this shouldn't happen */
                                return LDAP_OTHER;
@@ -2751,12 +2777,12 @@ static int caseIgnoreIA5Indexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        int i;
        size_t slen, mlen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval digest;
@@ -2811,10 +2837,10 @@ static int caseIgnoreIA5Filter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
        size_t slen, mlen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval value;
@@ -2860,12 +2886,12 @@ static int caseIgnoreIA5SubstringsIndexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        ber_len_t i, nkeys;
        size_t slen, mlen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval digest;
@@ -3025,13 +3051,13 @@ static int caseIgnoreIA5SubstringsFilter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
        SubstringsAssertion *sa = assertValue;
        char pre;
        ber_len_t nkeys = 0;
        size_t slen, mlen, klen;
-       BVarray keys;
+       BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
        struct berval value;
@@ -3684,11 +3710,11 @@ static int certificateExactIndexer(
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       BVarray values,
-       BVarray *keysp )
+       BerVarray values,
+       BerVarray *keysp )
 {
        int i;
-       BVarray keys;
+       BerVarray keys;
        X509 *xcert;
        unsigned char *p;
        struct berval * serial;
@@ -3752,9 +3778,9 @@ static int certificateExactFilter(
        MatchingRule *mr,
        struct berval *prefix,
        void * assertValue,
-       BVarray *keysp )
+       BerVarray *keysp )
 {
-       BVarray keys;
+       BerVarray keys;
        struct berval *asserted_serial;
        struct berval *asserted_issuer_dn;