1 /* schema.c - routines to manage schema definitions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
22 #include <ac/string.h>
23 #include <ac/socket.h>
30 schema_info( Entry **entry, const char **text )
32 AttributeDescription *ad_structuralObjectClass
33 = slap_schema.si_ad_structuralObjectClass;
34 AttributeDescription *ad_objectClass
35 = slap_schema.si_ad_objectClass;
36 AttributeDescription *ad_createTimestamp
37 = slap_schema.si_ad_createTimestamp;
38 AttributeDescription *ad_modifyTimestamp
39 = slap_schema.si_ad_modifyTimestamp;
42 struct berval vals[5];
43 struct berval nvals[5];
45 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
47 /* Out of memory, do something about it */
48 Debug( LDAP_DEBUG_ANY,
49 "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0, 0 );
50 *text = "out of memory";
55 /* backend-specific schema info should be created by the
58 ber_dupbv( &e->e_name, &frontendDB->be_schemadn );
59 ber_dupbv( &e->e_nname, &frontendDB->be_schemandn );
62 BER_BVSTR( &vals[0], "subentry" );
63 if( attr_merge_one( e, ad_structuralObjectClass, vals, NULL ) ) {
64 /* Out of memory, do something about it */
66 *text = "out of memory";
70 BER_BVSTR( &vals[0], "top" );
71 BER_BVSTR( &vals[1], "subentry" );
72 BER_BVSTR( &vals[2], "subschema" );
73 BER_BVSTR( &vals[3], "extensibleObject" );
74 BER_BVZERO( &vals[4] );
75 if ( attr_merge( e, ad_objectClass, vals, NULL ) ) {
76 /* Out of memory, do something about it */
78 *text = "out of memory";
84 AttributeDescription *desc = NULL;
85 struct berval rdn = frontendDB->be_schemadn;
86 vals[0].bv_val = strchr( rdn.bv_val, '=' );
88 if( vals[0].bv_val == NULL ) {
89 *text = "improperly configured subschema subentry";
94 vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
95 rdn.bv_len -= vals[0].bv_len + 1;
97 rc = slap_bv2ad( &rdn, &desc, text );
99 if( rc != LDAP_SUCCESS ) {
101 *text = "improperly configured subschema subentry";
105 nvals[0].bv_val = strchr( frontendDB->be_schemandn.bv_val, '=' );
106 assert( nvals[0].bv_val );
108 nvals[0].bv_len = frontendDB->be_schemandn.bv_len -
109 (nvals[0].bv_val - frontendDB->be_schemandn.bv_val);
111 if ( attr_merge_one( e, desc, vals, nvals ) ) {
112 /* Out of memory, do something about it */
114 *text = "out of memory";
124 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
127 * According to RFC 2251:
129 Servers SHOULD provide the attributes createTimestamp and
130 modifyTimestamp in subschema entries, in order to allow clients to
131 maintain their caches of schema information.
133 * to be conservative, we declare schema created
134 * AND modified at server startup time ...
138 ltm = gmtime_r( &starttime, <m_buf );
140 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
141 ltm = gmtime( &starttime );
142 #endif /* HAVE_GMTIME_R */
143 lutil_gentime( timebuf, sizeof(timebuf), ltm );
144 #ifndef HAVE_GMTIME_R
145 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
148 vals[0].bv_val = timebuf;
149 vals[0].bv_len = strlen( timebuf );
151 if( attr_merge_one( e, ad_createTimestamp, vals, NULL ) ) {
152 /* Out of memory, do something about it */
154 *text = "out of memory";
157 if( attr_merge_one( e, ad_modifyTimestamp, vals, NULL ) ) {
158 /* Out of memory, do something about it */
160 *text = "out of memory";
165 if ( syn_schema_info( e )
166 || mr_schema_info( e )
167 || mru_schema_info( e )
168 || at_schema_info( e )
169 || oc_schema_info( e )
170 || cr_schema_info( e ) )
172 /* Out of memory, do something about it */
174 *text = "out of memory";