1 /* root_dse.c - Provides the Root DSA-Specific Entry */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
21 #include <ac/string.h>
28 #include "slapi/slapi.h"
31 static struct berval supportedFeatures[] = {
32 BER_BVC(LDAP_FEATURE_MODIFY_INCREMENT), /* Modify/increment */
33 BER_BVC(LDAP_FEATURE_ALL_OP_ATTRS), /* All Op Attrs (+) */
34 BER_BVC(LDAP_FEATURE_OBJECTCLASS_ATTRS), /* OCs in Attrs List (@class) */
35 BER_BVC(LDAP_FEATURE_ABSOLUTE_FILTERS), /* (&) and (|) search filters */
36 BER_BVC(LDAP_FEATURE_LANGUAGE_TAG_OPTIONS), /* Language Tag Options */
37 BER_BVC(LDAP_FEATURE_LANGUAGE_RANGE_OPTIONS),/* Language Range Options */
38 #ifdef LDAP_FEATURE_SUBORDINATE_SCOPE
39 BER_BVC(LDAP_FEATURE_SUBORDINATE_SCOPE), /* "children" search scope */
44 static Entry *usr_attr = NULL;
58 char ** supportedSASLMechanisms;
61 AttributeDescription *ad_structuralObjectClass
62 = slap_schema.si_ad_structuralObjectClass;
63 AttributeDescription *ad_objectClass
64 = slap_schema.si_ad_objectClass;
65 AttributeDescription *ad_namingContexts
66 = slap_schema.si_ad_namingContexts;
68 AttributeDescription *ad_supportedExtension
69 = slap_schema.si_ad_supportedExtension;
71 AttributeDescription *ad_supportedLDAPVersion
72 = slap_schema.si_ad_supportedLDAPVersion;
73 AttributeDescription *ad_supportedSASLMechanisms
74 = slap_schema.si_ad_supportedSASLMechanisms;
75 AttributeDescription *ad_supportedFeatures
76 = slap_schema.si_ad_supportedFeatures;
77 AttributeDescription *ad_monitorContext
78 = slap_schema.si_ad_monitorContext;
79 AttributeDescription *ad_configContext
80 = slap_schema.si_ad_configContext;
81 AttributeDescription *ad_ref
82 = slap_schema.si_ad_ref;
84 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
87 Debug( LDAP_DEBUG_ANY,
88 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
93 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
94 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
95 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
96 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
98 /* the DN is an empty string so no pretty/normalization is needed */
99 assert( !e->e_name.bv_len );
100 assert( !e->e_nname.bv_len );
104 BER_BVSTR( &val, "top" );
105 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
109 BER_BVSTR( &val, "OpenLDAProotDSE" );
110 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
113 if( attr_merge_one( e, ad_structuralObjectClass, &val, NULL ) ) {
117 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
118 if ( be->be_suffix == NULL
119 || be->be_nsuffix == NULL ) {
123 if ( SLAP_MONITOR( be )) {
124 if( attr_merge_one( e, ad_monitorContext,
126 &be->be_nsuffix[0] ) )
132 if ( SLAP_CONFIG( be )) {
133 if( attr_merge_one( e, ad_configContext,
135 & be->be_nsuffix[0] ) )
141 if ( SLAP_GLUE_SUBORDINATE( be ) && !SLAP_GLUE_ADVERTISE( be ) ) {
144 for ( j = 0; be->be_suffix[j].bv_val != NULL; j++ ) {
145 if( attr_merge_one( e, ad_namingContexts,
147 &be->be_nsuffix[0] ) )
154 /* altServer unsupported */
156 /* supportedControl */
157 if ( controls_root_dse_info( e ) != 0 ) {
161 /* supportedExtension */
162 if ( exop_root_dse_info( e ) != 0 ) {
167 /* netscape supportedExtension */
168 for ( i = 0; (bv = slapi_int_get_supported_extop(i)) != NULL; i++ ) {
169 if( attr_merge_one( e, ad_supportedExtension, bv, NULL ) ) {
173 #endif /* LDAP_SLAPI */
175 /* supportedFeatures */
176 if( attr_merge( e, ad_supportedFeatures, supportedFeatures, NULL ) ) {
180 /* supportedLDAPVersion */
181 /* don't publish version 2 as we don't really support it
182 * (even when configured to accept version 2 Bind requests)
183 * and the value would never be used by true LDAPv2 (or LDAPv3)
186 for ( i=LDAP_VERSION3; i<=LDAP_VERSION_MAX; i++ ) {
188 snprintf(buf, sizeof buf, "%d", i);
190 val.bv_len = strlen( val.bv_val );
191 if( attr_merge_one( e, ad_supportedLDAPVersion, &val, NULL ) ) {
196 /* supportedSASLMechanism */
197 supportedSASLMechanisms = slap_sasl_mechs( conn );
199 if( supportedSASLMechanisms != NULL ) {
200 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
201 val.bv_val = supportedSASLMechanisms[i];
202 val.bv_len = strlen( val.bv_val );
203 if( attr_merge_one( e, ad_supportedSASLMechanisms, &val, NULL ) ) {
207 ldap_charray_free( supportedSASLMechanisms );
210 if ( default_referral != NULL ) {
211 if( attr_merge( e, ad_ref, default_referral, NULL /* FIXME */ ) ) {
216 if( usr_attr != NULL) {
218 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
219 if( attr_merge( e, a->a_desc, a->a_vals,
220 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
232 * Read the entries specified in fname and merge the attributes
233 * to the user defined rootDSE. Note thaat if we find any errors
234 * what so ever, we will discard the entire entries, print an
235 * error message and return.
237 int read_root_dse_file( const char *fname )
240 int rc = 0, lineno = 0, lmax = 0;
243 if ( (fp = ldif_open( fname, "r" )) == NULL ) {
244 Debug( LDAP_DEBUG_ANY,
245 "could not open rootdse attr file \"%s\" - absolute path?\n",
251 usr_attr = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
252 if( usr_attr == NULL ) {
253 Debug( LDAP_DEBUG_ANY,
254 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
258 usr_attr->e_attrs = NULL;
260 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
261 Entry *e = str2entry( buf );
265 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
271 /* make sure the DN is the empty DN */
272 if( e->e_nname.bv_len ) {
274 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
282 * we found a valid entry, so walk thru all the attributes in the
283 * entry, and add each attribute type and description to the
287 for(a = e->e_attrs; a != NULL; a = a->a_next) {
288 if( attr_merge( usr_attr, a->a_desc, a->a_vals,
289 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
301 entry_free( usr_attr );
309 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);
314 slap_discover_feature(
321 LDAPMessage *res = NULL, *entry;
323 struct berval cred = BER_BVC( "" ),
326 char *attrs[ 2 ] = { NULL, NULL };
328 ber_str2bv( val, 0, 0, &bv_val );
329 attrs[ 0 ] = (char *) attr;
331 rc = ldap_initialize( &ld, uri );
332 if ( rc != LDAP_SUCCESS ) {
336 rc = ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
337 if ( rc != LDAP_SUCCESS ) {
341 rc = ldap_sasl_bind_s( ld, "", LDAP_SASL_SIMPLE,
342 &cred, NULL, NULL, NULL );
343 if ( rc != LDAP_SUCCESS ) {
347 rc = ldap_search_ext_s( ld, "", LDAP_SCOPE_BASE, "(objectClass=*)",
348 attrs, 0, NULL, NULL, NULL, 0, &res );
349 if ( rc != LDAP_SUCCESS ) {
353 entry = ldap_first_entry( ld, res );
354 if ( entry == NULL ) {
358 values = ldap_get_values_len( ld, entry, attrs[ 0 ] );
359 if ( values == NULL ) {
360 rc = LDAP_NO_SUCH_ATTRIBUTE;
364 for ( i = 0; values[ i ] != NULL; i++ ) {
365 if ( bvmatch( &bv_val, values[ i ] ) ) {
366 rc = LDAP_COMPARE_TRUE;
371 rc = LDAP_COMPARE_FALSE;
374 if ( values != NULL ) {
375 ldap_value_free_len( values );
382 ldap_unbind_ext( ld, NULL, NULL );