]> git.sur5r.net Git - openldap/blob - servers/slapd/schema.c
DNS SRV default referral handling
[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 int
22 schema_info( Entry **entry, const char **text )
23 {
24         AttributeDescription *ad_structuralObjectClass
25                 = slap_schema.si_ad_structuralObjectClass;
26         AttributeDescription *ad_objectClass
27                 = slap_schema.si_ad_objectClass;
28         AttributeDescription *ad_createTimestamp
29                 = slap_schema.si_ad_createTimestamp;
30         AttributeDescription *ad_modifyTimestamp
31                 = slap_schema.si_ad_modifyTimestamp;
32
33         Entry           *e;
34         struct berval   vals[5];
35
36         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
37
38         e->e_attrs = NULL;
39         /* backend-specific schema info should be created by the
40          * backend itself
41          */
42         ber_dupbv( &e->e_name, &global_schemadn );
43         ber_dupbv( &e->e_nname, &global_schemandn );
44         e->e_private = NULL;
45
46         vals[0].bv_val = "subentry";
47         vals[0].bv_len = sizeof("subentry")-1;
48         attr_merge_one( e, ad_structuralObjectClass, vals );
49
50         vals[0].bv_val = "top";
51         vals[0].bv_len = sizeof("top")-1;
52         vals[1].bv_val = "subentry";
53         vals[1].bv_len = sizeof("subentry")-1;
54         vals[2].bv_val = "subschema";
55         vals[2].bv_len = sizeof("subschema")-1;
56         vals[3].bv_val = "extensibleObject";
57         vals[3].bv_len = sizeof("extensibleObject")-1;
58         vals[4].bv_val = NULL;
59         attr_merge( e, ad_objectClass, vals );
60
61         {
62                 int rc;
63                 AttributeDescription *desc = NULL;
64                 struct berval rdn = global_schemadn;
65                 vals[0].bv_val = strchr( rdn.bv_val, '=' );
66
67                 if( vals[0].bv_val == NULL ) {
68                         *text = "improperly configured subschema subentry";
69                         return LDAP_OTHER;
70                 }
71
72                 vals[0].bv_val++;
73                 vals[0].bv_len = rdn.bv_len - (vals[0].bv_val - rdn.bv_val);
74                 rdn.bv_len -= vals[0].bv_len + 1;
75
76                 rc = slap_bv2ad( &rdn, &desc, text );
77
78                 if( rc != LDAP_SUCCESS ) {
79                         entry_free( e );
80                         *text = "improperly configured subschema subentry";
81                         return LDAP_OTHER;
82                 }
83
84                 attr_merge_one( e, desc, vals );
85         }
86
87         {
88                 struct          tm *ltm;
89                 char            timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
90
91                 /*
92                  * According to RFC 2251:
93
94    Servers SHOULD provide the attributes createTimestamp and
95    modifyTimestamp in subschema entries, in order to allow clients to
96    maintain their caches of schema information.
97
98                  * to be conservative, we declare schema created 
99                  * AND modified at server startup time ...
100                  */
101
102                 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
103                 ltm = gmtime( &starttime );
104                 lutil_gentime( timebuf, sizeof(timebuf), ltm );
105                 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
106
107                 vals[0].bv_val = timebuf;
108                 vals[0].bv_len = strlen( timebuf );
109
110                 attr_merge_one( e, ad_createTimestamp, vals );
111                 attr_merge_one( e, ad_modifyTimestamp, vals );
112         }
113
114         if ( syn_schema_info( e ) 
115                 || mr_schema_info( e )
116                 || mru_schema_info( e )
117                 || at_schema_info( e )
118                 || oc_schema_info( e ) )
119         {
120                 /* Out of memory, do something about it */
121                 entry_free( e );
122                 *text = "out of memory";
123                 return LDAP_OTHER;
124         }
125         
126         *entry = e;
127         return LDAP_SUCCESS;
128 }