]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_check.c
Clean up include logging
[openldap] / servers / slapd / schema_check.c
index 536211b4e8d24f7a22457b11ab23ed897c403502..6f7d993dd6df957bb0a6612c16438816953b08df 100644 (file)
@@ -27,15 +27,47 @@ static char *       oc_check_required(Entry *e, struct berval *ocname);
 
 int
 entry_schema_check( 
-       Entry *e, Attribute *oldattrs, const char** text )
+       Entry *e, Attribute *oldattrs, const char** text,
+       char *textbuf, size_t textlen )
 {
        Attribute       *a, *aoc;
        ObjectClass *oc;
        int             i;
-       int             ret;
        AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
        int extensible = 0;
 
+       *text = textbuf;
+
+       /* check single-valued attrs for multiple values */
+       for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
+               /* there should be at least one value */
+               assert( a->a_vals );
+               assert( a->a_vals[0] != NULL ); 
+
+               /* if single value type, check for multiple values */
+               if( is_at_single_value( a->a_desc->ad_type ) &&
+                       a->a_vals[1] != NULL )
+               {
+                       char *type = a->a_desc->ad_cname->bv_val;
+
+                       snprintf( textbuf, textlen, 
+                               "attribute '%s' cannot have multiple values",
+                               type );
+
+#ifdef NEW_LOGGING
+                       LDAP_LOG(( "schema", LDAP_LEVEL_INFO,
+                               "entry_schema_check: dn=\"%s\" %s\n",
+                               e->e_dn, textbuf ));
+#else
+                       Debug( LDAP_DEBUG_ANY,
+                           "Entry (%s), %s\n",
+                           e->e_dn, textbuf, 0 );
+#endif
+
+                       return LDAP_CONSTRAINT_VIOLATION;
+               }
+       }
+
        if( !global_schemacheck ) return LDAP_SUCCESS;
 
        /* find the object class attribute - could error out here */
@@ -55,34 +87,40 @@ entry_schema_check(
        /* check that the entry has required attrs for each oc */
        for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
                if ( (oc = oc_find( aoc->a_vals[i]->bv_val )) == NULL ) {
+                       snprintf( textbuf, textlen, 
+                               "unrecognized objectClass '%s'",
+                               aoc->a_vals[i]->bv_val );
+
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "schema", LDAP_LEVEL_INFO,
-                                  "entry_schema_check: dn (%s), objectClass \"%s\" not recognized\n",
-                                  e->e_dn, aoc->a_vals[i]->bv_val ));
+                               "entry_schema_check: dn (%s), %s\n",
+                               e->e_dn, textbuf ));
 #else
                        Debug( LDAP_DEBUG_ANY,
-                               "entry_check_schema(%s): objectClass \"%s\" not recognized\n",
-                               e->e_dn, aoc->a_vals[i]->bv_val, 0 );
+                               "entry_check_schema(%s): \"%s\" not recognized\n",
+                               e->e_dn, textbuf, 0 );
 #endif
 
-                       *text = "unrecognized object class";
                        return LDAP_OBJECT_CLASS_VIOLATION;
 
                } else {
                        char *s = oc_check_required( e, aoc->a_vals[i] );
 
                        if (s != NULL) {
+                               snprintf( textbuf, textlen, 
+                                       "object class '%s' requires attribute '%s'",
+                                       aoc->a_vals[i]->bv_val, s );
+
 #ifdef NEW_LOGGING
                                LDAP_LOG(( "schema", LDAP_LEVEL_INFO,
-                                          "entry_schema_check: dn (%s) oc \"%s\" requires att \"%s\"\n",
-                                          e->e_dn, aoc->a_vals[i]->bv_val, s ));
+                                       "entry_schema_check: dn=\"%s\" %s",
+                                       e->e_dn, textbuf ));
 #else
                                Debug( LDAP_DEBUG_ANY,
-                                       "Entry (%s), oc \"%s\" requires attr \"%s\"\n",
-                                       e->e_dn, aoc->a_vals[i]->bv_val, s );
+                                       "Entry (%s): %s\n",
+                                       e->e_dn, textbuf, 0 );
 #endif
 
-                               *text = "missing required attribute";
                                return LDAP_OBJECT_CLASS_VIOLATION;
                        }
 
@@ -97,30 +135,31 @@ entry_schema_check(
                return LDAP_SUCCESS;
        }
 
-       /* optimistic */
-       ret = LDAP_SUCCESS;
-
        /* check that each attr in the entry is allowed by some oc */
        for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
-               ret = oc_check_allowed( a->a_desc->ad_type, aoc->a_vals );
-               if ( ret != 0 ) {
+               int ret = oc_check_allowed( a->a_desc->ad_type, aoc->a_vals );
+               if ( ret != LDAP_SUCCESS ) {
                        char *type = a->a_desc->ad_cname->bv_val;
+
+                       snprintf( textbuf, textlen, 
+                               "attribute '%s' not allowed",
+                               type );
+
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "schema", LDAP_LEVEL_INFO,
-                                  "entry_schema_check: Entry (%s) attr \"%s\" not allowed.\n",
-                                  e->e_dn, type ));
+                               "entry_schema_check: dn=\"%s\" %s\n",
+                               e->e_dn, textbuf ));
 #else
                        Debug( LDAP_DEBUG_ANY,
-                           "Entry (%s), attr \"%s\" not allowed\n",
-                           e->e_dn, type, 0 );
+                           "Entry (%s), %s\n",
+                           e->e_dn, textbuf, 0 );
 #endif
 
-                       *text = "attribute not allowed";
-                       break;
+                       return ret;
                }
        }
 
-       return( ret );
+       return LDAP_SUCCESS;
 }
 
 static char *
@@ -186,7 +225,6 @@ int oc_check_allowed(
                at->sat_cname, 0, 0 );
 #endif
 
-
        /* always allow objectClass attribute */
        if ( strcasecmp( at->sat_cname, "objectClass" ) == 0 ) {
                return LDAP_SUCCESS;
@@ -221,18 +259,9 @@ int oc_check_allowed(
                                }
                        }
                        /* maybe the next oc allows it */
-
-#ifdef OC_UNDEFINED_IMPLES_EXTENSIBLE
-               /* we don't know about the oc. assume it allows it */
-               } else {
-                       if ( t != type )
-                               ldap_memfree( t );
-                       return LDAP_SUCCESS;
-#endif
                }
        }
 
-
        /* not allowed by any oc */
        return LDAP_OBJECT_CLASS_VIOLATION;
 }