]> git.sur5r.net Git - openldap/blob - servers/slapd/schema.c
d3f602b8997427e7890bd11b3827b1baec3bbf6f
[openldap] / servers / slapd / schema.c
1 /* schema.c - routines to manage schema definitions */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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
19
20 #if defined( SLAPD_SCHEMA_DN )
21
22 int
23 schema_info( Entry **entry, const char **text )
24 {
25         AttributeDescription *ad_structuralObjectClass
26                 = slap_schema.si_ad_structuralObjectClass;
27         AttributeDescription *ad_objectClass
28                 = slap_schema.si_ad_objectClass;
29
30         Entry           *e;
31         struct berval   val, *ndn = NULL;
32         struct berval   *vals[2];
33
34         vals[0] = &val;
35         vals[1] = NULL;
36
37         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
38
39         e->e_attrs = NULL;
40         ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1, &e->e_name);
41         dnNormalize( NULL, &e->e_name, &ndn );
42         e->e_nname = *ndn;
43         free( ndn );
44         e->e_private = NULL;
45
46         val.bv_val = "LDAPsubentry";
47         val.bv_len = sizeof("LDAPsubentry")-1;
48         attr_merge( e, ad_structuralObjectClass, vals );
49
50         val.bv_val = "top";
51         val.bv_len = sizeof("top")-1;
52         attr_merge( e, ad_objectClass, vals );
53
54         val.bv_val = "LDAPsubentry";
55         val.bv_len = sizeof("LDAPsubentry")-1;
56         attr_merge( e, ad_objectClass, vals );
57
58         val.bv_val = "subschema";
59         val.bv_len = sizeof("subschema")-1;
60         attr_merge( e, ad_objectClass, vals );
61
62         val.bv_val = "extensibleObject";
63         val.bv_len = sizeof("extensibleObject")-1;
64         attr_merge( e, ad_objectClass, vals );
65
66         {
67                 int rc;
68                 AttributeDescription *desc = NULL;
69                 struct berval rdn = { sizeof(SLAPD_SCHEMA_DN)-1,
70                         SLAPD_SCHEMA_DN };
71                 val.bv_val = strchr( rdn.bv_val, '=' );
72
73                 if( val.bv_val == NULL ) {
74                         *text = "improperly configured subschema subentry";
75                         return LDAP_OTHER;
76                 }
77
78                 val.bv_val++;
79                 val.bv_len = rdn.bv_len - (val.bv_val - rdn.bv_val);
80                 rdn.bv_len -= val.bv_len + 1;
81
82                 rc = slap_bv2ad( &rdn, &desc, text );
83
84                 if( rc != LDAP_SUCCESS ) {
85                         entry_free( e );
86                         *text = "improperly configured subschema subentry";
87                         return LDAP_OTHER;
88                 }
89
90                 attr_merge( e, desc, vals );
91         }
92
93         if ( syn_schema_info( e ) 
94                 || mr_schema_info( e )
95                 || at_schema_info( e )
96                 || oc_schema_info( e ) )
97         {
98                 /* Out of memory, do something about it */
99                 entry_free( e );
100                 *text = "out of memory";
101                 return LDAP_OTHER;
102         }
103         
104         *entry = e;
105         return LDAP_SUCCESS;
106 }
107 #endif
108