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;
57 char ** supportedSASLMechanisms;
60 AttributeDescription *ad_structuralObjectClass
61 = slap_schema.si_ad_structuralObjectClass;
62 AttributeDescription *ad_objectClass
63 = slap_schema.si_ad_objectClass;
64 AttributeDescription *ad_namingContexts
65 = slap_schema.si_ad_namingContexts;
66 AttributeDescription *ad_supportedExtension
67 = slap_schema.si_ad_supportedExtension;
68 AttributeDescription *ad_supportedLDAPVersion
69 = slap_schema.si_ad_supportedLDAPVersion;
70 AttributeDescription *ad_supportedSASLMechanisms
71 = slap_schema.si_ad_supportedSASLMechanisms;
72 AttributeDescription *ad_supportedFeatures
73 = slap_schema.si_ad_supportedFeatures;
74 AttributeDescription *ad_monitorContext
75 = slap_schema.si_ad_monitorContext;
76 AttributeDescription *ad_configContext
77 = slap_schema.si_ad_configContext;
78 AttributeDescription *ad_ref
79 = slap_schema.si_ad_ref;
81 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
84 Debug( LDAP_DEBUG_ANY,
85 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
90 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
91 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
92 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
93 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
95 /* the DN is an empty string so no pretty/normalization is needed */
96 assert( !e->e_name.bv_len );
97 assert( !e->e_nname.bv_len );
101 BER_BVSTR( &val, "top" );
102 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
106 BER_BVSTR( &val, "OpenLDAProotDSE" );
107 if( attr_merge_one( e, ad_objectClass, &val, NULL ) ) {
110 if( attr_merge_one( e, ad_structuralObjectClass, &val, NULL ) ) {
114 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
115 if ( be->be_suffix == NULL
116 || be->be_nsuffix == NULL ) {
120 if ( SLAP_MONITOR( be )) {
121 if( attr_merge_one( e, ad_monitorContext,
123 &be->be_nsuffix[0] ) )
129 if ( SLAP_CONFIG( be )) {
130 if( attr_merge_one( e, ad_configContext,
132 & be->be_nsuffix[0] ) )
138 if ( SLAP_GLUE_SUBORDINATE( be ) && !SLAP_GLUE_ADVERTISE( be ) ) {
141 for ( j = 0; be->be_suffix[j].bv_val != NULL; j++ ) {
142 if( attr_merge_one( e, ad_namingContexts,
144 &be->be_nsuffix[0] ) )
151 /* altServer unsupported */
153 /* supportedControl */
154 if ( controls_root_dse_info( e ) != 0 ) {
158 /* supportedExtension */
159 if ( exop_root_dse_info( e ) != 0 ) {
164 /* netscape supportedExtension */
165 for ( i = 0; (bv = slapi_int_get_supported_extop(i)) != NULL; i++ ) {
166 if( attr_merge_one( e, ad_supportedExtension, bv, NULL ) ) {
170 #endif /* LDAP_SLAPI */
172 /* supportedFeatures */
173 if( attr_merge( e, ad_supportedFeatures, supportedFeatures, NULL ) ) {
177 /* supportedLDAPVersion */
178 /* don't publish version 2 as we don't really support it
179 * (even when configured to accept version 2 Bind requests)
180 * and the value would never be used by true LDAPv2 (or LDAPv3)
183 for ( i=LDAP_VERSION3; i<=LDAP_VERSION_MAX; i++ ) {
185 snprintf(buf, sizeof buf, "%d", i);
187 val.bv_len = strlen( val.bv_val );
188 if( attr_merge_one( e, ad_supportedLDAPVersion, &val, NULL ) ) {
193 /* supportedSASLMechanism */
194 supportedSASLMechanisms = slap_sasl_mechs( conn );
196 if( supportedSASLMechanisms != NULL ) {
197 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
198 val.bv_val = supportedSASLMechanisms[i];
199 val.bv_len = strlen( val.bv_val );
200 if( attr_merge_one( e, ad_supportedSASLMechanisms, &val, NULL ) ) {
204 ldap_charray_free( supportedSASLMechanisms );
207 if ( default_referral != NULL ) {
208 if( attr_merge( e, ad_ref, default_referral, NULL /* FIXME */ ) ) {
213 if( usr_attr != NULL) {
215 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
216 if( attr_merge( e, a->a_desc, a->a_vals,
217 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
229 * Read the entries specified in fname and merge the attributes
230 * to the user defined rootDSE. Note thaat if we find any errors
231 * what so ever, we will discard the entire entries, print an
232 * error message and return.
234 int read_root_dse_file( const char *fname )
237 int rc = 0, lineno = 0, lmax = 0;
240 if ( (fp = ldif_open( fname, "r" )) == NULL ) {
241 Debug( LDAP_DEBUG_ANY,
242 "could not open rootdse attr file \"%s\" - absolute path?\n",
248 usr_attr = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
249 if( usr_attr == NULL ) {
250 Debug( LDAP_DEBUG_ANY,
251 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
255 usr_attr->e_attrs = NULL;
257 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
258 Entry *e = str2entry( buf );
262 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
268 /* make sure the DN is the empty DN */
269 if( e->e_nname.bv_len ) {
271 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
279 * we found a valid entry, so walk thru all the attributes in the
280 * entry, and add each attribute type and description to the
284 for(a = e->e_attrs; a != NULL; a = a->a_next) {
285 if( attr_merge( usr_attr, a->a_desc, a->a_vals,
286 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
298 entry_free( usr_attr );
306 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);
311 slap_discover_feature(
318 LDAPMessage *res = NULL, *entry;
320 struct berval cred = BER_BVC( "" ),
323 char *attrs[ 2 ] = { NULL, NULL };
325 ber_str2bv( val, 0, 0, &bv_val );
326 attrs[ 0 ] = (char *) attr;
328 rc = ldap_initialize( &ld, uri );
329 if ( rc != LDAP_SUCCESS ) {
333 rc = ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
334 if ( rc != LDAP_SUCCESS ) {
338 rc = ldap_sasl_bind_s( ld, "", LDAP_SASL_SIMPLE,
339 &cred, NULL, NULL, NULL );
340 if ( rc != LDAP_SUCCESS ) {
344 rc = ldap_search_ext_s( ld, "", LDAP_SCOPE_BASE, "(objectClass=*)",
345 attrs, 0, NULL, NULL, NULL, 0, &res );
346 if ( rc != LDAP_SUCCESS ) {
350 entry = ldap_first_entry( ld, res );
351 if ( entry == NULL ) {
355 values = ldap_get_values_len( ld, entry, attrs[ 0 ] );
356 if ( values == NULL ) {
357 rc = LDAP_NO_SUCH_ATTRIBUTE;
361 for ( i = 0; values[ i ] != NULL; i++ ) {
362 if ( bvmatch( &bv_val, values[ i ] ) ) {
363 rc = LDAP_COMPARE_TRUE;
368 rc = LDAP_COMPARE_FALSE;
371 if ( values != NULL ) {
372 ldap_value_free_len( values );
379 ldap_unbind_ext( ld, NULL, NULL );