]> git.sur5r.net Git - openldap/blob - servers/slapd/schema.c
more re-engineering; now rdn_attrs() and so are written in terms of ldap_str2rdn...
[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                 char *rdn = ch_strdup( SLAPD_SCHEMA_DN );
69                 val.bv_val = strchr( rdn, '=' );
70
71                 if( val.bv_val == NULL ) {
72                         free( rdn );
73                         *text = "improperly configured subschema subentry";
74                         return LDAP_OTHER;
75                 }
76
77                 *val.bv_val = '\0';
78                 val.bv_len = strlen( ++val.bv_val );
79
80                 rc = slap_str2ad( rdn, &desc, text );
81
82                 if( rc != LDAP_SUCCESS ) {
83                         free( rdn );
84                         entry_free( e );
85                         *text = "improperly configured subschema subentry";
86                         return LDAP_OTHER;
87                 }
88
89                 attr_merge( e, desc, vals );
90                 free( rdn );
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