]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_init.c
Fix cursor initialization, scope IDs
[openldap] / servers / slapd / schema_init.c
index 16271a6a29f4efa3bd634181785af0881f819f2b..d1e4068a23fcfdec981b9872af0ec0ace50c88ac 100644 (file)
 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
 #define HASH_Final(d,c)                        lutil_HASHFinal(d,c)
 
+#define SLAP_NVALUES 1
+
 #ifdef SLAP_NVALUES
 /* TO BE DELETED */
 #define SLAP_MR_DN_FOLD (0)
 
+#define SLAP_MR_ASSOCIATED(mr, with) \
+       ((mr) == (with) || (mr)->smr_associated == (with))
+
 #define xUTF8StringNormalize NULL
 #define xIA5StringNormalize NULL
 #define xtelephoneNumberNormalize NULL
 #define xintegerNormalize NULL
 #define xnumericStringNormalize NULL
 #define xnameUIDNormalize NULL
+#define xdnNormalize NULL
+
+/* (new) normalization routines */
+#define caseExactIA5Normalize                                          IA5StringNormalize
+#define caseIgnoreIA5Normalize                                         IA5StringNormalize
+#define caseExactNormalize                                                     UTF8StringNormalize
+#define caseIgnoreNormalize                                                    UTF8StringNormalize
+
+#define integerFirstComponentNormalize                         NULL
+#define objectIdentifierNormalize                                      NULL
+#define objectIdentifierFirstComponentNormalize                NULL
 
+#define distinguishedNameNormalize     dnNormalize
 #define distinguishedNameMatch         dnMatch
 #define distinguishedNameIndexer       octetStringIndexer
 #define distinguishedNameFilter                octetStringFilter
 
-#define uniqueMemberMatch                              dnMatch
+#define integerOrderingMatch                   integerMatch
+#define integerFirstComponentMatch             NULL
+#define integerIndexer                         octetStringIndexer
+#define integerFilter                          octetStringFilter
+
+#define generalizedTimeMatch                   caseIgnoreIA5Match
+#define generalizedTimeOrderingMatch   caseIgnoreIA5Match
+
+#define uniqueMemberMatch                      dnMatch /* FIXME! */
 
 #define objectIdentifierMatch  octetStringMatch
 #define objectIdentifierIndexer        octetStringIndexer
 #define objectIdentifierFilter octetStringFilter
 
+#define OpenLDAPaciMatch                                               NULL
+
 #define bitStringMatch                 octetStringMatch
 #define bitStringIndexer               octetStringIndexer
 #define bitStringFilter                        octetStringFilter
 
-#define integerMatch NULL
-#define integerOrderingMatch NULL
-#define integerIndexer NULL
-#define integerFilter NULL
-
-#define generalizedTimeMatch   NULL
-#define generalizedTimeOrderingMatch   NULL
-
 #define caseIgnoreMatch                octetStringMatch
 #define caseIgnoreOrderingMatch                octetStringOrderingMatch
 #define caseIgnoreIndexer      octetStringIndexer
 #define caseIgnoreFilter       octetStringFilter
 
-#define caseIgnoreSubstringsMatch              NULL
-#define caseIgnoreSubstringsIndexer            NULL
-#define caseIgnoreSubstringsFilter             NULL
+#define caseIgnoreSubstringsMatch              octetStringSubstringsMatch
+#define caseIgnoreSubstringsIndexer            octetStringSubstringsIndexer
+#define caseIgnoreSubstringsFilter             octetStringSubstringsFilter
 
 #define caseExactMatch         octetStringMatch
 #define caseExactOrderingMatch         octetStringOrderingMatch
 #define caseExactIndexer       octetStringIndexer
 #define caseExactFilter                octetStringFilter
 
-#define caseExactSubstringsMatch               NULL
-#define caseExactSubstringsIndexer             NULL
-#define caseExactSubstringsFilter              NULL
+#define caseExactSubstringsMatch               octetStringSubstringsMatch
+#define caseExactSubstringsIndexer             octetStringSubstringsIndexer
+#define caseExactSubstringsFilter              octetStringSubstringsFilter
 
 #define caseExactIA5Match              octetStringMatch
 #define caseExactIA5Indexer            octetStringIndexer
 #define caseExactIA5Filter             octetStringFilter
 
