1 /* database.c - deals with database subsystem */
3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
9 * This work has beed deveolped for the OpenLDAP Foundation
10 * in the hope that it may be useful to the Open Source community,
11 * but WITHOUT ANY WARRANTY.
13 * Permission is granted to anyone to use this software for any purpose
14 * on any computer system, and to alter it and redistribute it, subject
15 * to the following restrictions:
17 * 1. The author and SysNet s.n.c. are not responsible for the consequences
18 * of use of this software, no matter how awful, even if they arise from
21 * 2. The origin of this software must not be misrepresented, either by
22 * explicit claim or by omission. Since few users ever read sources,
23 * credits should appear in the documentation.
25 * 3. Altered versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software. Since few users
27 * ever read sources, credits should appear in the documentation.
28 * SysNet s.n.c. cannot be responsible for the consequences of the
31 * 4. This notice may not be removed or altered.
39 #include "slapi-plugin.h"
40 #include "slapi_pblock.h"
41 #include "back-monitor.h"
43 #if defined(LDAP_SLAPI)
44 static int monitor_back_add_plugin( Backend *be, Entry *e );
45 #endif /* defined(LDAP_SLAPI) */
48 monitor_subsys_database_init(
52 struct monitorinfo *mi;
53 Entry *e, *e_database, *e_tmp;
55 struct monitorentrypriv *mp;
56 AttributeDescription *ad_nc = slap_schema.si_ad_namingContexts;
57 AttributeDescription *ad_mc = slap_schema.si_ad_monitorContext;
58 AttributeDescription *ad_seeAlso = NULL;
59 const char *text = NULL;
62 assert( monitor_ad_desc != NULL );
64 mi = ( struct monitorinfo * )be->be_private;
66 if ( monitor_cache_get( mi,
67 &monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
70 LDAP_LOG( OPERATION, CRIT,
71 "monitor_subsys_database_init: "
72 "unable to get entry '%s'\n",
73 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0, 0 );
75 Debug( LDAP_DEBUG_ANY,
76 "monitor_subsys_database_init: "
77 "unable to get entry '%s'\n%s%s",
78 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
84 if ( slap_str2ad( "seeAlso", &ad_seeAlso, &text ) != LDAP_SUCCESS ) {
86 LDAP_LOG( OPERATION, CRIT,
87 "monitor_subsys_database_init: "
88 "unable to find 'seeAlso' attribute description\n",
91 Debug( LDAP_DEBUG_ANY,
92 "monitor_subsys_database_init: "
93 "unable to find 'seeAlso' attribute description\n",
100 for ( i = nBackendDB; i--; ) {
106 /* Subordinates are not exposed as their own naming context */
107 if ( be->be_flags & SLAP_BFLAG_GLUE_SUBORDINATE ) {
111 snprintf( buf, sizeof( buf ),
112 "dn: cn=Database %d,%s\n"
113 SLAPD_MONITOR_OBJECTCLASSES
117 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val,
119 be->bd_info->bi_type );
121 e = str2entry( buf );
124 LDAP_LOG( OPERATION, CRIT,
125 "monitor_subsys_database_init: "
126 "unable to create entry 'cn=Database %d,%s'\n",
127 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
129 Debug( LDAP_DEBUG_ANY,
130 "monitor_subsys_database_init: "
131 "unable to create entry 'cn=Database %d,%s'\n%s",
133 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
139 if ( be->be_flags & SLAP_BFLAG_MONITOR ) {
140 attr_merge( e, ad_mc, be->be_suffix );
141 attr_merge( e_database, ad_mc, be->be_suffix );
143 attr_merge( e, ad_nc, be->be_suffix );
144 attr_merge( e_database, ad_nc, be->be_suffix );
147 for ( j = nBackendInfo; j--; ) {
148 if ( backendInfo[ j ].bi_type == be->bd_info->bi_type ) {
151 snprintf( buf, sizeof( buf ),
153 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
155 bv.bv_len = strlen( buf );
156 attr_merge_one( e, ad_seeAlso, &bv );
160 /* we must find it! */
163 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
164 e->e_private = ( void * )mp;
166 mp->mp_children = NULL;
167 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
168 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
171 if ( monitor_cache_add( mi, e ) ) {
173 LDAP_LOG( OPERATION, CRIT,
174 "monitor_subsys_database_init: "
175 "unable to add entry 'cn=Database %d,%s'\n",
176 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
178 Debug( LDAP_DEBUG_ANY,
179 "monitor_subsys_database_init: "
180 "unable to add entry 'cn=Database %d,%s'\n",
182 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
188 #if defined(LDAP_SLAPI)
189 monitor_back_add_plugin( be, e );
190 #endif /* defined(LDAP_SLAPI) */
195 mp = ( struct monitorentrypriv * )e_database->e_private;
196 mp->mp_children = e_tmp;
198 monitor_cache_release( mi, e_database );
203 #if defined(LDAP_SLAPI)
205 monitor_back_add_plugin( Backend *be, Entry *e_database )
207 Slapi_PBlock *pCurrentPB;
208 int i, rc = LDAP_SUCCESS;
210 if ( slapi_x_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
212 * LDAP_OTHER is returned if no plugins are installed
220 Slapi_PluginDesc *srchdesc;
224 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
226 if ( rc != LDAP_SUCCESS ) {
230 snprintf( buf, sizeof(buf),
231 "plugin %d name: %s; "
237 srchdesc->spd_vendor,
238 srchdesc->spd_version,
239 srchdesc->spd_description );
242 bv.bv_len = strlen( buf );
243 attr_merge_one( e_database, monitor_ad_desc, &bv );
247 } while ( ( slapi_x_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
248 && ( pCurrentPB != NULL ) );
253 #endif /* defined(LDAP_SLAPI) */