1 /* database.c - deals with database subsystem */
3 * Copyright 1998-2003 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 "back-monitor.h"
41 #if defined(LDAP_SLAPI)
43 static int monitor_back_add_plugin( Backend *be, Entry *e );
44 #endif /* defined(LDAP_SLAPI) */
47 monitor_subsys_database_init(
51 struct monitorinfo *mi;
52 Entry *e, *e_database, *e_tmp;
54 struct monitorentrypriv *mp;
55 AttributeDescription *ad_nc = slap_schema.si_ad_namingContexts;
56 AttributeDescription *ad_mc = slap_schema.si_ad_monitorContext;
57 AttributeDescription *ad_seeAlso = NULL;
58 const char *text = NULL;
62 mi = ( struct monitorinfo * )be->be_private;
64 if ( monitor_cache_get( mi,
65 &monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
68 LDAP_LOG( OPERATION, CRIT,
69 "monitor_subsys_database_init: "
70 "unable to get entry '%s'\n",
71 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0, 0 );
73 Debug( LDAP_DEBUG_ANY,
74 "monitor_subsys_database_init: "
75 "unable to get entry '%s'\n%s%s",
76 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
82 if ( slap_str2ad( "seeAlso", &ad_seeAlso, &text ) != LDAP_SUCCESS ) {
84 LDAP_LOG( OPERATION, CRIT,
85 "monitor_subsys_database_init: "
86 "unable to find 'seeAlso' attribute description\n",
89 Debug( LDAP_DEBUG_ANY,
90 "monitor_subsys_database_init: "
91 "unable to find 'seeAlso' attribute description\n",
98 for ( i = nBackendDB; i--; ) {
104 /* Subordinates are not exposed as their own naming context */
105 if ( SLAP_GLUE_SUBORDINATE( be ) ) {
109 snprintf( buf, sizeof( buf ),
110 "dn: cn=Database %d,%s\n"
111 SLAPD_MONITOR_OBJECTCLASSES
115 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn.bv_val,
117 be->bd_info->bi_type );
119 e = str2entry( buf );
122 LDAP_LOG( OPERATION, CRIT,
123 "monitor_subsys_database_init: "
124 "unable to create entry 'cn=Database %d,%s'\n",
125 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
127 Debug( LDAP_DEBUG_ANY,
128 "monitor_subsys_database_init: "
129 "unable to create entry 'cn=Database %d,%s'\n%s",
131 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
137 if ( be->be_flags & SLAP_BFLAG_MONITOR ) {
138 attr_merge( e, ad_mc, be->be_suffix, be->be_nsuffix );
139 attr_merge( e_database, ad_mc, be->be_suffix, be->be_nsuffix );
141 attr_merge( e, ad_nc, be->be_suffix, be->be_nsuffix );
142 attr_merge( e_database, ad_nc, be->be_suffix, be->be_nsuffix );
145 for ( j = nBackendInfo; j--; ) {
146 if ( backendInfo[ j ].bi_type == be->bd_info->bi_type ) {
149 snprintf( buf, sizeof( buf ),
151 j, monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn.bv_val );
153 bv.bv_len = strlen( buf );
154 attr_merge_normalize_one( e, ad_seeAlso, &bv, NULL );
158 /* we must find it! */
161 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
162 e->e_private = ( void * )mp;
164 mp->mp_children = NULL;
165 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
166 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
169 if ( monitor_cache_add( mi, e ) ) {
171 LDAP_LOG( OPERATION, CRIT,
172 "monitor_subsys_database_init: "
173 "unable to add entry 'cn=Database %d,%s'\n",
174 i, monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val, 0 );
176 Debug( LDAP_DEBUG_ANY,
177 "monitor_subsys_database_init: "
178 "unable to add entry 'cn=Database %d,%s'\n",
180 monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn.bv_val,
186 #if defined(LDAP_SLAPI)
187 monitor_back_add_plugin( be, e );
188 #endif /* defined(LDAP_SLAPI) */
193 mp = ( struct monitorentrypriv * )e_database->e_private;
194 mp->mp_children = e_tmp;
196 monitor_cache_release( mi, e_database );
201 #if defined(LDAP_SLAPI)
203 monitor_back_add_plugin( Backend *be, Entry *e_database )
205 Slapi_PBlock *pCurrentPB;
206 int i, rc = LDAP_SUCCESS;
207 struct monitorinfo *mi = ( struct monitorinfo * )be->be_private;
209 if ( slapi_x_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
211 * LDAP_OTHER is returned if no plugins are installed
219 Slapi_PluginDesc *srchdesc;
223 rc = slapi_pblock_get( pCurrentPB, SLAPI_PLUGIN_DESCRIPTION,
225 if ( rc != LDAP_SUCCESS ) {
229 snprintf( buf, sizeof(buf),
230 "plugin %d name: %s; "
236 srchdesc->spd_vendor,
237 srchdesc->spd_version,
238 srchdesc->spd_description );
241 bv.bv_len = strlen( buf );
242 attr_merge_normalize_one( e_database,
243 mi->monitor_ad_description, &bv, NULL );
247 } while ( ( slapi_x_pblock_get_next( &pCurrentPB ) == LDAP_SUCCESS )
248 && ( pCurrentPB != NULL ) );
253 #endif /* defined(LDAP_SLAPI) */