]> git.sur5r.net Git - openldap/blob - servers/slapd/root_dse.c
Don't publish version 2 if disallowed
[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 int
21 root_dse_info(
22         Connection *conn,
23         Entry **entry,
24         const char **text )
25 {
26         char buf[BUFSIZ];
27         Entry           *e;
28         struct berval   val;
29         struct berval   *vals[2];
30         int             i, j;
31         char ** supportedSASLMechanisms;
32
33         AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
34         AttributeDescription *ad_namingContexts = slap_schema.si_ad_namingContexts;
35         AttributeDescription *ad_supportedControl = slap_schema.si_ad_supportedControl;
36         AttributeDescription *ad_supportedExtension = slap_schema.si_ad_supportedExtension;
37         AttributeDescription *ad_supportedLDAPVersion = slap_schema.si_ad_supportedLDAPVersion;
38         AttributeDescription *ad_supportedSASLMechanisms = slap_schema.si_ad_supportedSASLMechanisms;
39         AttributeDescription *ad_ref = slap_schema.si_ad_ref;
40
41         vals[0] = &val;
42         vals[1] = NULL;
43
44         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
45
46         e->e_attrs = NULL;
47         e->e_dn = ch_strdup( LDAP_ROOT_DSE );
48         e->e_ndn = ch_strdup( LDAP_ROOT_DSE );
49         (void) dn_normalize( e->e_ndn );
50         e->e_private = NULL;
51
52         val.bv_val = "top";
53         val.bv_len = sizeof("top")-1;
54         attr_merge( e, ad_objectClass, vals );
55
56         val.bv_val = "OpenLDAProotDSE";
57         val.bv_len = sizeof("OpenLDAProotDSE")-1;
58         attr_merge( e, ad_objectClass, vals );
59
60         for ( i = 0; i < nbackends; i++ ) {
61                 for ( j = 0; backends[i].be_suffix[j] != NULL; j++ ) {
62                         val.bv_val = backends[i].be_suffix[j];
63                         val.bv_len = strlen( val.bv_val );
64                         attr_merge( e, ad_namingContexts, vals );
65                 }
66         }
67
68         /* altServer unsupported */
69
70         /* supportedControl */
71         for ( i=0; supportedControls[i] != NULL; i++ ) {
72                 val.bv_val = supportedControls[i];
73                 val.bv_len = strlen( val.bv_val );
74                 attr_merge( e, ad_supportedControl, vals );
75         }
76
77         /* supportedExtension */
78         for ( i=0; (val.bv_val = get_supported_extop(i)) != NULL; i++ ) {
79                 val.bv_len = strlen( val.bv_val );
80                 attr_merge( e, ad_supportedExtension, vals );
81         }
82
83         /* supportedLDAPVersion */
84         for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
85                 if (( global_disallows & SLAP_DISALLOW_BIND_V2 ) &&
86                         ( i < LDAP_VERSION3 ) )
87                 {
88                         /* version 2 and lower are disallowed */
89                         continue;
90                 }
91                 sprintf(buf,"%d",i);
92                 val.bv_val = buf;
93                 val.bv_len = strlen( val.bv_val );
94                 attr_merge( e, ad_supportedLDAPVersion, vals );
95         }
96
97         /* supportedSASLMechanism */
98         supportedSASLMechanisms = slap_sasl_mechs( conn );
99
100         if( supportedSASLMechanisms != NULL ) {
101                 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
102                         val.bv_val = supportedSASLMechanisms[i];
103                         val.bv_len = strlen( val.bv_val );
104                         attr_merge( e, ad_supportedSASLMechanisms, vals );
105                 }
106         }
107
108         if ( default_referral != NULL ) {
109                 attr_merge( e, ad_ref, default_referral );
110         }
111
112         *entry = e;
113         return LDAP_SUCCESS;
114 }
115