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, '=' );
122 nvals[0].bv_len = global_schemandn.bv_len -
123 (nvals[0].bv_val - global_schemandn.bv_val);
125 if( attr_merge_one( e, desc, vals, nvals ) )
127 if( attr_merge_one( e, desc, vals ) )
130 /* Out of memory, do something about it */
132 *text = "out of memory";
139 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
142 * According to RFC 2251:
144 Servers SHOULD provide the attributes createTimestamp and
145 modifyTimestamp in subschema entries, in order to allow clients to
146 maintain their caches of schema information.
148 * to be conservative, we declare schema created
149 * AND modified at server startup time ...
152 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
153 ltm = gmtime( &starttime );
154 lutil_gentime( timebuf, sizeof(timebuf), ltm );
155 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
157 vals[0].bv_val = timebuf;
158 vals[0].bv_len = strlen( timebuf );
161 if( attr_merge_one( e, ad_createTimestamp, vals, vals ) )
163 if( attr_merge_one( e, ad_createTimestamp, vals ) )
166 /* Out of memory, do something about it */
168 *text = "out of memory";
172 if( attr_merge_one( e, ad_modifyTimestamp, vals, vals ) )
174 if( attr_merge_one( e, ad_modifyTimestamp, vals ) )
177 /* Out of memory, do something about it */
179 *text = "out of memory";
184 if ( syn_schema_info( e )
185 || mr_schema_info( e )
186 || mru_schema_info( e )
187 || at_schema_info( e )
188 || oc_schema_info( e )
189 || cr_schema_info( e ) )
191 /* Out of memory, do something about it */
193 *text = "out of memory";