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