2 /* root_dse.c - Provides the ROOT DSA-Specific Entry
4 * Copyright 1999-2002 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.
16 #include <ac/string.h>
22 static struct berval supportedFeatures[] = {
23 BER_BVC(LDAP_FEATURE_ALL_OPERATIONAL_ATTRS), /* all Operational Attributes ("+") */
24 BER_BVC(LDAP_FEATURE_OBJECTCLASS_ATTRS), /* OCs in Attributes List */
25 BER_BVC(LDAP_FEATURE_ABSOLUTE_FILTERS), /* (&) and (|) search filters */
26 BER_BVC(LDAP_FEATURE_LANGUAGE_TAG_OPTIONS), /* Language Tag Options */
27 BER_BVC(LDAP_FEATURE_LANGUAGE_RANGE_OPTIONS), /* Language Range Options */
31 static Entry *usr_attr = NULL;
40 struct berval vals[2], *bv;
42 char ** supportedSASLMechanisms;
44 AttributeDescription *ad_structuralObjectClass
45 = slap_schema.si_ad_structuralObjectClass;
46 AttributeDescription *ad_objectClass
47 = slap_schema.si_ad_objectClass;
48 AttributeDescription *ad_namingContexts
49 = slap_schema.si_ad_namingContexts;
50 AttributeDescription *ad_supportedControl
51 = slap_schema.si_ad_supportedControl;
52 AttributeDescription *ad_supportedExtension
53 = slap_schema.si_ad_supportedExtension;
54 AttributeDescription *ad_supportedLDAPVersion
55 = slap_schema.si_ad_supportedLDAPVersion;
56 AttributeDescription *ad_supportedSASLMechanisms
57 = slap_schema.si_ad_supportedSASLMechanisms;
58 AttributeDescription *ad_supportedFeatures
59 = slap_schema.si_ad_supportedFeatures;
60 AttributeDescription *ad_monitorContext
61 = slap_schema.si_ad_monitorContext;
62 AttributeDescription *ad_ref
63 = slap_schema.si_ad_ref;
65 vals[1].bv_val = NULL;
67 e = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
71 LDAP_LOG( OPERATION, ERR,
72 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
74 Debug( LDAP_DEBUG_ANY,
75 "root_dse_info: SLAP_CALLOC failed", 0, 0, 0 );
81 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
82 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
83 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
84 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
86 /* the DN is an empty string so no pretty/normalization is needed */
87 assert( !e->e_name.bv_len );
88 assert( !e->e_nname.bv_len );
92 vals[0].bv_val = "top";
93 vals[0].bv_len = sizeof("top")-1;
94 if( attr_merge( e, ad_objectClass, vals ) )
97 vals[0].bv_val = "OpenLDAProotDSE";
98 vals[0].bv_len = sizeof("OpenLDAProotDSE")-1;
99 if( attr_merge( e, ad_objectClass, vals ) )
101 if( attr_merge( e, ad_structuralObjectClass, vals ) )
104 for ( i = 0; i < nbackends; i++ ) {
105 if ( backends[i].be_flags & SLAP_BFLAG_MONITOR ) {
106 vals[0] = backends[i].be_suffix[0];
107 if( attr_merge( e, ad_monitorContext, vals ) )
111 if ( backends[i].be_flags & SLAP_BFLAG_GLUE_SUBORDINATE ) {
114 for ( j = 0; backends[i].be_suffix[j].bv_val != NULL; j++ ) {
115 vals[0] = backends[i].be_suffix[j];
116 if( attr_merge( e, ad_namingContexts, vals ) )
121 /* altServer unsupported */
123 /* supportedControl */
124 for ( i=0; (vals[0].bv_val = get_supported_ctrl(i)) != NULL; i++ ) {
125 vals[0].bv_len = strlen( vals[0].bv_val );
126 if( attr_merge( e, ad_supportedControl, vals ) )
130 /* supportedExtension */
131 for ( i=0; (bv = get_supported_extop(i)) != NULL; i++ ) {
133 if( attr_merge( e, ad_supportedExtension, vals ) )
137 /* supportedFeatures */
138 if( attr_merge( e, ad_supportedFeatures, supportedFeatures ) )
141 /* supportedLDAPVersion */
142 for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
144 if (!( global_allows & SLAP_ALLOW_BIND_V2 ) &&
145 ( i < LDAP_VERSION3 ) )
147 /* version 2 and lower are disallowed */
150 snprintf(buf, sizeof buf, "%d", i);
151 vals[0].bv_val = buf;
152 vals[0].bv_len = strlen( vals[0].bv_val );
153 if( attr_merge( e, ad_supportedLDAPVersion, vals ) )
157 /* supportedSASLMechanism */
158 supportedSASLMechanisms = slap_sasl_mechs( conn );
160 if( supportedSASLMechanisms != NULL ) {
161 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
162 vals[0].bv_val = supportedSASLMechanisms[i];
163 vals[0].bv_len = strlen( vals[0].bv_val );
164 if( attr_merge( e, ad_supportedSASLMechanisms, vals ) )
167 ldap_charray_free( supportedSASLMechanisms );
170 if ( default_referral != NULL ) {
171 if( attr_merge( e, ad_ref, default_referral ) )
175 if( usr_attr != NULL) {
177 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
178 if( attr_merge( e, a->a_desc, a->a_vals ) )
188 * Read the entries specified in fname and merge the attributes
189 * to the user defined rootDSE. Note thaat if we find any errors
190 * what so ever, we will discard the entire entries, print an
191 * error message and return.
193 int read_root_dse_file( const char *fname )
196 int rc = 0, lineno = 0, lmax = 0;
199 if ( (fp = fopen( fname, "r" )) == NULL ) {
200 Debug( LDAP_DEBUG_ANY,
201 "could not open rootdse attr file \"%s\" - absolute path?\n",
207 usr_attr = (Entry *) SLAP_CALLOC( 1, sizeof(Entry) );
208 if( usr_attr == NULL ) {
210 LDAP_LOG( OPERATION, ERR,
211 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
213 Debug( LDAP_DEBUG_ANY,
214 "read_root_dse_file: SLAP_CALLOC failed", 0, 0, 0 );
218 usr_attr->e_attrs = NULL;
220 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
221 Entry *e = str2entry( buf );
225 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
228 entry_free( usr_attr );
233 /* make sure the DN is the empty DN */
234 if( e->e_nname.bv_len ) {
236 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
239 entry_free( usr_attr );
245 * we found a valid entry, so walk thru all the attributes in the
246 * entry, and add each attribute type and description to the
250 for(a = e->e_attrs; a != NULL; a = a->a_next) {
251 if( attr_merge( usr_attr, a->a_desc, a->a_vals ) )
260 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);