]> git.sur5r.net Git - openldap/blob - servers/slapd/root_dse.c
Remove lint
[openldap] / servers / slapd / root_dse.c
1 /* $OpenLDAP$ */
2 /* root_dse.c - Provides the ROOT DSA-Specific Entry
3  *
4  * Copyright 1999-2000 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
20 static char *supportedFeatures[] = {
21         "1.3.6.1.4.1.4203.1.5.1", /* All Operational Attributes ("+") */
22         NULL
23 };
24
25 static Entry    *usr_attr = NULL;
26
27 int
28 root_dse_info(
29         Connection *conn,
30         Entry **entry,
31         const char **text )
32 {
33         char buf[BUFSIZ];
34         Entry           *e;
35         struct berval   val;
36         struct berval   *vals[2];
37         int             i, j;
38         char ** supportedSASLMechanisms;
39
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;
48
49         Attribute *a;
50
51         vals[0] = &val;
52         vals[1] = NULL;
53
54         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
55
56         e->e_attrs = NULL;
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 );
60         e->e_private = NULL;
61
62         val.bv_val = "top";
63         val.bv_len = sizeof("top")-1;
64         attr_merge( e, ad_objectClass, vals );
65
66         val.bv_val = "OpenLDAProotDSE";
67         val.bv_len = sizeof("OpenLDAProotDSE")-1;
68         attr_merge( e, ad_objectClass, vals );
69
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 );
75                 }
76         }
77
78         /* altServer unsupported */
79
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 );
85         }
86
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 );
91         }
92
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 );
98         }
99
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 ) )
104                 {
105                         /* version 2 and lower are disallowed */
106                         continue;
107                 }
108                 sprintf(buf,"%d",i);
109                 val.bv_val = buf;
110                 val.bv_len = strlen( val.bv_val );
111                 attr_merge( e, ad_supportedLDAPVersion, vals );
112         }
113
114         /* supportedSASLMechanism */
115         supportedSASLMechanisms = slap_sasl_mechs( conn );
116
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 );
122                 }
123                 charray_free( supportedSASLMechanisms );
124         }
125
126         if ( default_referral != NULL ) {
127                 attr_merge( e, ad_ref, default_referral );
128         }
129
130         if( usr_attr != NULL) {
131                 for(a = usr_attr->e_attrs; a != NULL; a = a->a_next) {
132                         attr_merge( e, a->a_desc, a->a_vals );
133                 }
134         }
135
136         *entry = e;
137         return LDAP_SUCCESS;
138 }
139
140 /*
141  * Read the entries specified in fname and merge the attributes
142  * to the user defined rootDSE. Note thaat if we find any errors
143  * what so ever, we will discard the entire entries, print an
144  * error message and return.
145  */
146 int read_root_dse_file( const char *fname )
147 {
148         FILE    *fp;
149         char    *line, *savefname, *saveline;
150         int rc = 0, lineno = 0, lmax = 0;
151         char    *buf = NULL;
152
153         Attribute *a;
154
155         if ( (fp = fopen( fname, "r" )) == NULL ) {
156                 Debug( LDAP_DEBUG_ANY,
157                         "could not open rootdse attr file \"%s\" - absolute path?\n",
158                         fname, 0, 0 );
159                 perror( fname );
160                 return EXIT_FAILURE;
161         }
162
163         usr_attr = (Entry *) ch_calloc( 1, sizeof(Entry) );
164         usr_attr->e_attrs = NULL;
165
166         while( ldif_read_record( fp, &lineno, &buf, &lmax ) ) {
167                 ID id;
168                 Entry *e = str2entry( buf );
169
170                 if( e == NULL ) {
171                         fprintf( stderr, "root_dse: could not parse entry (line=%d)\n",
172                                 lineno );
173                         entry_free( e );
174                         entry_free( usr_attr );
175                         usr_attr = NULL;
176                         return EXIT_FAILURE;
177                 }
178
179                 if( dn_normalize( e->e_ndn ) == NULL ) {
180                         fprintf( stderr, "root_dse: invalid dn=\"%s\" (line=%d)\n",
181                                 e->e_dn, lineno );
182                         entry_free( e );
183                         entry_free( usr_attr );
184                         usr_attr = NULL;
185                         return EXIT_FAILURE;
186                 }
187
188                 /* make sure the DN is a valid rootdse(rootdse is a null string) */
189                 if( strcmp(e->e_ndn, "") != 0 ) {
190                         fprintf( stderr,
191                                 "root_dse: invalid rootDSE - dn=\"%s\" (line=%d)\n",
192                                 e->e_dn, lineno );
193                         entry_free( e );
194                         entry_free( usr_attr );
195                         usr_attr = NULL;
196                         return EXIT_FAILURE;
197                 }
198
199                 /*
200                  * we found a valid entry, so walk thru all the attributes in the
201                  * entry, and add each attribute type and description to the
202                  * usr_attr entry
203                  */
204
205                 for(a = e->e_attrs; a != NULL; a = a->a_next) {
206                         attr_merge( usr_attr, a->a_desc, a->a_vals );
207                 }
208
209                 entry_free( e );
210         }
211
212         ch_free( buf );
213
214         Debug(LDAP_DEBUG_CONFIG,"rootDSE file %s read.\n", fname, 0, 0);
215         return rc;
216 }