1 /* schema.c - routines to manage schema definitions */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
21 #if defined( SLAPD_SCHEMA_DN )
24 schema_info( Entry **entry, const char **text )
26 AttributeDescription *ad_structuralObjectClass
27 = slap_schema.si_ad_structuralObjectClass;
28 AttributeDescription *ad_objectClass
29 = slap_schema.si_ad_objectClass;
30 AttributeDescription *ad_createTimestamp
31 = slap_schema.si_ad_createTimestamp;
32 AttributeDescription *ad_modifyTimestamp
33 = slap_schema.si_ad_modifyTimestamp;
36 struct berval vals[5];
38 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
41 /* backend-specific schema info should be created by the
44 ber_dupbv( &e->e_name, &global_schemadn );
45 ber_dupbv( &e->e_nname, &global_schemandn );
48 vals[0].bv_val = "subentry";
49 vals[0].bv_len = sizeof("subentry")-1;
50 attr_merge_one( e, ad_structuralObjectClass, vals );
52 vals[0].bv_val = "top";
53 vals[0].bv_len = sizeof("top")-1;
54 vals[1].bv_val = "subentry";
55 vals[1].bv_len = sizeof("subentry")-1;
56 vals[2].bv_val = "subschema";
57 vals[2].bv_len = sizeof("subschema")-1;
58 vals[3].bv_val = "extensibleObject";
59 vals[3].bv_len = sizeof("extensibleObject")-1;
60 vals[4].bv_val = NULL;
61 attr_merge( e, ad_objectClass, vals );
65 AttributeDescription *desc = NULL;
66 struct berval rdn = global_schemadn;
67 vals[0].bv_val = strchr( rdn.bv_val, '=' );
69 if( vals[0].bv_val == NULL ) {
70 *text = "improperly configured subschema subentry";
75 vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
76 rdn.bv_len -= vals[0].bv_len + 1;
78 rc = slap_bv2ad( &rdn, &desc, text );
80 if( rc != LDAP_SUCCESS ) {
82 *text = "improperly configured subschema subentry";
86 attr_merge_one( e, desc, vals );
91 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
94 * According to RFC 2251:
96 Servers SHOULD provide the attributes createTimestamp and
97 modifyTimestamp in subschema entries, in order to allow clients to
98 maintain their caches of schema information.
100 * to be conservative, we declare schema created
101 * AND modified at server startup time ...
104 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
105 ltm = gmtime( &starttime );
106 lutil_gentime( timebuf, sizeof(timebuf), ltm );
107 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
109 vals[0].bv_val = timebuf;
110 vals[0].bv_len = strlen( timebuf );
112 attr_merge_one( e, ad_createTimestamp, vals );
113 attr_merge_one( e, ad_modifyTimestamp, vals );
116 if ( syn_schema_info( e )
117 || mr_schema_info( e )
118 || mru_schema_info( e )
119 || at_schema_info( e )
120 || oc_schema_info( e ) )
122 /* Out of memory, do something about it */
124 *text = "out of memory";