X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fschema.c;h=f99fb5d37dfd62624de89eaeaa1cb9b0da8453dd;hb=12d5c6bba210de4a03363567be1c19a37f8e806b;hp=a324a60d1d8ca26a85fa06d025953bc21d763ef5;hpb=c0f5c884297aac7b930afad98f601912c83e9e72;p=openldap
diff --git a/servers/slapd/schema.c b/servers/slapd/schema.c
index a324a60d1d..f99fb5d37d 100644
--- a/servers/slapd/schema.c
+++ b/servers/slapd/schema.c
@@ -1,189 +1,187 @@
-/* schema.c - routines to enforce schema definitions */
+/* schema.c - routines to manage schema definitions */
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software .
+ *
+ * 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
+ * .
+ */
#include "portable.h"
#include
+#include
#include
#include
#include "slap.h"
+#include "ldap_pvt.h"
+#include "lutil.h"
-extern Attribute *attr_find();
-extern char **str2charray();
-extern void charray_merge();
-
-extern struct objclass *global_oc;
-extern int global_schemacheck;
-
-static struct objclass *oc_find();
-static int oc_check_required();
-static int oc_check_allowed();
-
-/*
- * oc_check - check that entry e conforms to the schema required by
- * its object class(es). returns 0 if so, non-zero otherwise.
- */
int
-oc_schema_check( Entry *e )
+schema_info( Entry **entry, const char **text )
{
- Attribute *a, *aoc;
- struct objclass *oc;
- int i;
- int ret = 0;
-
- /* find the object class attribute - could error out here */
- if ( (aoc = attr_find( e->e_attrs, "objectclass" )) == NULL ) {
- Debug( LDAP_DEBUG_ANY, "No object class for entry (%s)\n",
- e->e_dn, 0, 0 );
- return( 0 );
+ AttributeDescription *ad_structuralObjectClass
+ = slap_schema.si_ad_structuralObjectClass;
+ AttributeDescription *ad_objectClass
+ = slap_schema.si_ad_objectClass;
+ AttributeDescription *ad_createTimestamp
+ = slap_schema.si_ad_createTimestamp;
+ AttributeDescription *ad_modifyTimestamp
+ = slap_schema.si_ad_modifyTimestamp;
+
+ Entry *e;
+ struct berval vals[5];
+ struct berval nvals[5];
+
+ e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
+ if( e == NULL ) {
+ /* Out of memory, do something about it */
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, ERR,
+ "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0,0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0, 0 );
+#endif
+ *text = "out of memory";
+ return LDAP_OTHER;
}
- /* check that the entry has required attrs for each oc */
- for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
- if ( oc_check_required( e, aoc->a_vals[i]->bv_val ) != 0 ) {
- Debug( LDAP_DEBUG_ANY,
- "Entry (%s), required attr (%s) missing\n",
- e->e_dn, aoc->a_vals[i]->bv_val, 0 );
- ret = 1;
- }
+ e->e_attrs = NULL;
+ /* backend-specific schema info should be created by the
+ * backend itself
+ */
+ ber_dupbv( &e->e_name, &global_schemadn );
+ ber_dupbv( &e->e_nname, &global_schemandn );
+ e->e_private = NULL;
+
+ vals[0].bv_val = "subentry";
+ vals[0].bv_len = sizeof("subentry")-1;
+ if( attr_merge_one( e, ad_structuralObjectClass, vals, vals ) )
+ {
+ /* Out of memory, do something about it */
+ entry_free( e );
+ *text = "out of memory";
+ return LDAP_OTHER;
}
- if ( ret != 0 ) {
- return( ret );
+ vals[0].bv_val = "top";
+ vals[0].bv_len = sizeof("top")-1;
+ vals[1].bv_val = "subentry";
+ vals[1].bv_len = sizeof("subentry")-1;
+ vals[2].bv_val = "subschema";
+ vals[2].bv_len = sizeof("subschema")-1;
+ vals[3].bv_val = "extensibleObject";
+ vals[3].bv_len = sizeof("extensibleObject")-1;
+ vals[4].bv_val = NULL;
+ if( attr_merge( e, ad_objectClass, vals, vals ) )
+ {
+ /* Out of memory, do something about it */
+ entry_free( e );
+ *text = "out of memory";
+ return LDAP_OTHER;
}
- /* check that each attr in the entry is allowed by some oc */
- for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
- if ( oc_check_allowed( a->a_type, aoc->a_vals ) != 0 ) {
- Debug( LDAP_DEBUG_ANY,
- "Entry (%s), attr (%s) not allowed\n",
- e->e_dn, a->a_type, 0 );
- ret = 1;
- }
- }
+ {
+ int rc;
+ AttributeDescription *desc = NULL;
+ struct berval rdn = global_schemadn;
+ vals[0].bv_val = strchr( rdn.bv_val, '=' );
- return( ret );
-}
-
-static int
-oc_check_required( Entry *e, char *ocname )
-{
- struct objclass *oc;
- int i;
- Attribute *a;
+ if( vals[0].bv_val == NULL ) {
+ *text = "improperly configured subschema subentry";
+ return LDAP_OTHER;
+ }
- /* find global oc defn. it we don't know about it assume it's ok */
- if ( (oc = oc_find( ocname )) == NULL ) {
- return( 0 );
- }
+ vals[0].bv_val++;
+ vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
+ rdn.bv_len -= vals[0].bv_len + 1;
- /* check for empty oc_required */
- if(oc->oc_required == NULL) {
- return( 0 );
- }
+ rc = slap_bv2ad( &rdn, &desc, text );
- /* for each required attribute */
- for ( i = 0; oc->oc_required[i] != NULL; i++ ) {
- /* see if it's in the entry */
- for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
- if ( strcasecmp( a->a_type, oc->oc_required[i] )
- == 0 ) {
- break;
- }
+ if( rc != LDAP_SUCCESS ) {
+ entry_free( e );
+ *text = "improperly configured subschema subentry";
+ return LDAP_OTHER;
}
- /* not there => schema violation */
- if ( a == NULL ) {
- return( 1 );
+ nvals[0].bv_val = strchr( global_schemandn.bv_val, '=' );
+ assert( nvals[0].bv_val );
+ nvals[0].bv_val++;
+ nvals[0].bv_len = global_schemandn.bv_len -
+ (nvals[0].bv_val - global_schemandn.bv_val);
+
+ if( attr_merge_one( e, desc, vals, nvals ) )
+ {
+ /* Out of memory, do something about it */
+ entry_free( e );
+ *text = "out of memory";
+ return LDAP_OTHER;
}
}
- return( 0 );
-}
+ {
+ struct tm *ltm;
+ char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
-static int
-oc_check_allowed( char *type, struct berval **ocl )
-{
- struct objclass *oc;
- int i, j;
+ /*
+ * According to RFC 2251:
- /* always allow objectclass attribute */
- if ( strcasecmp( type, "objectclass" ) == 0 ) {
- return( 0 );
- }
+ Servers SHOULD provide the attributes createTimestamp and
+ modifyTimestamp in subschema entries, in order to allow clients to
+ maintain their caches of schema information.
- /* check that the type appears as req or opt in at least one oc */
- for ( i = 0; ocl[i] != NULL; i++ ) {
- /* if we know about the oc */
- if ( (oc = oc_find( ocl[i]->bv_val )) != NULL ) {
- /* does it require the type? */
- for ( j = 0; oc->oc_required != NULL &&
- oc->oc_required[j] != NULL; j++ ) {
- if ( strcasecmp( oc->oc_required[j], type )
- == 0 ) {
- return( 0 );
- }
- }
- /* does it allow the type? */
- for ( j = 0; oc->oc_allowed != NULL &&
- oc->oc_allowed[j] != NULL; j++ ) {
- if ( strcasecmp( oc->oc_allowed[j], type )
- == 0 || strcmp( oc->oc_allowed[j], "*" )
- == 0 )
- {
- return( 0 );
- }
- }
- /* maybe the next oc allows it */
-
- /* we don't know about the oc. assume it allows it */
- } else {
- return( 0 );
- }
- }
+ * to be conservative, we declare schema created
+ * AND modified at server startup time ...
+ */
- /* not allowed by any oc */
- return( 1 );
-}
+ ldap_pvt_thread_mutex_lock( &gmtime_mutex );
+ ltm = gmtime( &starttime );
+ lutil_gentime( timebuf, sizeof(timebuf), ltm );
+ ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
-static struct objclass *
-oc_find( char *ocname )
-{
- struct objclass *oc;
+ vals[0].bv_val = timebuf;
+ vals[0].bv_len = strlen( timebuf );
- for ( oc = global_oc; oc != NULL; oc = oc->oc_next ) {
- if ( strcasecmp( oc->oc_name, ocname ) == 0 ) {
- return( oc );
+ if( attr_merge_one( e, ad_createTimestamp, vals, vals ) )
+ {
+ /* Out of memory, do something about it */
+ entry_free( e );
+ *text = "out of memory";
+ return LDAP_OTHER;
}
- }
-
- return( NULL );
-}
-
-#ifdef LDAP_DEBUG
-
-static
-oc_print( struct objclass *oc )
-{
- int i;
-
- printf( "objectclass %s\n", oc->oc_name );
- if ( oc->oc_required != NULL ) {
- printf( "\trequires %s", oc->oc_required[0] );
- for ( i = 1; oc->oc_required[i] != NULL; i++ ) {
- printf( ",%s", oc->oc_required[i] );
+ if( attr_merge_one( e, ad_modifyTimestamp, vals, vals ) )
+ {
+ /* Out of memory, do something about it */
+ entry_free( e );
+ *text = "out of memory";
+ return LDAP_OTHER;
}
- printf( "\n" );
}
- if ( oc->oc_allowed != NULL ) {
- printf( "\tallows %s", oc->oc_allowed[0] );
- for ( i = 1; oc->oc_allowed[i] != NULL; i++ ) {
- printf( ",%s", oc->oc_allowed[i] );
- }
- printf( "\n" );
+
+ if ( syn_schema_info( e )
+ || mr_schema_info( e )
+ || mru_schema_info( e )
+ || at_schema_info( e )
+ || oc_schema_info( e )
+ || cr_schema_info( e ) )
+ {
+ /* Out of memory, do something about it */
+ entry_free( e );
+ *text = "out of memory";
+ return LDAP_OTHER;
}
+
+ *entry = e;
+ return LDAP_SUCCESS;
}
-
-#endif