1 /* schema.c - routines to manage schema definitions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 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 = ber_bvchr( &rdn, '=' );
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 = ber_bvchr( &frontendDB->be_schemandn, '=' );
106 assert( nvals[0].bv_val != NULL );
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";
120 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
123 * According to RFC 2251:
125 Servers SHOULD provide the attributes createTimestamp and
126 modifyTimestamp in subschema entries, in order to allow clients to
127 maintain their caches of schema information.
129 * to be conservative, we declare schema created
130 * AND modified at server startup time ...
133 vals[0].bv_val = timebuf;
134 vals[0].bv_len = sizeof( timebuf );
136 slap_timestamp( &starttime, vals );
138 if( attr_merge_one( e, ad_createTimestamp, vals, NULL ) ) {
139 /* Out of memory, do something about it */
141 *text = "out of memory";
144 if( attr_merge_one( e, ad_modifyTimestamp, vals, NULL ) ) {
145 /* Out of memory, do something about it */
147 *text = "out of memory";
152 if ( syn_schema_info( e )
153 || mr_schema_info( e )
154 || mru_schema_info( e )
155 || at_schema_info( e )
156 || oc_schema_info( e )
157 || cr_schema_info( e ) )
159 /* Out of memory, do something about it */
161 *text = "out of memory";