]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_check.c
ITS#2864 don't use sl_mark/release.
[openldap] / servers / slapd / schema_check.c
index 2aeafa3abd17bb2f00edba7052b9ce537a52d226..8f33e1516f2180b5488d7ffe59dff2235718bcd2 100644 (file)
@@ -1,8 +1,17 @@
 /* schema_check.c - routines to enforce schema definitions */
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 #include "portable.h"
@@ -42,10 +51,8 @@ entry_schema_check(
 {
        Attribute       *a, *asc, *aoc;
        ObjectClass *sc, *oc;
-#ifdef SLAP_EXTENDED_SCHEMA
        AttributeType *at;
        ContentRule *cr;
-#endif
        int     rc, i;
        struct berval nsc;
        AttributeDescription *ad_structuralObjectClass
@@ -56,6 +63,10 @@ entry_schema_check(
        int subentry = is_entry_subentry( e );
        int collectiveSubentry = 0;
 
+       if ( SLAP_NO_SCHEMA_CHECK( be )) {
+               return LDAP_SUCCESS;
+       }
+
        if( subentry ) {
                collectiveSubentry = is_entry_collectiveAttributeSubentry( e );
        }
@@ -225,16 +236,15 @@ entry_schema_check(
        }
 
        /* naming check */
-        if ( !is_entry_objectclass ( e, slap_schema.si_oc_glue, 0 ) ) {
-                rc = entry_naming_check( e, text, textbuf, textlen );
-                if( rc != LDAP_SUCCESS ) {
-                        return rc;
-                }
-        } else {
-                       /* Glue Entry */
-        }
-
-#ifdef SLAP_EXTENDED_SCHEMA
+       if ( !is_entry_objectclass ( e, slap_schema.si_oc_glue, 0 ) ) {
+               rc = entry_naming_check( e, text, textbuf, textlen );
+               if( rc != LDAP_SUCCESS ) {
+                       return rc;
+               }
+       } else {
+               /* Glue Entry */
+       }
+
        /* find the content rule for the structural class */
        cr = cr_find( sc->soc_oid );
 
@@ -318,7 +328,6 @@ entry_schema_check(
                        }
                }
        }
-#endif /* SLAP_EXTENDED_SCHEMA */
 
        /* check that the entry has required attrs for each oc */
        for ( i = 0; aoc->a_vals[i].bv_val != NULL; i++ ) {
@@ -430,7 +439,6 @@ entry_schema_check(
                } else if ( oc->soc_kind != LDAP_SCHEMA_STRUCTURAL || oc == sc ) {
                        char *s;
 
-#ifdef SLAP_EXTENDED_SCHEMA
                        if( oc->soc_kind == LDAP_SCHEMA_AUXILIARY ) {
                                int k;
 
@@ -471,7 +479,6 @@ entry_schema_check(
                                        return LDAP_OBJECT_CLASS_VIOLATION;
                                }
                        }
-#endif /* SLAP_EXTENDED_SCHEMA */
 
                        s = oc_check_required( e, oc, &aoc->a_vals[i] );
                        if (s != NULL) {
@@ -505,7 +512,6 @@ entry_schema_check(
        for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
                int ret;
 
-#ifdef SLAP_EXTENDED_SCHEMA
                ret = LDAP_OBJECT_CLASS_VIOLATION;
 
                if( cr && cr->scr_required ) {
@@ -527,7 +533,6 @@ entry_schema_check(
                }
 
                if( ret != LDAP_SUCCESS ) 
-#endif /* SLAP_EXTENDED_SCHEMA */
                {
                        ret = oc_check_allowed( a->a_desc->ad_type, aoc->a_vals, sc );
                }
@@ -723,7 +728,7 @@ int structural_class(
                                        if( xc == NULL ) {
                                                snprintf( textbuf, textlen,
                                                        "unrecognized objectClass '%s'",
-                                                       ocs[i].bv_val );
+                                                       ocs[j].bv_val );
                                                *text = textbuf;
                                                return LDAP_OBJECT_CLASS_VIOLATION;
                                        }
@@ -845,40 +850,98 @@ entry_naming_check(
                Attribute *attr;
                const char *errtext;
 
+               if( ava->la_flags & LDAP_AVA_BINARY ) {
+                       snprintf( textbuf, textlen, 
+                               "value of naming attribute '%s' in unsupported BER form",
+                               ava->la_attr.bv_val );
+                       rc = LDAP_NAMING_VIOLATION;
+               }
+
                rc = slap_bv2ad( &ava->la_attr, &desc, &errtext );
                if ( rc != LDAP_SUCCESS ) {
                        snprintf( textbuf, textlen, "%s (in RDN)", errtext );
                        break;
                }
 
-               /* find the naming attribute */
-               attr = attr_find( e->e_attrs, desc );
-               if ( attr == NULL ) {
+               if( desc->ad_type->sat_usage ) {
                        snprintf( textbuf, textlen, 
-                               "naming attribute '%s' is not present in entry",
+                               "naming attribute '%s' is operational",
+                               ava->la_attr.bv_val );
+                       rc = LDAP_NAMING_VIOLATION;
+                       break;
+               }
+               if( desc->ad_type->sat_collective ) {
+                       snprintf( textbuf, textlen, 
+                               "naming attribute '%s' is collective",
                                ava->la_attr.bv_val );
                        rc = LDAP_NAMING_VIOLATION;
                        break;
                }
 
-               if( ava->la_flags & LDAP_AVA_BINARY ) {
+               if( desc->ad_type->sat_obsolete ) {
                        snprintf( textbuf, textlen, 
-                               "value of naming attribute '%s' in unsupported BER form",
+                               "naming attribute '%s' is collective",
                                ava->la_attr.bv_val );
                        rc = LDAP_NAMING_VIOLATION;
+                       break;
                }
 
-               if ( value_find_ex( desc,
-                       SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
-                       attr->a_nvals,
-                       &ava->la_value, NULL ) != 0 )
-               {
+               if( !desc->ad_type->sat_equality ) {
+                       snprintf( textbuf, textlen, 
+                               "naming attribute '%s' has no equality matching rule",
+                               ava->la_attr.bv_val );
+                       rc = LDAP_NAMING_VIOLATION;
+                       break;
+               }
+
+               if( !desc->ad_type->sat_equality->smr_match ) {
                        snprintf( textbuf, textlen, 
-                               "value of naming attribute '%s' is not present in entry",
+                               "naming attribute '%s' has unsupported equality matching rule",
                                ava->la_attr.bv_val );
                        rc = LDAP_NAMING_VIOLATION;
                        break;
                }
+
+               /* find the naming attribute */
+               attr = attr_find( e->e_attrs, desc );
+               if ( attr == NULL ) {
+                       snprintf( textbuf, textlen, 
+                               "naming attribute '%s' is not present in entry",
+                               ava->la_attr.bv_val );
+                       rc = LDAP_NAMING_VIOLATION;
+                       break;
+               }
+
+               rc = value_find_ex( desc, SLAP_MR_VALUE_OF_ASSERTION_SYNTAX|
+                       SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
+                       attr->a_nvals, &ava->la_value, NULL );
+
+               if( rc != 0 ) {
+                       switch( rc ) {
+                       case LDAP_INAPPROPRIATE_MATCHING:
+                               snprintf( textbuf, textlen, 
+                                       "inappropriate matching for naming attribute '%s'",
+                                       ava->la_attr.bv_val );
+                               break;
+                       case LDAP_INVALID_SYNTAX:
+                               snprintf( textbuf, textlen, 
+                                       "value of naming attribute '%s' is invalid",
+                                       ava->la_attr.bv_val );
+                               break;
+                       case LDAP_NO_SUCH_ATTRIBUTE:
+                               snprintf( textbuf, textlen, 
+                                       "value of naming attribute '%s' is not present in entry",
+                                       ava->la_attr.bv_val );
+                               break;
+                       default:
+                               snprintf( textbuf, textlen, 
+                                       "naming attribute '%s' is inappropriate",
+                                       ava->la_attr.bv_val );
+                       }
+                       rc = LDAP_NAMING_VIOLATION;
+                       break;
+               }
        }
 
        ldap_rdnfree( rdn );