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 builtin_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 */
43 static struct berval *supportedFeatures;
45 static Entry *usr_attr = NULL;
48 supported_feature_init( void )
52 if ( supportedFeatures != NULL ) {
56 for ( i = 0; !BER_BVISNULL( &builtin_supportedFeatures[ i ] ); i++ )
59 supportedFeatures = ch_calloc( sizeof( struct berval ), i + 1 );
60 if ( supportedFeatures == NULL ) {
64 for ( i = 0; !BER_BVISNULL( &builtin_supportedFeatures[ i ] ); i++ ) {
65 ber_dupbv( &supportedFeatures[ i ], &builtin_supportedFeatures[ i ] );
67 BER_BVZERO( &supportedFeatures[ i ] );
73 supported_feature_destroy( void )
77 if ( supportedFeatures == NULL ) {
81 for ( i = 0; !BER_BVISNULL( &supportedFeatures[ i ] ); i++ ) {
82 ch_free( supportedFeatures[ i ].bv_val );
85 ch_free( supportedFeatures );
86 supportedFeatures = NULL;
92 supported_feature_load( struct berval *f )
97 supported_feature_init();
99 for ( i = 0; !BER_BVISNULL( &supportedFeatures[ i ] ); i++ )
102 tmp = ch_realloc( supportedFeatures, sizeof( struct berval ) * ( i + 2 ) );
106 supportedFeatures = tmp;
108 ber_dupbv( &supportedFeatures[ i ], f );
109 BER_BVZERO( &supportedFeatures[ i + 1 ] );
126 char ** supportedSASLMechanisms;
129 AttributeDescription *ad_structuralObjectClass
130 = slap_schema.si_ad_structuralObjectClass;
131 AttributeDescription *ad_objectClass
132 = slap_schema.si_ad_objectClass;
133 AttributeDescription *ad_namingContexts
134 = slap_schema.si_ad_namingContexts;
136 AttributeDescription *ad_supportedExtension
137 = slap_schema.si_ad_supportedExtension;
139 AttributeDescription *ad_supportedLDAPVersion
140 = slap_schema.si_ad_supportedLDAPVersion;
141 AttributeDescription *ad_supportedSASLMechanisms
142 = slap_schema.si_ad_supportedSASLMechanisms;
143 AttributeDescription *ad_supportedFeatures
144 = slap_schema.si_ad_supportedFeatures;
145 AttributeDescription *ad_monitorContext
146 = slap_schema.si_ad_monitorContext;
147 AttributeDescription *ad_configContext
148 = slap_schema.si_ad_configContext;
149 AttributeDescription *ad_ref
150 = slap_schema.si_ad_ref;
152 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
155 Debug( LDAP_DEBUG_ANY,
156 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
161 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
162 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
163 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
164 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
166 /* the DN is an empty string so no pretty/normalization is needed */
167 assert( !e->e_name.bv_len );
168 assert( !e->e_nname.bv_len );
172 BER_BVSTR( &val, "top" );
173 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
177 BER_BVSTR( &val, "OpenLDAProotDSE" );
178 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
181 if( attr_merge_one( e, ad_structuralObjectClass, &val, NULL ) ) {
185 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
186 if ( be->be_suffix == NULL
187 || be->be_nsuffix == NULL ) {
191 if ( SLAP_MONITOR( be )) {
192 if( attr_merge_one( e, ad_monitorContext,
194 &be->be_nsuffix[0] ) )
200 if ( SLAP_CONFIG( be )) {
201 if( attr_merge_one( e, ad_configContext,
203 & be->be_nsuffix[0] ) )
209 if ( SLAP_GLUE_SUBORDINATE( be ) && !SLAP_GLUE_ADVERTISE( be ) ) {
212 for ( j = 0; be->be_suffix[j].bv_val != NULL; j++ ) {
213 if( attr_merge_one( e, ad_namingContexts,
215 &be->be_nsuffix[0] ) )
222 /* altServer unsupported */
224 /* supportedControl */
225 if ( controls_root_dse_info( e ) != 0 ) {
229 /* supportedExtension */
230 if ( exop_root_dse_info( e ) != 0 ) {
235 /* netscape supportedExtension */
236 for ( i = 0; (bv = slapi_int_get_supported_extop(i)) != NULL; i++ ) {
237 if( attr_merge_one( e, ad_supportedExtension, bv, NULL ) ) {
241 #endif /* LDAP_SLAPI */
243 /* supportedFeatures */
244 if ( supportedFeatures == NULL ) {
245 supported_feature_init();
248 if( attr_merge( e, ad_supportedFeatures, supportedFeatures, NULL ) ) {
252 /* supportedLDAPVersion */
253 /* don't publish version 2 as we don't really support it
254 * (even when configured to accept version 2 Bind requests)
255 * and the value would never be used by true LDAPv2 (or LDAPv3)
258 for ( i=LDAP_VERSION3; i<=LDAP_VERSION_MAX; i++ ) {
260 snprintf(buf, sizeof buf, "%d", i);
262 val.bv_len = strlen( val.bv_val );
263 if( attr_merge_one( e, ad_supportedLDAPVersion, &val, NULL ) ) {
268 /* supportedSASLMechanism */
269 supportedSASLMechanisms = slap_sasl_mechs( conn );
271 if( supportedSASLMechanisms != NULL ) {
272 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
273 val.bv_val = supportedSASLMechanisms[i];
274 val.bv_len = strlen( val.bv_val );
275 if( attr_merge_one( e, ad_supportedSASLMechanisms, &val, NULL ) ) {
279 ldap_charray_free( supportedSASLMechanisms );
282 if ( default_referral != NULL ) {
283 if( attr_merge( e, ad_ref, default_referral, NULL /* FIXME */ ) ) {
288 if( usr_attr != NULL) {
290 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
291 if( attr_merge( e, a->a_desc, a->a_vals,
292 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
304 * Read the entries specified in fname and merge the attributes
305 * to the user defined rootDSE. Note thaat if we find any errors
306 * what so ever, we will discard the entire entries, print an
307 * error message and return.
309 int read_root_dse_file( const char *fname )
312 int rc = 0, lineno = 0, lmax = 0;
315 if ( (fp = ldif_open( fname, "r" )) == NULL ) {
316 Debug( LDAP_DEBUG_ANY,
317 "could not open rootdse attr file \"%s\" - absolute path?\n",
323 usr_attr = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
324 if( usr_attr == NULL ) {
325 Debug( LDAP_DEBUG_ANY,
326 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
330 usr_attr->e_attrs = NULL;
332 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
333 Entry *e = str2entry( buf );
337 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
343 /* make sure the DN is the empty DN */
344 if( e->e_nname.bv_len ) {
346 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
354 * we found a valid entry, so walk thru all the attributes in the
355 * entry, and add each attribute type and description to the
359 for(a = e->e_attrs; a != NULL; a = a->a_next) {
360 if( attr_merge( usr_attr, a->a_desc, a->a_vals,
361 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
373 entry_free( usr_attr );
381 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);
386 slap_discover_feature(
393 LDAPMessage *res = NULL, *entry;
395 struct berval cred = BER_BVC( "" ),
398 char *attrs[ 2 ] = { NULL, NULL };
400 ber_str2bv( val, 0, 0, &bv_val );
401 attrs[ 0 ] = (char *) attr;
403 rc = ldap_initialize( &ld, uri );
404 if ( rc != LDAP_SUCCESS ) {
408 rc = ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
409 if ( rc != LDAP_SUCCESS ) {
413 rc = ldap_sasl_bind_s( ld, "", LDAP_SASL_SIMPLE,
414 &cred, NULL, NULL, NULL );
415 if ( rc != LDAP_SUCCESS ) {
419 rc = ldap_search_ext_s( ld, "", LDAP_SCOPE_BASE, "(objectClass=*)",
420 attrs, 0, NULL, NULL, NULL, 0, &res );
421 if ( rc != LDAP_SUCCESS ) {
425 entry = ldap_first_entry( ld, res );
426 if ( entry == NULL ) {
430 values = ldap_get_values_len( ld, entry, attrs[ 0 ] );
431 if ( values == NULL ) {
432 rc = LDAP_NO_SUCH_ATTRIBUTE;
436 for ( i = 0; values[ i ] != NULL; i++ ) {
437 if ( bvmatch( &bv_val, values[ i ] ) ) {
438 rc = LDAP_COMPARE_TRUE;
443 rc = LDAP_COMPARE_FALSE;
446 if ( values != NULL ) {
447 ldap_value_free_len( values );
454 ldap_unbind_ext( ld, NULL, NULL );