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 vals[2], *bv;
56 struct berval nvals[2];
58 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_ref
77 = slap_schema.si_ad_ref;
79 vals[1].bv_val = NULL;
80 nvals[1].bv_val = NULL;
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 vals[0].bv_val = "top";
103 vals[0].bv_len = sizeof("top")-1;
104 if( attr_merge( e, ad_objectClass, vals, NULL ) ) {
108 vals[0].bv_val = "OpenLDAProotDSE";
109 vals[0].bv_len = sizeof("OpenLDAProotDSE")-1;
110 if( attr_merge( e, ad_objectClass, vals, NULL ) ) {
113 if( attr_merge( e, ad_structuralObjectClass, vals, NULL ) ) {
117 for ( i = 0; i < nbackends; i++ ) {
118 if ( backends[i].be_suffix == NULL
119 || backends[i].be_nsuffix == NULL ) {
123 if ( SLAP_MONITOR( &backends[i] )) {
124 vals[0] = backends[i].be_suffix[0];
125 nvals[0] = backends[i].be_nsuffix[0];
126 if( attr_merge( e, ad_monitorContext, vals, nvals ) ) {
131 if ( SLAP_GLUE_SUBORDINATE( &backends[i] ) && !SLAP_GLUE_ADVERTISE( &backends[i] ) ) {
134 for ( j = 0; backends[i].be_suffix[j].bv_val != NULL; j++ ) {
135 vals[0] = backends[i].be_suffix[j];
136 nvals[0] = backends[i].be_nsuffix[0];
137 if( attr_merge( e, ad_namingContexts, vals, nvals ) ) {
143 /* altServer unsupported */
145 /* supportedControl */
146 if ( controls_root_dse_info( e ) != 0 ) {
150 /* supportedExtension */
151 if ( exop_root_dse_info( e ) != 0 ) {
156 /* netscape supportedExtension */
157 for ( i = 0; (bv = slapi_int_get_supported_extop(i)) != NULL; i++ ) {
159 if( attr_merge( e, ad_supportedExtension, vals, NULL )) {
163 #endif /* LDAP_SLAPI */
165 /* supportedFeatures */
166 if( attr_merge( e, ad_supportedFeatures, supportedFeatures, NULL ) ) {
170 /* supportedLDAPVersion */
171 for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
173 if (!( global_allows & SLAP_ALLOW_BIND_V2 ) &&
174 ( i < LDAP_VERSION3 ) )
176 /* version 2 and lower are disallowed */
179 snprintf(buf, sizeof buf, "%d", i);
180 vals[0].bv_val = buf;
181 vals[0].bv_len = strlen( vals[0].bv_val );
182 if( attr_merge( e, ad_supportedLDAPVersion, vals, NULL ) ) {
187 /* supportedSASLMechanism */
188 supportedSASLMechanisms = slap_sasl_mechs( conn );
190 if( supportedSASLMechanisms != NULL ) {
191 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
192 vals[0].bv_val = supportedSASLMechanisms[i];
193 vals[0].bv_len = strlen( vals[0].bv_val );
194 if( attr_merge( e, ad_supportedSASLMechanisms, vals, NULL ) ) {
198 ldap_charray_free( supportedSASLMechanisms );
201 if ( default_referral != NULL ) {
202 if( attr_merge( e, ad_ref, default_referral, NULL /* FIXME */ ) ) {
207 if( usr_attr != NULL) {
209 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
210 if( attr_merge( e, a->a_desc, a->a_vals,
211 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
223 * Read the entries specified in fname and merge the attributes
224 * to the user defined rootDSE. Note thaat if we find any errors
225 * what so ever, we will discard the entire entries, print an
226 * error message and return.
228 int read_root_dse_file( const char *fname )
231 int rc = 0, lineno = 0, lmax = 0;
234 if ( (fp = fopen( fname, "r" )) == NULL ) {
235 Debug( LDAP_DEBUG_ANY,
236 "could not open rootdse attr file \"%s\" - absolute path?\n",
242 usr_attr = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
243 if( usr_attr == NULL ) {
244 Debug( LDAP_DEBUG_ANY,
245 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
249 usr_attr->e_attrs = NULL;
251 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
252 Entry *e = str2entry( buf );
256 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
262 /* make sure the DN is the empty DN */
263 if( e->e_nname.bv_len ) {
265 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
273 * we found a valid entry, so walk thru all the attributes in the
274 * entry, and add each attribute type and description to the
278 for(a = e->e_attrs; a != NULL; a = a->a_next) {
279 if( attr_merge( usr_attr, a->a_desc, a->a_vals,
280 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
292 entry_free( usr_attr );
300 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);