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-2006 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 * allow modules to register functions that muck with the root DSE entry
51 typedef struct entry_info_t {
52 SLAP_ENTRY_INFO_FN func;
54 struct entry_info_t *next;
57 static entry_info_t *extra_info;
60 entry_info_register( SLAP_ENTRY_INFO_FN func, void *arg )
62 entry_info_t *ei = ch_calloc( 1, sizeof( entry_info_t ) );
67 ei->next = extra_info;
74 entry_info_unregister( SLAP_ENTRY_INFO_FN func, void *arg )
78 for ( eip = &extra_info; *eip != NULL; eip = &(*eip)->next ) {
79 if ( (*eip)->func == func && (*eip)->arg == arg ) {
80 entry_info_t *ei = *eip;
94 entry_info_destroy( void )
98 for ( eip = &extra_info; *eip != NULL; ) {
99 entry_info_t *ei = *eip;
108 * Allow modules to register supported features
112 supported_feature_init( void )
116 if ( supportedFeatures != NULL ) {
120 for ( i = 0; !BER_BVISNULL( &builtin_supportedFeatures[ i ] ); i++ )
123 supportedFeatures = ch_calloc( sizeof( struct berval ), i + 1 );
124 if ( supportedFeatures == NULL ) {
128 for ( i = 0; !BER_BVISNULL( &builtin_supportedFeatures[ i ] ); i++ ) {
129 ber_dupbv( &supportedFeatures[ i ], &builtin_supportedFeatures[ i ] );
131 BER_BVZERO( &supportedFeatures[ i ] );
137 supported_feature_destroy( void )
141 if ( supportedFeatures == NULL ) {
145 for ( i = 0; !BER_BVISNULL( &supportedFeatures[ i ] ); i++ ) {
146 ch_free( supportedFeatures[ i ].bv_val );
149 ch_free( supportedFeatures );
150 supportedFeatures = NULL;
156 supported_feature_load( struct berval *f )
161 supported_feature_init();
163 for ( i = 0; !BER_BVISNULL( &supportedFeatures[ i ] ); i++ )
166 tmp = ch_realloc( supportedFeatures, sizeof( struct berval ) * ( i + 2 ) );
170 supportedFeatures = tmp;
172 ber_dupbv( &supportedFeatures[ i ], f );
173 BER_BVZERO( &supportedFeatures[ i + 1 ] );
190 char ** supportedSASLMechanisms;
193 AttributeDescription *ad_structuralObjectClass
194 = slap_schema.si_ad_structuralObjectClass;
195 AttributeDescription *ad_objectClass
196 = slap_schema.si_ad_objectClass;
197 AttributeDescription *ad_namingContexts
198 = slap_schema.si_ad_namingContexts;
200 AttributeDescription *ad_supportedExtension
201 = slap_schema.si_ad_supportedExtension;
203 AttributeDescription *ad_supportedLDAPVersion
204 = slap_schema.si_ad_supportedLDAPVersion;
205 AttributeDescription *ad_supportedSASLMechanisms
206 = slap_schema.si_ad_supportedSASLMechanisms;
207 AttributeDescription *ad_supportedFeatures
208 = slap_schema.si_ad_supportedFeatures;
209 AttributeDescription *ad_monitorContext
210 = slap_schema.si_ad_monitorContext;
211 AttributeDescription *ad_configContext
212 = slap_schema.si_ad_configContext;
213 AttributeDescription *ad_ref
214 = slap_schema.si_ad_ref;
216 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
218 Debug( LDAP_DEBUG_ANY,
219 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
224 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
225 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
226 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
227 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
229 /* the DN is an empty string so no pretty/normalization is needed */
230 assert( !e->e_name.bv_len );
231 assert( !e->e_nname.bv_len );
235 /* FIXME: is this really needed? */
236 BER_BVSTR( &val, "top" );
237 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
241 BER_BVSTR( &val, "OpenLDAProotDSE" );
242 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
245 if( attr_merge_one( e, ad_structuralObjectClass, &val, NULL ) ) {
249 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
250 if ( be->be_suffix == NULL
251 || be->be_nsuffix == NULL ) {
255 if ( SLAP_MONITOR( be )) {
256 if( attr_merge_one( e, ad_monitorContext,
258 &be->be_nsuffix[0] ) )
264 if ( SLAP_CONFIG( be )) {
265 if( attr_merge_one( e, ad_configContext,
267 & be->be_nsuffix[0] ) )
273 if ( SLAP_GLUE_SUBORDINATE( be ) && !SLAP_GLUE_ADVERTISE( be ) ) {
276 for ( j = 0; be->be_suffix[j].bv_val != NULL; j++ ) {
277 if( attr_merge_one( e, ad_namingContexts,
279 &be->be_nsuffix[0] ) )
286 /* altServer unsupported */
288 /* supportedControl */
289 if ( controls_root_dse_info( e ) != 0 ) {
293 /* supportedExtension */
294 if ( exop_root_dse_info( e ) != 0 ) {
299 /* netscape supportedExtension */
300 for ( i = 0; (bv = slapi_int_get_supported_extop(i)) != NULL; i++ ) {
301 if( attr_merge_one( e, ad_supportedExtension, bv, NULL ) ) {
305 #endif /* LDAP_SLAPI */
307 /* supportedFeatures */
308 if ( supportedFeatures == NULL ) {
309 supported_feature_init();
312 if( attr_merge( e, ad_supportedFeatures, supportedFeatures, NULL ) ) {
316 /* supportedLDAPVersion */
317 /* don't publish version 2 as we don't really support it
318 * (even when configured to accept version 2 Bind requests)
319 * and the value would never be used by true LDAPv2 (or LDAPv3)
322 for ( i=LDAP_VERSION3; i<=LDAP_VERSION_MAX; i++ ) {
324 snprintf(buf, sizeof buf, "%d", i);
326 val.bv_len = strlen( val.bv_val );
327 if( attr_merge_one( e, ad_supportedLDAPVersion, &val, NULL ) ) {
332 /* supportedSASLMechanism */
333 supportedSASLMechanisms = slap_sasl_mechs( conn );
335 if( supportedSASLMechanisms != NULL ) {
336 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
337 val.bv_val = supportedSASLMechanisms[i];
338 val.bv_len = strlen( val.bv_val );
339 if( attr_merge_one( e, ad_supportedSASLMechanisms, &val, NULL ) ) {
343 ldap_charray_free( supportedSASLMechanisms );
346 if ( default_referral != NULL ) {
347 if( attr_merge( e, ad_ref, default_referral, NULL /* FIXME */ ) ) {
352 if( usr_attr != NULL) {
354 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
355 if( attr_merge( e, a->a_desc, a->a_vals,
356 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
364 entry_info_t *ei = extra_info;
366 for ( ; ei; ei = ei->next ) {
367 ei->func( ei->arg, e );
376 * Read the entries specified in fname and merge the attributes
377 * to the user defined rootDSE. Note thaat if we find any errors
378 * what so ever, we will discard the entire entries, print an
379 * error message and return.
381 int read_root_dse_file( const char *fname )
384 int rc = 0, lineno = 0, lmax = 0;
387 if ( (fp = ldif_open( fname, "r" )) == NULL ) {
388 Debug( LDAP_DEBUG_ANY,
389 "could not open rootdse attr file \"%s\" - absolute path?\n",
395 usr_attr = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
396 if( usr_attr == NULL ) {
397 Debug( LDAP_DEBUG_ANY,
398 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
402 usr_attr->e_attrs = NULL;
404 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
405 Entry *e = str2entry( buf );
409 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
415 /* make sure the DN is the empty DN */
416 if( e->e_nname.bv_len ) {
418 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
426 * we found a valid entry, so walk thru all the attributes in the
427 * entry, and add each attribute type and description to the
431 for(a = e->e_attrs; a != NULL; a = a->a_next) {
432 if( attr_merge( usr_attr, a->a_desc, a->a_vals,
433 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
445 entry_free( usr_attr );
453 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);
458 slap_discover_feature(
465 LDAPMessage *res = NULL, *entry;
467 struct berval cred = BER_BVC( "" ),
470 char *attrs[ 2 ] = { NULL, NULL };
472 ber_str2bv( val, 0, 0, &bv_val );
473 attrs[ 0 ] = (char *) attr;
475 rc = ldap_initialize( &ld, uri );
476 if ( rc != LDAP_SUCCESS ) {
480 rc = ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
481 (const void *)&version );
482 if ( rc != LDAP_SUCCESS ) {
486 rc = ldap_sasl_bind_s( ld, "", LDAP_SASL_SIMPLE,
487 &cred, NULL, NULL, NULL );
488 if ( rc != LDAP_SUCCESS ) {
492 rc = ldap_search_ext_s( ld, "", LDAP_SCOPE_BASE, "(objectClass=*)",
493 attrs, 0, NULL, NULL, NULL, 0, &res );
494 if ( rc != LDAP_SUCCESS ) {
498 entry = ldap_first_entry( ld, res );
499 if ( entry == NULL ) {
503 values = ldap_get_values_len( ld, entry, attrs[ 0 ] );
504 if ( values == NULL ) {
505 rc = LDAP_NO_SUCH_ATTRIBUTE;
509 for ( i = 0; values[ i ] != NULL; i++ ) {
510 if ( bvmatch( &bv_val, values[ i ] ) ) {
511 rc = LDAP_COMPARE_TRUE;
516 rc = LDAP_COMPARE_FALSE;
519 if ( values != NULL ) {
520 ldap_value_free_len( values );
527 ldap_unbind_ext( ld, NULL, NULL );