1 /* schema.c - routines to manage schema definitions */
4 * Copyright 1998-2003 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 struct berval nvals[5];
39 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
41 /* Out of memory, do something about it */
43 LDAP_LOG( OPERATION, ERR,
44 "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0,0 );
46 Debug( LDAP_DEBUG_ANY,
47 "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0, 0 );
49 *text = "out of memory";
54 /* backend-specific schema info should be created by the
57 ber_dupbv( &e->e_name, &global_schemadn );
58 ber_dupbv( &e->e_nname, &global_schemandn );
61 vals[0].bv_val = "subentry";
62 vals[0].bv_len = sizeof("subentry")-1;
64 if( attr_merge_one( e, ad_structuralObjectClass, vals, vals ) )
66 if( attr_merge_one( e, ad_structuralObjectClass, vals ) )
69 /* Out of memory, do something about it */
71 *text = "out of memory";
75 vals[0].bv_val = "top";
76 vals[0].bv_len = sizeof("top")-1;
77 vals[1].bv_val = "subentry";
78 vals[1].bv_len = sizeof("subentry")-1;
79 vals[2].bv_val = "subschema";
80 vals[2].bv_len = sizeof("subschema")-1;
81 vals[3].bv_val = "extensibleObject";
82 vals[3].bv_len = sizeof("extensibleObject")-1;
83 vals[4].bv_val = NULL;
85 if( attr_merge( e, ad_objectClass, vals, vals ) )
87 if( attr_merge( e, ad_objectClass, vals ) )
90 /* Out of memory, do something about it */
92 *text = "out of memory";
98 AttributeDescription *desc = NULL;
99 struct berval rdn = global_schemadn;
100 vals[0].bv_val = strchr( rdn.bv_val, '=' );
102 if( vals[0].bv_val == NULL ) {
103 *text = "improperly configured subschema subentry";
108 vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
109 rdn.bv_len -= vals[0].bv_len + 1;
111 rc = slap_bv2ad( &rdn, &desc, text );
113 if( rc != LDAP_SUCCESS ) {
115 *text = "improperly configured subschema subentry";
120 nvals[0].bv_val = strchr( global_schemandn.bv_val, '=' );
121 assert( nvals[0].bv_val );
123 nvals[0].bv_len = global_schemandn.bv_len -
124 (nvals[0].bv_val - global_schemandn.bv_val);
126 if( attr_merge_one( e, desc, vals, nvals ) )
128 if( attr_merge_one( e, desc, vals ) )
131 /* Out of memory, do something about it */
133 *text = "out of memory";
140 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
143 * According to RFC 2251:
145 Servers SHOULD provide the attributes createTimestamp and
146 modifyTimestamp in subschema entries, in order to allow clients to
147 maintain their caches of schema information.
149 * to be conservative, we declare schema created
150 * AND modified at server startup time ...
153 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
154 ltm = gmtime( &starttime );
155 lutil_gentime( timebuf, sizeof(timebuf), ltm );
156 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
158 vals[0].bv_val = timebuf;
159 vals[0].bv_len = strlen( timebuf );
162 if( attr_merge_one( e, ad_createTimestamp, vals, vals ) )
164 if( attr_merge_one( e, ad_createTimestamp, vals ) )
167 /* Out of memory, do something about it */
169 *text = "out of memory";
173 if( attr_merge_one( e, ad_modifyTimestamp, vals, vals ) )
175 if( attr_merge_one( e, ad_modifyTimestamp, vals ) )
178 /* Out of memory, do something about it */
180 *text = "out of memory";
185 if ( syn_schema_info( e )
186 || mr_schema_info( e )
187 || mru_schema_info( e )
188 || at_schema_info( e )
189 || oc_schema_info( e )
190 || cr_schema_info( e ) )
192 /* Out of memory, do something about it */
194 *text = "out of memory";