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 *) ch_calloc( 1, sizeof(Entry) );
70 e->e_name.bv_val = ch_strdup( LDAP_ROOT_DSE );
71 e->e_name.bv_len = sizeof( LDAP_ROOT_DSE )-1;
72 e->e_nname.bv_val = ch_strdup( LDAP_ROOT_DSE );
73 e->e_nname.bv_len = sizeof( LDAP_ROOT_DSE )-1;
75 /* the DN is an empty string so no pretty/normalization is needed */
76 assert( !e->e_name.bv_len );
77 assert( !e->e_nname.bv_len );
81 vals[0].bv_val = "top";
82 vals[0].bv_len = sizeof("top")-1;
83 attr_merge( e, ad_objectClass, vals );
85 vals[0].bv_val = "OpenLDAProotDSE";
86 vals[0].bv_len = sizeof("OpenLDAProotDSE")-1;
87 attr_merge( e, ad_objectClass, vals );
88 attr_merge( e, ad_structuralObjectClass, vals );
90 for ( i = 0; i < nbackends; i++ ) {
91 if ( backends[i].be_flags & SLAP_BFLAG_MONITOR ) {
92 vals[0] = backends[i].be_suffix[0];
93 attr_merge( e, ad_monitorContext, vals );
96 if ( backends[i].be_flags & SLAP_BFLAG_GLUE_SUBORDINATE ) {
99 for ( j = 0; backends[i].be_suffix[j].bv_val != NULL; j++ ) {
100 vals[0] = backends[i].be_suffix[j];
101 attr_merge( e, ad_namingContexts, vals );
105 /* altServer unsupported */
107 /* supportedControl */
108 for ( i=0; (vals[0].bv_val = get_supported_ctrl(i)) != NULL; i++ ) {
109 vals[0].bv_len = strlen( vals[0].bv_val );
110 attr_merge( e, ad_supportedControl, vals );
113 /* supportedExtension */
114 for ( i=0; (bv = get_supported_extop(i)) != NULL; i++ ) {
116 attr_merge( e, ad_supportedExtension, vals );
119 /* supportedFeatures */
120 attr_merge( e, ad_supportedFeatures, supportedFeatures );
122 /* supportedLDAPVersion */
123 for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
125 if (!( global_allows & SLAP_ALLOW_BIND_V2 ) &&
126 ( i < LDAP_VERSION3 ) )
128 /* version 2 and lower are disallowed */
131 snprintf(buf, sizeof buf, "%d", i);
132 vals[0].bv_val = buf;
133 vals[0].bv_len = strlen( vals[0].bv_val );
134 attr_merge( e, ad_supportedLDAPVersion, vals );
137 /* supportedSASLMechanism */
138 supportedSASLMechanisms = slap_sasl_mechs( conn );
140 if( supportedSASLMechanisms != NULL ) {
141 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
142 vals[0].bv_val = supportedSASLMechanisms[i];
143 vals[0].bv_len = strlen( vals[0].bv_val );
144 attr_merge( e, ad_supportedSASLMechanisms, vals );
146 charray_free( supportedSASLMechanisms );
149 if ( default_referral != NULL ) {
150 attr_merge( e, ad_ref, default_referral );
153 if( usr_attr != NULL) {
155 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
156 attr_merge( e, a->a_desc, a->a_vals );
165 * Read the entries specified in fname and merge the attributes
166 * to the user defined rootDSE. Note thaat if we find any errors
167 * what so ever, we will discard the entire entries, print an
168 * error message and return.
170 int read_root_dse_file( const char *fname )
173 int rc = 0, lineno = 0, lmax = 0;
176 if ( (fp = fopen( fname, "r" )) == NULL ) {
177 Debug( LDAP_DEBUG_ANY,
178 "could not open rootdse attr file \"%s\" - absolute path?\n",
184 usr_attr = (Entry *) ch_calloc( 1, sizeof(Entry) );
185 usr_attr->e_attrs = NULL;
187 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
188 Entry *e = str2entry( buf );
192 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
195 entry_free( usr_attr );
200 /* make sure the DN is the empty DN */
201 if( e->e_nname.bv_len ) {
203 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
206 entry_free( usr_attr );
212 * we found a valid entry, so walk thru all the attributes in the
213 * entry, and add each attribute type and description to the
217 for(a = e->e_attrs; a != NULL; a = a->a_next) {
218 attr_merge( usr_attr, a->a_desc, a->a_vals );
226 Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);