-#define caseExactIA5SubstringsMatch                    NULL
-#define caseExactIA5SubstringsIndexer          NULL
-#define caseExactIA5SubstringsFilter           NULL
+#define caseExactIA5SubstringsMatch                    octetStringSubstringsMatch
+#define caseExactIA5SubstringsIndexer          octetStringSubstringsIndexer
+#define caseExactIA5SubstringsFilter           octetStringSubstringsFilter
 
 #define caseIgnoreIA5Match             octetStringMatch
 #define caseIgnoreIA5Indexer   octetStringIndexer
 #define telephoneNumberSubstringsIndexer       caseExactIA5SubstringsIndexer
 #define telephoneNumberSubstringsFilter                caseExactIA5SubstringsFilter
 
+#define booleanIndexer                                 octetStringIndexer
+#define booleanFilter                                  octetStringFilter
 #endif
 
 /* validatation routines */
 #define berValidate                                            blobValidate
 
-/* (new) normalization routines */
-#define caseExactNormalize                                                     NULL
-#define caseExactIA5Normalize                                          NULL
-#define caseIgnoreNormalize                                                    NULL
-#define caseIgnoreIA5Normalize                                         NULL
-#define distinguishedNameNormalize                                     NULL
-#define integerNormalize                                                       NULL
-#define integerFirstComponentNormalize                         NULL
-#define numericStringNormalize                                         NULL
-#define objectIdentifierNormalize                                      NULL
-#define objectIdentifierFirstComponentNormalize                NULL
-#define generalizedTimeNormalize                                       NULL
-#define uniqueMemberNormalize                                          NULL
-#define bitStringNormalize                                                     NULL
-#define telephoneNumberNormalize                                       NULL
-
 /* approx matching rules */
 #ifdef SLAP_NVALUES
 #define directoryStringApproxMatchOID  NULL
 
 #ifndef SLAP_NVALUES
 
+#define xdnNormalize dnNormalize
+
+/* (new) normalization routines */
+#define caseExactNormalize                                                     NULL
+#define caseExactIA5Normalize                                          NULL
+#define caseIgnoreNormalize                                                    NULL
+#define caseIgnoreIA5Normalize                                         NULL
+#define distinguishedNameNormalize                                     NULL
+#define integerNormalize                                                       NULL
+#define integerFirstComponentNormalize                         NULL
+#define numericStringNormalize                                         NULL
+#define objectIdentifierNormalize                                      NULL
+#define objectIdentifierFirstComponentNormalize                NULL
+#define generalizedTimeNormalize                                       NULL
+#define uniqueMemberNormalize                                          NULL
+#define telephoneNumberNormalize                                       NULL
+
+
 /* matching routines */
 #define bitStringMatch                                 octetStringMatch
 #define bitStringIndexer                               octetStringIndexer
 #define objectIdentifierIndexer                        caseIgnoreIA5Indexer
 #define objectIdentifierFilter                 caseIgnoreIA5Filter
 
+#define octetStringSubstringsMatch             NULL
+#define OpenLDAPaciMatch                               NULL
+
 #define generalizedTimeMatch                   caseIgnoreIA5Match
 #define generalizedTimeOrderingMatch   caseIgnoreIA5Match
 
 #define telephoneNumberFilter                          caseIgnoreIA5Filter
 #define telephoneNumberSubstringsIndexer       caseIgnoreIA5SubstringsIndexer
 #define telephoneNumberSubstringsFilter                caseIgnoreIA5SubstringsFilter
+
+#define booleanIndexer                                 octetStringIndexer
+#define booleanFilter                                  octetStringFilter
 #endif
 
 
@@ -458,13 +487,21 @@ nameUIDValidate(
        return rc;
 }
 
