2 /* root_dse.c - Provides the ROOT DSA-Specific Entry
4 * Copyright 1999-2003 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.
17 #include <ac/string.h>
27 static struct berval supportedFeatures[] = {
28 BER_BVC(LDAP_FEATURE_ALL_OPERATIONAL_ATTRS), /* all Operational Attributes ("+") */
29 BER_BVC(LDAP_FEATURE_OBJECTCLASS_ATTRS), /* OCs in Attributes List */
30 BER_BVC(LDAP_FEATURE_ABSOLUTE_FILTERS), /* (&) and (|) search filters */
31 BER_BVC(LDAP_FEATURE_LANGUAGE_TAG_OPTIONS), /* Language Tag Options */
32 BER_BVC(LDAP_FEATURE_LANGUAGE_RANGE_OPTIONS), /* Language Range Options */
36 static Entry *usr_attr = NULL;
45 struct berval vals[2], *bv;
47 struct berval nvals[2];
50 char ** supportedSASLMechanisms;
52 AttributeDescription *ad_structuralObjectClass
53 = slap_schema.si_ad_structuralObjectClass;
54 AttributeDescription *ad_objectClass
55 = slap_schema.si_ad_objectClass;
56 AttributeDescription *ad_namingContexts
57 = slap_schema.si_ad_namingContexts;
58 AttributeDescription *ad_supportedExtension
59 = slap_schema.si_ad_supportedExtension;
60 AttributeDescription *ad_supportedLDAPVersion
61 = slap_schema.si_ad_supportedLDAPVersion;
62 AttributeDescription *ad_supportedSASLMechanisms
63 = slap_schema.si_ad_supportedSASLMechanisms;
64 AttributeDescription *ad_supportedFeatures
65 = slap_schema.si_ad_supportedFeatures;
66 AttributeDescription *ad_monitorContext
67 = slap_schema.si_ad_monitorContext;
68 AttributeDescription *ad_ref
69 = slap_schema.si_ad_ref;
71 vals[1].bv_val = NULL;
73 nvals[1].bv_val = NULL;
76 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
80 LDAP_LOG( OPERATION, ERR,
81 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
83 Debug( LDAP_DEBUG_ANY,
84 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
90 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
91 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
92 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
93 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
95 /* the DN is an empty string so no pretty/normalization is needed */
96 assert( !e->e_name.bv_len );
97 assert( !e->e_nname.bv_len );
101 vals[0].bv_val = "top";
102 vals[0].bv_len = sizeof("top")-1;
104 if( attr_merge( e, ad_objectClass, vals, vals ) )
106 if( attr_merge( e, ad_objectClass, vals ) )
112 vals[0].bv_val = "OpenLDAProotDSE";
113 vals[0].bv_len = sizeof("OpenLDAProotDSE")-1;
115 if( attr_merge( e, ad_objectClass, vals, vals ) )
117 if( attr_merge( e, ad_objectClass, vals ) )
121 if( attr_merge( e, ad_structuralObjectClass, vals, vals ) )
123 if( attr_merge( e, ad_structuralObjectClass, vals ) )
127 for ( i = 0; i < nbackends; i++ ) {
128 if ( backends[i].be_flags & SLAP_BFLAG_MONITOR ) {
129 vals[0] = backends[i].be_suffix[0];
131 if( attr_merge( e, ad_monitorContext, vals, nvals ) )
133 if( attr_merge( e, ad_monitorContext, vals ) )
140 if ( backends[i].be_flags & SLAP_BFLAG_GLUE_SUBORDINATE ) {
143 for ( j = 0; backends[i].be_suffix[j].bv_val != NULL; j++ ) {
144 vals[0] = backends[i].be_suffix[j];
146 if( attr_merge( e, ad_namingContexts, vals, NULL ) )
148 if( attr_merge( e, ad_namingContexts, vals ) )
156 /* altServer unsupported */
158 /* supportedControl */
159 if ( controls_root_dse_info( e ) != 0 ) {
163 /* supportedExtension */
164 for ( i=0; (bv = get_supported_extop(i)) != NULL; i++ ) {
167 if( attr_merge( e, ad_supportedExtension, vals, NULL ) )
169 if( attr_merge( e, ad_supportedExtension, vals ) )
177 /* netscape supportedExtension */
178 for ( i = 0; (bv = ns_get_supported_extop(i)) != NULL; i++ ) {
181 if( attr_merge( e, ad_supportedExtension, vals, NULL ))
183 if( attr_merge( e, ad_supportedExtension, vals ))
189 #endif /* LDAP_SLAPI */
191 /* supportedFeatures */
193 if( attr_merge( e, ad_supportedFeatures,
194 supportedFeatures, supportedFeatures ) )
196 if( attr_merge( e, ad_supportedFeatures, supportedFeatures ) )
202 /* supportedLDAPVersion */
203 for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
205 if (!( global_allows & SLAP_ALLOW_BIND_V2 ) &&
206 ( i < LDAP_VERSION3 ) )
208 /* version 2 and lower are disallowed */
211 snprintf(buf, sizeof buf, "%d", i);
212 vals[0].bv_val = buf;
213 vals[0].bv_len = strlen( vals[0].bv_val );
215 if( attr_merge( e, ad_supportedLDAPVersion, vals, NULL ) )
217 if( attr_merge( e, ad_supportedLDAPVersion, vals ) )
224 /* supportedSASLMechanism */
225 supportedSASLMechanisms = slap_sasl_mechs( conn );
227 if( supportedSASLMechanisms != NULL ) {
228 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
229 vals[0].bv_val = supportedSASLMechanisms[i];
230 vals[0].bv_len = strlen( vals[0].bv_val );
232 if( attr_merge( e, ad_supportedSASLMechanisms, vals, NULL ) )
234 if( attr_merge( e, ad_supportedSASLMechanisms, vals ) )
240 ldap_charray_free( supportedSASLMechanisms );
243 if ( default_referral != NULL ) {
245 if( attr_merge( e, ad_ref, default_referral, NULL /* FIXME */ ) )
247 if( attr_merge( e, ad_ref, default_referral ) )
254 if( usr_attr != NULL) {
256 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
258 if( attr_merge( e, a->a_desc, a->a_vals, a->a_nvals ) )
260 if( attr_merge( e, a->a_desc, a->a_vals ) )
273 * Read the entries specified in fname and merge the attributes
274 * to the user defined rootDSE. Note thaat if we find any errors
275 * what so ever, we will discard the entire entries, print an
276 * error message and return.
278 int read_root_dse_file( const char *fname )
281 int rc = 0, lineno = 0, lmax = 0;
284 if ( (fp = fopen( fname, "r" )) == NULL ) {
285 Debug( LDAP_DEBUG_ANY,
286 "could not open rootdse attr file \"%s\" - absolute path?\n",
292 usr_attr = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
293 if( usr_attr == NULL ) {
295 LDAP_LOG( OPERATION, ERR,
296 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
298 Debug( LDAP_DEBUG_ANY,
299 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
303 usr_attr->e_attrs = NULL;
305 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
306 Entry *e = str2entry( buf );
310 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
312 entry_free( usr_attr );
317 /* make sure the DN is the empty DN */
318 if( e->e_nname.bv_len ) {
320 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
323 entry_free( usr_attr );
329 * we found a valid entry, so walk thru all the attributes in the
330 * entry, and add each attribute type and description to the
334 for(a = e->e_attrs; a != NULL; a = a->a_next) {
336 if( attr_merge( usr_attr, a->a_desc, a->a_vals, a->a_nvals ) )
338 if( attr_merge( usr_attr, a->a_desc, a->a_vals ) )
350 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);