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;
55 struct berval val, *bv;
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;
67 AttributeDescription *ad_supportedExtension
68 = slap_schema.si_ad_supportedExtension;
69 AttributeDescription *ad_supportedLDAPVersion
70 = slap_schema.si_ad_supportedLDAPVersion;
71 AttributeDescription *ad_supportedSASLMechanisms
72 = slap_schema.si_ad_supportedSASLMechanisms;
73 AttributeDescription *ad_supportedFeatures
74 = slap_schema.si_ad_supportedFeatures;
75 AttributeDescription *ad_monitorContext
76 = slap_schema.si_ad_monitorContext;
77 AttributeDescription *ad_configContext
78 = slap_schema.si_ad_configContext;
79 AttributeDescription *ad_ref
80 = slap_schema.si_ad_ref;
82 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
85 Debug( LDAP_DEBUG_ANY,
86 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
91 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
92 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
93 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
94 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
96 /* the DN is an empty string so no pretty/normalization is needed */
97 assert( !e->e_name.bv_len );
98 assert( !e->e_nname.bv_len );
102 BER_BVSTR( &val, "top" );
103 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
107 BER_BVSTR( &val, "OpenLDAProotDSE" );
108 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
111 if( attr_merge_one( e, ad_structuralObjectClass, &val, NULL ) ) {
115 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
116 if ( be->be_suffix == NULL
117 || be->be_nsuffix == NULL ) {
121 if ( SLAP_MONITOR( be )) {
122 if( attr_merge_one( e, ad_monitorContext,
124 &be->be_nsuffix[0] ) )
130 if ( SLAP_CONFIG( be )) {
131 if( attr_merge_one( e, ad_configContext,
133 & be->be_nsuffix[0] ) )
139 if ( SLAP_GLUE_SUBORDINATE( be ) && !SLAP_GLUE_ADVERTISE( be ) ) {
142 for ( j = 0; be->be_suffix[j].bv_val != NULL; j++ ) {
143 if( attr_merge_one( e, ad_namingContexts,
145 &be->be_nsuffix[0] ) )
152 /* altServer unsupported */
154 /* supportedControl */
155 if ( controls_root_dse_info( e ) != 0 ) {
159 /* supportedExtension */
160 if ( exop_root_dse_info( e ) != 0 ) {
165 /* netscape supportedExtension */
166 for ( i = 0; (bv = slapi_int_get_supported_extop(i)) != NULL; i++ ) {
167 if( attr_merge_one( e, ad_supportedExtension, bv, NULL ) ) {
171 #endif /* LDAP_SLAPI */
173 /* supportedFeatures */
174 if( attr_merge( e, ad_supportedFeatures, supportedFeatures, NULL ) ) {
178 /* supportedLDAPVersion */
179 /* don't publish version 2 as we don't really support it
180 * (even when configured to accept version 2 Bind requests)
181 * and the value would never be used by true LDAPv2 (or LDAPv3)
184 for ( i=LDAP_VERSION3; i<=LDAP_VERSION_MAX; i++ ) {
186 snprintf(buf, sizeof buf, "%d", i);
188 val.bv_len = strlen( val.bv_val );
189 if( attr_merge_one( e, ad_supportedLDAPVersion, &val, NULL ) ) {
194 /* supportedSASLMechanism */
195 supportedSASLMechanisms = slap_sasl_mechs( conn );
197 if( supportedSASLMechanisms != NULL ) {
198 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
199 val.bv_val = supportedSASLMechanisms[i];
200 val.bv_len = strlen( val.bv_val );
201 if( attr_merge_one( e, ad_supportedSASLMechanisms, &val, NULL ) ) {
205 ldap_charray_free( supportedSASLMechanisms );
208 if ( default_referral != NULL ) {
209 if( attr_merge( e, ad_ref, default_referral, NULL /* FIXME */ ) ) {
214 if( usr_attr != NULL) {
216 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
217 if( attr_merge( e, a->a_desc, a->a_vals,
218 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
230 * Read the entries specified in fname and merge the attributes
231 * to the user defined rootDSE. Note thaat if we find any errors
232 * what so ever, we will discard the entire entries, print an
233 * error message and return.
235 int read_root_dse_file( const char *fname )
238 int rc = 0, lineno = 0, lmax = 0;
241 if ( (fp = ldif_open( fname, "r" )) == NULL ) {
242 Debug( LDAP_DEBUG_ANY,
243 "could not open rootdse attr file \"%s\" - absolute path?\n",
249 usr_attr = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
250 if( usr_attr == NULL ) {
251 Debug( LDAP_DEBUG_ANY,
252 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
256 usr_attr->e_attrs = NULL;
258 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
259 Entry *e = str2entry( buf );
263 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
269 /* make sure the DN is the empty DN */
270 if( e->e_nname.bv_len ) {
272 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
280 * we found a valid entry, so walk thru all the attributes in the
281 * entry, and add each attribute type and description to the
285 for(a = e->e_attrs; a != NULL; a = a->a_next) {
286 if( attr_merge( usr_attr, a->a_desc, a->a_vals,
287 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
299 entry_free( usr_attr );
307 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);
312 slap_discover_feature(
319 LDAPMessage *res = NULL, *entry;
321 struct berval cred = BER_BVC( "" ),
324 char *attrs[ 2 ] = { NULL, NULL };
326 ber_str2bv( val, 0, 0, &bv_val );
329 rc = ldap_initialize( &ld, uri );
330 if ( rc != LDAP_SUCCESS ) {
334 rc = ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
335 if ( rc != LDAP_SUCCESS ) {
339 rc = ldap_sasl_bind_s( ld, "", LDAP_SASL_SIMPLE,
340 &cred, NULL, NULL, NULL );
341 if ( rc != LDAP_SUCCESS ) {
345 rc = ldap_search_ext_s( ld, "", LDAP_SCOPE_BASE, "(objectClass=*)",
346 attrs, 0, NULL, NULL, NULL, 0, &res );
347 if ( rc != LDAP_SUCCESS ) {
351 entry = ldap_first_entry( ld, res );
352 if ( entry == NULL ) {
356 values = ldap_get_values_len( ld, entry, attrs[ 0 ] );
357 if ( values == NULL ) {
358 rc = LDAP_NO_SUCH_ATTRIBUTE;
362 for ( i = 0; values[ i ] != NULL; i++ ) {
363 if ( bvmatch( &bv_val, values[ i ] ) ) {
364 rc = LDAP_COMPARE_TRUE;
369 rc = LDAP_COMPARE_FALSE;
372 if ( values != NULL ) {
373 ldap_value_free_len( values );
380 ldap_unbind_ext( ld, NULL, NULL );