1 /* schema.c - routines to manage schema definitions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 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>
31 schema_info( Entry **entry, const char **text )
33 AttributeDescription *ad_structuralObjectClass
34 = slap_schema.si_ad_structuralObjectClass;
35 AttributeDescription *ad_objectClass
36 = slap_schema.si_ad_objectClass;
37 AttributeDescription *ad_createTimestamp
38 = slap_schema.si_ad_createTimestamp;
39 AttributeDescription *ad_modifyTimestamp
40 = slap_schema.si_ad_modifyTimestamp;
43 struct berval vals[5];
44 struct berval nvals[5];
46 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
48 /* Out of memory, do something about it */
50 LDAP_LOG( OPERATION, ERR,
51 "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0,0 );
53 Debug( LDAP_DEBUG_ANY,
54 "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0, 0 );
56 *text = "out of memory";
61 /* backend-specific schema info should be created by the
64 ber_dupbv( &e->e_name, &global_schemadn );
65 ber_dupbv( &e->e_nname, &global_schemandn );
68 BER_BVSTR( &vals[0], "subentry" );
69 if( attr_merge_one( e, ad_structuralObjectClass, vals, NULL ) ) {
70 /* Out of memory, do something about it */
72 *text = "out of memory";
76 BER_BVSTR( &vals[0], "top" );
77 BER_BVSTR( &vals[1], "subentry" );
78 BER_BVSTR( &vals[2], "subschema" );
79 BER_BVSTR( &vals[3], "extensibleObject" );
80 BER_BVZERO( &vals[4] );
81 if ( attr_merge( e, ad_objectClass, vals, NULL ) ) {
82 /* Out of memory, do something about it */
84 *text = "out of memory";
90 AttributeDescription *desc = NULL;
91 struct berval rdn = global_schemadn;
92 vals[0].bv_val = strchr( rdn.bv_val, '=' );
94 if( vals[0].bv_val == NULL ) {
95 *text = "improperly configured subschema subentry";
100 vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
101 rdn.bv_len -= vals[0].bv_len + 1;
103 rc = slap_bv2ad( &rdn, &desc, text );
105 if( rc != LDAP_SUCCESS ) {
107 *text = "improperly configured subschema subentry";
111 nvals[0].bv_val = strchr( global_schemandn.bv_val, '=' );
112 assert( nvals[0].bv_val );
114 nvals[0].bv_len = global_schemandn.bv_len -
115 (nvals[0].bv_val - global_schemandn.bv_val);
117 if ( attr_merge_one( e, desc, vals, nvals ) ) {
118 /* Out of memory, do something about it */
120 *text = "out of memory";
130 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
133 * According to RFC 2251:
135 Servers SHOULD provide the attributes createTimestamp and
136 modifyTimestamp in subschema entries, in order to allow clients to
137 maintain their caches of schema information.
139 * to be conservative, we declare schema created
140 * AND modified at server startup time ...
144 ltm = gmtime_r( &starttime, <m_buf );
146 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
147 ltm = gmtime( &starttime );
148 #endif /* HAVE_GMTIME_R */
149 lutil_gentime( timebuf, sizeof(timebuf), ltm );
150 #ifndef HAVE_GMTIME_R
151 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
154 vals[0].bv_val = timebuf;
155 vals[0].bv_len = strlen( timebuf );
157 if( attr_merge_one( e, ad_createTimestamp, vals, NULL ) ) {
158 /* Out of memory, do something about it */
160 *text = "out of memory";
163 if( attr_merge_one( e, ad_modifyTimestamp, vals, NULL ) ) {
164 /* Out of memory, do something about it */
166 *text = "out of memory";
171 if ( syn_schema_info( e )
172 || mr_schema_info( e )
173 || mru_schema_info( e )
174 || at_schema_info( e )
175 || oc_schema_info( e )
176 || cr_schema_info( e ) )
178 /* Out of memory, do something about it */
180 *text = "out of memory";