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-2014 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 BER_BVC(LDAP_FEATURE_SUBORDINATE_SCOPE), /* "children" search scope */
41 static struct berval *supportedFeatures;
43 static Entry *usr_attr = NULL;
46 * allow modules to register functions that muck with the root DSE entry
49 typedef struct entry_info_t {
50 SLAP_ENTRY_INFO_FN func;
52 struct entry_info_t *next;
55 static entry_info_t *extra_info;
58 entry_info_register( SLAP_ENTRY_INFO_FN func, void *arg )
60 entry_info_t *ei = ch_calloc( 1, sizeof( entry_info_t ) );
65 ei->next = extra_info;
72 entry_info_unregister( SLAP_ENTRY_INFO_FN func, void *arg )
76 for ( eip = &extra_info; *eip != NULL; eip = &(*eip)->next ) {
77 if ( (*eip)->func == func && (*eip)->arg == arg ) {
78 entry_info_t *ei = *eip;
92 entry_info_destroy( void )
96 for ( eip = &extra_info; *eip != NULL; ) {
97 entry_info_t *ei = *eip;
106 * Allow modules to register supported features
110 supported_feature_init( void )
114 if ( supportedFeatures != NULL ) {
118 for ( i = 0; !BER_BVISNULL( &builtin_supportedFeatures[ i ] ); i++ )
121 supportedFeatures = ch_calloc( sizeof( struct berval ), i + 1 );
122 if ( supportedFeatures == NULL ) {
126 for ( i = 0; !BER_BVISNULL( &builtin_supportedFeatures[ i ] ); i++ ) {
127 ber_dupbv( &supportedFeatures[ i ], &builtin_supportedFeatures[ i ] );
129 BER_BVZERO( &supportedFeatures[ i ] );
135 supported_feature_destroy( void )
139 if ( supportedFeatures == NULL ) {
143 for ( i = 0; !BER_BVISNULL( &supportedFeatures[ i ] ); i++ ) {
144 ch_free( supportedFeatures[ i ].bv_val );
147 ch_free( supportedFeatures );
148 supportedFeatures = NULL;
154 supported_feature_load( struct berval *f )
159 supported_feature_init();
161 for ( i = 0; !BER_BVISNULL( &supportedFeatures[ i ] ); i++ )
164 tmp = ch_realloc( supportedFeatures, sizeof( struct berval ) * ( i + 2 ) );
168 supportedFeatures = tmp;
170 ber_dupbv( &supportedFeatures[ i ], f );
171 BER_BVZERO( &supportedFeatures[ i + 1 ] );
188 char ** supportedSASLMechanisms;
191 AttributeDescription *ad_structuralObjectClass
192 = slap_schema.si_ad_structuralObjectClass;
193 AttributeDescription *ad_objectClass
194 = slap_schema.si_ad_objectClass;
195 AttributeDescription *ad_namingContexts
196 = slap_schema.si_ad_namingContexts;
198 AttributeDescription *ad_supportedExtension
199 = slap_schema.si_ad_supportedExtension;
201 AttributeDescription *ad_supportedLDAPVersion
202 = slap_schema.si_ad_supportedLDAPVersion;
203 AttributeDescription *ad_supportedSASLMechanisms
204 = slap_schema.si_ad_supportedSASLMechanisms;
205 AttributeDescription *ad_supportedFeatures
206 = slap_schema.si_ad_supportedFeatures;
207 AttributeDescription *ad_monitorContext
208 = slap_schema.si_ad_monitorContext;
209 AttributeDescription *ad_configContext
210 = slap_schema.si_ad_configContext;
211 AttributeDescription *ad_ref
212 = slap_schema.si_ad_ref;
216 Debug( LDAP_DEBUG_ANY,
217 "root_dse_info: entry_alloc failed", 0, 0, 0 );
222 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
223 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
224 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
225 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
227 /* the DN is an empty string so no pretty/normalization is needed */
228 assert( !e->e_name.bv_len );
229 assert( !e->e_nname.bv_len );
233 /* FIXME: is this really needed? */
234 BER_BVSTR( &val, "top" );
235 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,
278 &be->be_suffix[j], NULL ) )
285 /* altServer unsupported */
287 /* supportedControl */
288 if ( controls_root_dse_info( e ) != 0 ) {
292 /* supportedExtension */
293 if ( exop_root_dse_info( e ) != 0 ) {
298 /* netscape supportedExtension */
299 for ( i = 0; (bv = slapi_int_get_supported_extop(i)) != NULL; i++ ) {
300 if( attr_merge_one( e, ad_supportedExtension, bv, NULL ) ) {
304 #endif /* LDAP_SLAPI */
306 /* supportedFeatures */
307 if ( supportedFeatures == NULL ) {
308 supported_feature_init();
311 if( attr_merge( e, ad_supportedFeatures, supportedFeatures, NULL ) ) {
315 /* supportedLDAPVersion */
316 /* don't publish version 2 as we don't really support it
317 * (even when configured to accept version 2 Bind requests)
318 * and the value would never be used by true LDAPv2 (or LDAPv3)
321 for ( i=LDAP_VERSION3; i<=LDAP_VERSION_MAX; i++ ) {
322 char buf[sizeof("255")];
323 snprintf(buf, sizeof buf, "%d", i);
325 val.bv_len = strlen( val.bv_val );
326 if( attr_merge_one( e, ad_supportedLDAPVersion, &val, NULL ) ) {
331 /* supportedSASLMechanism */
332 supportedSASLMechanisms = slap_sasl_mechs( conn );
334 if( supportedSASLMechanisms != NULL ) {
335 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
336 val.bv_val = supportedSASLMechanisms[i];
337 val.bv_len = strlen( val.bv_val );
338 if( attr_merge_one( e, ad_supportedSASLMechanisms, &val, NULL ) ) {
339 ldap_charray_free( supportedSASLMechanisms );
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 root_dse_init( void )
382 root_dse_destroy( void )
385 entry_free( usr_attr );
393 * Read the entries specified in fname and merge the attributes
394 * to the user defined rootDSE. Note thaat if we find any errors
395 * what so ever, we will discard the entire entries, print an
396 * error message and return.
399 root_dse_read_file( const char *fname )
402 int rc = 0, lmax = 0, ldifrc;
403 unsigned long lineno = 0;
406 if ( (fp = ldif_open( fname, "r" )) == NULL ) {
407 Debug( LDAP_DEBUG_ANY,
408 "root_dse_read_file: could not open rootdse attr file \"%s\" - absolute path?\n",
414 usr_attr = entry_alloc();
415 if( usr_attr == NULL ) {
416 Debug( LDAP_DEBUG_ANY,
417 "root_dse_read_file: entry_alloc failed", 0, 0, 0 );
421 usr_attr->e_attrs = NULL;
423 while(( ldifrc = ldif_read_record( fp, &lineno, &buf, &lmax )) > 0 ) {
424 Entry *e = str2entry( buf );
428 Debug( LDAP_DEBUG_ANY, "root_dse_read_file: "
429 "could not parse entry (file=\"%s\" line=%lu)\n",
435 /* make sure the DN is the empty DN */
436 if( e->e_nname.bv_len ) {
437 Debug( LDAP_DEBUG_ANY,
438 "root_dse_read_file: invalid rootDSE "
439 "- dn=\"%s\" (file=\"%s\" line=%lu)\n",
440 e->e_dn, fname, lineno );
447 * we found a valid entry, so walk thru all the attributes in the
448 * entry, and add each attribute type and description to the
452 for(a = e->e_attrs; a != NULL; a = a->a_next) {
453 if( attr_merge( usr_attr, a->a_desc, a->a_vals,
454 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
469 entry_free( usr_attr );
477 Debug(LDAP_DEBUG_CONFIG, "rootDSE file=\"%s\" read.\n", fname, 0, 0);
482 slap_discover_feature(
488 LDAPMessage *res = NULL, *entry;
490 struct berval bv_val,
492 char *attrs[ 2 ] = { NULL, NULL };
494 rc = slap_client_connect( &ld, sb );
495 if ( rc != LDAP_SUCCESS ) {
499 attrs[ 0 ] = (char *) attr;
500 rc = ldap_search_ext_s( ld, "", LDAP_SCOPE_BASE, "(objectClass=*)",
501 attrs, 0, NULL, NULL, NULL, 0, &res );
502 if ( rc != LDAP_SUCCESS ) {
506 entry = ldap_first_entry( ld, res );
507 if ( entry == NULL ) {
511 values = ldap_get_values_len( ld, entry, attrs[ 0 ] );
512 if ( values == NULL ) {
513 rc = LDAP_NO_SUCH_ATTRIBUTE;
517 ber_str2bv( val, 0, 0, &bv_val );
518 for ( i = 0; values[ i ] != NULL; i++ ) {
519 if ( bvmatch( &bv_val, values[ i ] ) ) {
520 rc = LDAP_COMPARE_TRUE;
525 rc = LDAP_COMPARE_FALSE;
528 if ( values != NULL ) {
529 ldap_value_free_len( values );
536 ldap_unbind_ext( ld, NULL, NULL );