2 /* root_dse.c - Provides the Root DSA-Specific Entry
4 * Copyright 1999-2003 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms are permitted only
8 * as authorized by the OpenLDAP Public License. A copy of this
9 * license is available at http://www.OpenLDAP.org/license.html or
10 * in file LICENSE in the top-level directory of the distribution.
17 #include <ac/string.h>
27 static struct berval supportedFeatures[] = {
28 BER_BVC(LDAP_FEATURE_ALL_OPERATIONAL_ATTRS), /* All Op Attrs (+) */
29 BER_BVC(LDAP_FEATURE_OBJECTCLASS_ATTRS), /* OCs in Attrs List (+person) */
30 BER_BVC(LDAP_FEATURE_ABSOLUTE_FILTERS), /* (&) and (|) search filters */
31 BER_BVC(LDAP_FEATURE_LANGUAGE_TAG_OPTIONS), /* Language Tag Options */
32 BER_BVC(LDAP_FEATURE_LANGUAGE_RANGE_OPTIONS), /* Language Range Options */
34 BER_BVC(LDAP_FEATURE_MODIFY_INCREMENT), /* Modify/increment */
39 static Entry *usr_attr = NULL;
48 struct berval vals[2], *bv;
49 struct berval nvals[2];
51 char ** supportedSASLMechanisms;
53 AttributeDescription *ad_structuralObjectClass
54 = slap_schema.si_ad_structuralObjectClass;
55 AttributeDescription *ad_objectClass
56 = slap_schema.si_ad_objectClass;
57 AttributeDescription *ad_namingContexts
58 = slap_schema.si_ad_namingContexts;
59 AttributeDescription *ad_supportedExtension
60 = slap_schema.si_ad_supportedExtension;
61 AttributeDescription *ad_supportedLDAPVersion
62 = slap_schema.si_ad_supportedLDAPVersion;
63 AttributeDescription *ad_supportedSASLMechanisms
64 = slap_schema.si_ad_supportedSASLMechanisms;
65 AttributeDescription *ad_supportedFeatures
66 = slap_schema.si_ad_supportedFeatures;
67 AttributeDescription *ad_monitorContext
68 = slap_schema.si_ad_monitorContext;
69 AttributeDescription *ad_ref
70 = slap_schema.si_ad_ref;
72 vals[1].bv_val = NULL;
73 nvals[1].bv_val = NULL;
75 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
79 LDAP_LOG( OPERATION, ERR,
80 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
82 Debug( LDAP_DEBUG_ANY,
83 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
89 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
90 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
91 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
92 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
94 /* the DN is an empty string so no pretty/normalization is needed */
95 assert( !e->e_name.bv_len );
96 assert( !e->e_nname.bv_len );
100 vals[0].bv_val = "top";
101 vals[0].bv_len = sizeof("top")-1;
102 if( attr_merge( e, ad_objectClass, vals, NULL ) ) {
106 vals[0].bv_val = "OpenLDAProotDSE";
107 vals[0].bv_len = sizeof("OpenLDAProotDSE")-1;
108 if( attr_merge( e, ad_objectClass, vals, NULL ) ) {
111 if( attr_merge( e, ad_structuralObjectClass, vals, NULL ) ) {
115 for ( i = 0; i < nbackends; i++ ) {
116 if ( backends[i].be_flags & SLAP_BFLAG_MONITOR ) {
117 vals[0] = backends[i].be_suffix[0];
118 nvals[0] = backends[i].be_nsuffix[0];
119 if( attr_merge( e, ad_monitorContext, vals, nvals ) ) {
124 if ( SLAP_GLUE_SUBORDINATE( &backends[i] ) ) {
127 for ( j = 0; backends[i].be_suffix[j].bv_val != NULL; j++ ) {
128 vals[0] = backends[i].be_suffix[j];
129 nvals[0] = backends[i].be_nsuffix[0];
130 if( attr_merge( e, ad_namingContexts, vals, nvals ) ) {
136 /* altServer unsupported */
138 /* supportedControl */
139 if ( controls_root_dse_info( e ) != 0 ) {
143 /* supportedExtension */
144 if ( exop_root_dse_info( e ) != 0 ) {
149 /* netscape supportedExtension */
150 for ( i = 0; (bv = ns_get_supported_extop(i)) != NULL; i++ ) {
152 if( attr_merge( e, ad_supportedExtension, vals, NULL )) {
156 #endif /* LDAP_SLAPI */
158 /* supportedFeatures */
159 if( attr_merge( e, ad_supportedFeatures, supportedFeatures, NULL ) ) {
163 /* supportedLDAPVersion */
164 for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
166 if (!( global_allows & SLAP_ALLOW_BIND_V2 ) &&
167 ( i < LDAP_VERSION3 ) )
169 /* version 2 and lower are disallowed */
172 snprintf(buf, sizeof buf, "%d", i);
173 vals[0].bv_val = buf;
174 vals[0].bv_len = strlen( vals[0].bv_val );
175 if( attr_merge( e, ad_supportedLDAPVersion, vals, NULL ) ) {
180 /* supportedSASLMechanism */
181 supportedSASLMechanisms = slap_sasl_mechs( conn );
183 if( supportedSASLMechanisms != NULL ) {
184 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
185 vals[0].bv_val = supportedSASLMechanisms[i];
186 vals[0].bv_len = strlen( vals[0].bv_val );
187 if( attr_merge( e, ad_supportedSASLMechanisms, vals, NULL ) ) {
191 ldap_charray_free( supportedSASLMechanisms );
194 if ( default_referral != NULL ) {
195 if( attr_merge( e, ad_ref, default_referral, NULL /* FIXME */ ) ) {
200 if( usr_attr != NULL) {
202 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
203 if( attr_merge( e, a->a_desc, a->a_vals,
204 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
216 * Read the entries specified in fname and merge the attributes
217 * to the user defined rootDSE. Note thaat if we find any errors
218 * what so ever, we will discard the entire entries, print an
219 * error message and return.
221 int read_root_dse_file( const char *fname )
224 int rc = 0, lineno = 0, lmax = 0;
227 if ( (fp = fopen( fname, "r" )) == NULL ) {
228 Debug( LDAP_DEBUG_ANY,
229 "could not open rootdse attr file \"%s\" - absolute path?\n",
235 usr_attr = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
236 if( usr_attr == NULL ) {
238 LDAP_LOG( OPERATION, ERR,
239 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
241 Debug( LDAP_DEBUG_ANY,
242 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
247 usr_attr->e_attrs = NULL;
249 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
250 Entry *e = str2entry( buf );
254 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
260 /* make sure the DN is the empty DN */
261 if( e->e_nname.bv_len ) {
263 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
271 * we found a valid entry, so walk thru all the attributes in the
272 * entry, and add each attribute type and description to the
276 for(a = e->e_attrs; a != NULL; a = a->a_next) {
277 if( attr_merge( usr_attr, a->a_desc, a->a_vals,
278 (a->a_nvals == a->a_vals) ? NULL : a->a_nvals ) )
290 entry_free( usr_attr );
298 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);