2 /* root_dse.c - Provides the ROOT DSA-Specific Entry
4 * Copyright 1999-2000 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms are permitted only
8 * as authorized by the OpenLDAP Public License. A copy of this
9 * license is available at http://www.OpenLDAP.org/license.html or
10 * in file LICENSE in the top-level directory of the distribution.
16 #include <ac/string.h>
21 static char *supportedFeatures[] = {
22 "1.3.6.1.4.1.4203.1.5.1", /* All Operational Attributes ("+") */
23 "1.3.6.1.4.1.4203.1.5.2", /* OCs in Attributes List */
27 static Entry *usr_attr = NULL;
38 struct berval *vals[2];
40 char ** supportedSASLMechanisms;
42 AttributeDescription *ad_structuralObjectClass
43 = slap_schema.si_ad_structuralObjectClass;
44 AttributeDescription *ad_objectClass
45 = slap_schema.si_ad_objectClass;
46 AttributeDescription *ad_namingContexts
47 = slap_schema.si_ad_namingContexts;
48 AttributeDescription *ad_supportedControl
49 = slap_schema.si_ad_supportedControl;
50 AttributeDescription *ad_supportedExtension
51 = slap_schema.si_ad_supportedExtension;
52 AttributeDescription *ad_supportedLDAPVersion
53 = slap_schema.si_ad_supportedLDAPVersion;
54 AttributeDescription *ad_supportedSASLMechanisms
55 = slap_schema.si_ad_supportedSASLMechanisms;
56 AttributeDescription *ad_supportedFeatures
57 = slap_schema.si_ad_supportedFeatures;
58 AttributeDescription *ad_ref
59 = slap_schema.si_ad_ref;
66 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
69 e->e_dn = ch_strdup( LDAP_ROOT_DSE );
70 e->e_ndn = ch_strdup( LDAP_ROOT_DSE );
71 (void) dn_normalize( e->e_ndn );
74 val.bv_val = "OpenLDAProotDSE";
75 val.bv_len = sizeof("OpenLDAProotDSE")-1;
76 attr_merge( e, ad_structuralObjectClass, vals );
79 val.bv_len = sizeof("top")-1;
80 attr_merge( e, ad_objectClass, vals );
82 val.bv_val = "OpenLDAProotDSE";
83 val.bv_len = sizeof("OpenLDAProotDSE")-1;
84 attr_merge( e, ad_objectClass, vals );
86 for ( i = 0; i < nbackends; i++ ) {
87 if ( backends[i].be_glueflags & SLAP_GLUE_SUBORDINATE )
89 for ( j = 0; backends[i].be_suffix[j] != NULL; j++ ) {
90 val = *backends[i].be_suffix[j];
91 attr_merge( e, ad_namingContexts, vals );
95 /* altServer unsupported */
97 /* supportedControl */
98 for ( i=0; supportedControls[i] != NULL; i++ ) {
99 val.bv_val = supportedControls[i];
100 val.bv_len = strlen( val.bv_val );
101 attr_merge( e, ad_supportedControl, vals );
104 /* supportedExtension */
105 for ( i=0; (val.bv_val = get_supported_extop(i)) != NULL; i++ ) {
106 val.bv_len = strlen( val.bv_val );
107 attr_merge( e, ad_supportedExtension, vals );
110 /* supportedFeatures */
111 for ( i=0; supportedFeatures[i] != NULL; i++ ) {
112 val.bv_val = supportedFeatures[i];
113 val.bv_len = strlen( val.bv_val );
114 attr_merge( e, ad_supportedFeatures, vals );
117 /* supportedLDAPVersion */
118 for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
119 if (!( global_allows & SLAP_ALLOW_BIND_V2 ) &&
120 ( i < LDAP_VERSION3 ) )
122 /* version 2 and lower are disallowed */
127 val.bv_len = strlen( val.bv_val );
128 attr_merge( e, ad_supportedLDAPVersion, vals );
131 /* supportedSASLMechanism */
132 supportedSASLMechanisms = slap_sasl_mechs( conn );
134 if( supportedSASLMechanisms != NULL ) {
135 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
136 val.bv_val = supportedSASLMechanisms[i];
137 val.bv_len = strlen( val.bv_val );
138 attr_merge( e, ad_supportedSASLMechanisms, vals );
140 charray_free( supportedSASLMechanisms );
143 if ( default_referral != NULL ) {
144 attr_merge( e, ad_ref, default_referral );
147 if( usr_attr != NULL) {
148 for(a = usr_attr->e_attrs; a != NULL; a = a->a_next) {
149 attr_merge( e, a->a_desc, a->a_vals );
158 * Read the entries specified in fname and merge the attributes
159 * to the user defined rootDSE. Note thaat if we find any errors
160 * what so ever, we will discard the entire entries, print an
161 * error message and return.
163 int read_root_dse_file( const char *fname )
166 int rc = 0, lineno = 0, lmax = 0;
171 if ( (fp = fopen( fname, "r" )) == NULL ) {
172 Debug( LDAP_DEBUG_ANY,
173 "could not open rootdse attr file \"%s\" - absolute path?\n",
179 usr_attr = (Entry *) ch_calloc( 1, sizeof(Entry) );
180 usr_attr->e_attrs = NULL;
182 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
183 Entry *e = str2entry( buf );
186 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
189 entry_free( usr_attr );
194 if( dn_normalize( e->e_ndn ) == NULL ) {
195 fprintf( stderr, "root_dse: invalid dn=\"%s\" (line=%d)\n",
198 entry_free( usr_attr );
203 /* make sure the DN is a valid rootdse(rootdse is a null string) */
204 if( strcmp(e->e_ndn, "") != 0 ) {
206 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
209 entry_free( usr_attr );
215 * we found a valid entry, so walk thru all the attributes in the
216 * entry, and add each attribute type and description to the
220 for(a = e->e_attrs; a != NULL; a = a->a_next) {
221 attr_merge( usr_attr, a->a_desc, a->a_vals );
229 Debug(LDAP_DEBUG_CONFIG,"rootDSE file %s read.\n", fname, 0, 0);