]> git.sur5r.net Git - openldap/blob - servers/slapd/schema.c
Extend checks to substrings rules. Need to kludge around
[openldap] / servers / slapd / schema.c
1 /* schema.c - routines to manage schema definitions */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/ctype.h>
13 #include <ac/string.h>
14 #include <ac/socket.h>
15
16 #include "slap.h"
17 #include "ldap_pvt.h"
18 #include "lutil.h"
19
20
21 #if defined( SLAPD_SCHEMA_DN )
22
23 int
24 schema_info( Entry **entry, const char **text )
25 {
26         AttributeDescription *ad_structuralObjectClass
27                 = slap_schema.si_ad_structuralObjectClass;
28         AttributeDescription *ad_objectClass
29                 = slap_schema.si_ad_objectClass;
30         AttributeDescription *ad_createTimestamp
31                 = slap_schema.si_ad_createTimestamp;
32         AttributeDescription *ad_modifyTimestamp
33                 = slap_schema.si_ad_modifyTimestamp;
34
35         Entry           *e;
36         struct berval   vals[5];
37
38         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
39
40         e->e_attrs = NULL;
41         /* backend-specific schema info should be created by the
42          * backend itself
43          */
44         ber_dupbv( &e->e_name, &global_schemadn );
45         ber_dupbv( &e->e_nname, &global_schemandn );
46         e->e_private = NULL;
47
48         vals[0].bv_val = "subentry";
49         vals[0].bv_len = sizeof("subentry")-1;
50         attr_merge_one( e, ad_structuralObjectClass, vals );
51
52         vals[0].bv_val = "top";
53         vals[0].bv_len = sizeof("top")-1;
54         vals[1].bv_val = "subentry";
55         vals[1].bv_len = sizeof("subentry")-1;
56         vals[2].bv_val = "subschema";
57         vals[2].bv_len = sizeof("subschema")-1;
58         vals[3].bv_val = "extensibleObject";
59         vals[3].bv_len = sizeof("extensibleObject")-1;
60         vals[4].bv_val = NULL;
61         attr_merge( e, ad_objectClass, vals );
62
63         {
64                 int rc;
65                 AttributeDescription *desc = NULL;
66                 struct berval rdn = global_schemadn;
67                 vals[0].bv_val = strchr( rdn.bv_val, '=' );
68
69                 if( vals[0].bv_val == NULL ) {
70                         *text = "improperly configured subschema subentry";
71                         return LDAP_OTHER;
72                 }
73
74                 vals[0].bv_val++;
75                 vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
76                 rdn.bv_len -= vals[0].bv_len + 1;
77
78                 rc = slap_bv2ad( &rdn, &desc, text );
79
80                 if( rc != LDAP_SUCCESS ) {
81                         entry_free( e );
82                         *text = "improperly configured subschema subentry";
83                         return LDAP_OTHER;
84                 }
85
86                 attr_merge_one( e, desc, vals );
87         }
88
89         {
90                 struct          tm *ltm;
91                 char            timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
92
93                 /*
94                  * According to RFC 2251:
95
96    Servers SHOULD provide the attributes createTimestamp and
97    modifyTimestamp in subschema entries, in order to allow clients to
98    maintain their caches of schema information.
99
100                  * to be conservative, we declare schema created 
101                  * AND modified at server startup time ...
102                  */
103
104                 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
105                 ltm = gmtime( &starttime );
106                 lutil_gentime( timebuf, sizeof(timebuf), ltm );
107                 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
108
109                 vals[0].bv_val = timebuf;
110                 vals[0].bv_len = strlen( timebuf );
111
112                 attr_merge_one( e, ad_createTimestamp, vals );
113                 attr_merge_one( e, ad_modifyTimestamp, vals );
114         }
115
116         if ( syn_schema_info( e ) 
117                 || mr_schema_info( e )
118                 || mru_schema_info( e )
119                 || at_schema_info( e )
120                 || oc_schema_info( e ) )
121         {
122                 /* Out of memory, do something about it */
123                 entry_free( e );
124                 *text = "out of memory";
125                 return LDAP_OTHER;
126         }
127         
128         *entry = e;
129         return LDAP_SUCCESS;
130 }
131 #endif