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];
35 struct berval nvals[5];
37 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
39 /* Out of memory, do something about it */
41 LDAP_LOG( OPERATION, ERR,
42 "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0,0 );
44 Debug( LDAP_DEBUG_ANY,
45 "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0, 0 );
47 *text = "out of memory";
52 /* backend-specific schema info should be created by the
55 ber_dupbv( &e->e_name, &global_schemadn );
56 ber_dupbv( &e->e_nname, &global_schemandn );
59 vals[0].bv_val = "subentry";
60 vals[0].bv_len = sizeof("subentry")-1;
61 if( attr_merge_one( e, ad_structuralObjectClass, vals, vals ) )
63 /* Out of memory, do something about it */
65 *text = "out of memory";
69 vals[0].bv_val = "top";
70 vals[0].bv_len = sizeof("top")-1;
71 vals[1].bv_val = "subentry";
72 vals[1].bv_len = sizeof("subentry")-1;
73 vals[2].bv_val = "subschema";
74 vals[2].bv_len = sizeof("subschema")-1;
75 vals[3].bv_val = "extensibleObject";
76 vals[3].bv_len = sizeof("extensibleObject")-1;
77 vals[4].bv_val = NULL;
78 if( attr_merge( e, ad_objectClass, vals, vals ) )
80 /* Out of memory, do something about it */
82 *text = "out of memory";
88 AttributeDescription *desc = NULL;
89 struct berval rdn = global_schemadn;
90 vals[0].bv_val = strchr( rdn.bv_val, '=' );
92 if( vals[0].bv_val == NULL ) {
93 *text = "improperly configured subschema subentry";
98 vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
99 rdn.bv_len -= vals[0].bv_len + 1;
101 rc = slap_bv2ad( &rdn, &desc, text );
103 if( rc != LDAP_SUCCESS ) {
105 *text = "improperly configured subschema subentry";
109 nvals[0].bv_val = strchr( global_schemandn.bv_val, '=' );
110 assert( nvals[0].bv_val );
112 nvals[0].bv_len = global_schemandn.bv_len -
113 (nvals[0].bv_val - global_schemandn.bv_val);
115 if( attr_merge_one( e, desc, vals, nvals ) )
117 /* Out of memory, do something about it */
119 *text = "out of memory";
126 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
129 * According to RFC 2251:
131 Servers SHOULD provide the attributes createTimestamp and
132 modifyTimestamp in subschema entries, in order to allow clients to
133 maintain their caches of schema information.
135 * to be conservative, we declare schema created
136 * AND modified at server startup time ...
139 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
140 ltm = gmtime( &starttime );
141 lutil_gentime( timebuf, sizeof(timebuf), ltm );
142 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
144 vals[0].bv_val = timebuf;
145 vals[0].bv_len = strlen( timebuf );
147 if( attr_merge_one( e, ad_createTimestamp, vals, vals ) )
149 /* Out of memory, do something about it */
151 *text = "out of memory";
154 if( attr_merge_one( e, ad_modifyTimestamp, vals, vals ) )
156 /* Out of memory, do something about it */
158 *text = "out of memory";
163 if ( syn_schema_info( e )
164 || mr_schema_info( e )
165 || mru_schema_info( e )
166 || at_schema_info( e )
167 || oc_schema_info( e )
168 || cr_schema_info( e ) )
170 /* Out of memory, do something about it */
172 *text = "out of memory";