]> git.sur5r.net Git - openldap/blob - servers/slapd/schema.c
Add entryDN MRA support. This is intended to be used:
[openldap] / servers / slapd / schema.c
1 /* schema.c - routines to manage schema definitions */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2004 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/ctype.h>
22 #include <ac/string.h>
23 #include <ac/socket.h>
24
25 #include "slap.h"
26 #include "ldap_pvt.h"
27 #include "lutil.h"
28
29
30 int
31 schema_info( Entry **entry, const char **text )
32 {
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;
41
42         Entry           *e;
43         struct berval   vals[5];
44         struct berval   nvals[5];
45
46         e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
47         if( e == NULL ) {
48                 /* Out of memory, do something about it */
49                 Debug( LDAP_DEBUG_ANY, 
50                         "schema_info: SLAP_CALLOC failed - out of memory.\n", 0, 0, 0 );
51                 *text = "out of memory";
52                 return LDAP_OTHER;
53         }
54
55         e->e_attrs = NULL;
56         /* backend-specific schema info should be created by the
57          * backend itself
58          */
59         ber_dupbv( &e->e_name, &frontendDB->be_schemadn );
60         ber_dupbv( &e->e_nname, &frontendDB->be_schemandn );
61         e->e_private = NULL;
62
63         BER_BVSTR( &vals[0], "subentry" );
64         if( attr_merge_one( e, ad_structuralObjectClass, vals, NULL ) ) {
65                 /* Out of memory, do something about it */
66                 entry_free( e );
67                 *text = "out of memory";
68                 return LDAP_OTHER;
69         }
70
71         BER_BVSTR( &vals[0], "top" );
72         BER_BVSTR( &vals[1], "subentry" );
73         BER_BVSTR( &vals[2], "subschema" );
74         BER_BVSTR( &vals[3], "extensibleObject" );
75         BER_BVZERO( &vals[4] );
76         if ( attr_merge( e, ad_objectClass, vals, NULL ) ) {
77                 /* Out of memory, do something about it */
78                 entry_free( e );
79                 *text = "out of memory";
80                 return LDAP_OTHER;
81         }
82
83         {
84                 int rc;
85                 AttributeDescription *desc = NULL;
86                 struct berval rdn = frontendDB->be_schemadn;
87                 vals[0].bv_val = strchr( rdn.bv_val, '=' );
88
89                 if( vals[0].bv_val == NULL ) {
90                         *text = "improperly configured subschema subentry";
91                         return LDAP_OTHER;
92                 }
93
94                 vals[0].bv_val++;
95                 vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
96                 rdn.bv_len -= vals[0].bv_len + 1;
97
98                 rc = slap_bv2ad( &rdn, &desc, text );
99
100                 if( rc != LDAP_SUCCESS ) {
101                         entry_free( e );
102                         *text = "improperly configured subschema subentry";
103                         return LDAP_OTHER;
104                 }
105
106                 nvals[0].bv_val = strchr( frontendDB->be_schemandn.bv_val, '=' );
107                 assert( nvals[0].bv_val );
108                 nvals[0].bv_val++;
109                 nvals[0].bv_len = frontendDB->be_schemandn.bv_len -
110                         (nvals[0].bv_val - frontendDB->be_schemandn.bv_val);
111
112                 if ( attr_merge_one( e, desc, vals, nvals ) ) {
113                         /* Out of memory, do something about it */
114                         entry_free( e );
115                         *text = "out of memory";
116                         return LDAP_OTHER;
117                 }
118         }
119
120         {
121                 struct          tm *ltm;
122 #ifdef HAVE_GMTIME_R
123                 struct          tm ltm_buf;
124 #endif
125                 char            timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
126
127                 /*
128                  * According to RFC 2251:
129
130    Servers SHOULD provide the attributes createTimestamp and
131    modifyTimestamp in subschema entries, in order to allow clients to
132    maintain their caches of schema information.
133
134                  * to be conservative, we declare schema created 
135                  * AND modified at server startup time ...
136                  */
137
138 #ifdef HAVE_GMTIME_R
139                 ltm = gmtime_r( &starttime, &ltm_buf );
140 #else
141                 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
142                 ltm = gmtime( &starttime );
143 #endif /* HAVE_GMTIME_R */
144                 lutil_gentime( timebuf, sizeof(timebuf), ltm );
145 #ifndef HAVE_GMTIME_R
146                 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
147 #endif
148
149                 vals[0].bv_val = timebuf;
150                 vals[0].bv_len = strlen( timebuf );
151
152                 if( attr_merge_one( e, ad_createTimestamp, vals, NULL ) ) {
153                         /* Out of memory, do something about it */
154                         entry_free( e );
155                         *text = "out of memory";
156                         return LDAP_OTHER;
157                 }
158                 if( attr_merge_one( e, ad_modifyTimestamp, vals, NULL ) ) {
159                         /* Out of memory, do something about it */
160                         entry_free( e );
161                         *text = "out of memory";
162                         return LDAP_OTHER;
163                 }
164         }
165
166         if ( syn_schema_info( e ) 
167                 || mr_schema_info( e )
168                 || mru_schema_info( e )
169                 || at_schema_info( e )
170                 || oc_schema_info( e )
171                 || cr_schema_info( e ) )
172         {
173                 /* Out of memory, do something about it */
174                 entry_free( e );
175                 *text = "out of memory";
176                 return LDAP_OTHER;
177         }
178         
179         *entry = e;
180         return LDAP_SUCCESS;
181 }