]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_init.c
Move backend_syncfreq code down into back-ldbm. Creates new configuration
[openldap] / servers / slapd / schema_init.c
index 0067470fda4344122467bbc96b231ece96b9482a..00c4ca9955f793c1824c1aca09f178d8b1a81021 100644 (file)
@@ -71,7 +71,6 @@
 /* unimplemented matching routines */
 #define caseIgnoreListMatch                            NULL
 #define caseIgnoreListSubstringsMatch  NULL
-#define presentationAddressMatch               NULL
 #define protocolInformationMatch               NULL
 #define integerFirstComponentMatch             NULL
 
 #define integerIndexer                                 caseIgnoreIA5Indexer
 #define integerFilter                                  caseIgnoreIA5Filter
 
+#define telephoneNumberIndexer                 caseIgnoreIA5Indexer
+#define telephoneNumberFilter                  caseIgnoreIA5Filter
+#define telephoneNumberSubstringsIndexer       caseIgnoreIA5SubstringsIndexer
+#define telephoneNumberSubstringsFilter                caseIgnoreIA5SubstringsFilter
+
 static char *strcasechr( const char *str, int c )
 {
        char *lower = strchr( str, TOLOWER(c) );
@@ -238,21 +242,23 @@ dnValidate(
        return rc;
 }
 
-static int
+int
 dnNormalize(
        Syntax *syntax,
        struct berval *val,
        struct berval **normalized )
 {
-       struct berval *out = ber_bvdup( val );
+       struct berval *out;
 
-       if( out->bv_len != 0 ) {
+       if ( val->bv_len != 0 ) {
                char *dn;
 #ifdef USE_DN_NORMALIZE
-               dn = dn_normalize( out->bv_val );
+               out = ber_bvstr( UTF8normalize( val->bv_val, UTF8_CASEFOLD ) );
 #else
-               dn = dn_validate( out->bv_val );
+               out = ber_bvdup( val );
+               ldap_pvt_str2upper( out->bv_val );
 #endif
+               dn = dn_validate( out->bv_val );
 
                if( dn == NULL ) {
                        ber_bvfree( out );
@@ -261,6 +267,8 @@ dnNormalize(
 
                out->bv_val = dn;
                out->bv_len = strlen( dn );
+       } else {
+               out = ber_bvdup( val );
        }
 
        *normalized = out;
@@ -432,6 +440,7 @@ bitStringValidate(
        if( in->bv_len < 3 ) {
                return LDAP_INVALID_SYNTAX;
        }
+
        if( in->bv_val[0] != 'B' ||
                in->bv_val[1] != '\'' ||
                in->bv_val[in->bv_len-1] != '\'' )
@@ -492,60 +501,6 @@ booleanMatch(
 }
 
 #if UTF8MATCH
-static int
-UTF8casecmp(
-       struct berval *right,
-       struct berval *left )
-{
-       ber_len_t r, l;
-       int rlen, llen;
-       ldap_unicode_t ru, lu;
-       ldap_unicode_t ruu, luu;
-
-       for( r=0, l=0;
-               r < right->bv_len && l < left->bv_len;
-               r+=rlen, l+=llen )
-       {
-               /*
-                * XXYYZ: we convert to ucs4 even though -llunicode
-                * expects ucs2 in an unsigned long
-                */
-               ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
-               if( ru == LDAP_UCS4_INVALID ) {
-                       return 1;
-               }
-
-               lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
-               if( lu == LDAP_UCS4_INVALID ) {
-                       return -1;
-               }
-
-               ruu = uctoupper( ru );
-               luu = uctoupper( lu );
-
-               if( ruu > luu ) {
-                       return 1;
-               } else if( luu > ruu ) {
-                       return -1;
-               }
-
-               rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
-               llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
-       }
-
-       if( r < right->bv_len ) {
-               /* less left */
-               return -1;
-       }
-
-       if( l < left->bv_len ) {
-               /* less right */
-               return 1;
-       }
-
-       return 0;
-}
-
 /* case insensitive UTF8 strncmp with offset for second string */
 static int
 UTF8oncasecmp(
@@ -555,8 +510,8 @@ UTF8oncasecmp(
        ber_len_t offset )
 {
        ber_len_t r, l;
-       int rlen, llen;
-       int rslen, lslen;
+       ber_len_t rlen, llen;
+       ber_len_t rslen, lslen;
        ldap_unicode_t ru, lu;
        ldap_unicode_t ruu, luu;
 
@@ -1214,7 +1169,12 @@ int caseExactIndexer(
        mlen = strlen( mr->smr_oid );
 
        for( i=0; values[i] != NULL; i++ ) {
-               struct berval *value = values[i];
+               struct berval *value;
+#if UTF8MATCH
+               value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
+#else
+               value = values[i];
+#endif
 
                HASH_Init( &HASHcontext );
                if( prefix != NULL && prefix->bv_len > 0 ) {
@@ -1229,6 +1189,10 @@ int caseExactIndexer(
                        value->bv_val, value->bv_len );
                HASH_Final( HASHdigest, &HASHcontext );
 
+#if UTF8MATCH
+               ber_bvfree( value );
+#endif
+
                keys[i] = ber_bvdup( &digest );
        }
 
@@ -1259,7 +1223,11 @@ int caseExactFilter(
        slen = strlen( syntax->ssyn_oid );
        mlen = strlen( mr->smr_oid );
 
+#if UTF8MATCH
+        value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val, UTF8_NOCASEFOLD ) );
+#else
        value = (struct berval *) assertValue;
+#endif 
 
        keys = ch_malloc( sizeof( struct berval * ) * 2 );
 
@@ -1279,6 +1247,10 @@ int caseExactFilter(
        keys[0] = ber_bvdup( &digest );
        keys[1] = NULL;
 
+#if UTF8MATCH
+       ber_bvfree( value );
+#endif
+
        *keysp = keys;
        return LDAP_SUCCESS;
 }
@@ -1353,8 +1325,13 @@ int caseExactSubstringsIndexer(
                ber_len_t j,max;
                struct berval *value;
 
+               if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
+
+#if UTF8MATCH
+                value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
+#else
                value = values[i];
-               if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
+#endif
 
                if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
                        ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
@@ -1431,6 +1408,11 @@ int caseExactSubstringsIndexer(
                        }
 
                }
+
+#if UTF8MATCH
+               ber_bvfree( value );
+#endif
+
        }
 
        if( nkeys > 0 ) {
@@ -1504,7 +1486,11 @@ int caseExactSubstringsFilter(
                sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
        {
                pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
+#if UTF8MATCH
+                value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_NOCASEFOLD ) );
+#else
                value = sa->sa_initial;
+#endif
 
                klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
                        ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
@@ -1524,6 +1510,9 @@ int caseExactSubstringsFilter(
                        value->bv_val, klen );
                HASH_Final( HASHdigest, &HASHcontext );
 
+#if UTF8MATCH
+               ber_bvfree( value );
+#endif
                keys[nkeys++] = ber_bvdup( &digest );
        }
 
@@ -1537,7 +1526,11 @@ int caseExactSubstringsFilter(
                                continue;
                        }
 
+#if UTF8MATCH
+                        value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_NOCASEFOLD ) );
+#else
                        value = sa->sa_any[i];
+#endif
 
                        for(j=0;
                                j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
@@ -1560,6 +1553,10 @@ int caseExactSubstringsFilter(
 
                                keys[nkeys++] = ber_bvdup( &digest );
                        }
+
+#if UTF8MATCH
+                       ber_bvfree( value );
+#endif
                }
        }
 
@@ -1567,7 +1564,11 @@ int caseExactSubstringsFilter(
                sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
        {
                pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
+#if UTF8MATCH
+                value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_NOCASEFOLD ) );
+#else
                value = sa->sa_final;
+#endif
 
                klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
                        ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
@@ -1587,6 +1588,9 @@ int caseExactSubstringsFilter(
                        &value->bv_val[value->bv_len-klen], klen );
                HASH_Final( HASHdigest, &HASHcontext );
 
+#if UTF8MATCH
+               ber_bvfree( value );
+#endif
                keys[nkeys++] = ber_bvdup( &digest );
        }
 
@@ -1611,7 +1615,9 @@ caseIgnoreMatch(
        void *assertedValue )
 {
 #if UTF8MATCH
-       *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
+       *matchp = UTF8normcmp( value->bv_val,
+                              ((struct berval *) assertedValue)->bv_val,
+                              UTF8_CASEFOLD );
 #else
        int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
 
@@ -1811,9 +1817,13 @@ int caseIgnoreIndexer(
        mlen = strlen( mr->smr_oid );
 
        for( i=0; values[i] != NULL; i++ ) {
-               struct berval *value = ber_bvdup( values[i] );
+               struct berval *value;
+#if UTF8MATCH
+               value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
+#else
+               value = ber_bvdup( values[i] );
                ldap_pvt_str2upper( value->bv_val );
-
+#endif
                HASH_Init( &HASHcontext );
                if( prefix != NULL && prefix->bv_len > 0 ) {
                        HASH_Update( &HASHcontext,
@@ -1859,8 +1869,12 @@ int caseIgnoreFilter(
        slen = strlen( syntax->ssyn_oid );
        mlen = strlen( mr->smr_oid );
 
+#if UTF8MATCH
+       value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val, UTF8_CASEFOLD ) );
+#else
        value = ber_bvdup( (struct berval *) assertValue );
        ldap_pvt_str2upper( value->bv_val );
+#endif
 
        keys = ch_malloc( sizeof( struct berval * ) * 2 );
 
@@ -1959,8 +1973,12 @@ int caseIgnoreSubstringsIndexer(
 
                if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
 
+#if UTF8MATCH
+               value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
+#else
                value = ber_bvdup( values[i] );
                ldap_pvt_str2upper( value->bv_val );
+#endif
 
                if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
                        ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
@@ -2112,8 +2130,12 @@ int caseIgnoreSubstringsFilter(
                sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
        {
                pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
+#if UTF8MATCH
+               value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_CASEFOLD ) );
+#else
                value = ber_bvdup( sa->sa_initial );
                ldap_pvt_str2upper( value->bv_val );
+#endif
 
                klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
                        ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
@@ -2147,8 +2169,12 @@ int caseIgnoreSubstringsFilter(
                                continue;
                        }
 
+#if UTF8MATCH
+                       value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_CASEFOLD ) );
+#else
                        value = ber_bvdup( sa->sa_any[i] );
                        ldap_pvt_str2upper( value->bv_val );
+#endif
 
                        for(j=0;
                                j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
@@ -2180,8 +2206,12 @@ int caseIgnoreSubstringsFilter(
                sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
        {
                pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
+#if UTF8MATCH
+               value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_CASEFOLD ) );
+#else
                value = ber_bvdup( sa->sa_final );
                ldap_pvt_str2upper( value->bv_val );
+#endif
 
                klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
                        ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
@@ -2325,8 +2355,6 @@ countryStringValidate(
        Syntax *syntax,
        struct berval *val )
 {
-       ber_len_t i;
-
        if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
 
        if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
@@ -3615,8 +3643,6 @@ numericStringValidate(
 {
        ber_len_t i;
 
-       /* disallow empty numeric strings */
-
        for(i=0; i < in->bv_len; i++) {
                if( !SLAP_NUMERIC(in->bv_val[i]) ) {
                        return LDAP_INVALID_SYNTAX;
@@ -3651,7 +3677,7 @@ numericStringNormalize(
                }
        }
 
-       assert( newval->bv_val < p );
+       assert( newval->bv_val <= p );
        assert( q <= p );
 
        /* null terminate */
@@ -4253,7 +4279,7 @@ struct syntax_defs_rec syntax_defs[] = {
 
        /* OpenLDAP Experimental Syntaxes */
        {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
-               0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
+               0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
                NULL, NULL},
        {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
                0, NULL, NULL, NULL},
@@ -4452,21 +4478,25 @@ struct mrule_defs_rec mrule_defs[] = {
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
                SLAP_MR_EQUALITY | SLAP_MR_EXT,
                NULL, NULL,
-               telephoneNumberMatch, NULL, NULL,
+               telephoneNumberMatch,
+               telephoneNumberIndexer,
+               telephoneNumberFilter,
                NULL},
 
        {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
                SLAP_MR_SUBSTR | SLAP_MR_EXT,
                NULL, NULL,
-               telephoneNumberSubstringsMatch, NULL, NULL,
+               telephoneNumberSubstringsMatch,
+               telephoneNumberSubstringsIndexer,
+               telephoneNumberSubstringsFilter,
                NULL},
 
        {"( 2.5.13.22 NAME 'presentationAddressMatch' "
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
                SLAP_MR_EQUALITY | SLAP_MR_EXT,
                NULL, NULL,
-               presentationAddressMatch, NULL, NULL,
+               NULL, NULL, NULL,
                NULL},
 
        {"( 2.5.13.23 NAME 'uniqueMemberMatch' "