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>
22 schema_info( Entry **entry, const char **text )
24 AttributeDescription *ad_structuralObjectClass
25 = slap_schema.si_ad_structuralObjectClass;
26 AttributeDescription *ad_objectClass
27 = slap_schema.si_ad_objectClass;
28 AttributeDescription *ad_createTimestamp
29 = slap_schema.si_ad_createTimestamp;
30 AttributeDescription *ad_modifyTimestamp
31 = slap_schema.si_ad_modifyTimestamp;
34 struct berval vals[5];
36 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
38 /* Out of memory, do something about it */
40 LDAP_LOG( OPERATION, ERR,
41 "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0,0 );
43 Debug( LDAP_DEBUG_ANY,
44 "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0, 0 );
46 *text = "out of memory";
51 /* backend-specific schema info should be created by the
54 ber_dupbv( &e->e_name, &global_schemadn );
55 ber_dupbv( &e->e_nname, &global_schemandn );
58 vals[0].bv_val = "subentry";
59 vals[0].bv_len = sizeof("subentry")-1;
60 if( attr_merge_one( e, ad_structuralObjectClass, vals ) ) {
61 /* Out of memory, do something about it */
63 *text = "out of memory";
67 vals[0].bv_val = "top";
68 vals[0].bv_len = sizeof("top")-1;
69 vals[1].bv_val = "subentry";
70 vals[1].bv_len = sizeof("subentry")-1;
71 vals[2].bv_val = "subschema";
72 vals[2].bv_len = sizeof("subschema")-1;
73 vals[3].bv_val = "extensibleObject";
74 vals[3].bv_len = sizeof("extensibleObject")-1;
75 vals[4].bv_val = NULL;
76 if( attr_merge( e, ad_objectClass, vals ) ) {
77 /* Out of memory, do something about it */
79 *text = "out of memory";
85 AttributeDescription *desc = NULL;
86 struct berval rdn = global_schemadn;
87 vals[0].bv_val = strchr( rdn.bv_val, '=' );
89 if( vals[0].bv_val == NULL ) {
90 *text = "improperly configured subschema subentry";
95 vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
96 rdn.bv_len -= vals[0].bv_len + 1;
98 rc = slap_bv2ad( &rdn, &desc, text );
100 if( rc != LDAP_SUCCESS ) {
102 *text = "improperly configured subschema subentry";
106 if( attr_merge_one( e, desc, vals ) ) {
107 /* Out of memory, do something about it */
109 *text = "out of memory";
116 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
119 * According to RFC 2251:
121 Servers SHOULD provide the attributes createTimestamp and
122 modifyTimestamp in subschema entries, in order to allow clients to
123 maintain their caches of schema information.
125 * to be conservative, we declare schema created
126 * AND modified at server startup time ...
129 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
130 ltm = gmtime( &starttime );
131 lutil_gentime( timebuf, sizeof(timebuf), ltm );
132 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
134 vals[0].bv_val = timebuf;
135 vals[0].bv_len = strlen( timebuf );
137 if( attr_merge_one( e, ad_createTimestamp, vals ) ) {
138 /* Out of memory, do something about it */
140 *text = "out of memory";
143 if( attr_merge_one( e, ad_modifyTimestamp, vals ) ) {
144 /* Out of memory, do something about it */
146 *text = "out of memory";
151 if ( syn_schema_info( e )
152 || mr_schema_info( e )
153 || mru_schema_info( e )
154 || at_schema_info( e )
155 || oc_schema_info( e )
156 || cr_schema_info( e ) )
158 /* Out of memory, do something about it */
160 *text = "out of memory";