]> git.sur5r.net Git - openldap/blob - servers/slapd/root_dse.c
Bug fix for new sockbuf code under NT. Added mutex protection against
[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( Entry **entry, const char **text )
22 {
23         char buf[BUFSIZ];
24         Entry           *e;
25         struct berval   val;
26         struct berval   *vals[2];
27         int             i, j;
28
29 #ifdef SLAPD_SCHEMA_NOT_COMPAT
30         AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
31         AttributeDescription *ad_namingContexts = slap_schema.si_ad_namingContexts;
32         AttributeDescription *ad_supportedControl = slap_schema.si_ad_supportedControl;
33         AttributeDescription *ad_supportedExtension = slap_schema.si_ad_supportedExtension;
34         AttributeDescription *ad_supportedLDAPVersion = slap_schema.si_ad_supportedLDAPVersion;
35         AttributeDescription *ad_supportedSASLMechanisms = slap_schema.si_ad_supportedSASLMechanisms;
36         AttributeDescription *ad_ref = slap_schema.si_ad_ref;
37 #else
38         char *ad_objectClass = "objectClass";
39         char *ad_namingContexts = "namingContexts";
40         char *ad_supportedControl = "supportedControl";
41         char *ad_supportedExtension = "supportedExtension";
42         char *ad_supportedLDAPVersion = "supportedLDAPVersion";
43         char *ad_supportedSASLMechanisms = "supportedSASLMechanisms";
44         char *ad_ref = "ref";
45 #endif
46
47         vals[0] = &val;
48         vals[1] = NULL;
49
50         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
51
52         e->e_attrs = NULL;
53         e->e_dn = ch_strdup( LDAP_ROOT_DSE );
54         e->e_ndn = ch_strdup( LDAP_ROOT_DSE );
55         (void) dn_normalize( e->e_ndn );
56         e->e_private = NULL;
57
58         val.bv_val = "top";
59         val.bv_len = sizeof("top")-1;
60         attr_merge( e, ad_objectClass, vals );
61
62         val.bv_val = "OpenLDAProotDSE";
63         val.bv_len = sizeof("OpenLDAProotDSE")-1;
64         attr_merge( e, ad_objectClass, vals );
65
66         for ( i = 0; i < nbackends; i++ ) {
67                 for ( j = 0; backends[i].be_suffix[j] != NULL; j++ ) {
68                         val.bv_val = backends[i].be_suffix[j];
69                         val.bv_len = strlen( val.bv_val );
70                         attr_merge( e, ad_namingContexts, vals );
71                 }
72         }
73
74         /* altServer unsupported */
75
76         /* supportedControl */
77         for ( i=0; supportedControls[i] != NULL; i++ ) {
78                 val.bv_val = supportedControls[i];
79                 val.bv_len = strlen( val.bv_val );
80                 attr_merge( e, ad_supportedControl, vals );
81         }
82
83         /* supportedExtension */
84         for ( i=0; (val.bv_val = get_supported_extop(i)) != NULL; i++ ) {
85                 val.bv_len = strlen( val.bv_val );
86                 attr_merge( e, ad_supportedExtension, vals );
87         }
88
89         /* supportedLDAPVersion */
90         for ( i=LDAP_VERSION_MIN; i<=LDAP_VERSION_MAX; i++ ) {
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         if( supportedSASLMechanisms != NULL ) {
99                 for ( i=0; supportedSASLMechanisms[i] != NULL; i++ ) {
100                         val.bv_val = supportedSASLMechanisms[i];
101                         val.bv_len = strlen( val.bv_val );
102                         attr_merge( e, ad_supportedSASLMechanisms, vals );
103                 }
104         }
105
106         if ( default_referral != NULL ) {
107                 attr_merge( e, ad_ref, default_referral );
108         }
109
110         *entry = e;
111         return LDAP_SUCCESS;
112 }
113