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>
20 static char *supportedFeatures[] = {
21 "1.3.6.1.4.1.4203.1.5.1", /* All Operational Attributes ("+") */
25 static Entry *usr_attr = NULL;
36 struct berval *vals[2];
38 char ** supportedSASLMechanisms;
40 AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
41 AttributeDescription *ad_namingContexts = slap_schema.si_ad_namingContexts;
42 AttributeDescription *ad_supportedControl = slap_schema.si_ad_supportedControl;
43 AttributeDescription *ad_supportedExtension = slap_schema.si_ad_supportedExtension;
44 AttributeDescription *ad_supportedLDAPVersion = slap_schema.si_ad_supportedLDAPVersion;
45 AttributeDescription *ad_supportedSASLMechanisms = slap_schema.si_ad_supportedSASLMechanisms;
46 AttributeDescription *ad_supportedFeatures = slap_schema.si_ad_supportedFeatures;
47 AttributeDescription *ad_ref = slap_schema.si_ad_ref;
54 e = (Entry *) ch_calloc( 1, sizeof(Entry) );
57 e->e_dn = ch_strdup( LDAP_ROOT_DSE );
58 e->e_ndn = ch_strdup( LDAP_ROOT_DSE );
59 (void) dn_normalize( e->e_ndn );
63 val.bv_len = sizeof("top")-1;
64 attr_merge( e, ad_objectClass, vals );
66 val.bv_val = "OpenLDAProotDSE";
67 val.bv_len = sizeof("OpenLDAProotDSE")-1;
68 attr_merge( e, ad_objectClass, vals );
70 for ( i = 0; i < nbackends; i++ ) {
71 for ( j = 0; backends[i].be_suffix[j] != NULL; j++ ) {
72 val.bv_val = backends[i].be_suffix[j];
73 val.bv_len = strlen( val.bv_val );
74 attr_merge( e, ad_namingContexts, vals );
78 /* altServer unsupported */
80 /* supportedControl */
81 for ( i=0; supportedControls[i] != NULL; i++ ) {
82 val.bv_val = supportedControls[i];
83 val.bv_len = strlen( val.bv_val );
84 attr_merge( e, ad_supportedControl, vals );
87 /* supportedExtension */
88 for ( i=0; (val.bv_val = get_supported_extop(i)) != NULL; i++ ) {
89 val.bv_len = strlen( val.bv_val );
90 attr_merge( e, ad_supportedExtension, vals );
93 /* supportedFeatures */
94 for ( i=0; supportedFeatures[i] != NULL; i++ ) {
95 val.bv_val = supportedFeatures[i];
96 val.bv_len = strlen( val.bv_val );
97 attr_merge( e, ad_supportedFeatures, vals );
100 /* supportedLDAPVersion */
101 for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
102 if (( global_disallows & SLAP_DISALLOW_BIND_V2 ) &&
103 ( i < LDAP_VERSION3 ) )
105 /* version 2 and lower are disallowed */
110 val.bv_len = strlen( val.bv_val );
111 attr_merge( e, ad_supportedLDAPVersion, vals );
114 /* supportedSASLMechanism */
115 supportedSASLMechanisms = slap_sasl_mechs( conn );
117 if( supportedSASLMechanisms != NULL ) {
118 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
119 val.bv_val = supportedSASLMechanisms[i];
120 val.bv_len = strlen( val.bv_val );
121 attr_merge( e, ad_supportedSASLMechanisms, vals );
125 if ( default_referral != NULL ) {
126 attr_merge( e, ad_ref, default_referral );
129 if( usr_attr != NULL) {
130 for(a = usr_attr->e_attrs; a != NULL; a = a->a_next) {
131 attr_merge( e, a->a_desc, a->a_vals );
140 * Read the entries specified in fname and merge the attributes
141 * to the user defined rootDSE. Note thaat if we find any errors
142 * what so ever, we will discard the entire entries, print an
143 * error message and return.
145 int read_root_dse_file( const char *fname )
148 char *line, *savefname, *saveline;
149 int rc = 0, lineno = 0, lmax = 0;
154 if ( (fp = fopen( fname, "r" )) == NULL ) {
155 Debug( LDAP_DEBUG_ANY,
156 "could not open rootdse attr file \"%s\" - absolute path?\n",
162 usr_attr = (Entry *) ch_calloc( 1, sizeof(Entry) );
163 usr_attr->e_attrs = NULL;
165 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);