Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
        size_t slen, mlen;
        BerVarray keys;
        HASH_CONTEXT   HASHcontext;
        unsigned char   HASHdigest[HASH_BYTES];
-       struct berval *value = (struct berval *) assertValue;
+       struct berval *value = (struct berval *) assertedValue;
        struct berval digest;
        digest.bv_val = HASHdigest;
        digest.bv_len = sizeof(HASHdigest);
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
        char *c;
        BerVarray keys;
 
        /* Yes, this is necessary */
-       val = UTF8bvnormalize( ((struct berval *)assertValue),
+       val = UTF8bvnormalize( ((struct berval *)assertedValue),
                NULL, LDAP_UTF8_APPROX );
        if( val == NULL || val->bv_val == NULL ) {
                keys = (struct berval *)ch_malloc( sizeof(struct berval) );
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
        BerVarray keys;
        keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
 
        /* Yes, this is necessary */
-       s = UTF8normalize( ((struct berval *)assertValue),
+       s = UTF8normalize( ((struct berval *)assertedValue),
                             UTF8_NOCASEFOLD );
        if( s == NULL ) {
                keys[0] = NULL;
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
        unsigned casefold;
        casefold = ( mr != caseExactMatchingRule )
                ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
 
-       UTF8bvnormalize( (struct berval *) assertValue, &value, casefold );
+       UTF8bvnormalize( (struct berval *) assertedValue, &value, casefold );
        /* This usually happens if filter contains bad UTF8 */
        if( value.bv_val == NULL ) {
                keys = ch_malloc( sizeof( struct berval ) );
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
        SubstringsAssertion *sa;
        casefold = ( mr != caseExactSubstringsMatchingRule )
                ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
 
-       sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
+       sa = UTF8SubstringsassertionNormalize( assertedValue, casefold );
        if( sa == NULL ) {
                *keysp = NULL;
                return LDAP_SUCCESS;
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
        size_t slen, mlen;
        slen = syntax->ssyn_oidlen;
        mlen = mr->smr_oidlen;
 
-       integerNormalize( syntax, assertValue, &norm );
+       integerNormalize( syntax, assertedValue, &norm );
 
        keys = ch_malloc( sizeof( struct berval ) * 2 );
 
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
        size_t slen, mlen;
        slen = syntax->ssyn_oidlen;
        mlen = mr->smr_oidlen;
 
-       value = (struct berval *) assertValue;
+       value = (struct berval *) assertedValue;
 
        keys = ch_malloc( sizeof( struct berval ) * 2 );
 
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
-       SubstringsAssertion *sa = assertValue;
+       SubstringsAssertion *sa = assertedValue;
        char pre;
        ber_len_t nkeys = 0;
        size_t slen, mlen, klen;
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
        size_t slen, mlen;
        slen = syntax->ssyn_oidlen;
        mlen = mr->smr_oidlen;
 
-       ber_dupbv( &value, (struct berval *) assertValue );
+       ber_dupbv( &value, (struct berval *) assertedValue );
        ldap_pvt_str2lower( value.bv_val );
 
        keys = ch_malloc( sizeof( struct berval ) * 2 );
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
-       SubstringsAssertion *sa = assertValue;
+       SubstringsAssertion *sa = assertedValue;
        char pre;
        ber_len_t nkeys = 0;
        size_t slen, mlen, klen;
        Syntax *syntax,
        MatchingRule *mr,
        struct berval *prefix,
-       void * assertValue,
+       void * assertedValue,
        BerVarray *keysp )
 {
        BerVarray keys;
        struct berval asserted_serial;
 
-       serial_and_issuer_parse(assertValue,
+       serial_and_issuer_parse(assertedValue,
                                &asserted_serial,
                                NULL);
 
 
 #include "ldap_pvt.h"
 #include "ldap_pvt_uc.h"
 
+#define OCDEBUG 0
+
 int schema_init_done = 0;
 
 struct slap_internal_schema slap_schema;
                ber_dupbv( out, in );
        }
 
-#if 0
+#if OCDEBUG
 #ifdef NEW_LOGGING
        LDAP_LOG( CONFIG, ENTRY, 
                "< objectClassNormalize(%s, %s)\n", in->bv_val, out->bv_val, 0 );
        ObjectClass *oc = oc_bvfind( value );
        ObjectClass *asserted = oc_bvfind( a );
 
-#if 0
+#if OCDEBUG
 #ifdef NEW_LOGGING
        LDAP_LOG( CONFIG, ENTRY, 
                "> objectSubClassMatch(%s, %s)\n", value->bv_val, a->bv_val, 0 );
                *matchp = !is_object_subclass( asserted, oc );
        }
 
-#if 0
+#if OCDEBUG
 #ifdef NEW_LOGGING
        LDAP_LOG( CONFIG, ENTRY, 
                "< objectSubClassMatch(%s, %s) = %d\n",
        BerVarray ocvalues;
        
        for( noc=0; values[noc].bv_val != NULL; noc++ ) {
-#if 0
+               /* just count em */;
+       }
+
+       /* over allocate */
+       ocvalues = ch_malloc( sizeof( struct berval ) * (noc+16) );
+
+       /* copy listed values (and termination) */
+       for( i=0; i<noc; i++ ) {
+               ObjectClass *oc = oc_bvfind( &values[i] );
+               if( oc ) {
+                       ocvalues[i] = oc->soc_cname;
+               } else {
+                       ocvalues[i] = values[i];
+               }
+#if OCDEBUG
 #ifdef NEW_LOGGING
                LDAP_LOG( CONFIG, ENTRY, 
                        "> objectSubClassIndexer(%d, %s)\n",
-                       noc, values[noc].bv_val, 0 );
+                       i, ocvalues[i].bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                        "> objectSubClassIndexer(%d, %s)\n",
-                       noc, values[noc].bv_val, 0 );
+                       i, ocvalues[i].bv_val, 0 );
 #endif
 #endif
-               /* just count em */;
        }
 
-       /* over allocate */
-       ocvalues = ch_malloc( sizeof( struct berval ) * (noc+16) );
-
-       /* copy listed values (and termination) */
-       AC_MEMCPY( ocvalues, values, sizeof( struct berval ) * noc+1 );
-
        /* expand values */
        for( i=0; i<noc; i++ ) {
                int j;
                                ocvalues[noc].bv_len = 0;
                                ocvalues[noc].bv_val = NULL;
 
-#if 0
+#if OCDEBUG
 #ifdef NEW_LOGGING
                                LDAP_LOG( CONFIG, ENTRY, 
                                        "< objectSubClassIndexer(%d, %d, %s)\n",
        return rc;
 }
 
-#define objectSubClassFilter octetStringFilter
+/* Index generation function */
+static int objectSubClassFilter(
+       slap_mask_t use,
+       slap_mask_t flags,
+       Syntax *syntax,
+       MatchingRule *mr,
+       struct berval *prefix,
+       void * assertedValue,
+       BerVarray *keysp )
+{
+#if OCDEBUG
+       struct berval *bv = (struct berval *) assertedValue;
+       ObjectClass *oc = oc_bvfind( bv );
+       if( oc ) {
+               bv = &oc->soc_cname;
+       }
+
+#ifdef NEW_LOGGING
+       LDAP_LOG( CONFIG, ENTRY, 
+               "< objectSubClassFilter(%s)\n", bv->bv_val, 0, 0 );
+#else
+       Debug( LDAP_DEBUG_TRACE, "< objectSubClassFilter(%s)\n",
+               bv->bv_val, 0, 0 );
+#endif
+#endif
+
+       return octetStringFilter( use, flags, syntax, mr,
+               prefix, assertedValue, keysp );
+}
 
 static ObjectClassSchemaCheckFN rootDseObjectClass;
 static ObjectClassSchemaCheckFN aliasObjectClass;
                        "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
                NULL, SLAP_AT_FINAL,
                NULL, objectClassNormalize, objectSubClassMatch,
-                       objectSubClassIndexer, NULL,
+                       objectSubClassIndexer, objectSubClassFilter,
                offsetof(struct slap_internal_schema, si_ad_objectClass) },
 
        /* user entry operational attributes */
                        "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
                NULL, 0,
                NULL, objectClassNormalize, objectSubClassMatch,
-                       objectSubClassIndexer, NULL,
+                       objectSubClassIndexer, objectSubClassFilter,
                offsetof(struct slap_internal_schema, si_ad_structuralObjectClass) },
        { "createTimestamp", "( 2.5.18.1 NAME 'createTimestamp' "
                        "DESC 'RFC2252: time which object was created' "
                        (*adp)->ad_type->sat_flags |= ad_map[i].ssam_flags;
 
                        /* install custom rule routine */
-                       if( ad_map[i].ssam_convert ) {
-                               (*adp)->ad_type->sat_equality->smr_convert
-                                       = ad_map[i].ssam_convert;
-                       }
-                       if( ad_map[i].ssam_normalize ) {
-                               (*adp)->ad_type->sat_equality->smr_normalize
-                                       = ad_map[i].ssam_normalize;
-                       }
-                       if( ad_map[i].ssam_match ) {
-                               (*adp)->ad_type->sat_equality->smr_match
-                                       = ad_map[i].ssam_match;
-                       }
-                       if( ad_map[i].ssam_indexer ) {
-                               (*adp)->ad_type->sat_equality->smr_indexer
-                                       = ad_map[i].ssam_indexer;
-                       }
-                       if( ad_map[i].ssam_filter ) {
-                               (*adp)->ad_type->sat_equality->smr_filter
-                                       = ad_map[i].ssam_filter;
+                       if( ad_map[i].ssam_convert ||
+                               ad_map[i].ssam_normalize ||
+                               ad_map[i].ssam_match ||
+                               ad_map[i].ssam_indexer ||
+                               ad_map[i].ssam_filter )
+                       {
+                               MatchingRule *mr = ch_malloc( sizeof( MatchingRule ) );
+                               *mr = *(*adp)->ad_type->sat_equality;
+                               (*adp)->ad_type->sat_equality = mr;
+                               
+                               if( ad_map[i].ssam_convert ) {
+                                       mr->smr_convert = ad_map[i].ssam_convert;
+                               }
+                               if( ad_map[i].ssam_normalize ) {
+                                       mr->smr_normalize = ad_map[i].ssam_normalize;
+                               }
+                               if( ad_map[i].ssam_match ) {
+                                       mr->smr_match = ad_map[i].ssam_match;
+                               }
+                               if( ad_map[i].ssam_indexer ) {
+                                       mr->smr_indexer = ad_map[i].ssam_indexer;
+                               }
+                               if( ad_map[i].ssam_filter ) {
+                                       mr->smr_filter = ad_map[i].ssam_filter;
+                               }
                        }
                }
        }