]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_check.c
slight improvements; doesn't work yet
[openldap] / servers / slapd / schema_check.c
index bc7c1e826f0f441f609922a83a81024f312dc3da..ccabe6dc17bb9fc394e1b0f6ab966a0eea319ef0 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-2004 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"
@@ -227,14 +236,14 @@ 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 */
-        }
+       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 );
@@ -719,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;
                                        }
@@ -841,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 obsolete",
                                ava->la_attr.bv_val );
                        rc = LDAP_NAMING_VIOLATION;
+                       break;
                }
 
-               if ( value_find_ex( desc,
-                       SLAP_MR_VALUE_OF_ASSERTION_SYNTAX|
-                               SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
-                       attr->a_nvals, &ava->la_value, NULL ) != 0 )
-               {
+               if( !desc->ad_type->sat_equality ) {
                        snprintf( textbuf, textlen, 
-                               "value of naming attribute '%s' is not present in entry",
+                               "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, 
+                               "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 );