]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_prep.c
Fixes for NO_THREADS
[openldap] / servers / slapd / schema_prep.c
index 406add538614b715b77b5c84ad95e08cbc0372bc..ed5b819b574a475599866408b66741d4c1f6d4f4 100644 (file)
@@ -17,6 +17,8 @@
 #include "ldap_pvt.h"
 #include "ldap_pvt_uc.h"
 
+#define OCDEBUG 0
+
 int schema_init_done = 0;
 
 struct slap_internal_schema slap_schema;
@@ -36,7 +38,7 @@ static int objectClassNormalize(
                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 );
@@ -62,7 +64,7 @@ objectSubClassMatch(
        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 );
@@ -94,7 +96,7 @@ objectSubClassMatch(
                *matchp = !is_object_subclass( asserted, oc );
        }
 
-#if 0
+#if OCDEBUG
 #ifdef NEW_LOGGING
        LDAP_LOG( CONFIG, ENTRY, 
                "< objectSubClassMatch(%s, %s) = %d\n",
@@ -121,30 +123,40 @@ static int objectSubClassIndexer(
        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 );
+       ocvalues[i].bv_val = NULL;
+       ocvalues[i].bv_len = 0;
 
        /* expand values */
        for( i=0; i<noc; i++ ) {
                int j;
-               ObjectClass *oc = oc_bvfind( &values[i] );
+               ObjectClass *oc = oc_bvfind( &ocvalues[i] );
                if( oc == NULL || oc->soc_sups == NULL ) continue;
                
                for( j=0; oc->soc_sups[j] != NULL; j++ ) {
@@ -165,7 +177,7 @@ static int objectSubClassIndexer(
                                        k, ocvalues[k].bv_val, sup->soc_cname.bv_val );
 #endif
 #endif
-                               if( ber_bvcmp( &ocvalues[k], &sup->soc_cname ) == 0 ) {
+                               if( bvmatch( &ocvalues[k], &sup->soc_cname ) ) {
                                        found++;
                                        break;
                                }
@@ -187,7 +199,7 @@ static int objectSubClassIndexer(
                                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",
@@ -219,7 +231,35 @@ static int objectSubClassIndexer(
        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;
@@ -320,7 +360,7 @@ static struct slap_schema_ad_map {
                        "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 */
@@ -331,7 +371,7 @@ static struct slap_schema_ad_map {
                        "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' "
@@ -410,6 +450,7 @@ static struct slap_schema_ad_map {
        { "entryCSN", "( 1.3.6.1.4.1.4203.666.1.7 NAME 'entryCSN' "
                        "DESC 'LCUP/LDUP: change sequence number' "
                        "EQUALITY octetStringMatch "
+                       "ORDERING octetStringOrderingMatch "
                        "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
                        "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
                NULL, SLAP_AT_HIDE,
@@ -479,7 +520,7 @@ static struct slap_schema_ad_map {
                offsetof(struct slap_internal_schema, si_ad_monitorContext) },
        { "vendorName", "( 1.3.6.1.1.4 NAME 'vendorName' "
                        "DESC 'RFC3045: name of implementation vendor' "
-                       "EQUALITY 1.3.6.1.4.1.1466.109.114.1 "
+                       "EQUALITY caseExactMatch "
                        "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
                        "SINGLE-VALUE NO-USER-MODIFICATION "
                        "USAGE dSAOperation )",
@@ -488,7 +529,7 @@ static struct slap_schema_ad_map {
                offsetof(struct slap_internal_schema, si_ad_vendorName) },
        { "vendorVersion", "( 1.3.6.1.1.5 NAME 'vendorVersion' "
                        "DESC 'RFC3045: version of implementation' "
-                       "EQUALITY 1.3.6.1.4.1.1466.109.114.1 "
+                       "EQUALITY caseExactMatch "
                        "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
                        "SINGLE-VALUE NO-USER-MODIFICATION "
                        "USAGE dSAOperation )",
@@ -560,7 +601,7 @@ static struct slap_schema_ad_map {
                        "DESC 'RFC2252: matching rule uses' "
                        "EQUALITY objectIdentifierFirstComponentMatch "
                        "SYNTAX 1.3.6.1.4.1.1466.115.121.1.31 USAGE directoryOperation )",
-               subentryAttribute, SLAP_AT_HIDE,
+               subentryAttribute, 0,
                NULL, NULL, NULL, NULL, NULL,
                offsetof(struct slap_internal_schema, si_ad_matchingRuleUse) },
 
@@ -771,7 +812,7 @@ slap_schema_load( void )
                *synp = syn_find( syn_map[i].sssm_name );
 
                if( *synp == NULL ) {
-                       fprintf( stderr, "slap_schema_check: "
+                       fprintf( stderr, "slap_schema_load: Syntax: "
                                "No syntax \"%s\" defined in schema\n",
                                syn_map[i].sssm_name );
                        return LDAP_INVALID_SYNTAX;
@@ -787,7 +828,7 @@ slap_schema_load( void )
                *mrp = mr_find( mr_map[i].ssmm_name );
 
                if( *mrp == NULL ) {
-                       fprintf( stderr, "slap_schema_check: "
+                       fprintf( stderr, "slap_schema_load: MatchingRule: "
                                "No matching rule \"%s\" defined in schema\n",
                                mr_map[i].ssmm_name );
                        return LDAP_INAPPROPRIATE_MATCHING;
@@ -805,22 +846,22 @@ slap_schema_load( void )
                                &code, &err, LDAP_SCHEMA_ALLOW_ALL );
                        if ( !at ) {
                                fprintf( stderr,
-                                       "slap_schema_load: %s: %s before %s\n",
+                                       "slap_schema_load: AttributeType \"%s\": %s before %s\n",
                                         ad_map[i].ssam_name, ldap_scherr2str(code), err );
                                return code;
                        }
 
                        if ( at->at_oid == NULL ) {
                                fprintf( stderr, "slap_schema_load: "
-                                       "attributeType \"%s\" has no OID\n",
+                                       "AttributeType \"%s\": no OID\n",
                                        ad_map[i].ssam_name );
                                return LDAP_OTHER;
                        }
 
                        code = at_add( at, &err );
                        if ( code ) {
-                               fprintf( stderr, "slap_schema_load: "
-                                       "%s: %s: \"%s\"\n",
+                               fprintf( stderr, "slap_schema_load: AttributeType "
+                                       "\"%s\": %s: \"%s\"\n",
                                         ad_map[i].ssam_name, scherr2str(code), err );
                                return code;
                        }
@@ -837,8 +878,8 @@ slap_schema_load( void )
 
                        rc = slap_str2ad( ad_map[i].ssam_name, adp, &text );
                        if( rc != LDAP_SUCCESS ) {
-                               fprintf( stderr, "slap_schema_check: "
-                                       "No attribute \"%s\" defined in schema\n",
+                               fprintf( stderr, "slap_schema_load: AttributeType \"%s\": "
+                                       "not defined in schema\n",
                                        ad_map[i].ssam_name );
                                return rc;
                        }
@@ -851,25 +892,31 @@ slap_schema_load( void )
                        (*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;
+                               }
                        }
                }
        }
@@ -884,23 +931,23 @@ slap_schema_load( void )
                        oc = ldap_str2objectclass( oc_map[i].ssom_defn, &code, &err,
                                LDAP_SCHEMA_ALLOW_ALL );
                        if ( !oc ) {
-                               fprintf( stderr, "slap_schema_load: "
-                                       "%s: %s before %s\n",
+                               fprintf( stderr, "slap_schema_load: ObjectClass "
+                                       "\"%s\": %s before %s\n",
                                        oc_map[i].ssom_name, ldap_scherr2str(code), err );
                                return code;
                        }
 
                        if ( oc->oc_oid == NULL ) {
-                               fprintf( stderr, "slap_schema_load: "
-                                       "%s: objectclass has no OID\n",
+                               fprintf( stderr, "slap_schema_load: ObjectClass "
+                                       "\"%s\": no OID\n",
                                        oc_map[i].ssom_name );
                                return LDAP_OTHER;
                        }
 
                        code = oc_add(oc,0,&err);
                        if ( code ) {
-                               fprintf( stderr, "slap_schema_load: "
-                                       "%s: %s: \"%s\"\n",
+                               fprintf( stderr, "slap_schema_load: ObjectClass "
+                                       "\"%s\": %s: \"%s\"\n",
                                        oc_map[i].ssom_name, scherr2str(code), err);
                                return code;
                        }
@@ -915,8 +962,8 @@ slap_schema_load( void )
 
                        *ocp = oc_find( oc_map[i].ssom_name );
                        if( *ocp == NULL ) {
-                               fprintf( stderr, "slap_schema_check: "
-                                       "No objectClass \"%s\" defined in schema\n",
+                               fprintf( stderr, "slap_schema_load: "
+                                       "ObjectClass \"%s\": not defined in schema\n",
                                        oc_map[i].ssom_name );
                                return LDAP_OBJECT_CLASS_VIOLATION;
                        }
@@ -942,6 +989,13 @@ slap_schema_check( void )
        /* we should only be called once after schema_init() was called */
        assert( schema_init_done == 1 );
 
+       /*
+        * cycle thru attributeTypes to build matchingRuleUse
+        */
+       if ( matching_rule_use_init() ) {
+               return LDAP_OTHER;
+       }
+
        ++schema_init_done;
        return LDAP_SUCCESS;
 }