2 /* root_dse.c - Provides the ROOT DSA-Specific Entry
4 * Copyright 1999-2000 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>
21 static char *supportedFeatures[] = {
22 "1.3.6.1.4.1.4203.1.5.1", /* All Operational Attributes ("+") */
26 static Entry *usr_attr = NULL;
37 struct berval *vals[2];
39 char ** supportedSASLMechanisms;
41 AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
42 AttributeDescription *ad_namingContexts = slap_schema.si_ad_namingContexts;
43 AttributeDescription *ad_supportedControl = slap_schema.si_ad_supportedControl;
44 AttributeDescription *ad_supportedExtension = slap_schema.si_ad_supportedExtension;
45 AttributeDescription *ad_supportedLDAPVersion = slap_schema.si_ad_supportedLDAPVersion;
46 AttributeDescription *ad_supportedSASLMechanisms = slap_schema.si_ad_supportedSASLMechanisms;
47 AttributeDescription *ad_supportedFeatures = slap_schema.si_ad_supportedFeatures;
48 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
55 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
58 e->e_dn = ch_strdup( LDAP_ROOT_DSE );
59 e->e_ndn = ch_strdup( LDAP_ROOT_DSE );
60 (void) dn_normalize( e->e_ndn );
64 val.bv_len = sizeof("top")-1;
65 attr_merge( e, ad_objectClass, vals );
67 val.bv_val = "OpenLDAProotDSE";
68 val.bv_len = sizeof("OpenLDAProotDSE")-1;
69 attr_merge( e, ad_objectClass, vals );
71 for ( i = 0; i < nbackends; i++ ) {
72 for ( j = 0; backends[i].be_suffix[j] != NULL; j++ ) {
73 val.bv_val = backends[i].be_suffix[j];
74 val.bv_len = strlen( val.bv_val );
75 attr_merge( e, ad_namingContexts, vals );
79 /* altServer unsupported */
81 /* supportedControl */
82 for ( i=0; supportedControls[i] != NULL; i++ ) {
83 val.bv_val = supportedControls[i];
84 val.bv_len = strlen( val.bv_val );
85 attr_merge( e, ad_supportedControl, vals );
88 /* supportedExtension */
89 for ( i=0; (val.bv_val = get_supported_extop(i)) != NULL; i++ ) {
90 val.bv_len = strlen( val.bv_val );
91 attr_merge( e, ad_supportedExtension, vals );
94 /* supportedFeatures */
95 for ( i=0; supportedFeatures[i] != NULL; i++ ) {
96 val.bv_val = supportedFeatures[i];
97 val.bv_len = strlen( val.bv_val );
98 attr_merge( e, ad_supportedFeatures, vals );
101 /* supportedLDAPVersion */
102 for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
103 if (( global_disallows & SLAP_DISALLOW_BIND_V2 ) &&
104 ( i < LDAP_VERSION3 ) )
106 /* version 2 and lower are disallowed */
111 val.bv_len = strlen( val.bv_val );
112 attr_merge( e, ad_supportedLDAPVersion, vals );
115 /* supportedSASLMechanism */
116 supportedSASLMechanisms = slap_sasl_mechs( conn );
118 if( supportedSASLMechanisms != NULL ) {
119 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
120 val.bv_val = supportedSASLMechanisms[i];
121 val.bv_len = strlen( val.bv_val );
122 attr_merge( e, ad_supportedSASLMechanisms, vals );
124 charray_free( supportedSASLMechanisms );
127 if ( default_referral != NULL ) {
128 attr_merge( e, ad_ref, default_referral );
131 if( usr_attr != NULL) {
132 for(a = usr_attr->e_attrs; a != NULL; a = a->a_next) {
133 attr_merge( e, a->a_desc, a->a_vals );
142 * Read the entries specified in fname and merge the attributes
143 * to the user defined rootDSE. Note thaat if we find any errors
144 * what so ever, we will discard the entire entries, print an
145 * error message and return.
147 int read_root_dse_file( const char *fname )
150 int rc = 0, lineno = 0, lmax = 0;
155 if ( (fp = fopen( fname, "r" )) == NULL ) {
156 Debug( LDAP_DEBUG_ANY,
157 "could not open rootdse attr file \"%s\" - absolute path?\n",
163 usr_attr = (Entry *) ch_calloc( 1, sizeof(Entry) );
164 usr_attr->e_attrs = NULL;
166 while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
167 Entry *e = str2entry( buf );
170 fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
173 entry_free( usr_attr );
178 if( dn_normalize( e->e_ndn ) == NULL ) {
179 fprintf( stderr, "root_dse: invalid dn=\"%s\" (line=%d)\n",
182 entry_free( usr_attr );
187 /* make sure the DN is a valid rootdse(rootdse is a null string) */
188 if( strcmp(e->e_ndn, "") != 0 ) {
190 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
193 entry_free( usr_attr );
199 * we found a valid entry, so walk thru all the attributes in the
200 * entry, and add each attribute type and description to the
204 for(a = e->e_attrs; a != NULL; a = a->a_next) {
205 attr_merge( usr_attr, a->a_desc, a->a_vals );
213 Debug(LDAP_DEBUG_CONFIG,"rootDSE file %s read.\n", fname, 0, 0);