]> git.sur5r.net Git - openldap/blob - servers/slapd/root_dse.c
Changed supportedFeatures to array of struct bervals
[openldap] / servers / slapd / root_dse.c
1 /* $OpenLDAP$ */
2 /* root_dse.c - Provides the ROOT DSA-Specific Entry
3  *
4  * Copyright 1999-2002 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
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.
11  */
12
13 #include "portable.h"
14
15 #include <stdio.h>
16 #include <ac/string.h>
17
18 #include "slap.h"
19 #include <ldif.h>
20
21 #define BVC(x) {sizeof(x)-1, x}
22
23 static struct berval supportedFeatures[] = {
24         BVC("1.3.6.1.4.1.4203.1.5.1"), /* all Operational Attributes ("+") */
25         BVC("1.3.6.1.4.1.4203.1.5.2"), /* OCs in Attributes List */
26         BVC("1.3.6.1.4.1.4203.1.5.3"), /* (&) and (|) search filters */
27         BVC("1.3.6.1.4.1.4203.1.5.4"), /* Language Tag Options */
28         BVC("1.3.6.1.4.1.4203.1.5.5"), /* Language Range Options */
29         {0,NULL}
30 };
31
32 static Entry    *usr_attr = NULL;
33
34 int
35 root_dse_info(
36         Connection *conn,
37         Entry **entry,
38         const char **text )
39 {
40         char buf[BUFSIZ];
41         Entry           *e;
42         struct berval   vals[2], *bv;
43         int             i, j;
44         char ** supportedSASLMechanisms;
45
46         AttributeDescription *ad_structuralObjectClass
47                 = slap_schema.si_ad_structuralObjectClass;
48         AttributeDescription *ad_objectClass
49                 = slap_schema.si_ad_objectClass;
50         AttributeDescription *ad_namingContexts
51                 = slap_schema.si_ad_namingContexts;
52         AttributeDescription *ad_supportedControl
53                 = slap_schema.si_ad_supportedControl;
54         AttributeDescription *ad_supportedExtension
55                 = slap_schema.si_ad_supportedExtension;
56         AttributeDescription *ad_supportedLDAPVersion
57                 = slap_schema.si_ad_supportedLDAPVersion;
58         AttributeDescription *ad_supportedSASLMechanisms
59                 = slap_schema.si_ad_supportedSASLMechanisms;
60         AttributeDescription *ad_supportedFeatures
61                 = slap_schema.si_ad_supportedFeatures;
62         AttributeDescription *ad_ref
63                 = slap_schema.si_ad_ref;
64
65         vals[1].bv_val = NULL;
66
67         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
68
69         e->e_attrs = NULL;
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;
74
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 );
78
79         e->e_private = NULL;
80
81         vals[0].bv_val = "OpenLDAProotDSE";
82         vals[0].bv_len = sizeof("OpenLDAProotDSE")-1;
83         attr_merge( e, ad_structuralObjectClass, vals );
84
85         vals[0].bv_val = "top";
86         vals[0].bv_len = sizeof("top")-1;
87         attr_merge( e, ad_objectClass, vals );
88
89         vals[0].bv_val = "OpenLDAProotDSE";
90         vals[0].bv_len = sizeof("OpenLDAProotDSE")-1;
91         attr_merge( e, ad_objectClass, vals );
92
93         for ( i = 0; i < nbackends; i++ ) {
94                 if ( backends[i].be_flags & SLAP_BFLAG_GLUE_SUBORDINATE ) {
95                         continue;
96                 }
97                 for ( j = 0; backends[i].be_suffix[j] != NULL; j++ ) {
98                         vals[0] = *backends[i].be_suffix[j];
99                         attr_merge( e, ad_namingContexts, vals );
100                 }
101         }
102
103         /* altServer unsupported */
104
105         /* supportedControl */
106         for ( i=0; (vals[0].bv_val = get_supported_ctrl(i)) != NULL; i++ ) {
107                 vals[0].bv_len = strlen( vals[0].bv_val );
108                 attr_merge( e, ad_supportedControl, vals );
109         }
110
111         /* supportedExtension */
112         for ( i=0; (bv = get_supported_extop(i)) != NULL; i++ ) {
113                 vals[0] = *bv;
114                 attr_merge( e, ad_supportedExtension, vals );
115         }
116
117         /* supportedFeatures */
118         attr_merge( e, ad_supportedFeatures, supportedFeatures );
119
120         /* supportedLDAPVersion */
121         for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
122                 if (!( global_allows & SLAP_ALLOW_BIND_V2 ) &&
123                         ( i < LDAP_VERSION3 ) )
124                 {
125                         /* version 2 and lower are disallowed */
126                         continue;
127                 }
128                 sprintf(buf,"%d",i);
129                 vals[0].bv_val = buf;
130                 vals[0].bv_len = strlen( vals[0].bv_val );
131                 attr_merge( e, ad_supportedLDAPVersion, vals );
132         }
133
134         /* supportedSASLMechanism */
135         supportedSASLMechanisms = slap_sasl_mechs( conn );
136
137         if( supportedSASLMechanisms != NULL ) {
138                 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
139                         vals[0].bv_val = supportedSASLMechanisms[i];
140                         vals[0].bv_len = strlen( vals[0].bv_val );
141                         attr_merge( e, ad_supportedSASLMechanisms, vals );
142                 }
143                 charray_free( supportedSASLMechanisms );
144         }
145
146         if ( default_referral != NULL ) {
147                 attr_merge( e, ad_ref, default_referral );
148         }
149
150         if( usr_attr != NULL) {
151                 Attribute *a;
152                 for( a = usr_attr->e_attrs; a != NULL; a = a->a_next ) {
153                         attr_merge( e, a->a_desc, a->a_vals );
154                 }
155         }
156
157         *entry = e;
158         return LDAP_SUCCESS;
159 }
160
161 /*
162  * Read the entries specified in fname and merge the attributes
163  * to the user defined rootDSE. Note thaat if we find any errors
164  * what so ever, we will discard the entire entries, print an
165  * error message and return.
166  */
167 int read_root_dse_file( const char *fname )
168 {
169         FILE    *fp;
170         int rc = 0, lineno = 0, lmax = 0;
171         char    *buf = NULL;
172
173         if ( (fp = fopen( fname, "r" )) == NULL ) {
174                 Debug( LDAP_DEBUG_ANY,
175                         "could not open rootdse attr file \"%s\" - absolute path?\n",
176                         fname, 0, 0 );
177                 perror( fname );
178                 return EXIT_FAILURE;
179         }
180
181         usr_attr = (Entry *) ch_calloc( 1, sizeof(Entry) );
182         usr_attr->e_attrs = NULL;
183
184         while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
185                 Entry *e = str2entry( buf );
186                 Attribute *a;
187
188                 if( e == NULL ) {
189                         fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
190                                 lineno );
191                         entry_free( e );
192                         entry_free( usr_attr );
193                         usr_attr = NULL;
194                         return EXIT_FAILURE;
195                 }
196
197                 /* make sure the DN is the empty DN */
198                 if( e->e_nname.bv_len ) {
199                         fprintf( stderr,
200                                 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
201                                 e->e_dn, lineno );
202                         entry_free( e );
203                         entry_free( usr_attr );
204                         usr_attr = NULL;
205                         return EXIT_FAILURE;
206                 }
207
208                 /*
209                  * we found a valid entry, so walk thru all the attributes in the
210                  * entry, and add each attribute type and description to the
211                  * usr_attr entry
212                  */
213
214                 for(a = e->e_attrs; a != NULL; a = a->a_next) {
215                         attr_merge( usr_attr, a->a_desc, a->a_vals );
216                 }
217
218                 entry_free( e );
219         }
220
221         ch_free( buf );
222
223         Debug(LDAP_DEBUG_CONFIG, "rootDSE file %s read.\n", fname, 0, 0);
224         return rc;
225 }