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_ALL_OP_ATTRS), /* All Op Attrs (+) */
33 BER_BVC(LDAP_FEATURE_OBJECTCLASS_ATTRS), /* OCs in Attrs List (@class) */
34 BER_BVC(LDAP_FEATURE_ABSOLUTE_FILTERS), /* (&) and (|) search filters */
35 BER_BVC(LDAP_FEATURE_LANGUAGE_TAG_OPTIONS), /* Language Tag Options */
36 BER_BVC(LDAP_FEATURE_LANGUAGE_RANGE_OPTIONS),/* Language Range Options */
37 #ifdef LDAP_FEATURE_SUBORDINATE_SCOPE
38 BER_BVC(LDAP_FEATURE_SUBORDINATE_SCOPE), /* "children" search scope */
40 #ifdef LDAP_FEATURE_MODIFY_INCREMENT
41 BER_BVC(LDAP_FEATURE_MODIFY_INCREMENT), /* Modify/increment */
46 static Entry *usr_attr = NULL;
60 char ** supportedSASLMechanisms;
63 AttributeDescription *ad_structuralObjectClass
64 = slap_schema.si_ad_structuralObjectClass;
65 AttributeDescription *ad_objectClass
66 = slap_schema.si_ad_objectClass;
67 AttributeDescription *ad_namingContexts
68 = slap_schema.si_ad_namingContexts;
70 AttributeDescription *ad_supportedExtension
71 = slap_schema.si_ad_supportedExtension;
73 AttributeDescription *ad_supportedLDAPVersion
74 = slap_schema.si_ad_supportedLDAPVersion;
75 AttributeDescription *ad_supportedSASLMechanisms
76 = slap_schema.si_ad_supportedSASLMechanisms;
77 AttributeDescription *ad_supportedFeatures
78 = slap_schema.si_ad_supportedFeatures;
79 AttributeDescription *ad_monitorContext
80 = slap_schema.si_ad_monitorContext;
81 AttributeDescription *ad_configContext
82 = slap_schema.si_ad_configContext;
83 AttributeDescription *ad_ref
84 = slap_schema.si_ad_ref;
86 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
89 Debug( LDAP_DEBUG_ANY,
90 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
95 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
96 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
97 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
98 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
100 /* the DN is an empty string so no pretty/normalization is needed */
101 assert( !e->e_name.bv_len );
102 assert( !e->e_nname.bv_len );
106 BER_BVSTR( &val, "top" );
107 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
111 BER_BVSTR( &val, "OpenLDAProotDSE" );
112 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
115 if( attr_merge_one( e, ad_structuralObjectClass, &val, NULL ) ) {
119 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
120 if ( be->be_suffix == NULL
121 || be->be_nsuffix == NULL ) {
125 if ( SLAP_MONITOR( be )) {
126 if( attr_merge_one( e, ad_monitorContext,
128 &be->be_nsuffix[0] ) )
134 if ( SLAP_CONFIG( be )) {
135 if( attr_merge_one( e, ad_configContext,
137 & be->be_nsuffix[0] ) )
143 if ( SLAP_GLUE_SUBORDINATE( be ) && !SLAP_GLUE_ADVERTISE( be ) ) {
146 for ( j = 0; be->be_suffix[j].bv_val != NULL; j++ ) {
147 if( attr_merge_one( e, ad_namingContexts,
149 &be->be_nsuffix[0] ) )
156 /* altServer unsupported */
158 /* supportedControl */
159 if ( controls_root_dse_info( e ) != 0 ) {
163 /* supportedExtension */
164 if ( exop_root_dse_info( e ) != 0 ) {
169 /* netscape supportedExtension */
170 for ( i = 0; (bv = slapi_int_get_supported_extop(i)) != NULL; i++ ) {
171 if( attr_merge_one( e, ad_supportedExtension, bv, NULL ) ) {
175 #endif /* LDAP_SLAPI */
177 /* supportedFeatures */
178 if( attr_merge( e, ad_supportedFeatures, supportedFeatures, NULL ) ) {
182 /* supportedLDAPVersion */
183 /* don't publish version 2 as we don't really support it
184 * (even when configured to accept version 2 Bind requests)
185 * and the value would never be used by true LDAPv2 (or LDAPv3)
188 for ( i=LDAP_VERSION3; i<=LDAP_VERSION_MAX; i++ ) {
190 snprintf(buf, sizeof buf, "%d", i);
192 val.bv_len = strlen( val.bv_val );
193 if( attr_merge_one( e, ad_supportedLDAPVersion, &val, NULL ) ) {
198 /* supportedSASLMechanism */
199 supportedSASLMechanisms = slap_sasl_mechs( conn );
201 if( supportedSASLMechanisms != NULL ) {
202 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
203 val.bv_val = supportedSASLMechanisms[i];
204 val.bv_len = strlen( val.bv_val );
205 if( attr_merge_one( e, ad_supportedSASLMechanisms, &val, NULL ) ) {
209 ldap_charray_free( supportedSASLMechanisms );
212 if ( default_referral != NULL ) {
213 if( attr_merge( e, ad_ref, default_referral, NULL /* FIXME */ ) ) {
218 if( usr_attr != NULL) {
220 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
221 if( attr_merge( e, a->a_desc, a->a_vals,
222 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
234 * Read the entries specified in fname and merge the attributes
235 * to the user defined rootDSE. Note thaat if we find any errors
236 * what so ever, we will discard the entire entries, print an
237 * error message and return.
239 int read_root_dse_file( const char *fname )
242 int rc = 0, lineno = 0, lmax = 0;
245 if ( (fp = ldif_open( fname, "r" )) == NULL ) {
246 Debug( LDAP_DEBUG_ANY,
247 "could not open rootdse attr file \"%s\" - absolute path?\n",
253 usr_attr = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
254 if( usr_attr == NULL ) {
255 Debug( LDAP_DEBUG_ANY,
256 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
260 usr_attr->e_attrs = NULL;
262 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
263 Entry *e = str2entry( buf );
267 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
273 /* make sure the DN is the empty DN */
274 if( e->e_nname.bv_len ) {
276 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
284 * we found a valid entry, so walk thru all the attributes in the
285 * entry, and add each attribute type and description to the
289 for(a = e->e_attrs; a != NULL; a = a->a_next) {
290 if( attr_merge( usr_attr, a->a_desc, a->a_vals,
291 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
303 entry_free( usr_attr );
311 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);
316 slap_discover_feature(
323 LDAPMessage *res = NULL, *entry;
325 struct berval cred = BER_BVC( "" ),
328 char *attrs[ 2 ] = { NULL, NULL };
330 ber_str2bv( val, 0, 0, &bv_val );
331 attrs[ 0 ] = (char *) attr;
333 rc = ldap_initialize( &ld, uri );
334 if ( rc != LDAP_SUCCESS ) {
338 rc = ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
339 if ( rc != LDAP_SUCCESS ) {
343 rc = ldap_sasl_bind_s( ld, "", LDAP_SASL_SIMPLE,
344 &cred, NULL, NULL, NULL );
345 if ( rc != LDAP_SUCCESS ) {
349 rc = ldap_search_ext_s( ld, "", LDAP_SCOPE_BASE, "(objectClass=*)",
350 attrs, 0, NULL, NULL, NULL, 0, &res );
351 if ( rc != LDAP_SUCCESS ) {
355 entry = ldap_first_entry( ld, res );
356 if ( entry == NULL ) {
360 values = ldap_get_values_len( ld, entry, attrs[ 0 ] );
361 if ( values == NULL ) {
362 rc = LDAP_NO_SUCH_ATTRIBUTE;
366 for ( i = 0; values[ i ] != NULL; i++ ) {
367 if ( bvmatch( &bv_val, values[ i ] ) ) {
368 rc = LDAP_COMPARE_TRUE;
373 rc = LDAP_COMPARE_FALSE;
376 if ( values != NULL ) {
377 ldap_value_free_len( values );
384 ldap_unbind_ext( ld, NULL, NULL );