-#ifndef SLAP_NVALUES
-
+#ifdef SLAP_NVALUES
+static int
+uniqueMemberNormalize(
+       slap_mask_t usage,
+       Syntax *syntax,
+       MatchingRule *mr,
+       struct berval *val,
+       struct berval *normalized )
+#else
 static int
 xnameUIDNormalize(
        Syntax *syntax,
        struct berval *val,
        struct berval *normalized )
+#endif
 {
        struct berval out;
        int rc;
@@ -520,7 +557,6 @@ xnameUIDNormalize(
        return LDAP_SUCCESS;
 }
 
-#endif
 /*
  * Handling boolean syntax and matching is quite rigid.
  * A more flexible approach would be to allow a variety
@@ -569,9 +605,10 @@ LDAP/X.500 string syntax / matching rules have a few oddities.  This
 comment attempts to detail how slapd(8) treats them.
 
 Summary:
-  StringSyntax         X.500   LDAP    Matching
+  StringSyntax         X.500   LDAP    Matching/Comments
   DirectoryString      CHOICE  UTF8    i/e + ignore insignificant spaces
   PrintableString      subset  subset  i/e + ignore insignificant spaces
+  PrintableString      subset  subset  i/e + ignore insignificant spaces
   NumericString                subset  subset  ignore all spaces
   IA5String                    ASCII   ASCII   i/e + ignore insignificant spaces
   TeletexString                T.61    T.61    i/e + ignore insignificant spaces
@@ -588,6 +625,7 @@ Directory String -
   must be non-empty.
 
   In LDAPv3, a directory string is a UTF-8 encoded UCS string.
+  A directory string cannot be zero length.
 
   For matching, there are both case ignore and exact rules.  Both
   also require that "insignificant" spaces be ignored.
@@ -643,7 +681,10 @@ UTF8StringValidate(
        int len;
        unsigned char *u = in->bv_val;
 
-       if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
+       if( in->bv_len == 0 && syntax == slap_schema.si_syn_directoryString ) {
+               /* directory strings cannot be empty */
+               return LDAP_INVALID_SYNTAX;
+       }
 
        for( count = in->bv_len; count > 0; count-=len, u+=len ) {
                /* get the length indicated by the first byte */
@@ -683,12 +724,80 @@ UTF8StringValidate(
                if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
        }
 
-       if( count != 0 ) return LDAP_INVALID_SYNTAX;
+       if( count != 0 ) {
+               return LDAP_INVALID_SYNTAX;
+       }
 
        return LDAP_SUCCESS;
 }
 
