]> git.sur5r.net Git - openldap/blob - servers/slapd/schema.c
Changed ma_rule_text to struct berval.
[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;
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         e->e_dn = ch_strdup( SLAPD_SCHEMA_DN );
41         e->e_ndn = ch_strdup( SLAPD_SCHEMA_DN );
42         (void) dn_normalize( e->e_ndn );
43         e->e_private = NULL;
44
45         val.bv_val = "LDAPsubentry";
46         val.bv_len = sizeof("LDAPsubentry")-1;
47         attr_merge( e, ad_structuralObjectClass, vals );
48
49         val.bv_val = "top";
50         val.bv_len = sizeof("top")-1;
51         attr_merge( e, ad_objectClass, vals );
52
53         val.bv_val = "LDAPsubentry";
54         val.bv_len = sizeof("LDAPsubentry")-1;
55         attr_merge( e, ad_objectClass, vals );
56
57         val.bv_val = "subschema";
58         val.bv_len = sizeof("subschema")-1;
59         attr_merge( e, ad_objectClass, vals );
60
61         val.bv_val = "extensibleObject";
62         val.bv_len = sizeof("extensibleObject")-1;
63         attr_merge( e, ad_objectClass, vals );
64
65         {
66                 int rc;
67                 AttributeDescription *desc = NULL;
68                 struct berval rdn = { sizeof(SLAPD_SCHEMA_DN)-1,
69                         SLAPD_SCHEMA_DN };
70                 val.bv_val = strchr( rdn.bv_val, '=' );
71
72                 if( val.bv_val == NULL ) {
73                         *text = "improperly configured subschema subentry";
74                         return LDAP_OTHER;
75                 }
76
77                 val.bv_val++;
78                 val.bv_len = rdn.bv_len - (val.bv_val - rdn.bv_val);
79                 rdn.bv_len -= val.bv_len + 1;
80
81                 rc = slap_bv2ad( &rdn, &desc, text );
82
83                 if( rc != LDAP_SUCCESS ) {
84                         entry_free( e );
85                         *text = "improperly configured subschema subentry";
86                         return LDAP_OTHER;
87                 }
88
89                 attr_merge( e, desc, vals );
90         }
91
92         if ( syn_schema_info( e ) 
93                 || mr_schema_info( e )
94                 || at_schema_info( e )
95                 || oc_schema_info( e ) )
96         {
97                 /* Out of memory, do something about it */
98                 entry_free( e );
99                 *text = "out of memory";
100                 return LDAP_OTHER;
101         }
102         
103         *entry = e;
104         return LDAP_SUCCESS;
105 }
106 #endif
107