-#ifndef SLAP_NVALUES
+#ifdef SLAP_NVALUES
+static int
+UTF8StringNormalize(
+       slap_mask_t use,
+       Syntax *syntax,
+       MatchingRule *mr,
+       struct berval *val,
+       struct berval *normalized )
+{
+       struct berval tmp, nvalue;
+       int flags;
+       int i, wasspace;
+
+       if( val->bv_val == NULL ) {
+               /* assume we're dealing with a syntax (e.g., UTF8String)
+                * which allows empty strings
+                */
+               normalized->bv_len = 0;
+               normalized->bv_val = NULL;
+               return LDAP_SUCCESS;
+       }
+
+       flags = SLAP_MR_ASSOCIATED(mr, slap_schema.si_mr_caseExactMatch )
+               ? LDAP_UTF8_NOCASEFOLD : LDAP_UTF8_CASEFOLD;
+       flags |= ( ( use & SLAP_MR_EQUALITY_APPROX ) == SLAP_MR_EQUALITY_APPROX )
+               ? LDAP_UTF8_APPROX : 0;
+
+       val = UTF8bvnormalize( val, &tmp, flags );
+       if( val == NULL ) {
+               return LDAP_OTHER;
+       }
+       
+       /* collapse spaces (in place) */
+       nvalue.bv_len = 0;
+       nvalue.bv_val = tmp.bv_val;
+
+       wasspace=1; /* trim leading spaces */
+       for( i=0; i<tmp.bv_len; i++) {
+               if ( ASCII_SPACE( tmp.bv_val[i] )) {
+                       if( wasspace++ == 0 ) {
+                               /* trim repeated spaces */
+                               nvalue.bv_val[nvalue.bv_len++] = tmp.bv_val[i];
+                       }
+               } else {
+                       wasspace = 0;
+                       nvalue.bv_val[nvalue.bv_len++] = tmp.bv_val[i];
+               }
+       }
+
+       if( nvalue.bv_len ) {
+               if( wasspace ) {
+                       /* last character was a space, trim it */
+                       --nvalue.bv_len;
+               }
+               nvalue.bv_val[nvalue.bv_len] = '\0';
+
+       } else {
+               /* string of all spaces is treated as one space */
+               nvalue.bv_val[0] = ' ';
+               nvalue.bv_val[1] = '\0';
+               nvalue.bv_len = 1;
+       }
+
+       *normalized = nvalue;
+       return LDAP_SUCCESS;
+}
+#else
 
 static int
 xUTF8StringNormalize(
@@ -1488,10 +1597,16 @@ static int caseExactIgnoreFilter(
        *keysp = keys;
        return LDAP_SUCCESS;
 }
+#endif
 
 /* Substrings Index generation function */
-static int caseExactIgnoreSubstringsIndexer(
-       slap_mask_t use,
+static int
+#ifdef SLAP_NVALUES
+octetStringSubstringsIndexer
+#else
+caseExactIgnoreSubstringsIndexer
+#endif
+       ( slap_mask_t use,
        slap_mask_t flags,
        Syntax *syntax,
        MatchingRule *mr,
@@ -1499,11 +1614,13 @@ static int caseExactIgnoreSubstringsIndexer(
        BerVarray values,
        BerVarray *keysp )
 {
-       unsigned casefold, wasspace;
        ber_len_t i, j, nkeys;
        size_t slen, mlen;
        BerVarray keys;
+#ifndef SLAP_NVALUES
        BerVarray tvalues, nvalues;
+       unsigned casefold, wasspace;
+#endif
 
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
@@ -1511,8 +1628,7 @@ static int caseExactIgnoreSubstringsIndexer(
        digest.bv_val = HASHdigest;
        digest.bv_len = sizeof(HASHdigest);
 
-       nkeys=0;
-
+#ifndef SLAP_NVALUES
        for( i=0; values[i].bv_val != NULL; i++ ) {
                /* empty - just count them */
        }
@@ -1558,6 +1674,9 @@ static int caseExactIgnoreSubstringsIndexer(
        tvalues[i].bv_val = NULL;
        nvalues[i].bv_val = NULL;
        values = nvalues;
+#endif
+
+       nkeys=0;
 
        for( i=0; values[i].bv_val != NULL; i++ ) {
                /* count number of indices to generate */
@@ -1593,8 +1712,10 @@ static int caseExactIgnoreSubstringsIndexer(
        if( nkeys == 0 ) {
                /* no keys to generate */
                *keysp = NULL;
+#ifndef SLAP_NVALUES
                ber_bvarray_free( tvalues );
                ch_free( nvalues );
+#endif
                return LDAP_SUCCESS;
        }
 
@@ -1695,14 +1816,21 @@ static int caseExactIgnoreSubstringsIndexer(
                *keysp = NULL;
        }
 
+#ifndef SLAP_NVALUES
        ber_bvarray_free( tvalues );
        ch_free( nvalues );
+#endif
 
        return LDAP_SUCCESS;
 }
 
-static int caseExactIgnoreSubstringsFilter(
-       slap_mask_t use,
+static int
+#ifdef SLAP_NVALUES
+octetStringSubstringsFilter
+#else
+caseExactIgnoreSubstringsFilter
+#endif
+       ( slap_mask_t use,
        slap_mask_t flags,
        Syntax *syntax,
        MatchingRule *mr,
@@ -1721,6 +1849,7 @@ static int caseExactIgnoreSubstringsFilter(
        struct berval *value;
        struct berval digest;
 
+#ifndef SLAP_NVALUES
        casefold = ( mr != slap_schema.si_mr_caseExactSubstringsMatch )
                ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
 
@@ -1729,6 +1858,9 @@ static int caseExactIgnoreSubstringsFilter(
                *keysp = NULL;
                return LDAP_SUCCESS;
        }
+#else
+       sa = (SubstringsAssertion *) assertedValue;
+#endif
 
        if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
                sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
@@ -1754,10 +1886,12 @@ static int caseExactIgnoreSubstringsFilter(
        }
 
        if( nkeys == 0 ) {
+#ifndef SLAP_NVALUES
                if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
                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 );
+#endif
                *keysp = NULL;
                return LDAP_SUCCESS;
        }
@@ -1869,13 +2003,17 @@ static int caseExactIgnoreSubstringsFilter(
                ch_free( keys );
                *keysp = NULL;
        }
+
+#ifndef SLAP_NVALUES
        if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
        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 );
+#endif
 
        return LDAP_SUCCESS;
 }
+#ifndef SLAP_NVALUES
 
 static int
 caseIgnoreMatch(
@@ -1891,13 +2029,23 @@ caseIgnoreMatch(
                LDAP_UTF8_CASEFOLD );
        return LDAP_SUCCESS;
 }
+#endif
        
 /* Remove all spaces and '-' characters */
 static int
+#ifdef SLAP_NVALUES
+telephoneNumberNormalize(
+       slap_mask_t usage,
+       Syntax *syntax,
+       MatchingRule *mr,
+       struct berval *val,
+       struct berval *normalized )
+#else
 xtelephoneNumberNormalize(
        Syntax *syntax,
        struct berval *val,
        struct berval *normalized )
+#endif
 {
        char *p, *q;
 
@@ -1922,7 +2070,6 @@ xtelephoneNumberNormalize(
 
        return LDAP_SUCCESS;
 }
-#endif
 
 static int
 oidValidate(
@@ -1963,8 +2110,6 @@ oidValidate(
        return LDAP_INVALID_SYNTAX;
 }
 
-#ifndef SLAP_NVALUES
-
 static int
 integerMatch(
        int *matchp,
@@ -1983,18 +2128,20 @@ integerMatch(
        /* Skip leading space/sign/zeroes, and get the sign of the *value number */
        v = value->bv_val;
        vlen = value->bv_len;
+
+#ifndef SLAP_NVALUES
        if( mr == slap_schema.si_mr_integerFirstComponentMatch ) {
                char *tmp = memchr( v, '$', vlen );
-               if( tmp )
-                       vlen = tmp - v;
-               while( vlen && ASCII_SPACE( v[vlen-1] ))
-                       vlen--;
+               if( tmp ) vlen = tmp - v;
+               while( vlen && ASCII_SPACE( v[vlen-1] )) vlen--;
+       }
+#endif
+
+       for( ; vlen && ( *v < '1' || '9' < *v ); v++, vlen-- ) { /* ANSI 2.2.1 */
+               if( *v == '-' ) vsign = -1;
        }
-       for( ; vlen && ( *v < '1' || '9' < *v ); v++, vlen-- ) /* ANSI 2.2.1 */
-               if( *v == '-' )
-                       vsign = -1;
-       if( vlen == 0 )
-               vsign = 0;
+
+       if( vlen == 0 ) vsign = 0;
 
        /* Do the same with the *assertedValue number */
        asserted = (struct berval *) assertedValue;
@@ -2019,7 +2166,6 @@ integerMatch(
        return LDAP_SUCCESS;
 }
        
-#endif
 static int
 integerValidate(
        Syntax *syntax,
@@ -2031,6 +2177,7 @@ integerValidate(
 
        if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
                if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
+
        } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
                return LDAP_INVALID_SYNTAX;
        }
@@ -2042,12 +2189,20 @@ integerValidate(
        return LDAP_SUCCESS;
 }
 
-#ifndef SLAP_NVALUES
 static int
+#ifdef SLAP_NVALUES
+integerNormalize(
+       slap_mask_t use,
+       Syntax *syntax,
+       MatchingRule *mr,
+       struct berval *val,
+       struct berval *normalized )
+#else
 xintegerNormalize(
        Syntax *syntax,
        struct berval *val,
        struct berval *normalized )
+#endif
 {
        char *p;
        int negative=0;
@@ -2083,13 +2238,11 @@ xintegerNormalize(
        if( len == 0 ) {
                normalized->bv_val = ch_strdup("0");
                normalized->bv_len = 1;
-       }
-       else {
+
+       else {
                normalized->bv_len = len+negative;
                normalized->bv_val = ch_malloc( normalized->bv_len + 1 );
-               if( negative ) {
-                       normalized->bv_val[0] = '-';
-               }
+               if( negative ) normalized->bv_val[0] = '-';
                AC_MEMCPY( normalized->bv_val + negative, p, len );
                normalized->bv_val[len+negative] = '\0';
        }
@@ -2097,6 +2250,8 @@ xintegerNormalize(
        return LDAP_SUCCESS;
 }
 
+#ifndef SLAP_NVALUES
+
 /* Index generation function */
 static int integerIndexer(
        slap_mask_t use,
@@ -2288,15 +2443,25 @@ IA5StringValidate(
        return LDAP_SUCCESS;
 }
 
-#ifndef SLAP_NVALUES
-
 static int
+#ifdef SLAP_NVALUES
+IA5StringNormalize(
+       slap_mask_t use,
+       Syntax *syntax,
+       MatchingRule *mr,
+       struct berval *val,
+       struct berval *normalized )
+#else
 xIA5StringNormalize(
        Syntax *syntax,
        struct berval *val,
        struct berval *normalized )
+#endif
 {
        char *p, *q;
+#ifdef SLAP_NVALUES
+       int casefold = !SLAP_MR_ASSOCIATED(mr, slap_schema.si_mr_caseExactIA5Match);
+#endif
 
        assert( val->bv_len );
 
@@ -2318,6 +2483,13 @@ xIA5StringNormalize(
                        while ( ASCII_SPACE( *p ) ) {
                                p++;
                        }
+
+#ifdef SLAP_NVALUES
+               } else if ( casefold ) {
+                       /* Most IA5 rules require casefolding */
+                       *q++ = TOLOWER(*p++);
+#endif
+
                } else {
                        *q++ = *p++;
                }
@@ -2351,6 +2523,8 @@ xIA5StringNormalize(
        return LDAP_SUCCESS;
 }
 
+#ifndef SLAP_NVALUES
+
 static int
 caseExactIA5Match(
        int *matchp,
@@ -2373,7 +2547,12 @@ caseExactIA5Match(
 }
 
 static int
-caseExactIA5SubstringsMatch(
+caseExactIA5SubstringsMatch
+#else
+static int
+octetStringSubstringsMatch
+#endif
+(
        int *matchp,
        slap_mask_t flags,
        Syntax *syntax,
@@ -2406,7 +2585,7 @@ caseExactIA5SubstringsMatch(
                        goto done;
                }
 
-               match = strncmp( sub->sa_initial.bv_val, left.bv_val,
+               match = memcmp( sub->sa_initial.bv_val, left.bv_val,
                        sub->sa_initial.bv_len );
 
                if( match != 0 ) {
@@ -2424,7 +2603,7 @@ caseExactIA5SubstringsMatch(
                        goto done;
                }
 
-               match = strncmp( sub->sa_final.bv_val,
+               match = memcmp( sub->sa_final.bv_val,
                        &left.bv_val[left.bv_len - sub->sa_final.bv_len],
                        sub->sa_final.bv_len );
 
@@ -2452,7 +2631,7 @@ retry:
                                continue;
                        }
 
-                       p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
+                       p = memchr( left.bv_val, *sub->sa_any[i].bv_val, left.bv_len );
 
                        if( p == NULL ) {
                                match = 1;
@@ -2475,7 +2654,7 @@ retry:
                                goto done;
                        }
 
-                       match = strncmp( left.bv_val,
+                       match = memcmp( left.bv_val,
                                sub->sa_any[i].bv_val,
                                sub->sa_any[i].bv_len );
 
@@ -2496,6 +2675,8 @@ done:
        return LDAP_SUCCESS;
 }
 
+#ifndef SLAP_NVALUES
+
 /* Index generation function */
 static int caseExactIA5Indexer(
        slap_mask_t use,
@@ -3539,13 +3720,20 @@ numericStringValidate(
        return LDAP_SUCCESS;
 }
 
-#ifndef SLAP_NVALUES
-
 static int
+#ifdef SLAP_NVALUES
+numericStringNormalize(
+       slap_mask_t usage,
+       Syntax *syntax,
+       MatchingRule *mr,
+       struct berval *val,
+       struct berval *normalized )
+#else
 xnumericStringNormalize(
        Syntax *syntax,
        struct berval *val,
        struct berval *normalized )
+#endif
 {
        /* removal all spaces */
        char *p, *q;
@@ -3584,6 +3772,7 @@ xnumericStringNormalize(
        return LDAP_SUCCESS;
 }
 
+#ifndef SLAP_NVALUES
 static int
 objectIdentifierFirstComponentMatch(
        int *matchp,
@@ -4312,13 +4501,20 @@ generalizedTimeValidate(
        return check_time_syntax(in, 0, parts);
 }
 
-#ifndef SLAP_NVALUES
-
 static int
+#ifdef SLAP_NVALUES
+generalizedTimeNormalize(
+       slap_mask_t usage,
+       Syntax *syntax,
+       MatchingRule *mr,
+       struct berval *val,
+       struct berval *normalized )
+#else
 xgeneralizedTimeNormalize(
        Syntax *syntax,
        struct berval *val,
        struct berval *normalized )
+#endif
 {
        int parts[9], rc;
 
@@ -4340,7 +4536,6 @@ xgeneralizedTimeNormalize(
        return LDAP_SUCCESS;
 }
 
-#endif
 static int
 nisNetgroupTripleValidate(
        Syntax *syntax,
@@ -4464,7 +4659,7 @@ static slap_syntax_defs_rec syntax_defs[] = {
        {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
                0, countryStringValidate, xIA5StringNormalize, NULL},
        {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
-               0, dnValidate, dnNormalize2, dnPretty2},
+               0, dnValidate, xdnNormalize, dnPretty2},
        {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
                0, NULL, NULL, NULL},
        {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
@@ -4621,7 +4816,6 @@ char *objectIdentifierFirstComponentMatchSyntaxes[] = {
  * Other matching rules in X.520 that we do not use (yet):
  *
  * 2.5.13.9            numericStringOrderingMatch
- * 2.5.13.19   octetStringSubstringsMatch
  * 2.5.13.25   uTCTimeMatch
  * 2.5.13.26   uTCTimeOrderingMatch
  * 2.5.13.31   directoryStringFirstComponentMatch
@@ -4753,7 +4947,10 @@ static slap_mrule_defs_rec mrule_defs[] = {
        {"( 2.5.13.13 NAME 'booleanMatch' "
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
                SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
-               NULL, NULL, booleanMatch, NULL, NULL, NULL},
+               NULL,
+               NULL, booleanMatch,
+               booleanIndexer, booleanFilter,
+               NULL},
 
        {"( 2.5.13.14 NAME 'integerMatch' "
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
@@ -4774,7 +4971,7 @@ static slap_mrule_defs_rec mrule_defs[] = {
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
                SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
                NULL,
-               bitStringNormalize, bitStringMatch,
+               NULL, bitStringMatch,
                bitStringIndexer, bitStringFilter,
                NULL},
 
@@ -4792,6 +4989,13 @@ static slap_mrule_defs_rec mrule_defs[] = {
                octetStringOrderingMatch, NULL, NULL,
                NULL},
 
+       {"( 2.5.13.19 NAME 'octetStringSubstringsMatch' "
+               "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
+               SLAP_MR_SUBSTR, NULL,
+               NULL, NULL,
+               octetStringSubstringsMatch, NULL, NULL,
+               NULL},
+
        {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
                SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD, NULL,
@@ -4839,7 +5043,7 @@ static slap_mrule_defs_rec mrule_defs[] = {
                "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
                SLAP_MR_ORDERING, NULL,
                NULL,
-               generalizedTimeOrderingMatch, generalizedTimeOrderingMatch,
+               generalizedTimeNormalize, generalizedTimeOrderingMatch,
                NULL, NULL,
                NULL},